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