Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stackcount: add -K, -U, -d, -D, and -f #1335

Merged
merged 3 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
stackcount: add -D for duration
  • Loading branch information
brendangregg committed Sep 3, 2017
commit 198d2a6a3cccd9f4235c156c0863c08075ce5152
5 changes: 4 additions & 1 deletion man/man8/stackcount.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SH NAME
stackcount \- Count function calls and their stack traces. Uses Linux eBPF/bcc.
.SH SYNOPSIS
.B stackcount [\-h] [\-p PID] [\-i INTERVAL] [\-T] [\-r] [\-s]
.B stackcount [\-h] [\-p PID] [\-i INTERVAL] [\-D DURATION] [\-T] [\-r] [\-s]
[\-P] [\-K] [\-U] [\-v] [\-d] pattern
.SH DESCRIPTION
stackcount traces functions and frequency counts them with their entire
Expand Down Expand Up @@ -46,6 +46,9 @@ Print the source of the BPF program when loading it (for debugging purposes).
\-i interval
Summary interval, in seconds.
.TP
\-D duration
Total duration of trace, in seconds.
.TP
\-p PID
Trace this process ID only (filtered in-kernel).
.TP
Expand Down
18 changes: 15 additions & 3 deletions tools/stackcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# stackcount Count events and their stack traces.
# For Linux, uses BCC, eBPF.
#
# USAGE: stackcount [-h] [-p PID] [-i INTERVAL] [-T] [-r] [-s]
# [-P] [-v] pattern
# USAGE: stackcount.py [-h] [-p PID] [-i INTERVAL] [-D DURATION] [-T] [-r] [-s]
# [-P] [-K] [-U] [-v] [-d] [--debug]
#
# The pattern is a string with optional '*' wildcards, similar to file
# globbing. If you'd prefer to use regular expressions, use the -r option.
Expand Down Expand Up @@ -227,8 +227,10 @@ def __init__(self):
epilog=examples)
parser.add_argument("-p", "--pid", type=int,
help="trace this PID only")
parser.add_argument("-i", "--interval", default=99999999,
parser.add_argument("-i", "--interval",
help="summary interval, seconds")
parser.add_argument("-D", "--duration",
help="total duration of trace, seconds")
parser.add_argument("-T", "--timestamp", action="store_true",
help="include timestamp on output")
parser.add_argument("-r", "--regexp", action="store_true",
Expand All @@ -252,6 +254,12 @@ def __init__(self):
self.args = parser.parse_args()
global debug
debug = self.args.debug

if self.args.duration and not self.args.interval:
self.args.interval = self.args.duration
if not self.args.interval:
self.args.interval = 99999999

if self.args.kernel_stacks_only and self.args.user_stacks_only:
print("ERROR: -K and -U are mutually exclusive. If you want " +
"both stacks, that is the default.")
Expand Down Expand Up @@ -300,13 +308,17 @@ def run(self):
print("Tracing %d functions for \"%s\"... Hit Ctrl-C to end." %
(self.probe.matched, self.args.pattern))
exiting = 0 if self.args.interval else 1
seconds = 0
while True:
try:
sleep(int(self.args.interval))
seconds += int(self.args.interval)
except KeyboardInterrupt:
exiting = 1
# as cleanup can take many seconds, trap Ctrl-C:
signal.signal(signal.SIGINT, Tool._signal_ignore)
if self.args.duration and seconds >= int(self.args.duration):
exiting = 1

print()
if self.args.timestamp:
Expand Down
6 changes: 4 additions & 2 deletions tools/stackcount_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ Use -r to allow regular expressions.
USAGE message:

# ./stackcount -h
usage: stackcount [-h] [-p PID] [-i INTERVAL] [-T] [-r] [-s] [-P] [-K] [-U]
[-v] [-d] [--debug]
usage: stackcount [-h] [-p PID] [-i INTERVAL] [-D DURATION] [-T] [-r] [-s]
[-P] [-K] [-U] [-v] [-d] [--debug]
pattern

Count events and their stack traces
Expand All @@ -839,6 +839,8 @@ optional arguments:
-p PID, --pid PID trace this PID only
-i INTERVAL, --interval INTERVAL
summary interval, seconds
-D DURATION, --duration DURATION
total duration of trace, seconds
-T, --timestamp include timestamp on output
-r, --regexp use regular expressions. Default is "*" wildcards
only.
Expand Down