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
00043 #include "cg_instru_lib.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 if (fread(pu_headers, sizeof(Pu_Hdr), file_header.fb_pu_hdr_num, fp) != file_header.fb_pu_hdr_num)
00066 {
00067 fprintf(stderr, "Error reading pu_headers\n");
00068 exit(-1);
00069 }
00070
00071 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00072 {
00073 pu_headers[i].Print(stdout, i);
00074 }
00075 }
00076
00077 char * str_table = NULL;
00078 static void _dump_Str_Header( FILE * fp )
00079 {
00080 str_table = (char *) malloc (file_header.fb_str_table_size + 2);
00081 if (!str_table)
00082 {
00083 fprintf(stderr, "failed to malloc mem for str_table\n");
00084 exit(-1);
00085 }
00086 if (fread(str_table, sizeof(char), file_header.fb_str_table_size, fp) != file_header.fb_str_table_size)
00087 {
00088 fprintf(stderr, "Error while reading str table!\n");
00089 exit(-1);
00090 }
00091 str_table[file_header.fb_str_table_size] = 0;
00092 fprintf(stdout,"\n************ Str table **************\n");
00093 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00094 {
00095 fprintf(stdout, "No %d : %s \n", i, str_table+pu_headers[i].pu_name_index);
00096 }
00097 }
00098
00099 static void _dump_pu_data( FILE * fp )
00100 {
00101 for (int i=0; i<file_header.fb_pu_hdr_num; i++)
00102 {
00103 fprintf(stdout, "\n*********** PU Data No %d ************\n", i );
00104 fprintf(stdout, "*********** edge profile info: ************\n");
00105 FB_FREQ fb_freq;
00106 for (int j=0;j<pu_headers[i].pu_num_edge_entries; j++)
00107 {
00108 if (fread(&fb_freq, sizeof(FB_FREQ), 1, fp) != 1)
00109 {
00110 fprintf(stderr, "Error while reading fb_freq\n");
00111 exit(-1);
00112 }
00113 fprintf(stdout, "_type = %d | _value = %f \n", fb_freq._type, fb_freq._value);
00114 }
00115 fprintf(stdout, "*********** value profile info: ************\n");
00116 FB_TNV fb_tnv;
00117 fseek(fp,pu_headers[i].pu_value_offset,SEEK_SET);
00118 for (int j=0; j<pu_headers[i].pu_instr_count ; j++)
00119 {
00120 if (fread(&fb_tnv, sizeof(FB_TNV), 1, fp) != 1)
00121 {
00122 fprintf(stderr, "Error while reading fb_tnv\n");
00123 exit(-1);
00124 }
00125
00126 fb_tnv.Print(stdout);
00127 }
00128 long pu_ofst=file_header.fb_profile_offset + pu_headers[i].pu_file_offset;
00129 fprintf(stdout, "*********** stride profile info: ************\n");
00130 fseek(fp,pu_ofst+pu_headers[i].pu_stride_offset,SEEK_SET);
00131 for (int j=0; j<pu_headers[i].pu_ld_count ; j++)
00132 {
00133 if (fread(&fb_tnv, sizeof(FB_TNV), 1, fp) != 1)
00134 {
00135 fprintf(stderr, "Error while reading fb_tnv\n");
00136 exit(-1);
00137 }
00138
00139 fb_tnv.Print(stdout);
00140 }
00141 }
00142 }
00143
00144 int main(int argc, char * argv[])
00145 {
00146 if ( argc < 2)
00147 {
00148 fprintf(stderr, "USAGE: %s fb_file_name\n", argv[0]);
00149 exit(-1);
00150 }
00151 FILE * fpin;
00152 if (!(fpin = fopen(argv[1], "rb")) )
00153 {
00154 fprintf(stderr, "Error to open file %s\n", argv[1]);
00155 exit(-1);
00156 }
00157 fprintf(stdout, "Start to dump data from feedback file: %s\n", argv[1]);
00158 _dump_File_Header(fpin);
00159 _dump_Pu_Headers(fpin);
00160 _dump_Str_Header(fpin);
00161 _dump_pu_data(fpin);
00162 fprintf(stdout,"************ End of dump **************\n\n");
00163
00164 fclose(fpin);
00165 }
00166
00167