00001
00016
00017
00018
00019 #include <assert.h>
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include "Text_Raw_Reader.hh"
00023 #include "types-and-constants.hh"
00024
00025
00026
00027
00028
00029 Text_Raw_Reader::Text_Raw_Reader
00030 (const char* const reference_trace_pathname) :
00031 Reference_Reader(reference_trace_pathname) {
00032
00033
00034 reference_time = 0;
00035 instruction_time = 0;
00036
00037 }
00038
00039
00040
00041
00042
00043 void
00044 Text_Raw_Reader::read (reference_record_s* const reference_record) {
00045
00046
00047 char* read_result = fgets(buffer, BUFFER_SIZE, reference_stream);
00048
00049
00050 if (read_result == NULL) {
00051
00052
00053
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
00065
00066 reference_record->tag = buffer[0];
00067
00068
00069
00070
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
00081
00082 instruction_time++;
00083
00084
00085
00086 case TAG_USER_READ:
00087 case TAG_KERNEL_READ:
00088 case TAG_USER_WRITE:
00089 case TAG_KERNEL_WRITE:
00090
00091
00092
00093 reference_time++;
00094
00095
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
00105
00106 reference_record->instruction_timestamp = current_instruction_time;
00107 reference_record->reference_timestamp = current_reference_time;
00108
00109
00110
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
00119
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
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
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 }
00163