trace: include filename when printing parser error messages
Improves error messages from: ValueError: Error on line 72: need more than 1 value to unpack To ValueError: Error at /home/berrange/src/virt/qemu/trace-events:72: need more than 1 value to unpack Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20180306154650.24075-1-berrange@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
e42860ae83
commit
86b5aacfb9
@ -168,7 +168,7 @@ class Analyzer(object):
|
|||||||
def process(events, log, analyzer, read_header=True):
|
def process(events, log, analyzer, read_header=True):
|
||||||
"""Invoke an analyzer on each event in a log."""
|
"""Invoke an analyzer on each event in a log."""
|
||||||
if isinstance(events, str):
|
if isinstance(events, str):
|
||||||
events = read_events(open(events, 'r'))
|
events = read_events(open(events, 'r'), events)
|
||||||
if isinstance(log, str):
|
if isinstance(log, str):
|
||||||
log = open(log, 'rb')
|
log = open(log, 'rb')
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ def run(analyzer):
|
|||||||
'<trace-file>\n' % sys.argv[0])
|
'<trace-file>\n' % sys.argv[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
events = read_events(open(sys.argv[1], 'r'))
|
events = read_events(open(sys.argv[1], 'r'), sys.argv[1])
|
||||||
process(events, sys.argv[2], analyzer, read_header=read_header)
|
process(events, sys.argv[2], analyzer, read_header=read_header)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -142,7 +142,7 @@ def main(args):
|
|||||||
events = []
|
events = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
with open(arg, "r") as fh:
|
with open(arg, "r") as fh:
|
||||||
events.extend(tracetool.read_events(fh))
|
events.extend(tracetool.read_events(fh, arg))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tracetool.generate(events, arg_group, arg_format, arg_backends,
|
tracetool.generate(events, arg_group, arg_format, arg_backends,
|
||||||
|
@ -291,13 +291,15 @@ class Event(object):
|
|||||||
self)
|
self)
|
||||||
|
|
||||||
|
|
||||||
def read_events(fobj):
|
def read_events(fobj, fname):
|
||||||
"""Generate the output for the given (format, backends) pair.
|
"""Generate the output for the given (format, backends) pair.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
fobj : file
|
fobj : file
|
||||||
Event description file.
|
Event description file.
|
||||||
|
fname : str
|
||||||
|
Name of event file
|
||||||
|
|
||||||
Returns a list of Event objects
|
Returns a list of Event objects
|
||||||
"""
|
"""
|
||||||
@ -312,7 +314,7 @@ def read_events(fobj):
|
|||||||
try:
|
try:
|
||||||
event = Event.build(line)
|
event = Event.build(line)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
arg0 = 'Error on line %d: %s' % (lineno, e.args[0])
|
arg0 = 'Error at %s:%d: %s' % (fname, lineno, e.args[0])
|
||||||
e.args = (arg0,) + e.args[1:]
|
e.args = (arg0,) + e.args[1:]
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user