mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
trace: Conditionally trace events based on their per-vCPU state
Events with the 'vcpu' property are conditionally emitted according to their per-vCPU state. Other events are emitted normally based on their global tracing state. Note that the per-vCPU condition check applies to all tracing backends. Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
4815185902
commit
40b9cd25f7
6 changed files with 57 additions and 29 deletions
|
@ -6,7 +6,7 @@ DTrace/SystemTAP backend.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
|
__copyright__ = "Copyright 2012-2016, Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__license__ = "GPL version 2 or (at your option) any later version"
|
__license__ = "GPL version 2 or (at your option) any later version"
|
||||||
|
|
||||||
__maintainer__ = "Stefan Hajnoczi"
|
__maintainer__ = "Stefan Hajnoczi"
|
||||||
|
@ -41,6 +41,6 @@ def generate_h_begin(events):
|
||||||
|
|
||||||
|
|
||||||
def generate_h(event):
|
def generate_h(event):
|
||||||
out(' QEMU_%(uppername)s(%(argnames)s);',
|
out(' QEMU_%(uppername)s(%(argnames)s);',
|
||||||
uppername=event.name.upper(),
|
uppername=event.name.upper(),
|
||||||
argnames=", ".join(event.args.names()))
|
argnames=", ".join(event.args.names()))
|
||||||
|
|
|
@ -30,17 +30,17 @@ def generate_h(event):
|
||||||
if len(event.args) > 0:
|
if len(event.args) > 0:
|
||||||
argnames = ", " + argnames
|
argnames = ", " + argnames
|
||||||
|
|
||||||
out(' {',
|
out(' {',
|
||||||
' char ftrace_buf[MAX_TRACE_STRLEN];',
|
' char ftrace_buf[MAX_TRACE_STRLEN];',
|
||||||
' int unused __attribute__ ((unused));',
|
' int unused __attribute__ ((unused));',
|
||||||
' int trlen;',
|
' int trlen;',
|
||||||
' if (trace_event_get_state(%(event_id)s)) {',
|
' if (trace_event_get_state(%(event_id)s)) {',
|
||||||
' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
|
' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
|
||||||
' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
|
' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
|
||||||
' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
|
' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
|
||||||
' unused = write(trace_marker_fd, ftrace_buf, trlen);',
|
' unused = write(trace_marker_fd, ftrace_buf, trlen);',
|
||||||
|
' }',
|
||||||
' }',
|
' }',
|
||||||
' }',
|
|
||||||
name=event.name,
|
name=event.name,
|
||||||
args=event.args,
|
args=event.args,
|
||||||
event_id="TRACE_" + event.name.upper(),
|
event_id="TRACE_" + event.name.upper(),
|
||||||
|
|
|
@ -6,7 +6,7 @@ Stderr built-in backend.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
|
__copyright__ = "Copyright 2012-2016, Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__license__ = "GPL version 2 or (at your option) any later version"
|
__license__ = "GPL version 2 or (at your option) any later version"
|
||||||
|
|
||||||
__maintainer__ = "Stefan Hajnoczi"
|
__maintainer__ = "Stefan Hajnoczi"
|
||||||
|
@ -30,15 +30,21 @@ def generate_h(event):
|
||||||
if len(event.args) > 0:
|
if len(event.args) > 0:
|
||||||
argnames = ", " + argnames
|
argnames = ", " + argnames
|
||||||
|
|
||||||
out(' if (trace_event_get_state(%(event_id)s)) {',
|
if "vcpu" in event.properties:
|
||||||
' struct timeval _now;',
|
# already checked on the generic format code
|
||||||
' gettimeofday(&_now, NULL);',
|
cond = "true"
|
||||||
' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
|
else:
|
||||||
' getpid(),',
|
cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
|
||||||
' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
|
|
||||||
' %(argnames)s);',
|
out(' if (%(cond)s) {',
|
||||||
' }',
|
' struct timeval _now;',
|
||||||
event_id="TRACE_" + event.name.upper(),
|
' gettimeofday(&_now, NULL);',
|
||||||
|
' qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
|
||||||
|
' getpid(),',
|
||||||
|
' (size_t)_now.tv_sec, (size_t)_now.tv_usec',
|
||||||
|
' %(argnames)s);',
|
||||||
|
' }',
|
||||||
|
cond=cond,
|
||||||
name=event.name,
|
name=event.name,
|
||||||
fmt=event.fmt.rstrip("\n"),
|
fmt=event.fmt.rstrip("\n"),
|
||||||
argnames=argnames)
|
argnames=argnames)
|
||||||
|
|
|
@ -36,7 +36,7 @@ def generate_h_begin(events):
|
||||||
|
|
||||||
|
|
||||||
def generate_h(event):
|
def generate_h(event):
|
||||||
out(' _simple_%(api)s(%(args)s);',
|
out(' _simple_%(api)s(%(args)s);',
|
||||||
api=event.api(),
|
api=event.api(),
|
||||||
args=", ".join(event.args.names()))
|
args=", ".join(event.args.names()))
|
||||||
|
|
||||||
|
@ -68,16 +68,23 @@ def generate_c(event):
|
||||||
if len(event.args) == 0:
|
if len(event.args) == 0:
|
||||||
sizestr = '0'
|
sizestr = '0'
|
||||||
|
|
||||||
|
event_id = 'TRACE_' + event.name.upper()
|
||||||
|
if "vcpu" in event.properties:
|
||||||
|
# already checked on the generic format code
|
||||||
|
cond = "true"
|
||||||
|
else:
|
||||||
|
cond = "trace_event_get_state(%s)" % event_id
|
||||||
|
|
||||||
out('',
|
out('',
|
||||||
' if (!trace_event_get_state(%(event_id)s)) {',
|
' if (!%(cond)s) {',
|
||||||
' return;',
|
' return;',
|
||||||
' }',
|
' }',
|
||||||
'',
|
'',
|
||||||
' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
|
' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
|
||||||
' return; /* Trace Buffer Full, Event Dropped ! */',
|
' return; /* Trace Buffer Full, Event Dropped ! */',
|
||||||
' }',
|
' }',
|
||||||
event_id='TRACE_' + event.name.upper(),
|
cond=cond,
|
||||||
|
event_id=event_id,
|
||||||
size_str=sizestr)
|
size_str=sizestr)
|
||||||
|
|
||||||
if len(event.args) > 0:
|
if len(event.args) > 0:
|
||||||
|
|
|
@ -6,7 +6,7 @@ LTTng User Space Tracing backend.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
|
__copyright__ = "Copyright 2012-2016, Lluís Vilanova <vilanova@ac.upc.edu>"
|
||||||
__license__ = "GPL version 2 or (at your option) any later version"
|
__license__ = "GPL version 2 or (at your option) any later version"
|
||||||
|
|
||||||
__maintainer__ = "Stefan Hajnoczi"
|
__maintainer__ = "Stefan Hajnoczi"
|
||||||
|
@ -30,6 +30,6 @@ def generate_h(event):
|
||||||
if len(event.args) > 0:
|
if len(event.args) > 0:
|
||||||
argnames = ", " + argnames
|
argnames = ", " + argnames
|
||||||
|
|
||||||
out(' tracepoint(qemu, %(name)s%(tp_args)s);',
|
out(' tracepoint(qemu, %(name)s%(tp_args)s);',
|
||||||
name=event.name,
|
name=event.name,
|
||||||
tp_args=argnames)
|
tp_args=argnames)
|
||||||
|
|
|
@ -23,21 +23,36 @@ def generate(events, backend):
|
||||||
'#define TRACE__GENERATED_TRACERS_H',
|
'#define TRACE__GENERATED_TRACERS_H',
|
||||||
'',
|
'',
|
||||||
'#include "qemu-common.h"',
|
'#include "qemu-common.h"',
|
||||||
|
'#include "trace/control.h"',
|
||||||
'')
|
'')
|
||||||
|
|
||||||
backend.generate_begin(events)
|
backend.generate_begin(events)
|
||||||
|
|
||||||
for e in events:
|
for e in events:
|
||||||
|
if "vcpu" in e.properties:
|
||||||
|
trace_cpu = next(iter(e.args))[1]
|
||||||
|
cond = "trace_event_get_vcpu_state(%(cpu)s,"\
|
||||||
|
" TRACE_%(id)s,"\
|
||||||
|
" TRACE_VCPU_%(id)s)"\
|
||||||
|
% dict(
|
||||||
|
cpu=trace_cpu,
|
||||||
|
id=e.name.upper())
|
||||||
|
else:
|
||||||
|
cond = "true"
|
||||||
|
|
||||||
out('',
|
out('',
|
||||||
'static inline void %(api)s(%(args)s)',
|
'static inline void %(api)s(%(args)s)',
|
||||||
'{',
|
'{',
|
||||||
|
' if (%(cond)s) {',
|
||||||
api=e.api(),
|
api=e.api(),
|
||||||
args=e.args)
|
args=e.args,
|
||||||
|
cond=cond)
|
||||||
|
|
||||||
if "disable" not in e.properties:
|
if "disable" not in e.properties:
|
||||||
backend.generate(e)
|
backend.generate(e)
|
||||||
|
|
||||||
out('}')
|
out(' }',
|
||||||
|
'}')
|
||||||
|
|
||||||
backend.generate_end(events)
|
backend.generate_end(events)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue