[libvirt] [PATCH] Allow stack traces to be included with log messages

Daniel P. Berrange berrange at redhat.com
Tue May 15 13:27:46 UTC 2012


On Mon, May 14, 2012 at 05:18:58PM -0600, Eric Blake wrote:
> On 05/09/2012 08:22 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange at 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.

Yep, glibc only, unless other platforms have equivalent APIs
we can use

> 
> > +++ 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?

It just logs a warning message instead of the stack trace

> 
> > @@ -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?

No.


> > +
> > +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?

It is printed every time in place of the stack trace. I guess I should
make it one-time only.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list