From b06db0322429df80ee0fe09d257520f0c5b71901 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Wed, 23 Mar 2016 23:22:01 +0100 Subject: Port st-dump and st-job-stats Include st-dump (formerly 'st_show') and st-job-stats (formerly 'st_job_stats') from https://github.com/brandenburg/sched-trace-tools in this repository. --- src/stdump.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/stdump.c (limited to 'src/stdump.c') 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 @@ +#include +#include +#include + +#include "load.h" +#include "sched_trace.h" +#include "eheap.h" + +static void usage(const char *str) +{ + fprintf(stderr, + "\n USAGE\n" + "\n" + " stdump [opts] +\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; +} -- cgit v1.2.2