3 #include <sys/gmon_out.h>
6 #define GMON_SEC "seconds s"
7 uint32_t mineip = 0xffffffff;
10 /* a hash structure to hold the arc */
18 struct arec *arc = NULL;
20 void note_arc(uint32_t eip, uint32_t from)
24 HASH_FIND_INT(arc, &eip, s);
26 s = malloc(sizeof(struct arec));
35 HASH_ADD_INT(arc, eip, s);
41 int main(int argc, char* argv[])
45 uint32_t eip, from, tmp;
51 fprintf(stderr, "Please specify the coreboot trace log as parameter\n");
55 f = fopen(argv[1], "r");
56 fo = fopen("gmon.out", "w+");
58 if ((f == NULL) || (fo == NULL)) {
59 fprintf(stderr, "Unable to manipulate with the input file\n");
64 if (fscanf(f, "~%x(%x)%*[^\n]\n", &eip, &from) == 2) {
66 } else if (fscanf(f, "%*c~%x(%x)%*[^\n]\n", &eip, &from) == 2) {
69 /* just drop a line */
70 tmp = fscanf(f, "%*[^\n]\n");
74 /* write gprof header */
75 fwrite(GMON_MAGIC, 1, sizeof(GMON_MAGIC) - 1, fo);
77 fwrite(&tmp, 1, sizeof(tmp), fo);
79 fwrite(&tmp, 1, sizeof(tmp), fo);
80 fwrite(&tmp, 1, sizeof(tmp), fo);
81 fwrite(&tmp, 1, sizeof(tmp), fo);
82 /* write fake histogram */
83 tag = GMON_TAG_TIME_HIST;
84 fwrite(&tag, 1, sizeof(tag), fo);
85 fwrite(&mineip, 1, sizeof(mineip), fo);
86 fwrite(&maxeip, 1, sizeof(maxeip), fo);
87 /* size of histogram */
89 fwrite(&tmp, 1, sizeof(tmp), fo);
92 fwrite(&tmp, 1, sizeof(tmp), fo);
93 fwrite(GMON_SEC, 1, sizeof(GMON_SEC) - 1, fo);
95 fwrite(&hit, 1, sizeof(hit), fo);
97 /* write call graph data */
98 tag = GMON_TAG_CG_ARC;
99 for (s = arc; s != NULL; s = s->hh.next) {
100 fwrite(&tag, 1, sizeof(tag), fo);
101 fwrite(&s->from, 1, sizeof(s->from), fo);
102 fwrite(&s->eip, 1, sizeof(s->eip), fo);
103 fwrite(&s->count, 1, sizeof(s->count), fo);