#include
struct trace_rec
{
char rw;
long unsigned int mem_addr;//4字节
long long unsigned int delta_cycle;//8字节
}; //声明一个 组织结构
int main()
{
struct trace_rec rec; //声明rec这个变量具有上面定义的组织结构
int i=0;
FILE *trace=fopen("trace_core0","rb"); // 用二进制模式打开 trace_core0 文件,并定位指针 trace
while(1)
{
if(!fread(&rec,sizeof(struct trace_rec),1,trace)) //从trace(这里是文件trace_core0)中读取1个数据块的数据,存放在 rec 中。这个数据块包括 rw,mem_addr,delta_cycle的信息
break;
//printf("%lld %ld\n",rec.delta_cycle,rec.mem_addr);
i++;
}
fclose(trace);
trace=fopen("trace_core1","rb");
while(1)
{
if(!fread(&rec,sizeof(struct trace_rec),1,trace))
break;
//printf("%lld %ld\n",rec.delta_cycle,rec.mem_addr);
i++;
}
fclose(trace);
trace=fopen("trace_core2","rb");
while(1)
{
if(!fread(&rec,sizeof(struct trace_rec),1,trace))
break;
//printf("%lld %ld\n",rec.delta_cycle,rec.mem_addr);
i++;
}
fclose(trace);
trace=fopen("trace_core3","rb");
while(1)
{
if(!fread(&rec,sizeof(struct trace_rec),1,trace))
break;
//printf("%lld %ld\n",rec.delta_cycle,rec.mem_addr);
i++;
}
fclose(trace);
printf("%d\n",i);
fclose(trace);
return 0;
}