From patchwork Wed Mar 21 21:52:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 148104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 680AAB73AC for ; Thu, 22 Mar 2012 09:43:22 +1100 (EST) Received: from localhost ([::1]:40372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SATTg-0004iB-QG for incoming@patchwork.ozlabs.org; Wed, 21 Mar 2012 17:53:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SATTG-0003rg-2b for qemu-devel@nongnu.org; Wed, 21 Mar 2012 17:53:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SATTE-0001f6-0B for qemu-devel@nongnu.org; Wed, 21 Mar 2012 17:53:29 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:42817 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SATTD-0001ep-DA for qemu-devel@nongnu.org; Wed, 21 Mar 2012 17:53:27 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id q2LLrMT7002156; Wed, 21 Mar 2012 22:53:22 +0100 Received: from localhost (unknown [84.88.53.92]) by gw.ac.upc.edu (Postfix) with ESMTP id DCBB02D0018; Wed, 21 Mar 2012 22:53:21 +0100 (CET) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Wed, 21 Mar 2012 22:52:50 +0100 Message-Id: <20120321215249.3272.91401.stgit@ginnungagap.bsc.es> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <20120321215224.3272.37570.stgit@ginnungagap.bsc.es> References: <20120321215224.3272.37570.stgit@ginnungagap.bsc.es> User-Agent: StGit/0.16 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id q2LLrMT7002156 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 147.83.33.10 Cc: stefanha@gmail.com, harsh@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v7 04/11] trace: [tracetool] Simplify event line parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Using regular expressions yields more compact and error-proof code when breaking the lines into pieces. Signed-off-by: LluĂ­s Vilanova Signed-off-by: Harsh Prateek Bora --- scripts/tracetool.py | 43 +++++++++++++++---------------------------- 1 files changed, 15 insertions(+), 28 deletions(-) diff --git a/scripts/tracetool.py b/scripts/tracetool.py index ff1519c..4f9060f 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -10,6 +10,7 @@ import sys import getopt +import re def usage(): print "Tracetool: Generate tracing code for trace events file on stdin" @@ -38,25 +39,14 @@ Options: ''' sys.exit(1) -def get_name(line, sep='('): - head, sep, tail = line.partition(sep) - property, sep, name = head.rpartition(' ') - return name - def get_properties(line, sep='('): head, sep, tail = line.partition(sep) property, sep, name = head.rpartition(' ') return property.split() -def get_args(line, sep1='(', sep2=')'): - head, sep1, tail = line.partition(sep1) - args, sep2, fmt_str = tail.partition(sep2) - return args - -def get_argnames(line, sep=','): +def get_argnames(args): nfields = 0 str = [] - args = get_args(line) for field in args.split(): nfields = nfields + 1 # Drop pointer star @@ -77,17 +67,6 @@ def get_argnames(line, sep=','): else: return '' -def get_argc(line): - argc = 0 - argnames = get_argnames(line) - if argnames: - for name in argnames.split(','): - argc = argc + 1 - return argc - -def get_fmt(line, sep=')'): - event, sep, fmt = line.partition(sep) - return fmt.rstrip('\n') def trace_h_begin(): print '''#ifndef TRACE_H @@ -400,15 +379,23 @@ trace_gen = { } # A trace event +cre = re.compile("(?P[^(\s]+)\((?P[^)]*)\)\s*(?P\".*)?") + class Event(object): def __init__(self, num, line): self.num = num - self.args = get_args(line) + m = cre.match(line) + assert m is not None + groups = m.groupdict('') + self.args = groups["args"] self.arglist = self.args.split(',') - self.name = get_name(line) - self.argc = get_argc(line) - self.argnames = get_argnames(line) - self.fmt = get_fmt(line) + self.name = groups["name"] + if len(self.arglist) == 1 and self.arglist[0] == "void": + self.argc = 0 + else: + self.argc = len(self.arglist) + self.argnames = get_argnames(self.args) + self.fmt = groups["fmt"] self.properties = get_properties(line) # Generator that yields Event objects given a trace-events file object