Hexdump sort window for debug

This commit is contained in:
Rodrigo Arias 2021-12-15 15:52:41 +01:00
parent 08b22bf6e8
commit 86eabb2b9d

50
sort.c
View File

@ -37,6 +37,7 @@
#include <stdatomic.h> #include <stdatomic.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h>
#include "ovni.h" #include "ovni.h"
#include "trace.h" #include "trace.h"
@ -127,17 +128,57 @@ ends_unsorted_region(struct ovni_ev *ev)
ev->header.value == ']'; ev->header.value == ']';
} }
static void
hexdump(uint8_t *buf, size_t size)
{
UNUSED(buf);
UNUSED(size);
#ifdef ENABLE_DEBUG
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; j++)
{
if(i+j < size)
fprintf(stderr, "%02x ", buf[i+j]);
else
fprintf(stderr, " ");
}
fprintf(stderr, " | ");
for(j=0; j<16; j++)
{
if(i+j < size && isprint(buf[i+j]))
fprintf(stderr, "%c", buf[i+j]);
else
fprintf(stderr, " ");
}
fprintf(stderr, "\n");
}
#endif
}
static void static void
sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize, sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
uint8_t *srcbad, uint8_t *srcnext) uint8_t *srcbad, uint8_t *srcnext)
{ {
uint8_t *p, *q; uint8_t *p, *q, *obuf=buf;
int64_t evsize, injected = 0; int64_t evsize, injected = 0, obufsize=bufsize;
struct ovni_ev *ep, *eq, *ev; struct ovni_ev *ep, *eq, *ev;
p = src; p = src;
q = srcbad; q = srcbad;
dbg("src before:\n");
hexdump(src, obufsize);
while(1) while(1)
{ {
ep = (struct ovni_ev *) p; ep = (struct ovni_ev *) p;
@ -171,6 +212,9 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
injected++; injected++;
} }
dbg("buf after:\n");
hexdump(obuf, obufsize);
dbg("injected %ld events in the past\n", injected); dbg("injected %ld events in the past\n", injected);
} }
@ -257,6 +301,7 @@ stream_winsort(struct ovni_stream *stream, struct ring *r)
if(ends_unsorted_region(ev)) if(ends_unsorted_region(ev))
{ {
sp.next = ev; sp.next = ev;
dbg("executing sort plan for stream tid=%d\n", stream->tid);
if(execute_sort_plan(&sp) < 0) if(execute_sort_plan(&sp) < 0)
{ {
err("sort failed for stream tid=%d\n", err("sort failed for stream tid=%d\n",
@ -325,6 +370,7 @@ process_trace(struct ovni_trace *trace)
stream = &trace->stream[i]; stream = &trace->stream[i];
if(operation_mode == SORT) if(operation_mode == SORT)
{ {
dbg("sorting stream tid=%d\n", stream->tid);
if(stream_winsort(stream, &ring) != 0) if(stream_winsort(stream, &ring) != 0)
{ {
err("sort stream tid=%d failed\n", stream->tid); err("sort stream tid=%d failed\n", stream->tid);