From patchwork Wed Jun 7 18:55:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 772668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wjd7p6gJYz9s8N for ; Thu, 8 Jun 2017 04:56:38 +1000 (AEST) Received: from localhost ([::1]:45749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIg8C-0003iZ-EZ for incoming@patchwork.ozlabs.org; Wed, 07 Jun 2017 14:56:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIg7U-0003gN-9d for qemu-devel@nongnu.org; Wed, 07 Jun 2017 14:55:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIg7T-00075a-GI for qemu-devel@nongnu.org; Wed, 07 Jun 2017 14:55:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIg7T-000750-B2 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 14:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48BD97F3EC; Wed, 7 Jun 2017 18:55:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 48BD97F3EC Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 48BD97F3EC Received: from localhost (ovpn-117-84.ams2.redhat.com [10.36.117.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E7E75DD65; Wed, 7 Jun 2017 18:55:49 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 7 Jun 2017 19:55:40 +0100 Message-Id: <20170607185540.12767-2-stefanha@redhat.com> In-Reply-To: <20170607185540.12767-1-stefanha@redhat.com> References: <20170607185540.12767-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 07 Jun 2017 18:55:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] simpletrace: Improve the error message if event is not declared X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Jose Ricardo Ziviani , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jose Ricardo Ziviani Today, if we use a trace-event file which does not declare an event existing in the log file we'll get the following error: $ scripts/simpletrace.py trace-events trace-68508 Traceback (most recent call last): File "scripts/simpletrace.py", line 242, in run(Formatter()) File "scripts/simpletrace.py", line 217, in run process(events, sys.argv[2], analyzer, read_header=read_header) File "scripts/simpletrace.py", line 192, in process for rec in read_trace_records(edict, log): File "scripts/simpletrace.py", line 107, in read_trace_records rec = read_record(edict, idtoname, fobj) File "scripts/simpletrace.py", line 71, in read_record return get_record(edict, idtoname, rechdr, fobj) File "scripts/simpletrace.py", line 45, in get_record event = edict[name] KeyError: 'qemu_mutex_locked' This patch improves this error by adding a hint instead of just that KeyError log: $ scripts/simpletrace.py trace-events trace-68508 'qemu_mutex_locked' event is logged but is not declared in the trace events file, try using trace-events-all instead. Signed-off-by: Jose Ricardo Ziviani Reviewed-by: Philippe Mathieu-Daudé Message-id: 1496075404-8845-1-git-send-email-joserz@linux.vnet.ibm.com Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index d60b3a0..f1be6e4 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -42,7 +42,15 @@ def get_record(edict, idtoname, rechdr, fobj): event_id = rechdr[0] name = idtoname[event_id] rec = (name, rechdr[1], rechdr[3]) - event = edict[name] + try: + event = edict[name] + except KeyError, e: + import sys + sys.stderr.write('%s event is logged but is not declared ' \ + 'in the trace events file, try using ' \ + 'trace-events-all instead.\n' % str(e)) + sys.exit(1) + for type, name in event.args: if is_string(type): l = fobj.read(4)