10 char *name; /* function name */
11 long time; /* ticks spent there */
15 error(int perr, char *s)
17 fprint(2, "kprof: %s", s);
27 compar(void *va, void *vb)
29 struct COUNTER *a, *b;
35 if(a->time == b->time)
40 main(int argc, char *argv[])
56 error(0, "usage: kprof text data");
60 fd = open(argv[1], OREAD);
63 if (!crackhdr(fd, &f))
64 error(1, "read text header");
66 error(0, "text file not an a.out");
67 if (syminit(fd, &f) < 0)
73 fd = open(argv[2], OREAD);
79 n = d->length/sizeof(data[0]);
81 error(0, "data file too short");
82 data = malloc(d->length);
85 if(read(fd, data, d->length) < 0)
86 error(1, "text read");
89 data[i] = beswal(data[i]);
90 delta = data[0]-data[1];
91 print("total: %ld in kernel text: %ld outside kernel text: %ld\n",
92 data[0], delta, data[1]);
96 error(0, "no text symbols");
99 if(tbase != s.value & ~0xFFF)
100 print("warning: kbase %.8llux != tbase %.8llux\n",
101 tbase, s.value&~0xFFF);
102 print("KTZERO %.8llux PGSIZE %dKb\n", tbase, mach->pgsize/1024);
104 * Accumulate counts for each function
108 for (i = 0, j = 2; j < n; i++) {
109 name = s.name; /* save name */
110 if (!textsym(&s, i)) /* get next symbol */
115 while (j < n && j < s.value)
118 cp = realloc(cp, (k+1)*sizeof(struct COUNTER));
127 error(0, "no counts");
128 cp[k].time = 0; /* "etext" can take no time */
130 * Sort by time and print
132 qsort(cp, k, sizeof(struct COUNTER), compar);
133 Binit(&outbuf, 1, OWRITE);
134 Bprint(&outbuf, "ms %% sym\n");
136 Bprint(&outbuf, "%ld\t%3lld.%lld\t%s\n",
138 100LL*cp[k].time/delta,
139 (1000LL*cp[k].time/delta)%10,