From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: saito.kazuya@jp.fujitsu.com,
Stefan Hajnoczi <stefanha@redhat.com>,
vilanova@ac.upc.edu
Subject: [Qemu-devel] [PATCH v2 2/4] trace: add tracetool simpletrace_stap format
Date: Sun, 22 Jun 2014 21:46:05 +0800 [thread overview]
Message-ID: <1403444767-2601-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1403444767-2601-1-git-send-email-stefanha@redhat.com>
This new tracetool "format" generates a SystemTap .stp file that outputs
simpletrace binary trace data.
In contrast to simpletrace or ftrace, SystemTap does not define its own
trace format. All output from SystemTap is generated by .stp files.
This patch lets us generate a .stp file that outputs in the simpletrace
binary format.
This makes it possible to reuse simpletrace.py to analyze traces
recorded using SystemTap. The simpletrace binary format is especially
useful for long-running traces like flight-recorder mode where string
formatting can be expensive.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/format/simpletrace_stap.py | 71 ++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 scripts/tracetool/format/simpletrace_stap.py
diff --git a/scripts/tracetool/format/simpletrace_stap.py b/scripts/tracetool/format/simpletrace_stap.py
new file mode 100644
index 0000000..7e44bc1
--- /dev/null
+++ b/scripts/tracetool/format/simpletrace_stap.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .stp file that outputs simpletrace binary traces (DTrace with SystemTAP only).
+"""
+
+__author__ = "Stefan Hajnoczi <redhat.com>"
+__copyright__ = "Copyright (C) 2014, Red Hat, Inc."
+__license__ = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__ = "stefanha@redhat.com"
+
+
+from tracetool import out
+from tracetool.backend.dtrace import binary, probeprefix
+from tracetool.backend.simple import is_string
+from tracetool.format.stap import stap_escape
+
+
+def generate(events, backend):
+ out('/* This file is autogenerated by tracetool, do not edit. */',
+ '')
+
+ for event_id, e in enumerate(events):
+ if 'disable' in e.properties:
+ continue
+
+ out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?',
+ '{',
+ probeprefix=probeprefix(),
+ name=e.name)
+
+ # Calculate record size
+ sizes = ['24'] # sizeof(TraceRecord)
+ for type_, name in e.args:
+ name = stap_escape(name)
+ if is_string(type_):
+ out(' try {',
+ ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"',
+ ' } catch {}',
+ ' arg%(name)s_len = strlen(arg%(name)s_str)',
+ name=name)
+ sizes.append('4 + arg%s_len' % name)
+ else:
+ sizes.append('8')
+ sizestr = ' + '.join(sizes)
+
+ # Generate format string and value pairs for record header and arguments
+ fields = [('8b', str(event_id)),
+ ('8b', 'gettimeofday_ns()'),
+ ('4b', sizestr),
+ ('4b', 'pid()')]
+ for type_, name in e.args:
+ name = stap_escape(name)
+ if is_string(type_):
+ fields.extend([('4b', 'arg%s_len' % name),
+ ('.*s', 'arg%s_len, arg%s_str' % (name, name))])
+ else:
+ fields.append(('8b', name))
+
+ # Emit the entire record in a single SystemTap printf()
+ fmt_str = '%'.join(fmt for fmt, _ in fields)
+ arg_str = ', '.join(arg for _, arg in fields)
+ out(' printf("%%%(fmt_str)s", %(arg_str)s)',
+ fmt_str=fmt_str, arg_str=arg_str)
+
+ out('}')
+
+ out()
--
1.9.3
next prev parent reply other threads:[~2014-06-22 13:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-22 13:46 [Qemu-devel] [PATCH v2 0/4] trace: add simpletrace-stap format to generate binary trace Stefan Hajnoczi
2014-06-22 13:46 ` [Qemu-devel] [PATCH v2 1/4] trace: extract stap_escape() function for reuse Stefan Hajnoczi
2014-06-22 13:46 ` Stefan Hajnoczi [this message]
2014-06-22 13:46 ` [Qemu-devel] [PATCH v2 3/4] simpletrace: add simpletrace.py --no-header option Stefan Hajnoczi
2014-06-22 13:46 ` [Qemu-devel] [PATCH v2 4/4] trace: install simpletrace SystemTap tapset Stefan Hajnoczi
2014-07-09 7:06 ` [Qemu-devel] [PATCH v2 0/4] trace: add simpletrace-stap format to generate binary trace Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403444767-2601-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=saito.kazuya@jp.fujitsu.com \
--cc=vilanova@ac.upc.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).