Skip to content

Commit

Permalink
tools/trace: don't raise an exception in a ctype callback
Browse files Browse the repository at this point in the history
To exit the tool when the maximal number of event is reached (-M
option), the tool currently call exit(), which raise a SystemExit
exception. The handling of exception from ctype callback doesn't seem
straightforward and dependent on python version.

This patch avoid the issue altogether by using a global variable
instead.

Closes iovisor#3049

Signed-off-by: Jerome Marchand <[email protected]>
  • Loading branch information
jeromemarchand authored and yonghong-song committed Nov 6, 2023
1 parent 58ce085 commit 5e3bb28
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Probe(object):
build_id_enabled = False
aggregate = False
symcount = {}
done = False

@classmethod
def configure(cls, args):
Expand Down Expand Up @@ -635,7 +636,7 @@ def print_event(self, bpf, cpu, data, size):
if self.aggregate:
self.print_aggregate_events()
sys.stdout.flush()
exit()
Probe.done = True;

def attach(self, bpf, verbose):
if len(self.library) == 0:
Expand Down Expand Up @@ -895,7 +896,7 @@ def _main_loop(self):
"-" if not all_probes_trivial else ""))
sys.stdout.flush()

while True:
while not Probe.done:
self.bpf.perf_buffer_poll()

def run(self):
Expand Down

0 comments on commit 5e3bb28

Please sign in to comment.