Remove trailing new line in err() and die()

This commit is contained in:
Rodrigo Arias 2023-03-21 16:05:33 +01:00 committed by Rodrigo Arias Mallo
parent 3f44be9f2f
commit 648411c686
25 changed files with 178 additions and 180 deletions

View File

@ -18,13 +18,13 @@ cb_chan_is_dirty(struct chan *chan, void *arg)
struct bay *bay = bchan->bay;
if (bay->state != BAY_READY && bay->state != BAY_PROPAGATING) {
err("cannot add dirty channel %s in current bay state\n",
err("cannot add dirty channel %s in current bay state",
chan->name);
return -1;
}
if (bchan->is_dirty) {
err("channel %s already on dirty list\n", chan->name);
err("channel %s already on dirty list", chan->name);
return -1;
}
@ -162,7 +162,7 @@ propagate_chan(struct bay_chan *bchan, enum bay_cb_type type)
UNUSED(propname);
dbg("- propagating channel '%s' phase %s\n",
dbg("- propagating channel '%s' phase %s",
bchan->chan->name, propname[type]);
struct bay_cb *cur = NULL;

View File

@ -19,7 +19,7 @@ chan_init(struct chan *chan, enum chan_type type, const char *fmt, ...)
int n = ARRAYLEN(chan->name);
int ret = vsnprintf(chan->name, n, fmt, ap);
if (ret >= n)
die("channel name too long\n");
die("channel name too long");
va_end(ap);
chan->type = type;
@ -46,7 +46,7 @@ set_dirty(struct chan *chan)
if (chan->prop[CHAN_DIRTY_WRITE])
return 0;
err("%s: already dirty\n", chan->name);
err("%s: already dirty", chan->name);
return -1;
}
@ -193,7 +193,7 @@ chan_pop(struct chan *chan, struct value evalue)
stack->n--;
if (set_dirty(chan) != 0) {
err("%s: set_dirty failed\n", chan->name);
err("%s: set_dirty failed", chan->name);
return -1;
}
@ -248,7 +248,7 @@ chan_dirty(struct chan *chan)
return 0;
if (set_dirty(chan) != 0) {
err("%s: set_dirty failed\n", chan->name);
err("%s: set_dirty failed", chan->name);
return -1;
}

View File

@ -19,13 +19,13 @@ static int
cadd(struct clkoff *table, struct clkoff_entry e)
{
if (cfind(table, e.name) != NULL) {
err("entry with name '%s' already exists\n", e.name);
err("entry with name '%s' already exists", e.name);
return -1;
}
struct clkoff_entry *entry = calloc(1, sizeof(struct clkoff_entry));
if (entry == NULL) {
err("calloc failed\n");
err("calloc failed");
return -1;
}
@ -43,7 +43,7 @@ cparse(struct clkoff *table, FILE *file)
/* Ignore header line */
char buf[1024];
if (fgets(buf, 1024, file) == NULL) {
err("missing header line in clock offset\n");
err("missing header line in clock offset");
return -1;
}
@ -66,18 +66,18 @@ cparse(struct clkoff *table, FILE *file)
break;
if (ret == EOF && errno != 0) {
err("fscanf() failed in line %d\n", line);
err("fscanf() failed in line %d", line);
return -1;
}
if (ret != 5) {
err("fscanf() read %d instead of 5 fields in line %d\n",
err("fscanf() read %d instead of 5 fields in line %d",
ret, line);
return -1;
}
if (cadd(table, e) != 0) {
err("cannot add entry of line %d\n",
err("cannot add entry of line %d",
line);
return -1;
}
@ -90,14 +90,14 @@ static int
cindex(struct clkoff *table)
{
if (table->nentries < 1) {
err("no entries\n");
err("no entries");
return -1;
}
table->index = calloc(table->nentries, sizeof(struct clkoff_entry *));
if (table->index == NULL) {
err("calloc failed\n");
err("calloc failed");
return -1;
}

View File

@ -296,7 +296,7 @@ cpu_remove_thread(struct cpu *cpu, struct thread *thread)
/* Not found, abort */
if (t == NULL) {
err("cannot remove missing thread %d from cpu %s\n",
err("cannot remove missing thread %d from cpu %s",
thread->tid, cpu->name);
return -1;
}

View File

@ -19,13 +19,13 @@ emu_init(struct emu *emu, int argc, char *argv[])
/* Load the streams into the trace */
if (trace_load(&emu->trace, emu->args.tracedir) != 0) {
err("cannot load trace '%s'\n", emu->args.tracedir);
err("cannot load trace '%s'", emu->args.tracedir);
return -1;
}
/* Parse the trace and build the emu_system */
if (system_init(&emu->system, &emu->args, &emu->trace) != 0) {
err("cannot init system for trace '%s'\n",
err("cannot init system for trace '%s'",
emu->args.tracedir);
return -1;
}
@ -46,7 +46,7 @@ emu_init(struct emu *emu, int argc, char *argv[])
}
if (player_init(&emu->player, &emu->trace, 0) != 0) {
err("cannot init player for trace '%s'\n",
err("cannot init player for trace '%s'",
emu->args.tracedir);
return -1;
}

View File

@ -55,7 +55,7 @@ emu_args_init(struct emu_args *args, int argc, char *argv[])
}
if (optind >= argc) {
err("missing tracedir\n");
err("missing tracedir");
usage();
}

View File

@ -53,7 +53,7 @@ model_kernel_event(struct emu *emu)
dbg("in kernel_event");
if (emu->ev->m != 'K') {
err("unexpected event model %c\n", emu->ev->m);
err("unexpected event model %c", emu->ev->m);
return -1;
}

View File

@ -53,7 +53,7 @@ loom_init_begin(struct loom *loom, const char *name)
}
if (snprintf(loom->name, PATH_MAX, "%s", name) >= PATH_MAX) {
err("name too long: %s\n", name);
err("name too long: %s", name);
return -1;
}

View File

@ -41,11 +41,11 @@ select_input(struct mux *mux,
{
if (mux->select_func == NULL) {
if (default_select(mux, key, input) != 0) {
err("default_select failed\n");
err("default_select failed");
return -1;
}
} else if (mux->select_func(mux, key, input) != 0) {
err("select_func failed\n");
err("select_func failed");
return -1;
}
@ -76,12 +76,12 @@ cb_select(struct chan *sel_chan, void *ptr)
char buf[128];
UNUSED(buf);
dbg("select channel got value %s\n",
dbg("select channel got value %s",
value_str(sel_value));
struct mux_input *input = NULL;
if (select_input(mux, sel_value, &input) != 0) {
err("select_input failed\n");
err("select_input failed");
return -1;
}
@ -89,7 +89,7 @@ cb_select(struct chan *sel_chan, void *ptr)
bay_enable_cb(input->cb);
input->selected = 1;
mux->selected = input->index;
dbg("mux selects input key=%s chan=%s\n",
dbg("mux selects input key=%s chan=%s",
value_str(sel_value), input->chan->name);
}
@ -119,7 +119,7 @@ cb_input(struct chan *in_chan, void *ptr)
struct value out_value;
if (chan_read(in_chan, &out_value) != 0) {
err("chan_read() failed\n");
err("chan_read() failed");
return -1;
}

View File

@ -530,7 +530,7 @@ model_nanos6_event(struct emu *emu)
}
if (emu->ev->m != '6') {
err("unexpected event model %c\n", emu->ev->m);
err("unexpected event model %c", emu->ev->m);
return -1;
}

View File

@ -266,7 +266,7 @@ end_lint(struct emu *emu)
return -1;
}
err("thread %d ended with %d stacked nanos6 subsystems\n",
err("thread %d ended with %d stacked nanos6 subsystems",
t->tid, stacked);
return -1;
}

View File

@ -109,7 +109,7 @@ model_nodes_event(struct emu *emu)
dbg("in nodes_event");
if (emu->ev->m != 'D') {
err("unexpected event model %c\n", emu->ev->m);
err("unexpected event model %c", emu->ev->m);
return -1;
}

View File

@ -529,7 +529,7 @@ model_nosv_event(struct emu *emu)
dbg("in nosv_event");
if (emu->ev->m != 'V') {
err("unexpected event model %c\n", emu->ev->m);
err("unexpected event model %c", emu->ev->m);
return -1;
}

View File

@ -239,7 +239,7 @@ end_lint(struct emu *emu)
return -1;
}
err("thread %d ended with %d stacked nosv subsystems\n",
err("thread %d ended with %d stacked nosv subsystems",
t->tid, stacked);
return -1;
}

View File

@ -88,7 +88,7 @@ static int
pre_thread_pause(struct thread *th)
{
if (th->state != TH_ST_RUNNING && th->state != TH_ST_COOLING) {
err("cannot pause thread %d: state not running or cooling\n",
err("cannot pause thread %d: state not running or cooling",
th->tid);
return -1;
}
@ -153,7 +153,7 @@ static int
pre_thread_warm(struct thread *th)
{
if (th->state != TH_ST_PAUSED) {
err("cannot warm thread %d: state not paused\n", th->tid);
err("cannot warm thread %d: state not paused", th->tid);
return -1;
}
@ -178,7 +178,7 @@ pre_thread(struct emu *emu)
switch (ev->v) {
case 'C': /* create */
dbg("thread %d creates a new thread at cpu=%d with args=%x %x\n",
dbg("thread %d creates a new thread at cpu=%d with args=%x %x",
th->tid,
ev->payload->u32[0],
ev->payload->u32[1],
@ -198,7 +198,7 @@ pre_thread(struct emu *emu)
case 'w':
return pre_thread_warm(th);
default:
err("unknown thread event value %c\n", ev->v);
err("unknown thread event value %c", ev->v);
return -1;
}
return 0;
@ -247,7 +247,7 @@ pre_affinity_set(struct emu *emu)
return -1;
}
dbg("thread %d now runs in %s\n", th->tid, newcpu->name);
dbg("thread %d now runs in %s", th->tid, newcpu->name);
return 0;
}
@ -323,7 +323,7 @@ pre_affinity(struct emu *emu)
case 'r':
return pre_affinity_remote(emu);
default:
err("unknown affinity event value %c\n",
err("unknown affinity event value %c",
emu->ev->v);
return -1;
}
@ -339,7 +339,7 @@ pre_cpu(struct emu *emu)
err("ignoring old event OCn");
return 0;
default:
err("unknown cpu event value %c\n",
err("unknown cpu event value %c",
emu->ev->v);
return -1;
}
@ -394,7 +394,7 @@ pre_burst(struct emu *emu)
avg /= (double) n;
double median = deltas[n / 2];
info("%s burst stats: median/avg/max = %3.0f/%3.0f/%3.0f ns\n",
info("%s burst stats: median/avg/max = %3.0f/%3.0f/%3.0f ns",
emu->loom->id, median, avg, maxdelta);
if (median > 100)
@ -434,7 +434,7 @@ pre_flush(struct emu *emu)
emu->thread->tid);
break;
default:
err("unexpected value '%c' (expecting '[' or ']')\n",
err("unexpected value '%c' (expecting '[' or ']')",
emu->ev->v);
return -1;
}
@ -446,7 +446,7 @@ int
model_ovni_event(struct emu *emu)
{
if (emu->ev->m != 'O') {
err("unexpected event model %c\n", emu->ev->m);
err("unexpected event model %c", emu->ev->m);
return -1;
}
@ -465,7 +465,7 @@ model_ovni_event(struct emu *emu)
/* Ignore sorting events */
return 0;
default:
err("unknown ovni event category %c\n",
err("unknown ovni event category %c",
emu->ev->c);
return -1;
}

View File

@ -67,7 +67,7 @@ parse_args(int argc, char *argv[])
}
if (optind >= argc) {
err("bad usage: missing directory\n");
err("bad usage: missing directory");
usage();
}

View File

@ -29,12 +29,12 @@ main(int argc, char *argv[])
}
if (emu_init(emu, argc, argv) != 0) {
err("emu_init failed\n");
err("emu_init failed");
return 1;
}
if (emu_connect(emu) != 0) {
err("emu_connect failed\n");
err("emu_connect failed");
return 1;
}

View File

@ -15,7 +15,6 @@
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
#include <stdatomic.h>
@ -97,7 +96,7 @@ find_destination(struct ring *r, uint64_t clock)
for (ssize_t i = start; i != end; i = i - 1 < 0 ? r->size - 1 : i - 1) {
last_clock = r->ev[i]->header.clock;
if (last_clock < clock) {
dbg("found suitable position %ld events backwards\n",
dbg("found suitable position %ld events backwards",
nback);
return i;
}
@ -109,16 +108,16 @@ find_destination(struct ring *r, uint64_t clock)
* before the sort window. So simply return the first marker. */
if (nback < (ssize_t) r->size - 1) {
if (r->head != 0)
die("ring head expected to be 0\n");
die("ring head expected to be 0");
if (r->tail >= r->size - 1)
die("ring tail=%ld expected to be less than %ld\n", r->tail, r->size - 1);
die("ring tail=%ld expected to be less than %ld", r->tail, r->size - 1);
dbg("starting of ring with nback=%ld\n", nback);
dbg("starting of ring with nback=%ld", nback);
return r->head;
}
err("cannot find a event previous to clock %lu\n", clock);
err("nback=%ld, last_clock=%lu\n", nback, last_clock);
err("cannot find a event previous to clock %lu", clock);
err("nback=%ld, last_clock=%lu", nback, last_clock);
return -1;
}
@ -167,10 +166,10 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
break;
if ((uint8_t *) ev > srcnext)
die("exceeded srcnext while sorting\n");
die("exceeded srcnext while sorting");
if (bufsize < evsize)
die("no space left in the sort buffer\n");
die("no space left in the sort buffer");
memcpy(buf, ev, evsize);
buf += evsize;
@ -178,7 +177,7 @@ sort_buf(uint8_t *src, uint8_t *buf, int64_t bufsize,
injected++;
}
dbg("injected %ld events in the past\n", injected);
dbg("injected %ld events in the past", injected);
}
static void
@ -189,7 +188,7 @@ write_stream(int fd, void *base, void *dst, const void *src, size_t size)
ssize_t written = pwrite(fd, src, size, offset);
if (written < 0)
die("pwrite failed: %s\n", strerror(errno));
die("pwrite failed:");
size -= written;
src = (void *) (((uint8_t *) src) + written);
@ -200,12 +199,12 @@ write_stream(int fd, void *base, void *dst, const void *src, size_t size)
static int
execute_sort_plan(struct sortplan *sp)
{
dbg("attempt to sort: start clock %ld\n", sp->bad0->header.clock);
dbg("attempt to sort: start clock %ld", sp->bad0->header.clock);
/* Cannot sort in one pass; just fail for now */
int64_t i0 = find_destination(sp->r, sp->bad0->header.clock);
if (i0 < 0) {
err("cannot find destination for region starting at clock %ld\n",
err("cannot find destination for region starting at clock %ld",
sp->bad0->header.clock);
return -1;
@ -218,11 +217,11 @@ execute_sort_plan(struct sortplan *sp)
int64_t bufsize = ((int64_t) sp->next) - ((int64_t) first);
if (bufsize <= 0)
die("bufsize is non-positive\n");
die("bufsize is non-positive");
uint8_t *buf = malloc(bufsize);
if (!buf)
die("malloc failed: %s\n", strerror(errno));
die("malloc failed:");
sort_buf((uint8_t *) first, buf, bufsize,
(uint8_t *) sp->bad0, (uint8_t *) sp->next);
@ -277,10 +276,10 @@ stream_winsort(struct stream *stream, struct ring *r)
if (ends_unsorted_region(ev)) {
updated = 1;
sp.next = ev;
dbg("executing sort plan for stream %s\n",
dbg("executing sort plan for stream %s",
stream->relpath);
if (execute_sort_plan(&sp) < 0) {
err("sort failed for stream %s\n",
err("sort failed for stream %s",
stream->relpath);
return -1;
}
@ -302,14 +301,14 @@ stream_winsort(struct stream *stream, struct ring *r)
}
if (empty_regions > 0)
warn("stream %s contains %ld empty sort regions\n",
warn("stream %s contains %ld empty sort regions",
stream->relpath, empty_regions);
if (updated && fdatasync(fd) < 0)
die("fdatasync %s failed: %s\n", fn, strerror(errno));
die("fdatasync %s failed:", fn);
if (close(fd) < 0)
die("close %s failed: %s\n", fn, strerror(errno));
die("close %s failed:", fn);
return 0;
}
@ -336,7 +335,7 @@ stream_check(struct stream *stream)
uint64_t cur_clock = ovni_ev_get_clock(ev);
if (cur_clock < last_clock) {
err("backwards jump in time %ld -> %ld for stream %s\n",
err("backwards jump in time %ld -> %ld for stream %s",
last_clock, cur_clock, stream->relpath);
ret = -1;
}
@ -362,22 +361,22 @@ process_trace(struct trace *trace)
ring.ev = malloc(ring.size * sizeof(struct ovni_ev *));
if (ring.ev == NULL)
die("malloc failed: %s\n", strerror(errno));
die("malloc failed:");
for (struct stream *stream = trace->streams; stream; stream = stream->next) {
stream_allow_unsorted(stream);
if (operation_mode == SORT) {
dbg("sorting stream %s\n", stream->relpath);
dbg("sorting stream %s", stream->relpath);
if (stream_winsort(stream, &ring) != 0) {
err("sort stream %s failed\n", stream->relpath);
err("sort stream %s failed", stream->relpath);
/* When sorting, return at the first
* attempt */
return -1;
}
} else {
if (stream_check(stream) != 0) {
err("stream %s is not sorted\n", stream->relpath);
err("stream %s is not sorted", stream->relpath);
/* When checking, report all errors and
* then fail */
ret = -1;
@ -389,9 +388,9 @@ process_trace(struct trace *trace)
if (operation_mode == CHECK) {
if (ret == 0) {
err("all streams sorted\n");
err("all streams sorted");
} else {
err("streams NOT sorted\n");
err("streams NOT sorted");
}
}
@ -401,21 +400,21 @@ process_trace(struct trace *trace)
static void
usage(void)
{
err("Usage: ovnisort [-c] tracedir\n");
err("\n");
err("Sorts the events in each stream of the trace given in\n");
err("tracedir, so they are suitable for the emulator ovniemu.\n");
err("Only the events enclosed by OU[ OU] are sorted. At most a\n");
err("total of %ld events are looked back to insert the unsorted\n",
rerr("Usage: ovnisort [-c] tracedir\n");
rerr("\n");
rerr("Sorts the events in each stream of the trace given in\n");
rerr("tracedir, so they are suitable for the emulator ovniemu.\n");
rerr("Only the events enclosed by OU[ OU] are sorted. At most a\n");
rerr("total of %ld events are looked back to insert the unsorted\n",
max_look_back);
err("events, so the sort procedure can fail with an error.\n");
err("\n");
err("Options:\n");
err(" -c Enable check mode: don't sort, ensure the\n");
err(" trace is already sorted.\n");
err("\n");
err(" tracedir The trace directory generated by ovni.\n");
err("\n");
rerr("events, so the sort procedure can fail with an error.\n");
rerr("\n");
rerr("Options:\n");
rerr(" -c Enable check mode: don't sort, ensure the\n");
rerr(" trace is already sorted.\n");
rerr("\n");
rerr(" tracedir The trace directory generated by ovni.\n");
rerr("\n");
exit(EXIT_FAILURE);
}
@ -436,7 +435,7 @@ parse_args(int argc, char *argv[])
}
if (optind >= argc) {
err("missing tracedir\n");
err("missing tracedir");
usage();
}

View File

@ -111,7 +111,7 @@ proc_load_metadata(struct proc *proc, JSON_Object *meta)
JSON_Value *appid_val = json_object_get_value(meta, "app_id");
if (appid_val == NULL) {
err("missing attribute 'app_id' in metadata\n");
err("missing attribute 'app_id' in metadata");
return -1;
}

View File

@ -88,7 +88,7 @@ emit(struct prv *prv, struct prv_chan *rchan)
struct value value;
struct chan *chan = rchan->chan;
if (chan_read(chan, &value) != 0) {
err("chan_read %s failed\n", chan->name);
err("chan_read %s failed", chan->name);
return -1;
}
@ -98,7 +98,7 @@ emit(struct prv *prv, struct prv_chan *rchan)
if (rchan->flags & PRV_SKIPDUP)
return 0;
err("error duplicated value %s for channel %s\n",
err("error duplicated value %s for channel %s",
value_str(value), chan->name);
return -1;
}

View File

@ -16,7 +16,7 @@ check_stream_header(struct stream *stream)
int ret = 0;
if (stream->size < (int64_t) sizeof(struct ovni_stream_header)) {
err("stream '%s': incomplete stream header\n",
err("stream '%s': incomplete stream header",
stream->path);
return -1;
}
@ -28,13 +28,13 @@ check_stream_header(struct stream *stream)
char magic[5];
memcpy(magic, h->magic, 4);
magic[4] = '\0';
err("stream '%s': wrong stream magic '%s' (expected '%s')\n",
err("stream '%s': wrong stream magic '%s' (expected '%s')",
stream->path, magic, OVNI_STREAM_MAGIC);
ret = -1;
}
if (h->version != OVNI_STREAM_VERSION) {
err("stream '%s': stream version mismatch %u (expected %u)\n",
err("stream '%s': stream version mismatch %u (expected %u)",
stream->path, h->version, OVNI_STREAM_VERSION);
ret = -1;
}

View File

@ -226,31 +226,30 @@ init_global_lists(struct system *sys)
static void
print_system(struct system *sys)
{
err("content of system:\n");
err("content of system: ");
for (struct loom *l = sys->looms; l; l = l->next) {
err("%s gindex=%d\n", l->id, l->gindex);
err("+ %ld processes:\n", l->nprocs);
err("%s gindex=%d", l->id, l->gindex);
err("+ %ld processes: ", l->nprocs);
for (struct proc *p = l->procs; p; p = p->hh.next) {
err("| %s gindex=%d pid=%d\n",
err("| %s gindex=%d pid=%d",
p->id, p->gindex, p->pid);
err("| + %ld threads:\n", p->nthreads);
err("| + %ld threads: ", p->nthreads);
for (struct thread *t = p->threads; t; t = t->hh.next) {
err("| | %s tid=%d\n",
err("| | %s tid=%d",
t->id, t->tid);
}
}
err("+ %ld phy cpus:\n", l->ncpus);
err("+ %ld phy cpus: ", l->ncpus);
for (struct cpu *cpu = l->cpus; cpu; cpu = cpu->hh.next) {
err("| %s gindex=%ld phyid=%d\n",
err("| %s gindex=%ld phyid=%d",
cpu->name,
cpu->gindex,
cpu->phyid);
//err(" - i %d\n", cpu->i);
}
err("+ 1 virtual cpu:\n", l->ncpus);
err("+ 1 virtual cpu: ", l->ncpus);
struct cpu *cpu = &l->vcpu;
err("| %s gindex=%ld phyid=%d\n",
err("| %s gindex=%ld phyid=%d",
cpu->name,
cpu->gindex,
cpu->phyid);
@ -504,7 +503,7 @@ system_connect(struct system *sys, struct bay *bay, struct recorder *rec)
for (struct thread *th = sys->threads; th; th = th->gnext) {
if (thread_connect(th, bay, rec) != 0) {
err("thread_connect failed\n");
err("thread_connect failed");
return -1;
}
@ -533,7 +532,7 @@ system_connect(struct system *sys, struct bay *bay, struct recorder *rec)
for (struct cpu *cpu = sys->cpus; cpu; cpu = cpu->next) {
if (cpu_connect(cpu, bay, rec) != 0) {
err("cpu_connect failed\n");
err("cpu_connect failed");
return -1;
}

View File

@ -74,7 +74,7 @@ value_str(struct value a)
ret = snprintf(buf, n, "{double %e}", a.d);
break;
default:
die("value_str: unexpected value type\n");
die("value_str: unexpected value type");
}
if (ret >= (int) n)

View File

@ -162,7 +162,7 @@ heap_pop_max(heap_head_t *head, heap_node_compare_t cmp)
size_t size = head->size;
heap_node_t *change = heap_get(head, size);
if (change == NULL)
die("heap_pop_max: heap_get() failed\n");
die("heap_get() failed");
head->size--;
@ -194,10 +194,10 @@ heap_pop_max(heap_head_t *head, heap_node_compare_t cmp)
change->parent->left = NULL;
if (change->left)
die("heap_pop_max: change->left not NULL\n");
die("change->left not NULL");
if (change->right)
die("heap_pop_max: change->right not NULL\n");
die("change->right not NULL");
change->left = max->left;
if (change->left)
@ -235,11 +235,11 @@ heap_insert(heap_head_t *head, heap_node_t *node, heap_node_compare_t cmp)
// Right child
if (head->size % 2) {
if (parent->right)
die("heap_insert: parent->right already set\n");
die("parent->right already set");
parent->right = node;
} else {
if (parent->left)
die("heap_insert: parent->left already set\n");
die("parent->left already set");
parent->left = node;
}

View File

@ -28,27 +28,27 @@ _Thread_local struct ovni_rthread rthread = {0};
void ovni_version_check_str(const char *version)
{
if (version == NULL)
die("ovni version string is NULL\n");
die("ovni version string is NULL");
int provided[3];
int expected[3];
if (version_parse(version, provided) != 0)
die("failed to parse provided version \"%s\"\n", version);
die("failed to parse provided version \"%s\"", version);
if (version_parse(OVNI_LIB_VERSION, expected) != 0)
die("failed to parse expected version \"%s\"\n", OVNI_LIB_VERSION);
die("failed to parse expected version \"%s\"", OVNI_LIB_VERSION);
/* Match the major */
if (provided[0] != expected[0]) {
die("ovni major version mismatch: found %d (%s), expected %d (%s)\n",
die("ovni major version mismatch: found %d (%s), expected %d (%s)",
provided[0], version,
expected[0], OVNI_LIB_VERSION);
}
/* Only fail if the minor is older */
if (provided[1] < expected[1]) {
die("ovni minor version too old: found %d (%s), expected %d (%s)\n",
die("ovni minor version too old: found %d (%s), expected %d (%s)",
provided[1], version,
expected[1], OVNI_LIB_VERSION);
}
@ -65,13 +65,13 @@ create_trace_stream(void)
rproc.procdir, rthread.tid, OVNI_STREAM_EXT);
if (written >= PATH_MAX)
die("thread trace path too long: %s/thread.%d%s\n",
die("thread trace path too long: %s/thread.%d%s",
rproc.procdir, rthread.tid, OVNI_STREAM_EXT);
rthread.streamfd = open(path, O_WRONLY | O_CREAT, 0644);
if (rthread.streamfd == -1)
die("open %s failed: %s\n", path, strerror(errno));
die("open %s failed:", path);
}
static void
@ -80,7 +80,7 @@ proc_metadata_init(struct ovni_rproc *proc)
proc->meta = json_value_init_object();
if (proc->meta == NULL)
die("failed to create metadata JSON object\n");
die("failed to create metadata JSON object");
}
static void
@ -89,35 +89,35 @@ proc_metadata_store(JSON_Value *meta, const char *procdir)
char path[PATH_MAX];
if (meta == NULL)
die("process metadata not initialized\n");
die("process metadata not initialized");
if (snprintf(path, PATH_MAX, "%s/metadata.json", procdir) >= PATH_MAX)
die("metadata path too long: %s/metadata.json\n",
die("metadata path too long: %s/metadata.json",
procdir);
if (json_serialize_to_file_pretty(meta, path) != JSONSuccess)
die("failed to write process metadata\n");
die("failed to write process metadata");
}
void
ovni_add_cpu(int index, int phyid)
{
if (index < 0)
die("ovni_add_cpu: cannot use negative index %d\n", index);
die("cannot use negative index %d", index);
if (phyid < 0)
die("ovni_add_cpu: cannot use negative CPU id %d\n", phyid);
die("cannot use negative CPU id %d", phyid);
if (!rproc.ready)
die("ovni_add_cpu: process not yet initialized\n");
die("process not yet initialized");
if (rproc.meta == NULL)
die("ovni_add_cpu: metadata not initialized\n");
die("metadata not initialized");
JSON_Object *meta = json_value_get_object(rproc.meta);
if (meta == NULL)
die("ovni_add_cpu: json_value_get_object() failed\n");
die("json_value_get_object() failed");
int first_time = 0;
@ -127,39 +127,39 @@ ovni_add_cpu(int index, int phyid)
if (cpuarray == NULL) {
JSON_Value *value = json_value_init_array();
if (value == NULL)
die("ovni_add_cpu: json_value_init_array() failed\n");
die("json_value_init_array() failed");
cpuarray = json_array(value);
if (cpuarray == NULL)
die("ovni_add_cpu: json_array() failed\n");
die("json_array() failed");
first_time = 1;
}
JSON_Value *valcpu = json_value_init_object();
if (valcpu == NULL)
die("ovni_add_cpu: json_value_init_object() failed\n");
die("json_value_init_object() failed");
JSON_Object *cpu = json_object(valcpu);
if (cpu == NULL)
die("ovni_add_cpu: json_object() failed\n");
die("json_object() failed");
if (json_object_set_number(cpu, "index", index) != 0)
die("ovni_add_cpu: json_object_set_number() failed\n");
die("json_object_set_number() failed");
if (json_object_set_number(cpu, "phyid", phyid) != 0)
die("ovni_add_cpu: json_object_set_number() failed\n");
die("json_object_set_number() failed");
if (json_array_append_value(cpuarray, valcpu) != 0)
die("ovni_add_cpu: json_array_append_value() failed\n");
die("json_array_append_value() failed");
if (first_time) {
JSON_Value *value = json_array_get_wrapping_value(cpuarray);
if (value == NULL)
die("ovni_add_cpu: json_array_get_wrapping_value() failed\n");
die("json_array_get_wrapping_value() failed");
if (json_object_set_value(meta, "cpus", value) != 0)
die("ovni_add_cpu: json_object_set_value failed\n");
die("json_object_set_value failed");
}
}
@ -169,10 +169,10 @@ proc_set_app(int appid)
JSON_Object *meta = json_value_get_object(rproc.meta);
if (meta == NULL)
die("json_value_get_object failed\n");
die("json_value_get_object failed");
if (json_object_set_number(meta, "app_id", appid) != 0)
die("json_object_set_number for app_id failed\n");
die("json_object_set_number for app_id failed");
}
static void
@ -181,13 +181,13 @@ proc_set_version(void)
JSON_Object *meta = json_value_get_object(rproc.meta);
if (meta == NULL)
die("json_value_get_object failed\n");
die("json_value_get_object failed");
if (json_object_set_number(meta, "version", OVNI_METADATA_VERSION) != 0)
die("json_object_set_number for version failed\n");
die("json_object_set_number for version failed");
if (json_object_set_string(meta, "model_version", OVNI_MODEL_VERSION) != 0)
die("json_object_set_string for model_version failed\n");
die("json_object_set_string for model_version failed");
}
@ -195,18 +195,18 @@ void
ovni_proc_set_rank(int rank, int nranks)
{
if (!rproc.ready)
die("ovni_proc_set_rank: process not yet initialized\n");
die("process not yet initialized");
JSON_Object *meta = json_value_get_object(rproc.meta);
if (meta == NULL)
die("json_value_get_object failed\n");
die("json_value_get_object failed");
if (json_object_set_number(meta, "rank", rank) != 0)
die("json_object_set_number for rank failed\n");
die("json_object_set_number for rank failed");
if (json_object_set_number(meta, "nranks", nranks) != 0)
die("json_object_set_number for nranks failed\n");
die("json_object_set_number for nranks failed");
}
/* Create $tracedir/loom.$loom/proc.$pid and return it in path. */
@ -227,7 +227,7 @@ mkdir_proc(char *path, const char *tracedir, const char *loom, int pid)
/* But this one shall not fail */
if (mkdir(path, 0755))
die("mkdir %s failed: %s\n", path, strerror(errno));
die("mkdir %s failed:", path);
}
static void
@ -249,12 +249,12 @@ void
ovni_proc_init(int app, const char *loom, int pid)
{
if (rproc.ready)
die("ovni_proc_init: pid %d already initialized\n", pid);
die("pid %d already initialized", pid);
memset(&rproc, 0, sizeof(rproc));
if (strlen(loom) >= OVNI_MAX_HOSTNAME)
die("ovni_proc_init: loom name too long: %s\n", loom);
die("loom name too long: %s", loom);
strcpy(rproc.loom, loom);
rproc.pid = pid;
@ -279,14 +279,14 @@ move_thread_to_final(const char *src, const char *dst)
FILE *infile = fopen(src, "r");
if (infile == NULL) {
err("fopen(%s) failed: %s\n", src, strerror(errno));
err("fopen(%s) failed:", src);
return -1;
}
FILE *outfile = fopen(dst, "w");
if (outfile == NULL) {
err("fopen(%s) failed: %s\n", src, strerror(errno));
err("fopen(%s) failed:", src);
return -1;
}
@ -298,7 +298,7 @@ move_thread_to_final(const char *src, const char *dst)
fclose(infile);
if (remove(src) != 0) {
err("remove(%s) failed: %s\n", src, strerror(errno));
err("remove(%s) failed:", src);
return -1;
}
@ -309,10 +309,10 @@ static void
move_procdir_to_final(const char *procdir, const char *procdir_final)
{
DIR *dir;
int err = 0;
int ret = 0;
if ((dir = opendir(procdir)) == NULL) {
err("opendir %s failed: %s\n", procdir, strerror(errno));
err("opendir %s failed:", procdir);
return;
}
@ -327,9 +327,9 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
if (snprintf(thread, PATH_MAX, "%s/%s", procdir,
dirent->d_name)
>= PATH_MAX) {
err("snprintf: path too large: %s/%s\n", procdir,
err("snprintf: path too large: %s/%s", procdir,
dirent->d_name);
err = 1;
ret = 1;
continue;
}
@ -337,33 +337,33 @@ move_procdir_to_final(const char *procdir, const char *procdir_final)
if (snprintf(thread_final, PATH_MAX, "%s/%s", procdir_final,
dirent->d_name)
>= PATH_MAX) {
err("snprintf: path too large: %s/%s\n", procdir_final,
err("snprintf: path too large: %s/%s", procdir_final,
dirent->d_name);
err = 1;
ret = 1;
continue;
}
if (move_thread_to_final(thread, thread_final) != 0)
err = 1;
ret = 1;
}
closedir(dir);
if (rmdir(procdir) != 0) {
err("rmdir(%s) failed: %s\n", procdir, strerror(errno));
err = 1;
err("rmdir(%s) failed:", procdir);
ret = 1;
}
/* Warn the user, but we cannot do much at this point */
if (err)
err("errors occurred when moving the trace to %s\n", procdir_final);
if (ret)
err("errors occurred when moving the trace to %s", procdir_final);
}
void
ovni_proc_fini(void)
{
if (!rproc.ready)
die("ovni_proc_fini: process not initialized\n");
die("process not initialized");
/* Mark the process no longer ready */
rproc.ready = 0;
@ -383,7 +383,7 @@ write_evbuf(uint8_t *buf, size_t size)
ssize_t written = write(rthread.streamfd, buf, size);
if (written < 0)
die("failed to write buffer to disk: %s\n", strerror(errno));
die("failed to write buffer to disk:");
size -= written;
buf += written;
@ -415,15 +415,15 @@ void
ovni_thread_init(pid_t tid)
{
if (rthread.ready) {
err("warning: thread %d already initialized, ignored\n", tid);
warn("thread %d already initialized, ignored", tid);
return;
}
if (tid == 0)
die("ovni_thread_init: cannot use tid=%d\n", tid);
die("cannot use tid=%d", tid);
if (!rproc.ready)
die("ovni_thread_init: process not yet initialized\n");
die("process not yet initialized");
memset(&rthread, 0, sizeof(rthread));
@ -432,7 +432,7 @@ ovni_thread_init(pid_t tid)
rthread.evbuf = malloc(OVNI_MAX_EV_BUF);
if (rthread.evbuf == NULL)
die("ovni_thread_init: malloc failed: %s", strerror(errno));
die("malloc failed:");
create_trace_stream();
write_stream_header();
@ -444,7 +444,7 @@ void
ovni_thread_free(void)
{
if (!rthread.ready)
die("ovni_thread_free: thread not initialized\n");
die("thread not initialized");
free(rthread.evbuf);
}
@ -475,7 +475,7 @@ clock_monotonic_now(void)
struct timespec tp;
if (clock_gettime(rproc.clockid, &tp))
die("clock_gettime() failed: %s\n", strerror(errno));
die("clock_gettime() failed:");
return tp.tv_sec * ns + tp.tv_nsec;
}
@ -538,16 +538,16 @@ void
ovni_payload_add(struct ovni_ev *ev, const uint8_t *buf, int size)
{
if (ev->header.flags & OVNI_EV_JUMBO)
die("ovni_payload_add: event is marked as jumbo\n");
die("event is marked as jumbo");
if (size < 2)
die("ovni_payload_add: payload size %d too small\n", size);
die("payload size %d too small", size);
size_t payload_size = ovni_payload_size(ev);
/* Ensure we have room */
if (payload_size + size > sizeof(ev->payload))
die("ovni_payload_add: no space left for %d bytes\n", size);
die("no space left for %d bytes", size);
memcpy(&ev->payload.u8[payload_size], buf, size);
payload_size += size;
@ -570,10 +570,10 @@ ovni_flush(void)
struct ovni_ev pre = {0}, post = {0};
if (!rthread.ready)
die("ovni_flush: thread is not initialized\n");
die("thread is not initialized");
if (!rproc.ready)
die("ovni_flush: process is not initialized\n");
die("process is not initialized");
ovni_ev_set_clock(&pre, ovni_clock_now());
ovni_ev_set_mcv(&pre, "OF[");
@ -611,7 +611,7 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
uint64_t t0, t1;
if (ovni_payload_size(ev) != 0)
die("ovni_ev_add_jumbo: the event payload must be empty\n");
die("the event payload must be empty");
ovni_payload_add(ev, (uint8_t *) &bufsize, sizeof(bufsize));
size_t evsize = ovni_ev_size(ev);
@ -619,7 +619,7 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize)
size_t totalsize = evsize + bufsize;
if (totalsize >= OVNI_MAX_EV_BUF)
die("ovni_ev_add_jumbo: event too large\n");
die("event too large");
/* Check if the event fits or flush first otherwise */
if (rthread.evlen + totalsize >= OVNI_MAX_EV_BUF) {