ovni/dump.c

151 lines
2.5 KiB
C
Raw Normal View History

2021-07-19 15:11:41 +02:00
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <stdatomic.h>
2021-07-19 19:05:26 +02:00
#include <dirent.h>
2021-07-19 15:11:41 +02:00
#include "ovni.h"
2021-07-28 11:56:35 +02:00
#include "ovni_trace.h"
#include "emu.h"
2021-07-19 15:11:41 +02:00
static void
hexdump(uint8_t *buf, size_t size)
2021-07-19 15:11:41 +02:00
{
int i, j;
2021-07-19 15:11:41 +02:00
//printf("writing %ld bytes in cpu=%d\n", size, rthread.cpu);
2021-07-19 15:11:41 +02:00
for(i=0; i<size; i+=16)
2021-07-19 15:11:41 +02:00
{
for(j=0; j<16 && i+j < size; j++)
2021-07-19 15:11:41 +02:00
{
fprintf(stderr, "%02x ", buf[i+j]);
2021-07-19 15:11:41 +02:00
}
fprintf(stderr, "\n");
2021-07-19 15:11:41 +02:00
}
}
void emit(struct ovni_stream *stream, struct ovni_ev *ev)
2021-07-19 15:11:41 +02:00
{
int64_t delta;
uint64_t clock;
int i, payloadsize;
2021-07-19 15:11:41 +02:00
//printf("sizeof(*ev) = %d\n", sizeof(*ev));
//hexdump((uint8_t *) ev, sizeof(*ev));
2021-07-19 15:11:41 +02:00
clock = ovni_ev_get_clock(ev);
2021-07-19 15:11:41 +02:00
delta = clock - stream->lastclock;
2021-07-19 15:11:41 +02:00
2021-09-28 19:21:22 +02:00
printf("%d.%d.%d %c %c %c % 20ld % 15ld ",
stream->loom, stream->proc, stream->tid,
2021-07-30 20:08:40 +02:00
ev->header.model, ev->header.class, ev->header.value, clock, delta);
2021-07-19 15:11:41 +02:00
payloadsize = ovni_payload_size(ev);
for(i=0; i<payloadsize; i++)
2021-07-19 15:11:41 +02:00
{
2021-07-28 11:56:35 +02:00
printf("%02x ", ev->payload.u8[i]);
2021-07-19 15:11:41 +02:00
}
printf("\n");
2021-07-19 15:11:41 +02:00
stream->lastclock = clock;
2021-07-19 15:11:41 +02:00
}
void dump_events(struct ovni_trace *trace)
2021-07-19 15:11:41 +02:00
{
int i, f;
uint64_t minclock, lastclock;
struct ovni_ev *ev;
struct ovni_stream *stream;
2021-07-19 15:11:41 +02:00
/* Load events */
for(i=0; i<trace->nstreams; i++)
{
stream = &trace->stream[i];
ovni_load_next_event(stream);
2021-07-19 15:11:41 +02:00
}
lastclock = 0;
while(1)
{
f = -1;
minclock = 0;
/* Select next event based on the clock */
for(i=0; i<trace->nstreams; i++)
{
stream = &trace->stream[i];
if(!stream->active)
continue;
2021-07-30 20:08:40 +02:00
ev = stream->cur_ev;
if(f < 0 || ovni_ev_get_clock(ev) < minclock)
2021-07-19 15:11:41 +02:00
{
f = i;
minclock = ovni_ev_get_clock(ev);
2021-07-19 15:11:41 +02:00
}
}
//fprintf(stderr, "f=%d minclock=%u\n", f, minclock);
if(f < 0)
break;
stream = &trace->stream[f];
2021-07-30 20:08:40 +02:00
if(lastclock > ovni_ev_get_clock(stream->cur_ev))
2021-07-19 15:11:41 +02:00
{
2021-07-22 12:35:38 +02:00
fprintf(stdout, "warning: backwards jump in time %lu -> %lu\n",
2021-07-30 20:08:40 +02:00
lastclock, ovni_ev_get_clock(stream->cur_ev));
2021-07-19 15:11:41 +02:00
}
/* Emit current event */
2021-07-30 20:08:40 +02:00
emit(stream, stream->cur_ev);
2021-07-19 15:11:41 +02:00
2021-07-30 20:08:40 +02:00
lastclock = ovni_ev_get_clock(stream->cur_ev);
2021-07-19 15:11:41 +02:00
/* Read the next one */
ovni_load_next_event(stream);
2021-07-19 15:11:41 +02:00
/* Unset the index */
f = -1;
minclock = 0;
}
}
int main(int argc, char *argv[])
{
char *tracedir;
struct ovni_trace trace;
2021-07-19 15:11:41 +02:00
if(argc != 2)
{
fprintf(stderr, "missing tracedir\n");
exit(EXIT_FAILURE);
}
tracedir = argv[1];
if(ovni_load_trace(&trace, tracedir))
2021-07-19 15:11:41 +02:00
return 1;
if(ovni_load_streams(&trace))
2021-07-19 15:11:41 +02:00
return 1;
dump_events(&trace);
ovni_free_streams(&trace);
2021-07-19 15:11:41 +02:00
return 0;
}