Allow TID filter in ovnidump
This commit is contained in:
parent
1eb90de88b
commit
806e0c9198
87
dump.c
87
dump.c
@ -15,6 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@ -24,11 +26,15 @@
|
||||
#include <sys/stat.h>
|
||||
#include <stdatomic.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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; i<trace->nstreams; 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; i<trace->nstreams; i++)
|
||||
{
|
||||
struct ovni_stream *stream;
|
||||
stream = &trace->stream[i];
|
||||
if(stream->tid != filter_tid)
|
||||
stream->active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
dump_events(trace);
|
||||
|
||||
ovni_free_streams(trace);
|
||||
|
Loading…
Reference in New Issue
Block a user