kmemtrace-report: pretty formatting.
[kmemtrace-user.git] / kmemtrace-show.c
blobd6a7137dc88fe069c3987424e784d4c4629a85e5
1 /*
2 * Copyright (C) 2008 Eduard - Gabriel Munteanu
4 * This file is released under GPL version 2.
5 */
7 #include <stdio.h>
8 #include <sys/stat.h>
9 #include <unistd.h>
11 #include <common.h>
12 #include <kmemtrace.h>
13 #include <dataset.h>
15 unsigned long ev_num = 1, target_ev;
17 static int show(struct kmemtrace_event *ev, void *extra)
19 struct kmemtrace_allocstats *stats = extra;
21 if (ev_num != target_ev) {
22 ev_num++;
23 return 0;
26 printf("Event %lu:\n", ev_num);
27 printf("\tevent_id\t%d\n\tkind_id\t\t%d\n\tevent_size\t0x%x\n"
28 "\tcall_site\t%p\n\tptr\t\t%p\n\tseq_num\t%ld\n",
29 ev->event_id, ev->type_id, (unsigned int) ev->event_size,
30 (void *) ev->call_site, (void *) ev->ptr, (long) ev->seq_num);
32 if (ev->event_id == KMEMTRACE_EVENT_ALLOC) {
33 if (ev->event_size != sizeof(struct kmemtrace_event) +
34 sizeof(struct kmemtrace_allocstats)) {
35 printf("Size of alloc event is wrong!\n");
36 return 1;
38 printf("\n\tbytes_req\t%lu\n\tbytes_alloc\t%lu\n"
39 "\tgfp_flags\t%d\n\tnuma_node\t%d\n",
40 (unsigned long) stats->bytes_req,
41 (unsigned long) stats->bytes_alloc,
42 (int) stats->gfp_flags, (int) stats->numa_node);
45 return 1;
48 int main(int argc, char **argv)
50 struct dataset *set;
51 unsigned long cpu;
53 if (argc != 3)
54 panic("There must be two arguments!\n");
56 cpu = strtoul(argv[1], NULL, 10);
57 set = dataset_open("cpu%lu.out", cpu);
58 if (!set)
59 panic("Could not open input file!\n");
61 target_ev = strtoul(argv[2], NULL, 10);
63 if (!dataset_iter(set, show))
64 printf("Not found!\n");
66 return 0;