#include <Text_Raw_Reader.hh>
Inheritance diagram for Text_Raw_Reader:
Public Methods | |
Text_Raw_Reader (const char *const reference_trace_pathname) | |
The constructor. | |
virtual void | read (reference_record_s *const reference_record) |
Read the next record from the reference trace. | |
Protected Attributes | |
timestamp_t | reference_time |
The current reference time. | |
timestamp_t | instruction_time |
The current instruction time. |
Definition at line 43 of file Text_Raw_Reader.hh.
|
The constructor.
Definition at line 30 of file Text_Raw_Reader.cc.
00030 : 00031 Reference_Reader(reference_trace_pathname) { 00032 00033 // Reset the clocks to zero. 00034 reference_time = 0; 00035 instruction_time = 0; 00036 00037 } // Text_Raw_Reader // =================================================================== |
|
Read the next record from the reference trace.
Implements Reference_Reader. Definition at line 44 of file Text_Raw_Reader.cc. References Reference_Reader::buffer, virtual_page_s::context_ID, reference_record_s::cycle_timestamp, instruction_time, reference_record_s::instruction_timestamp, reference_record_s::length, virtual_page_s::page_ID, PAGE_SIZE_ORDER, reference_time, reference_record_s::reference_timestamp, reference_record_s::tag, TAG_END_OF_TRACE, TAG_KERNEL_EVENT, TAG_KERNEL_INSTRUCTION_FETCH, TAG_KERNEL_READ, TAG_KERNEL_WRITE, TAG_USER_INSTRUCTION_FETCH, TAG_USER_READ, TAG_USER_WRITE, timestamp_t, reference_record_s::virtual_address, and reference_record_s::virtual_page.
00044 { 00045 00046 // Attempt to read the next record of the reference trace. 00047 char* read_result = fgets(buffer, BUFFER_SIZE, reference_stream); 00048 00049 // Did the read fail? 00050 if (read_result == NULL) { 00051 00052 // Distinguish between an EOF and other errors, but abort 00053 // processing in either case. 00054 if (feof(reference_stream)) { 00055 fprintf(stderr, 00056 "Text_Raw_Reader::read(): Premature EOF\n"); 00057 } else { 00058 fprintf(stderr, 00059 "Text_Raw_Reader::read(): Read error\n"); 00060 } 00061 exit(1); 00062 } 00063 00064 // Parse the record type, which should be the first character of the 00065 // buffer. 00066 reference_record->tag = buffer[0]; 00067 00068 // Attempt to parse the rest of the record based on its type. 00069 // Declare and assign some variables here to avoid compiler 00070 // complaints of skipping initialization in switch-case statement. 00071 unsigned int parse_result = 0; 00072 unsigned int items_to_parse = 0; 00073 timestamp_t current_instruction_time = instruction_time; 00074 timestamp_t current_reference_time = reference_time; 00075 switch (reference_record->tag) { 00076 00077 case TAG_USER_INSTRUCTION_FETCH: 00078 case TAG_KERNEL_INSTRUCTION_FETCH: 00079 00080 // Tick the instruction clock to reflect that _after_ this event, 00081 // instruction time will have advanced. 00082 instruction_time++; 00083 00084 // Fall through to read and parse the rest of the record... 00085 00086 case TAG_USER_READ: 00087 case TAG_KERNEL_READ: 00088 case TAG_USER_WRITE: 00089 case TAG_KERNEL_WRITE: 00090 00091 // Tick the reference clock to reflect that _after_ this event, 00092 // reference time will have advanced. 00093 reference_time++; 00094 00095 // Read the remainder of the record. 00096 items_to_parse = 4; 00097 parse_result = sscanf(&buffer[2], 00098 "%qx %hd %lx %lx", 00099 &reference_record->cycle_timestamp, 00100 &reference_record->length, 00101 &reference_record->virtual_page.context_ID, 00102 &reference_record->virtual_address); 00103 00104 // Place the current instruction and reference times into the 00105 // structure. 00106 reference_record->instruction_timestamp = current_instruction_time; 00107 reference_record->reference_timestamp = current_reference_time; 00108 00109 // Compute the page ID by isolating the upper bits of the virtual 00110 // address and recording that value in the structure. 00111 reference_record->virtual_page.page_ID = 00112 reference_record->virtual_address >> PAGE_SIZE_ORDER; 00113 00114 break; 00115 00116 case TAG_KERNEL_EVENT: 00117 00118 // Read the remainder of the record. We care only about the 00119 // timestamp. 00120 items_to_parse = 1; 00121 parse_result = sscanf(&buffer[2], 00122 "%qx", 00123 &reference_record->cycle_timestamp); 00124 reference_record->instruction_timestamp = current_instruction_time; 00125 reference_record->reference_timestamp = current_reference_time; 00126 reference_record->length = 0; 00127 reference_record->virtual_page.context_ID = 0; 00128 reference_record->virtual_page.page_ID = 0; 00129 reference_record->virtual_address = 0; 00130 break; 00131 00132 case TAG_END_OF_TRACE: 00133 00134 // Nothing to do. 00135 break; 00136 00137 default: 00138 fprintf(stderr, 00139 "Text_Raw_Reader::read(): Invalid reference tag %c(%d)\n", 00140 reference_record->tag, 00141 (int)reference_record->tag); 00142 exit(1); 00143 00144 } 00145 00146 // If the parse failed, emit the error and exit. 00147 if (parse_result != items_to_parse) { 00148 fprintf(stderr, 00149 "Text_Raw_Reader::read(): Could not parse remainder\n"); 00150 fprintf(stderr, 00151 " cycle_timestamp = %qx\n", 00152 reference_record->cycle_timestamp); 00153 fprintf(stderr, 00154 " instruction_timestamp = %qx\n", 00155 reference_record->instruction_timestamp); 00156 fprintf(stderr, 00157 " reference_timestamp = %qx\n", 00158 reference_record->reference_timestamp); 00159 exit(1); 00160 } 00161 00162 } // read |
|
The current instruction time.
Definition at line 78 of file Text_Raw_Reader.hh. Referenced by read(). |
|
The current reference time.
Definition at line 75 of file Text_Raw_Reader.hh. Referenced by read(). |