-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_ebbrt_mcd.c
109 lines (94 loc) · 2.65 KB
/
parse_ebbrt_mcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
union IxgbeLogEntry {
long long data[12];
struct {
long long tsc;
long long ninstructions;
long long ncycles;
long long nref_cycles;
long long nllc_miss;
long long joules;
long long c3;
long long c6;
long long c7;
int rx_desc;
int rx_bytes;
int tx_desc;
int tx_bytes;
long long pad;
} __attribute((packed)) Fields;
} __attribute((packed));
int main(int argc, char **argv) {
/* declare a file pointer */
FILE *infile;
char *buffer;
long numbytes;
union IxgbeLogEntry *le;
int i, num_entries;
if(argc != 2) {
printf("usecase: ./parse_ebbrt_mcd FILENAME\n");
return 0;
}
/* open an existing file for reading */
infile = fopen(argv[1], "r");
/* quit if the file does not exist */
if(infile == NULL)
return 1;
/* Get the number of bytes */
fseek(infile, 0L, SEEK_END);
numbytes = ftell(infile);
num_entries = numbytes/sizeof(union IxgbeLogEntry);
printf("numbytes=%lu num_entries=%d\n", numbytes, num_entries);
/* reset the file position indicator to
the beginning of the file */
fseek(infile, 0L, SEEK_SET);
/* grab sufficient memory for the
buffer to hold the text */
buffer = (char*)calloc(numbytes, sizeof(char));
/* memory error */
if(buffer == NULL) {
printf("buffer == NULL\n");
return 1;
}
/* copy all the text into the buffer */
fread(buffer, sizeof(char), numbytes, infile);
fclose(infile);
le = (union IxgbeLogEntry *)buffer;
for(i=0;i<10;i++) {
printf("%d %d %d %d %d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
i,
le[i].Fields.rx_desc, le[i].Fields.rx_bytes,
le[i].Fields.tx_desc, le[i].Fields.tx_bytes,
le[i].Fields.ninstructions,
le[i].Fields.ncycles,
le[i].Fields.nref_cycles,
le[i].Fields.nllc_miss,
le[i].Fields.c3,
le[i].Fields.c6,
le[i].Fields.c7,
le[i].Fields.joules,
le[i].Fields.tsc);
}
printf("******\n");
for(i=num_entries-10;i<num_entries;i++) {
printf("%d %d %d %d %d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
i,
le[i].Fields.rx_desc, le[i].Fields.rx_bytes,
le[i].Fields.tx_desc, le[i].Fields.tx_bytes,
le[i].Fields.ninstructions,
le[i].Fields.ncycles,
le[i].Fields.nref_cycles,
le[i].Fields.nllc_miss,
le[i].Fields.c3,
le[i].Fields.c6,
le[i].Fields.c7,
le[i].Fields.joules,
le[i].Fields.tsc);
}
/* confirm we have read the file by
outputing it to the console */
//printf("The file called test.dat contains this text\n\n%s", buffer);
/* free the memory we used for the buffer */
//free(buffer);
}