loader based trace using musl
[ldtrace] / loader / w / dump.c
diff --git a/loader/w/dump.c b/loader/w/dump.c
new file mode 100644 (file)
index 0000000..f3ce32e
--- /dev/null
@@ -0,0 +1,37 @@
+#define _XOPEN_SOURCE 700
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+static struct {
+       uint64_t c;
+       uint64_t t;
+} *tab;
+
+static char *names[] = {
+#define T(i,f) [i] = #f,
+#include "tab.h"
+#undef T
+};
+
+int main()
+{
+       int i;
+       int fd = open("/tmp/wrap", O_RDONLY);
+       if (fd == -1) {
+               dprintf(2, "open /tmp/wrap failed: %m\n");
+               return 1;
+       }
+       tab = mmap(0, 2000 * sizeof *tab, PROT_READ, MAP_PRIVATE, fd, 0);
+       if (tab == MAP_FAILED) {
+               dprintf(2, "mmap: %m\n");
+               return 1;
+       }
+       for (i = 0; i < sizeof names/sizeof *names; i++)
+               if (tab[i].c)
+                       dprintf(1, "%s: %llu calls %llu ns %f us/call\n",
+                         names[i], tab[i].c, tab[i].t, (double)tab[i].t/(1000*tab[i].c));
+       return 0;
+}