Fix empty streams

This commit is contained in:
Rodrigo Arias 2021-08-02 12:34:11 +02:00
parent 4e23d7d435
commit c42711908b
4 changed files with 33 additions and 19 deletions

View File

@ -1,8 +1,8 @@
CFLAGS=-fPIC
# Debug CFLAGS
#CFLAGS+=-fsanitize=address
#LDFLAGS+=-fsanitize=address
CFLAGS+=-fsanitize=address
LDFLAGS+=-fsanitize=address
CFLAGS+=-g -O0
# Performance CFLAGS
@ -10,7 +10,7 @@ CFLAGS+=-g -O0
#CFLAGS+=-fstack-protector-explicit
#CFLAGS+=-flto
BIN=dump libovni.a test_speed ovni2prv emu
BIN=dump test_speed ovni2prv emu libovni.so
all: $(BIN)
@ -21,7 +21,10 @@ dump: ovni.o dump.o
test_speed: test_speed.c ovni.o
emu: emu.o emu_ovni.o emu_nosv.o ovni.o
emu: emu.o emu_ovni.o emu_nosv.o ovni.o prv.o
libovni.so: ovni.o
$(LINK.c) -shared $^ -o $@
ovni2prv: ovni2prv.c ovni.o

View File

@ -224,7 +224,6 @@ pre_type(struct ovni_emu *emu)
void
hook_pre_nosv(struct ovni_emu *emu)
{
dbg("pre nosv\n");
switch(emu->cur_ev->header.class)
{
case 'T': pre_task(emu); break;
@ -276,7 +275,6 @@ emit_task(struct ovni_emu *emu)
void
hook_emit_nosv(struct ovni_emu *emu)
{
dbg("pre nosv\n");
switch(emu->cur_ev->header.class)
{
case 'T': emit_task(emu); break;

30
ovni.c
View File

@ -620,6 +620,16 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
return -1;
}
if(st.st_size == 0)
{
err("warning: stream %s is empty\n", stream->tid);
stream->size = 0;
stream->buf = NULL;
stream->active = 0;
return 0;
}
stream->size = st.st_size;
stream->buf = mmap(NULL, stream->size, PROT_READ, MAP_SHARED,
thread->stream_fd, 0);
@ -630,6 +640,8 @@ load_stream_buf(struct ovni_stream *stream, struct ovni_ethread *thread)
return -1;
}
stream->active = 1;
return 0;
}
@ -679,20 +691,20 @@ ovni_load_streams(struct ovni_trace *trace)
thread = &proc->thread[k];
stream = &trace->stream[s++];
stream->tid = thread->tid;
stream->thread = k;
stream->proc = j;
stream->loom = i;
stream->lastclock = 0;
stream->offset = 0;
stream->cur_ev = NULL;
if(load_stream_buf(stream, thread) != 0)
{
err("load_stream_buf failed\n");
return -1;
}
stream->tid = thread->tid;
stream->thread = k;
stream->proc = j;
stream->loom = i;
stream->active = 1;
stream->lastclock = 0;
stream->offset = 0;
stream->cur_ev = NULL;
}
}
}
@ -734,7 +746,7 @@ ovni_load_next_event(struct ovni_stream *stream)
if(stream->offset == stream->size)
{
stream->active = 0;
dbg("stream runs out of events\n");
dbg("stream %d runs out of events\n", stream->tid);
return -1;
}

View File

@ -11,7 +11,7 @@
#include "ovni.h"
#include "ovni_trace.h"
void emit(struct ovni_stream *stream, struct ovni_ev *ev)
void emit(struct ovni_stream *stream, struct ovni_ev *ev, int row)
{
static uint64_t firstclock = 0;
int64_t delta;
@ -31,12 +31,12 @@ void emit(struct ovni_stream *stream, struct ovni_ev *ev)
//2:0:1:1:7:1542091:6400025:1
//2:0:1:1:7:1542091:6400017:0
printf("2:0:1:1:%d:%ld:%d:%d\n", stream->thread+1, delta, ev->header.class, ev->header.value);
printf("2:0:1:1:%d:%ld:%d:%d\n", row, delta, ev->header.class, ev->header.value);
}
void dump_events(struct ovni_trace *trace)
{
int i, f;
int i, f, row;
uint64_t minclock, lastclock;
struct ovni_ev *ev;
struct ovni_stream *stream;
@ -84,7 +84,8 @@ void dump_events(struct ovni_trace *trace)
}
/* Emit current event */
emit(stream, stream->cur_ev);
row = f + 1;
emit(stream, stream->cur_ev, row);
lastclock = ovni_ev_get_clock(stream->cur_ev);