lightningd: use static buffer for common log path.
This speeds logging slightly, but most of the time is actually spent in fflush() (which we need). Result (10 runs, eatmydata): FAILED tests/test_connection.py::test_bench - assert 24.086638-25.347475(24.6901+/-0.4) == 0 This is an 8% performance improvement (over the entire series), which is not bad. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -208,6 +208,13 @@ static void log_to_files(const char *log_prefix,
|
||||
{
|
||||
char tstamp[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ ")];
|
||||
char *entry, nodestr[hex_str_size(PUBKEY_CMPR_LEN)];
|
||||
char buf[sizeof("%s%s%s %s-%s: %s\n")
|
||||
+ strlen(log_prefix)
|
||||
+ sizeof(tstamp)
|
||||
+ strlen(level_prefix(level))
|
||||
+ sizeof(nodestr)
|
||||
+ strlen(entry_prefix)
|
||||
+ strlen(str)];
|
||||
bool filtered;
|
||||
|
||||
if (print_timestamps) {
|
||||
@@ -235,14 +242,18 @@ static void log_to_files(const char *log_prefix,
|
||||
entry_prefix, str, dir, hex);
|
||||
tal_free(hex);
|
||||
} else {
|
||||
size_t len;
|
||||
entry = buf;
|
||||
if (!node_id)
|
||||
entry = tal_fmt(tmpctx, "%s%s%s %s: %s\n",
|
||||
log_prefix, tstamp, level_prefix(level), entry_prefix, str);
|
||||
len = snprintf(buf, sizeof(buf),
|
||||
"%s%s%s %s: %s\n",
|
||||
log_prefix, tstamp, level_prefix(level), entry_prefix, str);
|
||||
else
|
||||
entry = tal_fmt(tmpctx, "%s%s%s %s-%s: %s\n",
|
||||
log_prefix, tstamp, level_prefix(level),
|
||||
nodestr,
|
||||
entry_prefix, str);
|
||||
len = snprintf(buf, sizeof(buf), "%s%s%s %s-%s: %s\n",
|
||||
log_prefix, tstamp, level_prefix(level),
|
||||
nodestr,
|
||||
entry_prefix, str);
|
||||
assert(len < sizeof(buf));
|
||||
}
|
||||
|
||||
/* In complex configurations, we tell loggers to overshare: then we
|
||||
|
||||
Reference in New Issue
Block a user