aboutsummaryrefslogtreecommitdiffstats
path: root/src/stdump.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdump.c')
-rw-r--r--src/stdump.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/stdump.c b/src/stdump.c
new file mode 100644
index 0000000..c67b2ad
--- /dev/null
+++ b/src/stdump.c
@@ -0,0 +1,98 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4
5#include "load.h"
6#include "sched_trace.h"
7#include "eheap.h"
8
9static void usage(const char *str)
10{
11 fprintf(stderr,
12 "\n USAGE\n"
13 "\n"
14 " stdump [opts] <file.st>+\n"
15 "\n"
16 " OPTIONS\n"
17 " -r -- find task system release and exit\n"
18 " -f -- use first non-zero event as system release\n"
19 " if no system release event is found\n"
20 " -c -- display a count of the number of events\n"
21 "\n\n"
22 );
23 if (str) {
24 fprintf(stderr, "Aborted: %s\n", str);
25 exit(1);
26 } else {
27 exit(0);
28 }
29}
30
31#define OPTSTR "rcfh"
32
33int main(int argc, char** argv)
34{
35 unsigned int count;
36 struct heap *h;
37 struct heap_node *hn, *first = NULL;
38 u64 time;
39 struct st_event_record *rec;
40 int find_release = 0;
41 int show_count = 0;
42 int use_first_nonzero = 0;
43 int opt;
44
45 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
46 switch (opt) {
47 case 'r':
48 find_release = 1;
49 break;
50 case 'c':
51 show_count = 1;
52 break;
53 case 'f':
54 use_first_nonzero = 1;
55 break;
56 case 'h':
57 usage(NULL);
58 break;
59 case ':':
60 usage("Argument missing.");
61 break;
62 case '?':
63 default:
64 usage("Bad argument.");
65 break;
66 }
67 }
68
69
70 h = load(argv + optind, argc - optind, &count);
71 if (!h)
72 return 1;
73 if (show_count)
74 printf("Loaded %u events.\n", count);
75 while ((hn = heap_take(earlier_event, h))) {
76 time = event_time(heap_node_value(hn));
77 if (time != 0 && !first)
78 first = hn;
79 time /= 1000000; /* convert to milliseconds */
80 if (!find_release) {
81 printf("[%10llu] ", (unsigned long long) time);
82 print_event(heap_node_value(hn));
83 } else {
84 rec = heap_node_value(hn);
85 if (rec->hdr.type == ST_SYS_RELEASE) {
86 printf("%6.2fms\n", rec->data.raw[1] / 1000000.0);
87 find_release = 0;
88 break;
89 }
90 }
91 }
92 if (find_release && use_first_nonzero && first) {
93 rec = heap_node_value(first);
94 printf("%6.2fms\n", event_time(rec) / 1000000.0);
95 }
96
97 return 0;
98}