diff --git a/dump.c b/dump.c index 9c190da..91840a3 100644 --- a/dump.c +++ b/dump.c @@ -15,6 +15,8 @@ * along with this program. If not, see . */ +#define _GNU_SOURCE + #include #include #include @@ -24,11 +26,15 @@ #include #include #include +#include #include "ovni.h" #include "trace.h" #include "emu.h" +int filter_tid = -1; +char *tracedir; + //static void //hexdump(uint8_t *buf, size_t size) //{ @@ -88,7 +94,11 @@ dump_events(struct ovni_trace *trace) for(i=0; instreams; i++) { stream = &trace->stream[i]; - ovni_load_next_event(stream); + + /* It can be inactive if it has been disabled by the + * thread TID filter */ + if(stream->active) + ovni_load_next_event(stream); } lastclock = 0; @@ -142,26 +152,56 @@ dump_events(struct ovni_trace *trace) } } +static void +usage(int argc, char *argv[]) +{ + UNUSED(argc); + UNUSED(argv); + + err("Usage: ovnidump [-t TID] tracedir\n"); + err("\n"); + err("Dumps the events of the trace to the standard output.\n"); + err("\n"); + err("Options:\n"); + err(" -t TID Only events from the given TID are shown\n"); + err("\n"); + err(" tracedir The trace directory generated by ovni.\n"); + err("\n"); + + exit(EXIT_FAILURE); +} + +static void +parse_args(int argc, char *argv[]) +{ + int opt; + + while((opt = getopt(argc, argv, "t:")) != -1) + { + switch(opt) + { + case 't': + filter_tid = atoi(optarg); + break; + default: /* '?' */ + usage(argc, argv); + } + } + + if(optind >= argc) + { + err("missing tracedir\n"); + usage(argc, argv); + } + + tracedir = argv[optind]; +} + int main(int argc, char *argv[]) { - char *tracedir; - struct ovni_trace *trace; + parse_args(argc, argv); - trace = calloc(1, sizeof(struct ovni_trace)); - - if(trace == NULL) - { - perror("calloc"); - exit(EXIT_FAILURE); - } - - if(argc != 2) - { - fprintf(stderr, "missing tracedir\n"); - exit(EXIT_FAILURE); - } - - tracedir = argv[1]; + struct ovni_trace *trace = calloc(1, sizeof(struct ovni_trace)); if(ovni_load_trace(trace, tracedir)) return 1; @@ -169,6 +209,17 @@ int main(int argc, char *argv[]) if(ovni_load_streams(trace)) return 1; + if(filter_tid != -1) + { + for(size_t i=0; instreams; i++) + { + struct ovni_stream *stream; + stream = &trace->stream[i]; + if(stream->tid != filter_tid) + stream->active = 0; + } + } + dump_events(trace); ovni_free_streams(trace);