From f0517c283999b142affef029dff11631ac5c93d5 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 16 Aug 2017 11:47:59 +0200 Subject: [PATCH 2/4] simpletrace: fix flight recorder --no-header option RH-Author: Stefan Hajnoczi Message-id: <20170816114759.8421-3-stefanha@redhat.com> Patchwork-id: 75956 O-Subject: [RHV-7.4.z qemu-kvm-rhev PATCH 2/2] simpletrace: fix flight recorder --no-header option Bugzilla: 1482515 RH-Acked-by: Dr. David Alan Gilbert RH-Acked-by: Markus Armbruster RH-Acked-by: John Snow The simpletrace.py script can pretty-print flight recorder ring buffers. These are not full simpletrace binary trace files but just the end of a trace file. There is no header and the event ID mapping information is often unavailable since the ring buffer may have filled up and discarded event ID mapping records. The simpletrace.stp script that generates ring buffer traces uses the same trace-events-all input file as simpletrace.py. Therefore both scripts have the same global ordering of trace events. A dynamic event ID mapping isn't necessary: just use the trace-events-all file as the reference for how event IDs are numbered. It is now possible to analyze simpletrace.stp ring buffers again using: $ ./simpletrace.py trace-events-all path/to/ring-buffer Signed-off-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrange Message-id: 20170815084430.7128-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi (cherry picked from commit 840d8351774664d01c328d31ed33b0e2d85c866e) Signed-off-by: Stefan Hajnoczi Signed-off-by: Miroslav Rezanina --- scripts/simpletrace.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 4c99004..1e29e64 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -89,11 +89,17 @@ def read_trace_header(fobj): raise ValueError('Log format %d not supported with this QEMU release!' % log_version) -def read_trace_records(edict, fobj): - """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6).""" - idtoname = { - dropped_event_id: "dropped" - } +def read_trace_records(edict, idtoname, fobj): + """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6). + + Note that `idtoname` is modified if the file contains mapping records. + + Args: + edict (str -> Event): events dict, indexed by name + idtoname (int -> str): event names dict, indexed by event ID + fobj (file): input file + + """ while True: t = fobj.read(8) if len(t) == 0: @@ -142,10 +148,16 @@ def process(events, log, analyzer, read_header=True): dropped_event = Event.build("Dropped_Event(uint64_t num_events_dropped)") edict = {"dropped": dropped_event} + idtoname = {dropped_event_id: "dropped"} for event in events: edict[event.name] = event + # If there is no header assume event ID mapping matches events list + if not read_header: + for event_id, event in enumerate(events): + idtoname[event_id] = event.name + def build_fn(analyzer, event): if isinstance(event, str): return analyzer.catchall @@ -168,7 +180,7 @@ def process(events, log, analyzer, read_header=True): analyzer.begin() fn_cache = {} - for rec in read_trace_records(edict, log): + for rec in read_trace_records(edict, idtoname, log): event_num = rec[0] event = edict[event_num] if event_num not in fn_cache: -- 1.8.3.1