mb/supermicro/x11-lga1151-series: remove unneeded vendor id config
[coreboot.git] / util / genprof / genprof.c
blobf4dd4cb7c1ab27a46f1d1c595ea1bbc799a365d6
1 #include <stdio.h>
2 #include <uthash.h>
3 #include <sys/gmon_out.h>
4 #include <stdlib.h>
6 #define GMON_SEC "seconds s"
7 uint32_t mineip = 0xffffffff;
8 uint32_t maxeip = 0;
10 /* a hash structure to hold the arc */
11 struct arec {
12 uint32_t eip;
13 uint32_t from;
14 uint32_t count;
15 UT_hash_handle hh;
18 struct arec *arc = NULL;
20 void note_arc(uint32_t eip, uint32_t from)
22 struct arec *s;
24 HASH_FIND_INT(arc, &eip, s);
25 if (s == NULL) {
26 s = malloc(sizeof(struct arec));
27 s->eip = eip;
28 s->from = from;
29 s->count = 1;
30 if (eip > maxeip)
31 maxeip = eip;
32 if (eip < mineip)
33 maxeip = eip;
35 HASH_ADD_INT(arc, eip, s);
36 } else {
37 s->count++;
41 int main(int argc, char* argv[])
43 FILE *f, *fo;
44 struct arec *s;
45 uint32_t eip, from, tmp;
46 uint8_t tag;
47 uint16_t hit;
49 if (argc != 2) {
50 fprintf(stderr, "Please specify the coreboot trace log as parameter\n");
51 return 1;
54 f = fopen(argv[1], "r");
55 if (f == NULL) {
56 perror("Unable to open the input file");
57 return 1;
60 fo = fopen("gmon.out", "w+");
61 if (fo == NULL) {
62 perror("Unable to open the output file");
63 fclose(f);
64 return 1;
67 while (!feof(f)) {
68 if (fscanf(f, "~%x(%x)%*[^\n]\n", &eip, &from) == 2) {
69 note_arc(eip, from);
70 } else if (fscanf(f, "%*c~%x(%x)%*[^\n]\n", &eip, &from) == 2) {
71 note_arc(eip, from);
72 } else {
73 /* just drop a line */
74 tmp = fscanf(f, "%*[^\n]\n");
78 /* write gprof header */
79 fwrite(GMON_MAGIC, 1, sizeof(GMON_MAGIC) - 1, fo);
80 tmp = GMON_VERSION;
81 fwrite(&tmp, 1, sizeof(tmp), fo);
82 tmp = 0;
83 fwrite(&tmp, 1, sizeof(tmp), fo);
84 fwrite(&tmp, 1, sizeof(tmp), fo);
85 fwrite(&tmp, 1, sizeof(tmp), fo);
86 /* write fake histogram */
87 tag = GMON_TAG_TIME_HIST;
88 fwrite(&tag, 1, sizeof(tag), fo);
89 fwrite(&mineip, 1, sizeof(mineip), fo);
90 fwrite(&maxeip, 1, sizeof(maxeip), fo);
91 /* size of histogram */
92 tmp = 1;
93 fwrite(&tmp, 1, sizeof(tmp), fo);
94 /* prof rate */
95 tmp = 1000;
96 fwrite(&tmp, 1, sizeof(tmp), fo);
97 fwrite(GMON_SEC, 1, sizeof(GMON_SEC) - 1, fo);
98 hit = 1;
99 fwrite(&hit, 1, sizeof(hit), fo);
101 /* write call graph data */
102 tag = GMON_TAG_CG_ARC;
103 for (s = arc; s != NULL; s = s->hh.next) {
104 fwrite(&tag, 1, sizeof(tag), fo);
105 fwrite(&s->from, 1, sizeof(s->from), fo);
106 fwrite(&s->eip, 1, sizeof(s->eip), fo);
107 fwrite(&s->count, 1, sizeof(s->count), fo);
110 fclose(fo);
111 fclose(f);
113 return 0;