Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-requ…
Browse files Browse the repository at this point in the history
…est' into staging

# gpg: Signature made Fri 26 Sep 2014 11:59:34 BST using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <[email protected]>"
# gpg:                 aka "Stefan Hajnoczi <[email protected]>"

* remotes/stefanha/tags/tracing-pull-request:
  ohci: drop computed flags from trace events
  ohci: Split long traces to smaller ones
  scripts/tracetool: don't barf on formats with precision
  trace: install trace-events file
  trace-events: Fix comments pointing to source files
  trace-events: Drop orphaned monitor trace event
  trace-events: Drop unused megasas trace event
  cleanup-trace-events.pl: Tighten search for trace event call
  trace: tighten up trace-events regex to fix bad parse
  trace-events: drop orphan iscsi trace events
  trace-events: drop orphan usb_mtp_data_out
  trace-events: drop orphan virtio_blk_data_plane_complete_request
  trace: [hmp] Reimplement "trace-event" and "info trace-events" using QMP
  trace: [qmp] Add commands to query and control event tracing state
  trace: docs: add trace file description
  trace: [ust] Fix format string computation in tcg-enabled events

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Sep 26, 2014
2 parents 15124e1 + bc0d104 commit da1c4ec
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 79 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ endif
set -e; for x in $(KEYMAPS); do \
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
done
$(INSTALL_DATA) $(SRC_PATH)/trace-events "$(DESTDIR)$(qemu_datadir)/trace-events"
for d in $(TARGET_DIRS); do \
$(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \
done
Expand Down
1 change: 0 additions & 1 deletion block/iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "qemu/bitops.h"
#include "qemu/bitmap.h"
#include "block/block_int.h"
#include "trace.h"
#include "block/scsi.h"
#include "qemu/iov.h"
#include "sysemu/sysemu.h"
Expand Down
2 changes: 1 addition & 1 deletion docs/tracing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for debugging, profiling, and observing execution.

4. Pretty-print the binary trace file:

./scripts/simpletrace.py trace-events trace-*
./scripts/simpletrace.py trace-events trace-* # Override * with QEMU <pid>

== Trace events ==

Expand Down
21 changes: 12 additions & 9 deletions hw/usb/hcd-ohci.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,13 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed,
trace_usb_ohci_iso_td_head(
ed->head & OHCI_DPTR_MASK, ed->tail & OHCI_DPTR_MASK,
iso_td.flags, iso_td.bp, iso_td.next, iso_td.be,
iso_td.offset[0], iso_td.offset[1], iso_td.offset[2], iso_td.offset[3],
iso_td.offset[4], iso_td.offset[5], iso_td.offset[6], iso_td.offset[7],
ohci->frame_number, starting_frame,
frame_count, relative_frame_number,
OHCI_BM(iso_td.flags, TD_DI), OHCI_BM(iso_td.flags, TD_CC));
ohci->frame_number, starting_frame,
frame_count, relative_frame_number);
trace_usb_ohci_iso_td_head_offset(
iso_td.offset[0], iso_td.offset[1],
iso_td.offset[2], iso_td.offset[3],
iso_td.offset[4], iso_td.offset[5],
iso_td.offset[6], iso_td.offset[7]);

if (relative_frame_number < 0) {
trace_usb_ohci_iso_td_relative_frame_number_neg(relative_frame_number);
Expand Down Expand Up @@ -1199,13 +1201,14 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int completion)
}

