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
00030 #include <unistd.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <fcntl.h>
00034 #include <sys/mman.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <time.h>
00039 #include <vector>
00040 #include <ext/hash_map>
00041 using namespace std;
00042 #include "cg_instru_lib.h"
00043 #include "fb_info.h"
00044
00045 static Fb_Hdr file_header;
00046 static void _dump_File_Header( FILE * fp )
00047 {
00048 if (fread( &file_header, sizeof(Fb_Hdr), 1, fp) != 1)
00049 {
00050 fprintf(stderr, "Error when reading file header\n");
00051 exit(-1);
00052 }
00053 file_header.Print(stdout);
00054 }
00055
00056 static Pu_Hdr * pu_headers = NULL;
00057 static void _dump_Pu_Headers( FILE * fp )
00058 {
00059 pu_headers = (Pu_Hdr *)malloc(sizeof(Pu_Hdr)*file_header.fb_pu_hdr_num);
00060 if (!pu_headers)
00061 {
00062 fprintf(stderr,"Failed to malloc mem for pu_headers1\n");
00063 exit(-1);
00064 }
00065 fseek(fp,file_header.fb_pu_hdr_offset,SEEK_SET);
00066 if (fread(pu_headers, sizeof(Pu_Hdr), file_header.fb_pu_hdr_num, fp) != file_header.fb_pu_hdr_num)
00067 {
00068 fprintf(stderr, "Error reading pu_headers\n");
00069 exit(-1);
00070 }
00071
00072 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00073 {
00074 pu_headers[i].Print(stdout, i);
00075 }
00076 }
00077
00078 char * str_table = NULL;
00079 static void _dump_Str_Header( FILE * fp )
00080 {
00081 str_table = (char *) malloc (file_header.fb_str_table_size + 2);
00082 if (!str_table)
00083 {
00084 fprintf(stderr, "failed to malloc mem for str_table\n");
00085 exit(-1);
00086 }
00087 fseek(fp,file_header.fb_str_table_offset,SEEK_SET);
00088 if (fread(str_table, sizeof(char), file_header.fb_str_table_size, fp) != file_header.fb_str_table_size)
00089 {
00090 fprintf(stderr, "Error while reading str table!\n");
00091 exit(-1);
00092 }
00093 str_table[file_header.fb_str_table_size] = 0;
00094 fprintf(stdout,"\n************ Str table **************\n");
00095 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00096 {
00097 fprintf(stdout, "No %d : %s \n", i, str_table+pu_headers[i].pu_name_index);
00098 }
00099 }
00100
00101 static void _dump_pu_data( FILE * fp )
00102 {
00103 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00104 {
00105 fprintf(stdout, "\n*********** PU Data No %d ************\n", i );
00106 fprintf(stdout, "*********** whirl profile info: ************\n");
00107 fprintf(stdout, "*********** whirl profile info: invoke profile info ************\n");
00108 FB_Info_Invoke fb_info_invoke;
00109 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_inv_offset,SEEK_SET);
00110 for (int j=0;j<pu_headers[i].pu_num_inv_entries; j++)
00111 {
00112 if (fread(&fb_info_invoke, sizeof(FB_Info_Invoke), 1, fp) != 1)
00113 {
00114 fprintf(stderr, "Error while reading FB_Info_Invoke\n");
00115 exit(-1);
00116 }
00117 fb_info_invoke.Print_simple(stdout);
00118 }
00119 fprintf(stdout, "*********** whirl profile info: branch profile info ************\n");
00120 {
00121 FB_Info_Branch fb_info_branch;
00122 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_br_offset,SEEK_SET);
00123 for (int j=0;j<pu_headers[i].pu_num_br_entries; j++)
00124 {
00125 if (fread(&fb_info_branch, sizeof(FB_Info_Branch), 1, fp) != 1)
00126 {
00127 fprintf(stderr, "Error while reading FB_Info_Branch\n");
00128 exit(-1);
00129 }
00130 fb_info_branch.Print_simple(stdout);
00131 }
00132 }
00133 {
00134 fprintf(stdout, "*********** whirl profile info: switch profile info ************\n");
00135 vector<INT32> targets_vector (pu_headers[i].pu_num_switch_entries);
00136
00137 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_switch_offset,SEEK_SET);
00138 if (fread (&(targets_vector.front ()), sizeof(INT32),pu_headers[i].pu_num_switch_entries, fp) != pu_headers[i].pu_num_switch_entries)
00139 {
00140 fprintf(stderr, "Error while reading FB_Info_Switch\n");
00141 exit(-1);
00142 }
00143
00144 FB_Info_Switch fb_info_switch;
00145
00146 vector<INT32>::const_iterator target (targets_vector.begin ());
00147 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_switch_target_offset,SEEK_SET);
00148 for (int j=0;j<pu_headers[i].pu_num_switch_entries; j++)
00149 {
00150
00151 fb_info_switch.freq_targets.resize (*target);
00152 if (fread(&(fb_info_switch.freq_targets.front ()), sizeof(FB_FREQ), *target, fp) != *target)
00153 {
00154 fprintf(stderr, "Error while reading FB_Info_Switch\n");
00155 exit(-1);
00156 }
00157 fb_info_switch.Print_simple(stdout);
00158
00159 ++target;
00160 }
00161 }
00162 {
00163 fprintf(stdout, "*********** whirl profile info: cgoto profile info ************\n");
00164 vector<INT32> targets_vector (pu_headers[i].pu_num_cgoto_entries);
00165
00166 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_cgoto_offset,SEEK_SET);
00167 if (fread (&(targets_vector.front ()), sizeof(INT32),pu_headers[i].pu_num_switch_entries, fp) != pu_headers[i].pu_num_cgoto_entries)
00168 {
00169 fprintf(stderr, "Error while reading FB_Info_Switch(cgoto)\n");
00170 exit(-1);
00171 }
00172
00173 FB_Info_Switch fb_info_switch;
00174
00175 vector<INT32>::const_iterator target (targets_vector.begin ());
00176 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_cgoto_target_offset,SEEK_SET);
00177 for (int j=0;j<pu_headers[i].pu_num_cgoto_entries; j++)
00178 {
00179
00180 fb_info_switch.freq_targets.resize (*target);
00181 if (fread(&(fb_info_switch.freq_targets.front ()), sizeof(FB_FREQ), *target, fp) != *target)
00182 {
00183 fprintf(stderr, "Error while reading FB_Info_Switch(cgoto)\n");
00184 exit(-1);
00185 }
00186 fb_info_switch.Print_simple(stdout);
00187
00188 ++target;
00189 }
00190 }
00191 {
00192 fprintf(stdout, "*********** whirl profile info: loop profile info ************\n");
00193 FB_Info_Loop fb_info_loop;
00194 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_loop_offset,SEEK_SET);
00195 for (int j=0;j<pu_headers[i].pu_num_loop_entries; j++)
00196 {
00197 if (fread(&fb_info_loop, sizeof(FB_Info_Loop), 1, fp) != 1)
00198 {
00199 fprintf(stderr, "Error while reading FB_Info_Loop\n");
00200 exit(-1);
00201 }
00202 fb_info_loop.Print_simple(stdout);
00203 }
00204 }
00205 {
00206 fprintf(stdout, "*********** whirl profile info: scircuit profile info ************\n");
00207 FB_Info_Circuit fb_info_circuit;
00208 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_scircuit_offset,SEEK_SET);
00209 for (int j=0;j<pu_headers[i].pu_num_scircuit_entries; j++)
00210 {
00211 if (fread(&fb_info_circuit, sizeof(FB_Info_Circuit), 1, fp) != 1)
00212 {
00213 fprintf(stderr, "Error while reading FB_Info_Circuit\n");
00214 exit(-1);
00215 }
00216 fb_info_circuit.Print_simple(stdout);
00217 }
00218 }
00219 {
00220 fprintf(stdout, "*********** whirl profile info: call profile info ************\n");
00221 FB_Info_Call fb_info_call;
00222 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_call_offset,SEEK_SET);
00223 for (int j=0;j<pu_headers[i].pu_num_call_entries; j++)
00224 {
00225 if (fread(&fb_info_call, sizeof(FB_Info_Call), 1, fp) != 1)
00226 {
00227 fprintf(stderr, "Error while reading FB_Info_Call\n");
00228 exit(-1);
00229 }
00230 fb_info_call.Print_simple(stdout);
00231 }
00232 }
00233 {
00234 fprintf(stdout, "*********** whirl profile info: icall profile info ************\n");
00235 FB_Info_Icall fb_info_icall;
00236
00237 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_icall_offset,SEEK_SET);
00238 printf("pu_headers[i].pu_icall_offset=%d\n",pu_headers[i].pu_icall_offset);
00239 for (int j=0;j<pu_headers[i].pu_num_icall_entries; j++)
00240 {
00241 printf("sizeof(FB_Info_Icall)= %d\n",(int)sizeof(FB_Info_Icall) );
00242 if (fread(&fb_info_icall, sizeof(FB_Info_Icall), 1, fp) != 1)
00243 {
00244 fprintf(stderr, "Error whirl reading FB_Info_Icall\n");
00245 exit(-1);
00246 }
00247 fb_info_icall.Print(stdout);
00248 }
00249 }
00250 {
00251 fprintf(stdout, " \n*********** edge profile info: ************\n");
00252 FB_FREQ fb_freq;
00253 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_edge_offset,SEEK_SET);
00254 for (int j=0;j<pu_headers[i].pu_num_edge_entries; j++)
00255 {
00256 if (fread(&fb_freq, sizeof(FB_FREQ), 1, fp) != 1)
00257 {
00258 fprintf(stderr, "Error while reading fb_freq\n");
00259 exit(-1);
00260 }
00261 fb_freq.Print_simple(stdout);
00262 }
00263 }
00264 {
00265 fprintf(stdout, "*********** value profile info: ************\n");
00266 FB_TNV fb_tnv;
00267 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_value_offset,SEEK_SET);
00268 for (int j=0; j<pu_headers[i].pu_instr_count ; j++)
00269 {
00270 if (fread(&fb_tnv, sizeof(FB_TNV), 1, fp) != 1)
00271 {
00272 fprintf(stderr, "Error while reading fb_tnv\n");
00273 exit(-1);
00274 }
00275 fb_tnv.Print(stdout);
00276 }
00277 }
00278 {
00279 fprintf(stdout, "*********** stride profile info: ************\n");
00280 FB_TNV srd_fb_tnv;
00281 fseek(fp,file_header.fb_profile_offset + pu_headers[i].pu_file_offset + pu_headers[i].pu_stride_offset,SEEK_SET);
00282 for (int j=0; j<pu_headers[i].pu_ld_count ; j++)
00283 {
00284 if (fread(&srd_fb_tnv, sizeof(FB_TNV), 1, fp) != 1)
00285 {
00286 fprintf(stderr, "Error while reading fb_tnv\n");
00287 exit(-1);
00288 }
00289 srd_fb_tnv.Print(stdout);
00290 }
00291 }
00292 }
00293 }
00294
00295 void _realign_for_whirl_fb_file(FILE * fpin)
00296 {
00297 long currentpos = ftell(fpin);
00298 int alignunitsize = sizeof(mINT64);
00299 int adjustment=0;
00300 if (currentpos % alignunitsize == 0)
00301 return;
00302 --alignunitsize;
00303 adjustment = (currentpos+alignunitsize) &~ alignunitsize - currentpos;
00304 fseek(fpin, currentpos, SEEK_CUR);
00305 }
00306
00307 int main(int argc, char * argv[])
00308 {
00309 if ( argc < 2)
00310 {
00311 fprintf(stderr, "USAGE: %s fb_file_name\n", argv[0]);
00312 exit(-1);
00313 }
00314 FILE * fpin;
00315 if (!(fpin = fopen(argv[1], "rb")) )
00316 {
00317 fprintf(stderr, "Error to open file %s\n", argv[1]);
00318 exit(-1);
00319 }
00320 fprintf(stdout, "Start to dump data from feedback file: %s\n", argv[1]);
00321 _dump_File_Header(fpin);
00322 _realign_for_whirl_fb_file(fpin);
00323 _dump_Pu_Headers(fpin);
00324 _realign_for_whirl_fb_file(fpin);
00325 _dump_Str_Header(fpin);
00326 _realign_for_whirl_fb_file(fpin);
00327 _dump_pu_data(fpin);
00328 fprintf(stdout,"************ End of dump **************\n\n");
00329
00330 fclose(fpin);
00331 }
00332
00333