From patchwork Sat May 22 21:08:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 101682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4ML8qOg030951 for ; Sat, 22 May 2010 21:08:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758717Ab0EVVIp (ORCPT ); Sat, 22 May 2010 17:08:45 -0400 Received: from mtagate1.de.ibm.com ([195.212.17.161]:48940 "EHLO mtagate1.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758367Ab0EVVIh (ORCPT ); Sat, 22 May 2010 17:08:37 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate1.de.ibm.com (8.13.1/8.13.1) with ESMTP id o4ML8Vcp001040 for ; Sat, 22 May 2010 21:08:31 GMT Received: from d12av04.megacenter.de.ibm.com (d12av04.megacenter.de.ibm.com [9.149.165.229]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o4ML8Vk2856096 for ; Sat, 22 May 2010 23:08:31 +0200 Received: from d12av04.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av04.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o4ML8Ur5021970 for ; Sat, 22 May 2010 23:08:30 +0200 Received: from stefan-thinkpad.ibm.com (sig-9-145-133-4.de.ibm.com [9.145.133.4]) by d12av04.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o4ML8SrQ021941; Sat, 22 May 2010 23:08:29 +0200 From: Stefan Hajnoczi To: , Cc: Jan Kiszka , Prerna Saxena , Anthony Liguori , Stefan Hajnoczi Subject: [PATCH 2/5] trace: Add simple built-in tracing backend Date: Sat, 22 May 2010 22:08:20 +0100 Message-Id: <1274562503-10713-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1274562503-10713-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1274562503-10713-1-git-send-email-stefanha@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 22 May 2010 21:08:53 +0000 (UTC) diff --git a/.gitignore b/.gitignore index 4644557..68fb21d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ config-host.* config-target.* trace.h trace.c +events.py *-softmmu *-darwin-user *-linux-user @@ -39,6 +40,7 @@ qemu-monitor.texi *.log *.pdf *.pg +*.pyc *.toc *.tp *.vr diff --git a/Makefile.objs b/Makefile.objs index 9bbdf6f..d870767 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -252,6 +252,9 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o # trace trace-obj-y = trace.o +ifeq ($(TRACE_BACKEND),simple) +trace-obj-y += simpletrace.o +endif vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) diff --git a/configure b/configure index 5e66f3a..d599879 100755 --- a/configure +++ b/configure @@ -829,7 +829,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" -echo " --trace-backend=B Trace backend nop" +echo " --trace-backend=B Trace backend nop simple" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 diff --git a/simpletrace.c b/simpletrace.c new file mode 100644 index 0000000..2fec4d3 --- /dev/null +++ b/simpletrace.c @@ -0,0 +1,64 @@ +#include +#include +#include "trace.h" + +typedef struct { + unsigned long event; + unsigned long x1; + unsigned long x2; + unsigned long x3; + unsigned long x4; + unsigned long x5; +} TraceRecord; + +enum { + TRACE_BUF_LEN = 64 * 1024 / sizeof(TraceRecord), +}; + +static TraceRecord trace_buf[TRACE_BUF_LEN]; +static unsigned int trace_idx; +static FILE *trace_fp; + +static void trace(TraceEvent event, unsigned long x1, + unsigned long x2, unsigned long x3, + unsigned long x4, unsigned long x5) { + TraceRecord *rec = &trace_buf[trace_idx]; + rec->event = event; + rec->x1 = x1; + rec->x2 = x2; + rec->x3 = x3; + rec->x4 = x4; + rec->x5 = x5; + + if (++trace_idx == TRACE_BUF_LEN) { + trace_idx = 0; + + if (!trace_fp) { + trace_fp = fopen("/tmp/trace.log", "w"); + } + if (trace_fp) { + size_t result = fwrite(trace_buf, sizeof trace_buf, 1, trace_fp); + result = result; + } + } +} + +void trace1(TraceEvent event, unsigned long x1) { + trace(event, x1, 0, 0, 0, 0); +} + +void trace2(TraceEvent event, unsigned long x1, unsigned long x2) { + trace(event, x1, x2, 0, 0, 0); +} + +void trace3(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3) { + trace(event, x1, x2, x3, 0, 0); +} + +void trace4(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4) { + trace(event, x1, x2, x3, x4, 0); +} + +void trace5(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5) { + trace(event, x1, x2, x3, x4, x5); +} diff --git a/simpletrace.py b/simpletrace.py new file mode 100755 index 0000000..70609cf --- /dev/null +++ b/simpletrace.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import sys +import struct + +try: + from events import events +except ImportError: + sys.stderr.write('''Unable to import trace events from current working directory. Please run: +tracetool --simple --py events.py\n''') + sys.exit(1) + +trace_fmt = 'LLLLLL' +trace_len = struct.calcsize(trace_fmt) + +def read_record(fobj): + s = fobj.read(trace_len) + if len(s) != trace_len: + return None + return struct.unpack(trace_fmt, s) + +def format_record(rec): + event = events[rec[0]] + fields = [event[0]] + for i in xrange(1, len(event)): + fields.append('%s=0x%x' % (event[i], rec[i])) + return ' '.join(fields) + +if len(sys.argv) != 2: + sys.stderr.write('usage: %s \n' % sys.argv[0]) + sys.exit(1) + +f = open(sys.argv[1], 'rb') +while True: + rec = read_record(f) + if rec is None: + break + + print format_record(rec) diff --git a/tracetool b/tracetool index e243d42..bcd163e 100755 --- a/tracetool +++ b/tracetool @@ -3,15 +3,17 @@ usage() { cat >&2 <