Commit 77e2b172 authored by Lluís Vilanova's avatar Lluís Vilanova Committed by Stefan Hajnoczi
Browse files

trace: Add QAPI/QMP interfaces to query and control per-vCPU tracing state

parent bd71211d
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -646,10 +646,10 @@ ETEXI

    {
        .name       = "trace-events",
        .args_type  = "name:s?",
        .params     = "[name]",
        .args_type  = "name:s?,vcpu:i?",
        .params     = "[name] [vcpu]",
        .help       = "show available trace-events & their state "
                      "(name: event name pattern)",
                      "(name: event name pattern; vcpu: vCPU to query, default is any)",
        .mhandler.cmd = hmp_info_trace_events,
        .command_completion = info_trace_events_completion,
    },
+4 −3
Original line number Diff line number Diff line
@@ -281,9 +281,10 @@ ETEXI

    {
        .name       = "trace-event",
        .args_type  = "name:s,option:b",
        .params     = "name on|off",
        .help       = "changes status of a specific trace event",
        .args_type  = "name:s,option:b,vcpu:i?",
        .params     = "name on|off [vcpu]",
        .help       = "changes status of a specific trace event "
                      "(vcpu: vCPU to set, default is all)",
        .mhandler.cmd = hmp_trace_event,
        .command_completion = trace_event_completion,
    },
+15 −2
Original line number Diff line number Diff line
@@ -904,9 +904,16 @@ static void hmp_trace_event(Monitor *mon, const QDict *qdict)
{
    const char *tp_name = qdict_get_str(qdict, "name");
    bool new_state = qdict_get_bool(qdict, "option");
    bool has_vcpu = qdict_haskey(qdict, "vcpu");
    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
    Error *local_err = NULL;

    qmp_trace_event_set_state(tp_name, new_state, true, true, &local_err);
    if (vcpu < 0) {
        monitor_printf(mon, "argument vcpu must be positive");
        return;
    }

    qmp_trace_event_set_state(tp_name, new_state, true, true, has_vcpu, vcpu, &local_err);
    if (local_err) {
        error_report_err(local_err);
    }
@@ -1066,6 +1073,8 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
{
    const char *name = qdict_get_try_str(qdict, "name");
    bool has_vcpu = qdict_haskey(qdict, "vcpu");
    int vcpu = qdict_get_try_int(qdict, "vcpu", 0);
    TraceEventInfoList *events;
    TraceEventInfoList *elem;
    Error *local_err = NULL;
@@ -1073,8 +1082,12 @@ static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
    if (name == NULL) {
        name = "*";
    }
    if (vcpu < 0) {
        monitor_printf(mon, "argument vcpu must be positive");
        return;
    }

    events = qmp_trace_event_get_state(name, &local_err);
    events = qmp_trace_event_get_state(name, has_vcpu, vcpu, &local_err);
    if (local_err) {
        error_report_err(local_err);
        return;
+29 −4
Original line number Diff line number Diff line
# -*- mode: python -*-
#
# Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu>
# Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
#
# This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory.
@@ -29,11 +29,15 @@
#
# @name: Event name.
# @state: Tracing state.
# @vcpu: Whether this is a per-vCPU event (since 2.7).
#
# An event is per-vCPU if it has the "vcpu" property in the "trace-events"
# files.
#
# Since 2.2
##
{ 'struct': 'TraceEventInfo',
  'data': {'name': 'str', 'state': 'TraceEventState'} }
  'data': {'name': 'str', 'state': 'TraceEventState', 'vcpu': 'bool'} }

##
# @trace-event-get-state:
@@ -41,13 +45,23 @@
# Query the state of events.
#
# @name: Event name pattern (case-sensitive glob).
# @vcpu: #optional The vCPU to query (any by default; since 2.7).
#
# Returns: a list of @TraceEventInfo for the matching events
#
# An event is returned if:
# - its name matches the @name pattern, and
# - if @vcpu is given, the event has the "vcpu" property.
#
# Therefore, if @vcpu is given, the operation will only match per-vCPU events,
# returning their state on the specified vCPU. Special case: if @name is an
# exact match, @vcpu is given and the event does not have the "vcpu" property,
# an error is returned.
#
# Since 2.2
##
{ 'command': 'trace-event-get-state',
  'data': {'name': 'str'},
  'data': {'name': 'str', '*vcpu': 'int'},
  'returns': ['TraceEventInfo'] }

##
@@ -58,8 +72,19 @@
# @name: Event name pattern (case-sensitive glob).
# @enable: Whether to enable tracing.
# @ignore-unavailable: #optional Do not match unavailable events with @name.
# @vcpu: #optional The vCPU to act upon (all by default; since 2.7).
#
# An event's state is modified if:
# - its name matches the @name pattern, and
# - if @vcpu is given, the event has the "vcpu" property.
#
# Therefore, if @vcpu is given, the operation will only match per-vCPU events,
# setting their state on the specified vCPU. Special case: if @name is an exact
# match, @vcpu is given and the event does not have the "vcpu" property, an
# error is returned.
#
# Since 2.2
##
{ 'command': 'trace-event-set-state',
  'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool'} }
  'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool',
           '*vcpu': 'int'} }
+33 −2
Original line number Diff line number Diff line
@@ -4715,7 +4715,7 @@ EQMP

    {
        .name       = "trace-event-get-state",
        .args_type  = "name:s",
        .args_type  = "name:s,vcpu:i?",
        .mhandler.cmd_new = qmp_marshal_trace_event_get_state,
    },

@@ -4725,6 +4725,20 @@ trace-event-get-state

Query the state of events.

Arguments:

- "name": Event name pattern (json-string).
- "vcpu": The vCPU to query, any vCPU by default (json-int, optional).

An event is returned if:
- its name matches the "name" pattern, and
- if "vcpu" is given, the event has the "vcpu" property.

Therefore, if "vcpu" is given, the operation will only match per-vCPU events,
returning their state on the specified vCPU. Special case: if "name" is an exact
match, "vcpu" is given and the event does not have the "vcpu" property, an error
is returned.

Example:

-> { "execute": "trace-event-get-state", "arguments": { "name": "qemu_memalign" } }
@@ -4733,7 +4747,7 @@ EQMP

    {
        .name       = "trace-event-set-state",
        .args_type  = "name:s,enable:b,ignore-unavailable:b?",
        .args_type  = "name:s,enable:b,ignore-unavailable:b?,vcpu:i?",
        .mhandler.cmd_new = qmp_marshal_trace_event_set_state,
    },

@@ -4743,6 +4757,23 @@ trace-event-set-state

Set the state of events.

Arguments:

- "name": Event name pattern (json-string).
- "enable": Whether to enable or disable the event (json-bool).
- "ignore-unavailable": Whether to ignore errors for events that cannot be
  changed (json-bool, optional).
- "vcpu": The vCPU to act upon, all vCPUs by default (json-int, optional).

An event's state is modified if:
- its name matches the "name" pattern, and
- if "vcpu" is given, the event has the "vcpu" property.

Therefore, if "vcpu" is given, the operation will only match per-vCPU events,
setting their state on the specified vCPU. Special case: if "name" is an exact
match, "vcpu" is given and the event does not have the "vcpu" property, an error
is returned.

Example:

-> { "execute": "trace-event-set-state", "arguments": { "name": "qemu_memalign", "enable": "true" } }
Loading