On 05/09/2012 08:22 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Sometimes it is useful to see the callpath for log messages.
This change enhances the log filter syntax so that stck traces
s/stck/stack/
can be show by setting '1:+NAME' instead of '1:NAME'.
Cool.
* docs/logging.html.in: Document new syntax
* configure.ac: Check for execinfo.h
* src/util/logging.c, src/util/logging.h: Add support for
stack traces
Of course, this seems to be Linux-only, but still useful.
+++ b/docs/logging.html.in
@@ -114,8 +114,10 @@
</h3>
<p>The syntax for filters and outputs is the same for both types of
variables.</p>
- <p>The format for a filter is:</p>
- <pre>x:name</pre>
+ <p>The format for a filter is one of:</p>
+ <pre>
+ x:name (log message only)
+ x:+name (log message + stack trace)</pre>
Does x:+name error out on systems where tracing is not built in, or does
it silently fall back to x:name?
@@ -538,6 +546,7 @@ static int virLogFiltersCheck(const char *input)
{
for (i = 0;i < virLogNbFilters;i++) {
if (strstr(input, virLogFilters[i].match)) {
ret = virLogFilters[i].priority;
+ *flags = virLogFilters[i].flags;
Is the double space intentional?
+
+static void virLogStackTraceToFd(int fd)
+{
+#ifdef HAVE_EXECINFO_H
+ void *array[100];
+ int size;
+
+#define STRIP_DEPTH 3
+
+ size = backtrace(array, sizeof(array)/sizeof(array[0]));
Write the second argument as ARRAY_CARDINALITY(array).
+ backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH,
fd);
+ ignore_value(safewrite(fd, "\n", 1));
+#else
+ const char *msg = "stack trace not available on this platform";
+ ignore_value(safewrite(fd, msg, strlen(msg)));
Is this a one-time error message, printed on first use, or will it
appear on every log message?
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org