Use info() for information messages

Prefix err() messages with "ERROR:" too.
This commit is contained in:
Rodrigo Arias 2023-03-23 17:38:08 +01:00 committed by Rodrigo Arias Mallo
parent 76efd7c216
commit 2c09e40c44
8 changed files with 45 additions and 30 deletions

View File

@ -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();
}

View File

@ -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)

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;
}