Skip to content
Snippets Groups Projects
Commit 8ab9113a authored by Tomasz Grabiec's avatar Tomasz Grabiec Committed by Pekka Enberg
Browse files

trace: introduce '--period' time slicing option


This:

  --since 10.0 --period 100ms

is now equivalent to:

  --since 10.0 --until 10.1

This option makes it easier to slice the time based on the output of
'trace.py list-timed' which prints trace timestamp and duration.

Signed-off-by: default avatarTomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent e8509c7f
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ from operator import attrgetter ...@@ -10,6 +10,10 @@ from operator import attrgetter
from osv import trace, debug, prof from osv import trace, debug, prof
class InvalidArgumentsException(Exception):
def __init__(self, message):
self.message = message
class symbol_printer: class symbol_printer:
def __init__(self, resolver, formatter): def __init__(self, resolver, formatter):
self.resolver = resolver self.resolver = resolver
...@@ -99,6 +103,9 @@ def add_time_slicing_options(parser): ...@@ -99,6 +103,9 @@ def add_time_slicing_options(parser):
group = parser.add_argument_group('time slicing') group = parser.add_argument_group('time slicing')
group.add_argument("--since", action='store', help="show data starting on this timestamp [ns]") group.add_argument("--since", action='store', help="show data starting on this timestamp [ns]")
group.add_argument("--until", action='store', help="show data ending on this timestamp [ns] (exclusive)") group.add_argument("--until", action='store', help="show data ending on this timestamp [ns] (exclusive)")
group.add_argument("--period", action='store', help="""if only one of --since or --until is specified,
the amount of time passed in this option will be used to calculate the other. The value is interpreted
as nanoseconds unless unit is specified, eg: 500us""")
def add_profile_options(parser): def add_profile_options(parser):
add_time_slicing_options(parser) add_time_slicing_options(parser)
...@@ -118,7 +125,22 @@ def int_or_none(value): ...@@ -118,7 +125,22 @@ def int_or_none(value):
return None return None
def get_time_range(args): def get_time_range(args):
return trace.TimeRange(int_or_none(args.since), int_or_none(args.until)) start = int_or_none(args.since)
end = int_or_none(args.until)
if args.period:
if start and end:
raise InvalidArgumentsException("--period cannot be used when both --since and --until are specified")
period = prof.parse_time_as_nanos(args.period)
if start:
end = start + period
elif end:
start = end - period
else:
raise InvalidArgumentsException("--period must be used with --since or --until specified")
return trace.TimeRange(start, end)
def show_profile(args, sample_producer): def show_profile(args, sample_producer):
resolver = symbol_resolver(args) resolver = symbol_resolver(args)
...@@ -349,6 +371,8 @@ if __name__ == "__main__": ...@@ -349,6 +371,8 @@ if __name__ == "__main__":
try: try:
args.func(args) args.func(args)
except InvalidArgumentsException as e:
print "Invalid arguments:", e.message
except IOError as e: except IOError as e:
if e.errno != errno.EPIPE: if e.errno != errno.EPIPE:
raise raise
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment