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");
97 tbase = s.value & ~(mach->pgsize-1); /* align down to page */
98 print("KTZERO %.8llux\n", tbase);
100 * Accumulate counts for each function
104 for (i = 0, j = (s.value-tbase)/PCRES+2; j < n; i++) {
105 name = s.name; /* save name */
106 if (!textsym(&s, i)) /* get next symbol */
109 while (j < n && j*PCRES < s.value-tbase)
112 cp = realloc(cp, (k+1)*sizeof(struct COUNTER));
121 error(0, "no counts");
122 cp[k].time = 0; /* "etext" can take no time */
124 * Sort by time and print
126 qsort(cp, k, sizeof(struct COUNTER), compar);
127 Binit(&outbuf, 1, OWRITE);
128 Bprint(&outbuf, "ms %% sym\n");
130 Bprint(&outbuf, "%ld\t%3lld.%lld\t%s\n",
132 100LL*cp[k].time/delta,
133 (1000LL*cp[k].time/delta)%10,