mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
ftrace: Turn TraceCollector into a context manager
This allows using an TraceCollector instance as a context manager, so tracing will stop even if the devlib application is interrupted, or if an exception is raised.
This commit is contained in:
parent
fbf0875357
commit
22a5945460
@ -31,5 +31,13 @@ class TraceCollector(object):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.reset()
|
||||||
|
self.start()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
self.stop()
|
||||||
|
|
||||||
def get_trace(self, outfile):
|
def get_trace(self, outfile):
|
||||||
pass
|
pass
|
||||||
|
@ -323,18 +323,15 @@ You can collected traces (currently, just ftrace) using
|
|||||||
# the buffer size to be used.
|
# the buffer size to be used.
|
||||||
trace = FtraceCollector(t, events=['power*'], buffer_size=40000)
|
trace = FtraceCollector(t, events=['power*'], buffer_size=40000)
|
||||||
|
|
||||||
# clear ftrace buffer
|
# As a context manager, clear ftrace buffer using trace.reset(),
|
||||||
trace.reset()
|
# start trace collection using trace.start(), then stop it Using
|
||||||
|
# trace.stop(). Using a context manager brings the guarantee that
|
||||||
# start trace collection
|
# tracing will stop even if an exception occurs, including
|
||||||
trace.start()
|
# KeyboardInterrupt (ctr-C) and SystemExit (sys.exit)
|
||||||
|
with trace:
|
||||||
# Perform the operations you want to trace here...
|
# Perform the operations you want to trace here...
|
||||||
import time; time.sleep(5)
|
import time; time.sleep(5)
|
||||||
|
|
||||||
# stop trace collection
|
|
||||||
trace.stop()
|
|
||||||
|
|
||||||
# extract the trace file from the target into a local file
|
# extract the trace file from the target into a local file
|
||||||
trace.get_trace('/tmp/trace.bin')
|
trace.get_trace('/tmp/trace.bin')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user