MCPcopy Create free account
hub / github.com/iovisor/bcc / run

Method run

tools/stackcount.py:315–381  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

313 print(" %s [%d]" % (comm, pid))
314
315 def run(self):
316 self.probe.load()
317 self.probe.attach()
318 if not self.args.folded:
319 print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
320 (self.probe.matched, self.args.pattern))
321 b = self.probe.bpf
322 # check whether hash table batch ops is supported
323 htab_batch_ops = True if BPF.kernel_struct_has_field(b'bpf_map_ops',
324 b'map_lookup_and_delete_batch') == 1 else False
325 exiting = 0 if self.args.interval else 1
326 seconds = 0
327 while True:
328 try:
329 sleep(int(self.args.interval))
330 seconds += int(self.args.interval)
331 except KeyboardInterrupt:
332 exiting = 1
333 # as cleanup can take many seconds, trap Ctrl-C:
334 signal.signal(signal.SIGINT, Tool._signal_ignore)
335 if self.args.duration and seconds >= int(self.args.duration):
336 exiting = 1
337
338 if not self.args.folded:
339 print()
340 if self.args.timestamp:
341 print("%-8s\n" % strftime("%H:%M:%S"), end="")
342
343 counts = self.probe.bpf["counts"]
344 stack_traces = self.probe.bpf["stack_traces"]
345 self.comm_cache = {}
346 for k, v in sorted(counts.items_lookup_and_delete_batch()
347 if htab_batch_ops else counts.items(),
348 key=lambda counts: counts[1].value):
349 user_stack = [] if k.user_stack_id < 0 else \
350 stack_traces.walk(k.user_stack_id)
351 kernel_stack = [] if k.kernel_stack_id < 0 else \
352 stack_traces.walk(k.kernel_stack_id)
353
354 if self.args.folded:
355 # print folded stack output
356 user_stack = list(user_stack)
357 kernel_stack = list(kernel_stack)
358 line = [k.name.decode('utf-8', 'replace')] + \
359 [b.sym(addr, k.tgid).decode('utf-8', 'replace') for addr in
360 reversed(user_stack)] + \
361 (self.need_delimiter and ["-"] or []) + \
362 [b.ksym(addr).decode('utf-8', 'replace') for addr in reversed(kernel_stack)]
363 print("%s %d" % (";".join(line), v.value))
364 else:
365 # print multi-line stack output
366 for addr in kernel_stack:
367 self._print_kframe(addr)
368 if self.need_delimiter:
369 print(" --")
370 for addr in user_stack:
371 self._print_uframe(addr, k.tgid)
372 if not self.args.pid and k.tgid != 0xffffffff:

Callers 1

stackcount.pyFile · 0.45

Calls 15

_print_kframeMethod · 0.95
_print_uframeMethod · 0.95
_print_commMethod · 0.95
listFunction · 0.85
exitFunction · 0.85
itemsMethod · 0.80
walkMethod · 0.80
decodeMethod · 0.80
symMethod · 0.80
ksymMethod · 0.80

Tested by

no test coverage detected