ovni/dump.c

163 lines
2.7 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
2021-10-18 12:44:43 +02:00
//static void
//hexdump(uint8_t *buf, size_t size)
//{
// size_t i, j;
//
// //printf("writing %ld bytes in cpu=%d\n", size, rthread.cpu);
//
// for(i=0; i<size; i+=16)
// {
// for(j=0; j<16 && i+j < size; j++)
// {
// fprintf(stderr, "%02x ", buf[i+j]);
// }
// fprintf(stderr, "\n");
// }
//}
2021-07-19 15:11:41 +02:00
static void
2021-10-18 12:44:43 +02:00
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,
ev->header.model, ev->header.category, 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
}
2021-10-18 12:44:43 +02:00
static void
dump_events(struct ovni_trace *trace)
2021-07-19 15:11:41 +02:00
{
2021-10-18 12:44:43 +02:00
size_t i;
ssize_t f;
2021-07-19 15:11:41 +02:00
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;
2021-09-23 10:38:44 +02:00
struct ovni_trace *trace;
trace = calloc(1, sizeof(struct ovni_trace));
if(trace == NULL)
{
perror("calloc");
exit(EXIT_FAILURE);
}
2021-07-19 15:11:41 +02:00
if(argc != 2)
{
fprintf(stderr, "missing tracedir\n");
exit(EXIT_FAILURE);
}
tracedir = argv[1];
2021-09-23 10:38:44 +02:00
if(ovni_load_trace(trace, tracedir))
2021-07-19 15:11:41 +02:00
return 1;
2021-09-23 10:38:44 +02:00
if(ovni_load_streams(trace))
2021-07-19 15:11:41 +02:00
return 1;
2021-09-23 10:38:44 +02:00
dump_events(trace);
ovni_free_streams(trace);
2021-07-19 15:11:41 +02:00
2021-09-23 10:38:44 +02:00
free(trace);
2021-07-19 15:11:41 +02:00
return 0;
}