mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
util: drop support for stack traces with logging
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 548563956e
Author: Daniel P. Berrange <berrange@redhat.com>
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 <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
afbdc8495e
commit
9b80e0c12a
@ -33,7 +33,6 @@ connect
|
||||
configmake
|
||||
dirname-lgpl
|
||||
environ
|
||||
execinfo
|
||||
fclose
|
||||
fcntl
|
||||
fcntl-h
|
||||
|
@ -100,18 +100,15 @@
|
||||
</h2>
|
||||
<p>The syntax for filters and outputs is the same for both types of
|
||||
variables.</p>
|
||||
<p>The format for a filter is one of:</p>
|
||||
<p>The format for a filter is:</p>
|
||||
<pre>
|
||||
x:name (log message only)
|
||||
x:+name (log message + stack trace)</pre>
|
||||
x:name</pre>
|
||||
<p>where <code>name</code> 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., <code>remote</code>, <code>qemu</code>,
|
||||
or <code>util.json</code> (the name in the filter can be a
|
||||
substring of the full category name, in order to match multiple
|
||||
similar categories), the optional <code>+</code> prefix tells
|
||||
libvirt to log stack trace for each message
|
||||
matching <code>name</code>, and <code>x</code> is the minimal
|
||||
similar categories), and <code>x</code> is the minimal
|
||||
level where matching messages should be logged:</p>
|
||||
<ul>
|
||||
<li>1: DEBUG</li>
|
||||
|
@ -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:
|
||||
#
|
||||
|
@ -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:
|
||||
#
|
||||
|
@ -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:
|
||||
#
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <execinfo.h>
|
||||
#include <regex.h>
|
||||
#include <sys/uio.h>
|
||||
#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++;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <execinfo.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
|
Loading…
Reference in New Issue
Block a user