Commit 40b9cd25 authored by Lluís Vilanova's avatar Lluís Vilanova Committed by Stefan Hajnoczi
Browse files

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: default avatarLluís Vilanova <vilanova@ac.upc.edu>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 48151859
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ DTrace/SystemTAP backend.
"""

__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"

__maintainer__ = "Stefan Hajnoczi"
+16 −10
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Stderr built-in backend.
"""

__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"

__maintainer__ = "Stefan Hajnoczi"
@@ -30,7 +30,13 @@ def generate_h(event):
    if len(event.args) > 0:
        argnames = ", " + argnames

    out('    if (trace_event_get_state(%(event_id)s)) {',
    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) {',
        '            struct timeval _now;',
        '            gettimeofday(&_now, NULL);',
        '            qemu_log_mask(LOG_TRACE, "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",',
@@ -38,7 +44,7 @@ def generate_h(event):
        '                          (size_t)_now.tv_sec, (size_t)_now.tv_usec',
        '                          %(argnames)s);',
        '        }',
        event_id="TRACE_" + event.name.upper(),
        cond=cond,
        name=event.name,
        fmt=event.fmt.rstrip("\n"),
        argnames=argnames)
+10 −3
Original line number Diff line number Diff line
@@ -68,16 +68,23 @@ def generate_c(event):
    if len(event.args) == 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('',
        '    if (!trace_event_get_state(%(event_id)s)) {',
        '    if (!%(cond)s) {',
        '        return;',
        '    }',
        '',
        '    if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
        '        return; /* Trace Buffer Full, Event Dropped ! */',
        '    }',
        event_id='TRACE_' + event.name.upper(),
        cond=cond,
        event_id=event_id,
        size_str=sizestr)

    if len(event.args) > 0:
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ LTTng User Space Tracing backend.
"""

__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"

__maintainer__ = "Stefan Hajnoczi"
+17 −2
Original line number Diff line number Diff line
@@ -23,21 +23,36 @@ def generate(events, backend):
        '#define TRACE__GENERATED_TRACERS_H',
        '',
        '#include "qemu-common.h"',
        '#include "trace/control.h"',
        '')

    backend.generate_begin(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('',
            'static inline void %(api)s(%(args)s)',
            '{',
            '    if (%(cond)s) {',
            api=e.api(),
            args=e.args)
            args=e.args,
            cond=cond)

        if "disable" not in e.properties:
            backend.generate(e)

        out('}')
        out('    }',
            '}')

    backend.generate_end(events)

+10 −10

File changed.

Contains only whitespace changes.

Loading