From 9b80e0c12a75284a13e50aad2c2996ebbd8cce47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 2 Oct 2019 11:51:51 +0100 Subject: [PATCH] util: drop support for stack traces with logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The log filters have supported the use of a "+" before the source match string to request that a stack trace be emitted for every log message: commit 548563956e484e0e43e9a66a89bdda0f95930108 Author: Daniel P. Berrange Date: Wed May 9 15:18:56 2012 +0100 Allow stack traces to be included with log messages Sometimes it is useful to see the callpath for log messages. This change enhances the log filter syntax so that stack traces can be show by setting '1:+NAME' instead of '1:NAME'. With the huge & ever increasing number of logging statements per file, this will be incredibly verbose and have a major performance penalty. This makes the feature impractical to use widely and as such it is not worth the code maint cost. Removing this seldom used feature allows us to drop the 'execinfo' module in gnulib which provides the backtrace() function which doesn't exist on non-Linux. Users who want to get stack traces of parts of libvirt can use GDB, or systemtap for live tracing with minimal perf impact. Reviewed-by: Ján Tomko Signed-off-by: Daniel P. Berrangé --- bootstrap.conf | 1 - docs/logging.html.in | 9 +++----- src/locking/virtlockd.conf | 6 +----- src/logging/virtlogd.conf | 6 +----- src/remote/libvirtd.conf.in | 6 +----- src/util/virlog.c | 43 ++++++++----------------------------- tests/testutils.c | 2 +- tests/virtestmock.c | 1 - 8 files changed, 16 insertions(+), 58 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 1b5a68b873..0c7de2d2aa 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -33,7 +33,6 @@ connect configmake dirname-lgpl environ -execinfo fclose fcntl fcntl-h diff --git a/docs/logging.html.in b/docs/logging.html.in index be2fd4ab5b..65c13e8a19 100644 --- a/docs/logging.html.in +++ b/docs/logging.html.in @@ -100,18 +100,15 @@

The syntax for filters and outputs is the same for both types of variables.

-

The format for a filter is one of:

+

The format for a filter is:

-x:name  (log message only)
-x:+name (log message + stack trace)
+x:name

