[Qemu-devel] [PATCH] simpletrace: Improve the error message if event is not declared

Jose Ricardo Ziviani posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1496075404-8845-1-git-send-email-joserz@linux.vnet.ibm.com
Test checkpatch passed
Test docker passed
Test s390x passed
scripts/simpletrace.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH] simpletrace: Improve the error message if event is not declared
Posted by Jose Ricardo Ziviani 6 years, 10 months ago
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 <module>
    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 <joserz@linux.vnet.ibm.com>
---
 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)
-- 
2.7.4


Re: [Qemu-devel] [PATCH] simpletrace: Improve the error message if event is not declared
Posted by Philippe Mathieu-Daudé 6 years, 10 months ago
On 05/29/2017 01:30 PM, Jose Ricardo Ziviani wrote:
> 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 <module>
>     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 <joserz@linux.vnet.ibm.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  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)
>

Re: [Qemu-devel] [PATCH] simpletrace: Improve the error message if event is not declared
Posted by Stefan Hajnoczi 6 years, 10 months ago
On Mon, May 29, 2017 at 01:30:04PM -0300, Jose Ricardo Ziviani wrote:
> 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 <module>
>     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 <joserz@linux.vnet.ibm.com>
> ---
>  scripts/simpletrace.py | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan