Skip to content

Commit 9b80e0c

Browse files
committed
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 5485639 Author: Daniel P. Berrange <[email protected]> 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 <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent afbdc84 commit 9b80e0c

File tree

8 files changed

+16
-58
lines changed

8 files changed

+16
-58
lines changed

Diff for: bootstrap.conf

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ connect
3333
configmake
3434
dirname-lgpl
3535
environ
36-
execinfo
3736
fclose
3837
fcntl
3938
fcntl-h

Diff for: docs/logging.html.in

+3-6
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,15 @@
100100
</h2>
101101
<p>The syntax for filters and outputs is the same for both types of
102102
variables.</p>
103-
<p>The format for a filter is one of:</p>
103+
<p>The format for a filter is:</p>
104104
<pre>
105-
x:name (log message only)
106-
x:+name (log message + stack trace)</pre>
105+
x:name</pre>
107106
<p>where <code>name</code> is a string which is matched against
108107
the category given in the VIR_LOG_INIT() at the top of each
109108
libvirt source file, e.g., <code>remote</code>, <code>qemu</code>,
110109
or <code>util.json</code> (the name in the filter can be a
111110
substring of the full category name, in order to match multiple
112-
similar categories), the optional <code>+</code> prefix tells
113-
libvirt to log stack trace for each message
114-
matching <code>name</code>, and <code>x</code> is the minimal
111+
similar categories), and <code>x</code> is the minimal
115112
level where matching messages should be logged:</p>
116113
<ul>
117114
<li>1: DEBUG</li>

Diff for: src/locking/virtlockd.conf

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
# Logging filters:
2525
# A filter allows to select a different logging level for a given category
26-
# of logs. The format for a filter is one of:
26+
# of logs. The format for a filter is:
2727
#
2828
# level:match
29-
# level:+match
3029
#
3130
# where 'match' is a string which is matched against the category
3231
# given in the VIR_LOG_INIT() at the top of each libvirt source
@@ -35,9 +34,6 @@
3534
# The 'match' is always treated as a substring match. IOW a match
3635
# string 'foo' is equivalent to '*foo*'.
3736
#
38-
# If 'match' contains the optional "+" prefix, it tells libvirt
39-
# to log stack trace for each message matching name.
40-
#
4137
# 'level' is the minimal level where matching messages should
4238
# be logged:
4339
#

Diff for: src/logging/virtlogd.conf

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
# Logging filters:
2525
# A filter allows to select a different logging level for a given category
26-
# of logs. The format for a filter is one of:
26+
# of logs. The format for a filter is:
2727
#
2828
# level:match
29-
# level:+match
3029
#
3130
# where 'match' is a string which is matched against the category
3231
# given in the VIR_LOG_INIT() at the top of each libvirt source
@@ -35,9 +34,6 @@
3534
# The 'match' is always treated as a substring match. IOW a match
3635
# string 'foo' is equivalent to '*foo*'.
3736
#
38-
# If 'match' contains the optional "+" prefix, it tells libvirt
39-
# to log stack trace for each message matching name.
40-
#
4137
# 'level' is the minimal level where matching messages should
4238
# be logged:
4339
#

Diff for: src/remote/libvirtd.conf.in

+1-5
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,9 @@
369369

370370
# Logging filters:
371371
# A filter allows to select a different logging level for a given category
372-
# of logs. The format for a filter is one of:
372+
# of logs. The format for a filter is:
373373
#
374374
# level:match
375-
# level:+match
376375
#
377376
# where 'match' is a string which is matched against the category
378377
# given in the VIR_LOG_INIT() at the top of each libvirt source
@@ -381,9 +380,6 @@
381380
# The 'match' is always treated as a substring match. IOW a match
382381
# string 'foo' is equivalent to '*foo*'.
383382
#
384-
# If 'match' contains the optional "+" prefix, it tells libvirt
385-
# to log stack trace for each message matching name.
386-
#
387383
# 'level' is the minimal level where matching messages should
388384
# be logged:
389385
#

Diff for: src/util/virlog.c

+9-34
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <sys/stat.h>
2929
#include <fcntl.h>
3030
#include <unistd.h>
31-
#include <execinfo.h>
3231
#include <regex.h>
3332
#include <sys/uio.h>
3433
#if HAVE_SYSLOG_H
@@ -693,26 +692,6 @@ virLogVMessage(virLogSourcePtr source,
693692
}
694693

695694

696-
static void
697-
virLogStackTraceToFd(int fd)
698-
{
699-
void *array[100];
700-
int size;
701-
static bool doneWarning;
702-
const char *msg = "Stack trace not available on this platform\n";
703-
704-
#define STRIP_DEPTH 3
705-
size = backtrace(array, G_N_ELEMENTS(array));
706-
if (size) {
707-
backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH, fd);
708-
ignore_value(safewrite(fd, "\n", 1));
709-
} else if (!doneWarning) {
710-
ignore_value(safewrite(fd, msg, strlen(msg)));
711-
doneWarning = true;
712-
}
713-
#undef STRIP_DEPTH
714-
}
715-
716695
static void
717696
virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED,
718697
virLogPriority priority G_GNUC_UNUSED,
@@ -729,6 +708,8 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED,
729708
int fd = (intptr_t) data;
730709
char *msg;
731710

711+
virCheckFlags(0,);
712+
732713
if (fd < 0)
733714
return;
734715

@@ -737,9 +718,6 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED,
737718

738719
ignore_value(safewrite(fd, msg, strlen(msg)));
739720
VIR_FREE(msg);
740-
741-
if (flags & VIR_LOG_STACK_TRACE)
742-
virLogStackTraceToFd(fd);
743721
}
744722

745723

@@ -832,7 +810,7 @@ virLogOutputToSyslog(virLogSourcePtr source G_GNUC_UNUSED,
832810
const char *str,
833811
void *data G_GNUC_UNUSED)
834812
{
835-
virCheckFlags(VIR_LOG_STACK_TRACE,);
813+
virCheckFlags(0,);
836814

837815
syslog(virLogPrioritySyslog(priority), "%s", str);
838816
}
@@ -980,7 +958,7 @@ virLogOutputToJournald(virLogSourcePtr source,
980958
const char *str G_GNUC_UNUSED,
981959
void *data)
982960
{
983-
virCheckFlags(VIR_LOG_STACK_TRACE,);
961+
virCheckFlags(0,);
984962
int buffd = -1;
985963
int journalfd = (intptr_t) data;
986964
struct msghdr mh;
@@ -1168,8 +1146,6 @@ virLogGetFilters(void)
11681146
virLogLock();
11691147
for (i = 0; i < virLogNbFilters; i++) {
11701148
const char *sep = ":";
1171-
if (virLogFilters[i]->flags & VIR_LOG_STACK_TRACE)
1172-
sep = ":+";
11731149
virBufferAsprintf(&filterbuf, "%d%s%s ",
11741150
virLogFilters[i]->priority,
11751151
sep,
@@ -1416,7 +1392,7 @@ virLogFilterNew(const char *match,
14161392
char *mdup = NULL;
14171393
size_t mlen = strlen(match);
14181394

1419-
virCheckFlags(VIR_LOG_STACK_TRACE, NULL);
1395+
virCheckFlags(0, NULL);
14201396

14211397
if (priority < VIR_LOG_DEBUG || priority > VIR_LOG_ERROR) {
14221398
virReportError(VIR_ERR_INVALID_ARG, _("Invalid log priority %d"),
@@ -1659,11 +1635,8 @@ virLogParseOutput(const char *src)
16591635
* virLogParseFilter:
16601636
* @src: string defining a single filter
16611637
*
1662-
* The format of @src should be one of the following:
1638+
* The format of @src should be:
16631639
* x:name - filter affecting all modules which match 'name'
1664-
* x:+name
1665-
*
1666-
* '+' - hints the logger to also include a stack trace for every message
16671640
* 'name' - match string which either matches a name of a directory in
16681641
* libvirt's source tree which in turn affects all modules in
16691642
* that directory or it can matches a specific module within a
@@ -1711,7 +1684,9 @@ virLogParseFilter(const char *src)
17111684

17121685
match = tokens[1];
17131686
if (match[0] == '+') {
1714-
flags |= VIR_LOG_STACK_TRACE;
1687+
/* '+' used to indicate printing a stack trace,
1688+
* but we dropped that feature, so just chomp
1689+
* that leading '+' */
17151690
match++;
17161691
}
17171692

Diff for: tests/testutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ virtTestLogOutput(virLogSourcePtr source G_GNUC_UNUSED,
746746
void *data)
747747
{
748748
struct virtTestLogData *log = data;
749-
virCheckFlags(VIR_LOG_STACK_TRACE,);
749+
virCheckFlags(0,);
750750
virBufferAsprintf(&log->buf, "%s: %s", timestamp, str);
751751
}
752752

Diff for: tests/virtestmock.c

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <unistd.h>
2323
#include <sys/types.h>
2424
#include <fcntl.h>
25-
#include <execinfo.h>
2625
#include <sys/file.h>
2726
#include <sys/stat.h>
2827
#include <sys/socket.h>

0 commit comments

Comments
 (0)