trace: add syslog tracing backend
This patch adds a tracing backend which sends output using syslog(). The syslog backend is limited to POSIX compliant systems. openlog() is called with facility set to LOG_DAEMON, with the LOG_PID option. Trace events are logged at level LOG_INFO. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Message-id: 1470318254-29989-1-git-send-email-paul.durrant@citrix.com Cc: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
		
				
					committed by
					
						
						Stefan Hajnoczi
					
				
			
			
				
	
			
			
			
						parent
						
							e87d397e5e
						
					
				
				
					commit
					0a85241756
				
			
							
								
								
									
										19
									
								
								configure
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								configure
									
									
									
									
										vendored
									
									
								
							@@ -4191,6 +4191,18 @@ if compile_prog "" "" ; then
 | 
				
			|||||||
    posix_madvise=yes
 | 
					    posix_madvise=yes
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##########################################
 | 
				
			||||||
 | 
					# check if we have posix_syslog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					posix_syslog=no
 | 
				
			||||||
 | 
					cat > $TMPC << EOF
 | 
				
			||||||
 | 
					#include <syslog.h>
 | 
				
			||||||
 | 
					int main(void) { openlog("qemu", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "configure"); return 0; }
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					if compile_prog "" "" ; then
 | 
				
			||||||
 | 
					    posix_syslog=yes
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##########################################
 | 
					##########################################
 | 
				
			||||||
# check if trace backend exists
 | 
					# check if trace backend exists
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -5468,6 +5480,13 @@ if have_backend "ftrace"; then
 | 
				
			|||||||
    feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
 | 
					    feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					if have_backend "syslog"; then
 | 
				
			||||||
 | 
					  if test "$posix_syslog" = "yes" ; then
 | 
				
			||||||
 | 
					    echo "CONFIG_TRACE_SYSLOG=y" >> $config_host_mak
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    feature_not_found "syslog(trace backend)" "syslog not available"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 | 
					echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if test "$rdma" = "yes" ; then
 | 
					if test "$rdma" = "yes" ; then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,6 +192,18 @@ After running qemu by root user, you can get the trace:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Restriction: "ftrace" backend is restricted to Linux only.
 | 
					Restriction: "ftrace" backend is restricted to Linux only.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=== Syslog ===
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The "syslog" backend sends trace events using the POSIX syslog API. The log
 | 
				
			||||||
 | 
					is opened specifying the LOG_DAEMON facility and LOG_PID option (so events
 | 
				
			||||||
 | 
					are tagged with the pid of the particular QEMU process that generated
 | 
				
			||||||
 | 
					them). All events are logged at LOG_INFO level.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NOTE: syslog may squash duplicate consecutive trace events and apply rate
 | 
				
			||||||
 | 
					      limiting.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Restriction: "syslog" backend is restricted to POSIX compliant OS.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
==== Monitor commands ====
 | 
					==== Monitor commands ====
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* trace-file on|off|flush|set <path>
 | 
					* trace-file on|off|flush|set <path>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										45
									
								
								scripts/tracetool/backend/syslog.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								scripts/tracetool/backend/syslog.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env python
 | 
				
			||||||
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					Syslog built-in backend.
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__author__     = "Paul Durrant <paul.durrant@citrix.com>"
 | 
				
			||||||
 | 
					__copyright__  = "Copyright 2016, Citrix Systems Inc."
 | 
				
			||||||
 | 
					__license__    = "GPL version 2 or (at your option) any later version"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__maintainer__ = "Stefan Hajnoczi"
 | 
				
			||||||
 | 
					__email__      = "stefanha@redhat.com"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from tracetool import out
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PUBLIC = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def generate_h_begin(events):
 | 
				
			||||||
 | 
					    out('#include <syslog.h>',
 | 
				
			||||||
 | 
					        '#include "trace/control.h"',
 | 
				
			||||||
 | 
					        '')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def generate_h(event):
 | 
				
			||||||
 | 
					    argnames = ", ".join(event.args.names())
 | 
				
			||||||
 | 
					    if len(event.args) > 0:
 | 
				
			||||||
 | 
					        argnames = ", " + argnames
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if "vcpu" in event.properties:
 | 
				
			||||||
 | 
					        # already checked on the generic format code
 | 
				
			||||||
 | 
					        cond = "true"
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    out('        if (%(cond)s) {',
 | 
				
			||||||
 | 
					        '            syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
 | 
				
			||||||
 | 
					        '        }',
 | 
				
			||||||
 | 
					        cond=cond,
 | 
				
			||||||
 | 
					        name=event.name,
 | 
				
			||||||
 | 
					        fmt=event.fmt.rstrip("\n"),
 | 
				
			||||||
 | 
					        argnames=argnames)
 | 
				
			||||||
@@ -19,6 +19,9 @@
 | 
				
			|||||||
#ifdef CONFIG_TRACE_LOG
 | 
					#ifdef CONFIG_TRACE_LOG
 | 
				
			||||||
#include "qemu/log.h"
 | 
					#include "qemu/log.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef CONFIG_TRACE_SYSLOG
 | 
				
			||||||
 | 
					#include <syslog.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
#include "qapi/error.h"
 | 
					#include "qapi/error.h"
 | 
				
			||||||
#include "qemu/error-report.h"
 | 
					#include "qemu/error-report.h"
 | 
				
			||||||
#include "qemu/config-file.h"
 | 
					#include "qemu/config-file.h"
 | 
				
			||||||
@@ -250,6 +253,10 @@ bool trace_init_backends(void)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_TRACE_SYSLOG
 | 
				
			||||||
 | 
					    openlog(NULL, LOG_PID, LOG_DAEMON);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user