00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Basic_Consumer.hh"
00030
00031
00032
00033
00034
00035 Basic_Consumer::Basic_Consumer (Reference_Reader* const reference_reader,
00036 const char* const kernel_pathname,
00037 const char* const output_file_pathname) :
00038 Consumer(reference_reader, kernel_pathname) {
00039
00040
00041 output_stream = fopen(output_file_pathname, "w");
00042 if (output_stream == NULL) {
00043 perror("Failure opening output file");
00044 exit(1);
00045 }
00046
00047 }
00048
00049
00050
00051
00052
00053 Basic_Consumer::~Basic_Consumer () {
00054
00055
00056 int close_result = fclose(output_stream);
00057 if (close_result == EOF) {
00058 perror("Failure closing output file");
00059 exit(1);
00060 }
00061
00062 }
00063
00064
00065
00066
00067
00068 void
00069 Basic_Consumer::act_on_reference_record () {
00070
00071
00072 tag_t output_tag = 0;
00073 switch (reference_record->tag) {
00074
00075 case TAG_USER_READ:
00076 case TAG_KERNEL_READ:
00077 case TAG_USER_INSTRUCTION_FETCH:
00078 case TAG_KERNEL_INSTRUCTION_FETCH:
00079
00080 output_tag = TAG_KERNEL_READ;
00081 break;
00082
00083 case TAG_USER_WRITE:
00084 case TAG_KERNEL_WRITE:
00085
00086 output_tag = TAG_KERNEL_WRITE;
00087 break;
00088
00089 default:
00090 fprintf(stderr,
00091 "act_on_reference_record(): Invalid tag %c(%d)\n",
00092 reference_record->tag,
00093 (int)reference_record->tag);
00094 exit(1);
00095
00096 }
00097
00098
00099
00100 context_ID_t context_ID;
00101 if (reference_record->virtual_page.page_ID <
00102 KERNEL_VIRTUAL_PAGE_OFFSET) {
00103
00104 context_ID = reference_record->virtual_page.context_ID;
00105
00106 } else {
00107
00108 context_ID = KERNEL_CONTEXT;
00109
00110 }
00111 Process* process = safe_context_ID_to_process(context_ID);
00112 virtual_to_canonical_map_t* map = process->virtual_to_canonical_map;
00113
00114
00115 bool V2C_mapping_exists;
00116 canonical_page_ID_t canonical_page_ID;
00117 lookup_canonical_page_ID(&V2C_mapping_exists,
00118 &canonical_page_ID,
00119 map,
00120 reference_record->virtual_page.page_ID);
00121
00122
00123
00124 if (V2C_mapping_exists) {
00125 fprintf(output_stream, "%c %lx\n", output_tag, canonical_page_ID);
00126 }
00127
00128 }
00129