run script should use the loader
[ldtrace] / loader / w / dump.c
1 #define _XOPEN_SOURCE 700
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <sys/mman.h>
7
8 static struct {
9         uint64_t c;
10         uint64_t t;
11 } *tab;
12
13 static char *names[] = {
14 #define T(i,f) [i] = #f,
15 #include "tab.h"
16 #undef T
17 };
18
19 int main()
20 {
21         int i;
22         int fd = open("/tmp/wrap", O_RDONLY);
23         if (fd == -1) {
24                 dprintf(2, "open /tmp/wrap failed: %m\n");
25                 return 1;
26         }
27         tab = mmap(0, 2000 * sizeof *tab, PROT_READ, MAP_PRIVATE, fd, 0);
28         if (tab == MAP_FAILED) {
29                 dprintf(2, "mmap: %m\n");
30                 return 1;
31         }
32         for (i = 0; i < sizeof names/sizeof *names; i++)
33                 if (tab[i].c)
34                         dprintf(1, "%s: %llu calls %llu ns %f us/call\n",
35                           names[i], tab[i].c, tab[i].t, (double)tab[i].t/(1000*tab[i].c));
36         return 0;
37 }