Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tools/lib/ustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
from subprocess import call
from time import sleep, strftime
import signal

class Category(object):
THREAD = "THREAD"
Expand Down Expand Up @@ -242,10 +243,17 @@ def _detach_probes(self):
self.bpf.cleanup() # Cleans up all attached probes
self.bpf = None

def _sigint_handler(self, signum, frame):
self.exiting = True;
if self.in_sleep:
raise KeyboardInterrupt

def _loop_iter(self):
self._attach_probes()
try:
self.in_sleep = True
sleep(self.args.interval)
self.in_sleep = False
except KeyboardInterrupt:
self.exiting = True

Expand Down Expand Up @@ -293,6 +301,7 @@ def run(self):
self.args.interval)
countdown = self.args.count
self.exiting = False
signal.signal(signal.SIGINT, self._sigint_handler)
while True:
self._loop_iter()
countdown -= 1
Expand Down
Loading