diff --git a/src/common.c b/src/common.c index 40440a5..def8496 100644 --- a/src/common.c +++ b/src/common.c @@ -18,11 +18,14 @@ progname_set(char *name) } static void -vaerr(const char *func, const char *errstr, va_list ap) +vaerr(const char *prefix, const char *func, const char *errstr, va_list ap) { if (progname != NULL) fprintf(stderr, "%s: ", progname); + if (prefix != NULL) + fprintf(stderr, "%s: ", prefix); + if (func != NULL) fprintf(stderr, "%s: ", func); @@ -40,20 +43,20 @@ vaerr(const char *func, const char *errstr, va_list ap) } void -verr(const char *func, const char *errstr, ...) +verr(const char *prefix, const char *func, const char *errstr, ...) { va_list ap; va_start(ap, errstr); - vaerr(func, errstr, ap); + vaerr(prefix, func, errstr, ap); va_end(ap); } void -vdie(const char *func, const char *errstr, ...) +vdie(const char *prefix, const char *func, const char *errstr, ...) { va_list ap; va_start(ap, errstr); - vaerr(func, errstr, ap); + vaerr(prefix, func, errstr, ap); va_end(ap); abort(); } diff --git a/src/common.h b/src/common.h index a289985..b1a7caf 100644 --- a/src/common.h +++ b/src/common.h @@ -9,21 +9,21 @@ /* Debug macros */ void progname_set(char *name); -void verr(const char *func, const char *errstr, ...); -void vdie(const char *func, const char *errstr, ...); +void verr(const char *prefix, const char *func, const char *errstr, ...); +void vdie(const char *prefix, const char *func, const char *errstr, ...); /* clang-format off */ #define rerr(...) fprintf(stderr, __VA_ARGS__) -#define err(...) verr(__func__, __VA_ARGS__) -#define die(...) vdie(__func__, __VA_ARGS__) -#define info(...) verr("INFO", __VA_ARGS__) -#define warn(...) verr("WARN", __VA_ARGS__) +#define err(...) verr("ERROR", __func__, __VA_ARGS__) +#define die(...) vdie("FATAL", __func__, __VA_ARGS__) +#define info(...) verr("INFO", NULL, __VA_ARGS__) +#define warn(...) verr("WARN", NULL, __VA_ARGS__) #ifdef ENABLE_DEBUG -# define dbg(...) verr(__func__, __VA_ARGS__) +# define dbg(...) verr("DEBUG", __func__, __VA_ARGS__) #else -# define dbg(...) do { if (0) { verr(__func__, __VA_ARGS__); } } while(0) +# define dbg(...) do { if (0) { verr("DEBUG", __func__, __VA_ARGS__); } } while(0) #endif #define likely(x) __builtin_expect(!!(x), 1) diff --git a/src/emu/emu_stat.c b/src/emu/emu_stat.c index ea3b4fc..3365703 100644 --- a/src/emu/emu_stat.c +++ b/src/emu/emu_stat.c @@ -56,14 +56,14 @@ emu_stat_report(struct emu_stat *stat, struct player *player, int last) if (last) { int tmin = (int) (time_elapsed / 60.0); int tsec = (int) ((time_elapsed / 60.0 - tmin) * 60.0); - verr(NULL, "%5.1f%% done at avg %.0f kev/s\n", + info("%5.1f%% done at avg %.0f kev/s\n", progress * 100.0, avgspeed * 1e-3, tmin, tsec); - verr(NULL, "processed %ld input events in %d min %d s\n", + info("processed %ld input events in %d min %d s\n", nprocessed, tmin, tsec); } else { int tmin = (int) (time_left / 60.0); int tsec = (int) ((time_left / 60.0 - tmin) * 60.0); - verr(NULL, "%5.1f%% done at %.0f kev/s (%d min %d s left) \r", + info("%5.1f%% done at %.0f kev/s (%d min %d s left) \r", progress * 100.0, speed * 1e-3, tmin, tsec); } diff --git a/src/emu/ovniemu.c b/src/emu/ovniemu.c index 37e054c..ee0ffd7 100644 --- a/src/emu/ovniemu.c +++ b/src/emu/ovniemu.c @@ -40,31 +40,39 @@ main(int argc, char *argv[]) signal(SIGINT, stop_emulation); - err("emulation starts"); + info("emulation starts"); int ret = 0; + int partial = 0; while (run && (ret = emu_step(emu)) == 0); if (ret < 0) { err("emu_step failed"); ret = 1; /* continue to close the trace files */ - err("emulation aborts!"); + info("emulation aborts!"); } else { ret = 0; } - if (run == 0) - err("stopping emulation by user (^C again to abort)"); + if (run == 0) { + info("stopping emulation by user (^C again to abort)"); + partial = 1; + } if (emu_finish(emu) != 0) { err("emu_finish failed"); ret = 1; } - if (ret == 0) - err("emulation finished ok"); - else - err("emulation finished with errors"); + if (ret == 0) { + if (partial) { + info("emulation finished partially but ok"); + } else { + info("emulation finished ok"); + } + } else { + info("emulation finished with errors"); + } free(emu); diff --git a/src/emu/pv/cfg.c b/src/emu/pv/cfg.c index 29ac7bb..726d382 100644 --- a/src/emu/pv/cfg.c +++ b/src/emu/pv/cfg.c @@ -155,7 +155,7 @@ cfg_generate(const char *tracedir) struct stat st; if (stat(dst, &st) == 0) { warn("directory '%s' already exists, skipping config copy", dst); - return -1; + return 0; } if (copy_recursive(src, dst) != 0) { diff --git a/src/emu/recorder.c b/src/emu/recorder.c index b66fb92..f03f990 100644 --- a/src/emu/recorder.c +++ b/src/emu/recorder.c @@ -72,7 +72,7 @@ recorder_advance(struct recorder *rec, int64_t time) int recorder_finish(struct recorder *rec) { - err("writting the traces to disk, please wait"); + info("writing traces to disk, please wait"); for (struct pvt *pvt = rec->pvt; pvt; pvt = pvt->hh.next) { if (pvt_close(pvt) != 0) { @@ -84,7 +84,7 @@ recorder_finish(struct recorder *rec) /* TODO: Use configs per pvt */ if (cfg_generate(rec->dir) != 0) { err("cfg_generate failed"); - /* Ignore error */ + return -1; } return 0; diff --git a/src/emu/system.c b/src/emu/system.c index 37032d6..a8b345b 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -332,6 +332,10 @@ init_end_system(struct system *sys) return -1; } } + + info("loaded %ld looms, %ld processes, %ld threads and %ld cpus", + sys->nlooms, sys->nprocs, sys->nthreads, sys->nphycpus); + return 0; } @@ -374,7 +378,7 @@ load_clock_offsets(struct clkoff *clkoff, struct emu_args *args) return -1; } - err("loaded clock offset table from '%s' with %d entries", + info("loaded clock offset table from '%s' with %d entries", offset_file, clkoff_count(clkoff)); fclose(f); diff --git a/src/emu/trace.c b/src/emu/trace.c index 4ba0ca9..113025c 100644 --- a/src/emu/trace.c +++ b/src/emu/trace.c @@ -30,7 +30,7 @@ load_stream(struct trace *trace, const char *path) struct stream *stream = calloc(1, sizeof(struct stream)); if (stream == NULL) { - perror("calloc failed"); + err("calloc failed:"); return -1; } @@ -136,7 +136,7 @@ trace_load(struct trace *trace, const char *tracedir) /* Sort the streams */ DL_SORT(trace->streams, cmp_streams); - err("loaded %ld streams", trace->nstreams); + info("loaded %ld streams", trace->nstreams); return 0; }