where name is a string which is matched against the category given in the VIR_LOG_INIT() at the top of each libvirt source file, e.g., remote, qemu, or util.json (the name in the filter can be a substring of the full category name, in order to match multiple - similar categories), the optional + prefix tells - libvirt to log stack trace for each message - matching name, and x is the minimal + similar categories), and x is the minimal level where matching messages should be logged:

  • 1: DEBUG
  • diff --git a/src/locking/virtlockd.conf b/src/locking/virtlockd.conf index b65110fc3e..152d6a844f 100644 --- a/src/locking/virtlockd.conf +++ b/src/locking/virtlockd.conf @@ -23,10 +23,9 @@ # Logging filters: # A filter allows to select a different logging level for a given category -# of logs. The format for a filter is one of: +# of logs. The format for a filter is: # # level:match -# level:+match # # where 'match' is a string which is matched against the category # given in the VIR_LOG_INIT() at the top of each libvirt source @@ -35,9 +34,6 @@ # The 'match' is always treated as a substring match. IOW a match # string 'foo' is equivalent to '*foo*'. # -# If 'match' contains the optional "+" prefix, it tells libvirt -# to log stack trace for each message matching name. -# # 'level' is the minimal level where matching messages should # be logged: # diff --git a/src/logging/virtlogd.conf b/src/logging/virtlogd.conf index bc41edbc6b..8b1ff0156f 100644 --- a/src/logging/virtlogd.conf +++ b/src/logging/virtlogd.conf @@ -23,10 +23,9 @@ # Logging filters: # A filter allows to select a different logging level for a given category -# of logs. The format for a filter is one of: +# of logs. The format for a filter is: # # level:match -# level:+match # # where 'match' is a string which is matched against the category # given in the VIR_LOG_INIT() at the top of each libvirt source @@ -35,9 +34,6 @@ # The 'match' is always treated as a substring match. IOW a match # string 'foo' is equivalent to '*foo*'. # -# If 'match' contains the optional "+" prefix, it tells libvirt -# to log stack trace for each message matching name. -# # 'level' is the minimal level where matching messages should # be logged: # diff --git a/src/remote/libvirtd.conf.in b/src/remote/libvirtd.conf.in index fdef97f371..f984ce0478 100644 --- a/src/remote/libvirtd.conf.in +++ b/src/remote/libvirtd.conf.in @@ -369,10 +369,9 @@ # Logging filters: # A filter allows to select a different logging level for a given category -# of logs. The format for a filter is one of: +# of logs. The format for a filter is: # # level:match -# level:+match # # where 'match' is a string which is matched against the category # given in the VIR_LOG_INIT() at the top of each libvirt source @@ -381,9 +380,6 @@ # The 'match' is always treated as a substring match. IOW a match # string 'foo' is equivalent to '*foo*'. # -# If 'match' contains the optional "+" prefix, it tells libvirt -# to log stack trace for each message matching name. -# # 'level' is the minimal level where matching messages should # be logged: # diff --git a/src/util/virlog.c b/src/util/virlog.c index 5881a59cc5..2a745fca75 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #if HAVE_SYSLOG_H @@ -693,26 +692,6 @@ virLogVMessage(virLogSourcePtr source, } -static void -virLogStackTraceToFd(int fd) -{ - void *array[100]; - int size; - static bool doneWarning; - const char *msg = "Stack trace not available on this platform\n"; - -#define STRIP_DEPTH 3 - size = backtrace(array, G_N_ELEMENTS(array)); - if (size) { - backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH, fd); - ignore_value(safewrite(fd, "\n", 1)); - } else if (!doneWarning) { - ignore_value(safewrite(fd, msg, strlen(msg))); - doneWarning = true; - } -#undef STRIP_DEPTH -} - static void virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED, virLogPriority priority G_GNUC_UNUSED, @@ -729,6 +708,8 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED, int fd = (intptr_t) data; char *msg; + virCheckFlags(0,); + if (fd < 0) return; @@ -737,9 +718,6 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED, ignore_value(safewrite(fd, msg, strlen(msg))); VIR_FREE(msg); - - if (flags & VIR_LOG_STACK_TRACE) - virLogStackTraceToFd(fd); } @@ -832,7 +810,7 @@ virLogOutputToSyslog(virLogSourcePtr source G_GNUC_UNUSED, const char *str, void *data G_GNUC_UNUSED) { - virCheckFlags(VIR_LOG_STACK_TRACE,); + virCheckFlags(0,); syslog(virLogPrioritySyslog(priority), "%s", str); } @@ -980,7 +958,7 @@ virLogOutputToJournald(virLogSourcePtr source, const char *str G_GNUC_UNUSED, void *data) { - virCheckFlags(VIR_LOG_STACK_TRACE,); + virCheckFlags(0,); int buffd = -1; int journalfd = (intptr_t) data; struct msghdr mh; @@ -1168,8 +1146,6 @@ virLogGetFilters(void) virLogLock(); for (i = 0; i < virLogNbFilters; i++) { const char *sep = ":"; - if (virLogFilters[i]->flags & VIR_LOG_STACK_TRACE) - sep = ":+"; virBufferAsprintf(&filterbuf, "%d%s%s ", virLogFilters[i]->priority, sep, @@ -1416,7 +1392,7 @@ virLogFilterNew(const char *match, char *mdup = NULL; size_t mlen = strlen(match); - virCheckFlags(VIR_LOG_STACK_TRACE, NULL); + virCheckFlags(0, NULL); if (priority < VIR_LOG_DEBUG || priority > VIR_LOG_ERROR) { virReportError(VIR_ERR_INVALID_ARG, _("Invalid log priority %d"), @@ -1659,11 +1635,8 @@ virLogParseOutput(const char *src) * virLogParseFilter: * @src: string defining a single filter * - * The format of @src should be one of the following: + * The format of @src should be: * x:name - filter affecting all modules which match 'name' - * x:+name - * - * '+' - hints the logger to also include a stack trace for every message * 'name' - match string which either matches a name of a directory in * libvirt's source tree which in turn affects all modules in * that directory or it can matches a specific module within a @@ -1711,7 +1684,9 @@ virLogParseFilter(const char *src) match = tokens[1]; if (match[0] == '+') { - flags |= VIR_LOG_STACK_TRACE; + /* '+' used to indicate printing a stack trace, + * but we dropped that feature, so just chomp + * that leading '+' */ match++; } diff --git a/tests/testutils.c b/tests/testutils.c index 287567ab73..3a8e3142b4 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -746,7 +746,7 @@ virtTestLogOutput(virLogSourcePtr source G_GNUC_UNUSED, void *data) { struct virtTestLogData *log = data; - virCheckFlags(VIR_LOG_STACK_TRACE,); + virCheckFlags(0,); virBufferAsprintf(&log->buf, "%s: %s", timestamp, str); } diff --git a/tests/virtestmock.c b/tests/virtestmock.c index daae8ef41b..9fe774836b 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include