Skip to content

Commit 5e3bb28

Browse files
jeromemarchandyonghong-song
authored andcommitted
tools/trace: don't raise an exception in a ctype callback
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]>
1 parent 58ce085 commit 5e3bb28

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/trace.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Probe(object):
4343
build_id_enabled = False
4444
aggregate = False
4545
symcount = {}
46+
done = False
4647

4748
@classmethod
4849
def configure(cls, args):
@@ -635,7 +636,7 @@ def print_event(self, bpf, cpu, data, size):
635636
if self.aggregate:
636637
self.print_aggregate_events()
637638
sys.stdout.flush()
638-
exit()
639+
Probe.done = True;
639640

640641
def attach(self, bpf, verbose):
641642
if len(self.library) == 0:
@@ -895,7 +896,7 @@ def _main_loop(self):
895896
"-" if not all_probes_trivial else ""))
896897
sys.stdout.flush()
897898

898-
while True:
899+
while not Probe.done:
899900
self.bpf.perf_buffer_poll()
900901

901902
def run(self):

0 commit comments

Comments
 (0)