while ((ed.head & OHCI_DPTR_MASK) != ed.tail) {
trace_usb_ohci_ed_pkt(cur,
trace_usb_ohci_ed_pkt(cur, (ed.head & OHCI_ED_H) != 0,
(ed.head & OHCI_ED_C) != 0, ed.head & OHCI_DPTR_MASK,
ed.tail & OHCI_DPTR_MASK, ed.next & OHCI_DPTR_MASK);
trace_usb_ohci_ed_pkt_flags(
OHCI_BM(ed.flags, ED_FA), OHCI_BM(ed.flags, ED_EN),
OHCI_BM(ed.flags, ED_D), (ed.flags & OHCI_ED_S)!= 0,
(ed.flags & OHCI_ED_K) != 0, (ed.flags & OHCI_ED_F) != 0,
OHCI_BM(ed.flags, ED_MPS), (ed.head & OHCI_ED_H) != 0,
(ed.head & OHCI_ED_C) != 0, ed.head & OHCI_DPTR_MASK,
ed.tail & OHCI_DPTR_MASK, ed.next & OHCI_DPTR_MASK);
OHCI_BM(ed.flags, ED_MPS));

active = 1;

Expand Down
27 changes: 14 additions & 13 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,19 +886,12 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
{
const char *tp_name = qdict_get_str(qdict, "name");
bool new_state = qdict_get_bool(qdict, "option");
Error *local_err = NULL;

bool found = false;
TraceEvent *ev = NULL;
while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
found = true;
if (!trace_event_get_state_static(ev)) {
monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
} else {
trace_event_set_state_dynamic(ev, new_state);
}
}
if (!trace_event_is_pattern(tp_name) && !found) {
monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
qmp_trace_event_set_state(tp_name, new_state, true, true, &local_err);
if (local_err) {
qerror_report_err(local_err);
error_free(local_err);
}
}

Expand Down Expand Up @@ -1079,7 +1072,15 @@ static void do_info_cpu_stats(Monitor *mon, const QDict *qdict)

static void do_trace_print_events(Monitor *mon, const QDict *qdict)
{
trace_print_events((FILE *)mon, &monitor_fprintf);
TraceEventInfoList *events = qmp_trace_event_get_state("*", NULL);
TraceEventInfoList *elem;

for (elem = events; elem != NULL; elem = elem->next) {
monitor_printf(mon, "%s : state %u\n",
elem->value->name,
elem->value->state == TRACE_EVENT_STATE_ENABLED ? 1 : 0);
}
qapi_free_TraceEventInfoList(events);
}

static int client_migrate_info(Monitor *mon, const QDict *qdict,
Expand Down
3 changes: 3 additions & 0 deletions qapi-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# QAPI event definitions
{ 'include': 'qapi/event.json' }

# Tracing commands
{ 'include': 'qapi/trace.json' }

##
# LostTickPolicy:
#
Expand Down
65 changes: 65 additions & 0 deletions qapi/trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- mode: python -*-
#
# Copyright (C) 2011-2014 Lluís Vilanova <[email protected]>
#
# This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory.


##
# @TraceEventState:
#
# State of a tracing event.
#
# @unavailable: The event is statically disabled.
#
# @disabled: The event is dynamically disabled.
#
# @enabled: The event is dynamically enabled.
#
# Since 2.2
##
{ 'enum': 'TraceEventState',
'data': ['unavailable', 'disabled', 'enabled'] }

##
# @TraceEventInfo:
#
# Information of a tracing event.
#
# @name: Event name.
# @state: Tracing state.
#
# Since 2.2
##
{ 'type': 'TraceEventInfo',
'data': {'name': 'str', 'state': 'TraceEventState'} }

##
# @trace-event-get-state:
#
# Query the state of events.
#
# @name: Event name pattern (case-sensitive glob).
#
# Returns: a list of @TraceEventInfo for the matching events
#
# Since 2.2
##
{ 'command': 'trace-event-get-state',
'data': {'name': 'str'},
'returns': ['TraceEventInfo'] }

##
# @trace-event-set-state:
#
# Set the dynamic tracing state of events.
#
# @name: Event name pattern (case-sensitive glob).
# @enable: Whether to enable tracing.
# @ignore-unavailable: #optional Do not match unavailable events with @name.
#
# Since 2.2
##
{ 'command': 'trace-event-set-state',
'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool'} }
35 changes: 35 additions & 0 deletions qmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3752,5 +3752,40 @@ Example:
-> { "execute": "rtc-reset-reinjection" }
<- { "return": {} }
EQMP
{
.name = "trace-event-get-state",
.args_type = "name:s",
.mhandler.cmd_new = qmp_marshal_input_trace_event_get_state,
},

SQMP
trace-event-get-state
---------------------

Query the state of events.

Example:

-> { "execute": "trace-event-get-state", "arguments": { "name": "qemu_memalign" } }
<- { "return": [ { "name": "qemu_memalign", "state": "disabled" } ] }
EQMP

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

SQMP
trace-event-set-state
---------------------

Set the state of events.

Example:

-> { "execute": "trace-event-set-state", "arguments": { "name": "qemu_memalign", "enable": "true" } }
<- { "return": {} }
EQMP
2 changes: 1 addition & 1 deletion scripts/cleanup-trace-events.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sub out {

while (<>) {
if (/^(disable )?([a-z_0-9]+)\(/) {
open GREP, '-|', 'git', 'grep', '-l', "trace_$2"
open GREP, '-|', 'git', 'grep', '-lw', "trace_$2"
or die "run git grep: $!";
my $fname;
while ($fname = <GREP>) {
Expand Down
23 changes: 12 additions & 11 deletions scripts/tracetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,19 @@ class Event(object):
Properties of the event.
args : Arguments
The event arguments.
arg_fmts : str
The format strings for each argument.
"""

_CRE = re.compile("((?P<props>.*)\s+)?"
"(?P<name>[^(\s]+)"
_CRE = re.compile("((?P<props>[\w\s]+)\s+)?"
"(?P<name>\w+)"
"\((?P<args>[^)]*)\)"
"\s*"
"(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
"\s*")
_FMT = re.compile("(%\w+|%.*PRI\S+)")

_VALID_PROPS = set(["disable", "tcg", "tcg-trans", "tcg-exec"])

def __init__(self, name, props, fmt, args, arg_fmts, orig=None):
def __init__(self, name, props, fmt, args, orig=None):
"""
Parameters
----------
Expand All @@ -162,8 +160,6 @@ def __init__(self, name, props, fmt, args, arg_fmts, orig=None):
Event printing format (or formats).
args : Arguments
Event arguments.
arg_fmts : list of str
Format strings for each argument.
orig : Event or None
Original Event before transformation.
Expand All @@ -172,7 +168,6 @@ def __init__(self, name, props, fmt, args, arg_fmts, orig=None):
self.properties = props
self.fmt = fmt
self.args = args
self.arg_fmts = arg_fmts

if orig is None:
self.original = weakref.ref(self)
Expand Down Expand Up @@ -210,7 +205,6 @@ def build(line_str):
if len(fmt_trans) > 0:
fmt = [fmt_trans, fmt]
args = Arguments.build(groups["args"])
arg_fmts = Event._FMT.findall(fmt)

if "tcg-trans" in props:
raise ValueError("Invalid property 'tcg-trans'")
Expand All @@ -221,7 +215,7 @@ def build(line_str):
if "tcg" in props and isinstance(fmt, str):
raise ValueError("Events with 'tcg' property must have two formats")

return Event(name, props, fmt, args, arg_fmts)
return Event(name, props, fmt, args)

def __repr__(self):
"""Evaluable string representation for this object."""
Expand All @@ -234,6 +228,13 @@ def __repr__(self):
self.args,
fmt)

_FMT = re.compile("(%[\d\.]*\w+|%.*PRI\S+)")

def formats(self):
"""List of argument print formats."""
assert not isinstance(self.fmt, list)
return self._FMT.findall(self.fmt)

QEMU_TRACE = "trace_%(name)s"
QEMU_TRACE_TCG = QEMU_TRACE + "_tcg"

Expand Down
2 changes: 1 addition & 1 deletion scripts/tracetool/format/ust_events_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate(events, backend):

types = e.args.types()
names = e.args.names()
fmts = e.arg_fmts
fmts = e.formats()
for t,n,f in zip(types, names, fmts):
if ('char *' in t) or ('char*' in t):
out(' ctf_string(' + n + ', ' + n + ')')
Expand Down
Loading

0 comments on commit da1c4ec

Please sign in to comment.