Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
86df2b8b
Commit
86df2b8b
authored
Apr 23, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add -c option for profile.py
parent
7f22495b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
man/man8/profile.8
man/man8/profile.8
+9
-2
tools/profile.py
tools/profile.py
+21
-5
tools/profile_example.txt
tools/profile_example.txt
+6
-3
No files found.
man/man8/profile.8
View file @
86df2b8b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
.SH NAME
.SH NAME
profile \- Profile CPU usage by sampling stack traces. Uses Linux eBPF/bcc.
profile \- Profile CPU usage by sampling stack traces. Uses Linux eBPF/bcc.
.SH SYNOPSIS
.SH SYNOPSIS
.B profile [\-adfh] [\-p PID] [\-U | \-
k] [\-F FREQUENCY
]
.B profile [\-adfh] [\-p PID] [\-U | \-
K] [\-F FREQUENCY | \-c COUNT
]
.B [\-\-stack\-storage\-size COUNT] [duration]
.B [\-\-stack\-storage\-size COUNT] [duration]
.SH DESCRIPTION
.SH DESCRIPTION
This is a CPU profiler. It works by taking samples of stack traces at timed
This is a CPU profiler. It works by taking samples of stack traces at timed
...
@@ -32,7 +32,10 @@ Trace this process ID only (filtered in-kernel). Without this, all CPUs are
...
@@ -32,7 +32,10 @@ Trace this process ID only (filtered in-kernel). Without this, all CPUs are
profiled.
profiled.
.TP
.TP
\-F frequency
\-F frequency
Frequency to sample stacks (default 49).
Frequency to sample stacks.
.TP
\-c count
Sample stacks every one in this many events.
.TP
.TP
\-f
\-f
Print output in folded stack format.
Print output in folded stack format.
...
@@ -67,6 +70,10 @@ Profile at 99 Hertz for 5 seconds only:
...
@@ -67,6 +70,10 @@ Profile at 99 Hertz for 5 seconds only:
#
#
.B profile -F 99 5
.B profile -F 99 5
.TP
.TP
Profile 1 in a million events for 5 seconds only:
#
.B profile -c 1000000 5
.TP
Profile PID 181 only:
Profile PID 181 only:
#
#
.B profile -p 181
.B profile -p 181
...
...
tools/profile.py
View file @
86df2b8b
...
@@ -63,6 +63,7 @@ def positive_nonzero_int(val):
...
@@ -63,6 +63,7 @@ def positive_nonzero_int(val):
examples
=
"""examples:
examples
=
"""examples:
./profile # profile stack traces at 49 Hertz until Ctrl-C
./profile # profile stack traces at 49 Hertz until Ctrl-C
./profile -F 99 # profile stack traces at 99 Hertz
./profile -F 99 # profile stack traces at 99 Hertz
./profile -c 1000000 # profile stack traces every 1 in a million events
./profile 5 # profile at 49 Hertz for 5 seconds only
./profile 5 # profile at 49 Hertz for 5 seconds only
./profile -f 5 # output in folded format for flame graphs
./profile -f 5 # output in folded format for flame graphs
./profile -p 185 # only profile threads for PID 185
./profile -p 185 # only profile threads for PID 185
...
@@ -82,8 +83,11 @@ stack_group.add_argument("-U", "--user-stacks-only", action="store_true",
...
@@ -82,8 +83,11 @@ stack_group.add_argument("-U", "--user-stacks-only", action="store_true",
help
=
"show stacks from user space only (no kernel space stacks)"
)
help
=
"show stacks from user space only (no kernel space stacks)"
)
stack_group
.
add_argument
(
"-K"
,
"--kernel-stacks-only"
,
action
=
"store_true"
,
stack_group
.
add_argument
(
"-K"
,
"--kernel-stacks-only"
,
action
=
"store_true"
,
help
=
"show stacks from kernel space only (no user space stacks)"
)
help
=
"show stacks from kernel space only (no user space stacks)"
)
parser
.
add_argument
(
"-F"
,
"--frequency"
,
type
=
positive_int
,
default
=
49
,
sample_group
=
parser
.
add_mutually_exclusive_group
()
help
=
"sample frequency, Hertz (default 49)"
)
sample_group
.
add_argument
(
"-F"
,
"--frequency"
,
type
=
positive_int
,
help
=
"sample frequency, Hertz"
)
sample_group
.
add_argument
(
"-c"
,
"--count"
,
type
=
positive_int
,
help
=
"sample period, number of events"
)
parser
.
add_argument
(
"-d"
,
"--delimited"
,
action
=
"store_true"
,
parser
.
add_argument
(
"-d"
,
"--delimited"
,
action
=
"store_true"
,
help
=
"insert delimiter between kernel/user stacks"
)
help
=
"insert delimiter between kernel/user stacks"
)
parser
.
add_argument
(
"-a"
,
"--annotations"
,
action
=
"store_true"
,
parser
.
add_argument
(
"-a"
,
"--annotations"
,
action
=
"store_true"
,
...
@@ -214,10 +218,22 @@ else:
...
@@ -214,10 +218,22 @@ else:
bpf_text
=
bpf_text
.
replace
(
'USER_STACK_GET'
,
user_stack_get
)
bpf_text
=
bpf_text
.
replace
(
'USER_STACK_GET'
,
user_stack_get
)
bpf_text
=
bpf_text
.
replace
(
'KERNEL_STACK_GET'
,
kernel_stack_get
)
bpf_text
=
bpf_text
.
replace
(
'KERNEL_STACK_GET'
,
kernel_stack_get
)
sample_freq
=
0
sample_period
=
0
if
args
.
frequency
:
sample_freq
=
args
.
frequency
elif
args
.
count
:
sample_period
=
args
.
count
else
:
# If user didn't specify anything, use default 49Hz sampling
sample_freq
=
49
sample_context
=
"%s%d %s"
%
((
""
,
sample_freq
,
"Hertz"
)
if
sample_freq
else
(
"every "
,
sample_period
,
"events"
))
# header
# header
if
not
args
.
folded
:
if
not
args
.
folded
:
print
(
"Sampling at %
d Hertz
of %s by %s stack"
%
print
(
"Sampling at %
s
of %s by %s stack"
%
(
args
.
frequency
,
thread_context
,
stack_context
),
end
=
""
)
(
sample_context
,
thread_context
,
stack_context
),
end
=
""
)
if
duration
<
99999999
:
if
duration
<
99999999
:
print
(
" for %d secs."
%
duration
)
print
(
" for %d secs."
%
duration
)
else
:
else
:
...
@@ -232,7 +248,7 @@ if debug or args.ebpf:
...
@@ -232,7 +248,7 @@ if debug or args.ebpf:
b
=
BPF
(
text
=
bpf_text
)
b
=
BPF
(
text
=
bpf_text
)
b
.
attach_perf_event
(
ev_type
=
PerfType
.
SOFTWARE
,
b
.
attach_perf_event
(
ev_type
=
PerfType
.
SOFTWARE
,
ev_config
=
PerfSWConfig
.
CPU_CLOCK
,
fn_name
=
"do_perf_event"
,
ev_config
=
PerfSWConfig
.
CPU_CLOCK
,
fn_name
=
"do_perf_event"
,
sample_period
=
0
,
sample_freq
=
args
.
frequency
)
sample_period
=
sample_period
,
sample_freq
=
sample_freq
)
# signal handler
# signal handler
def
signal_ignore
(
signal
,
frame
):
def
signal_ignore
(
signal
,
frame
):
...
...
tools/profile_example.txt
View file @
86df2b8b
...
@@ -704,8 +704,8 @@ Run ./profile -h to see the default.
...
@@ -704,8 +704,8 @@ Run ./profile -h to see the default.
USAGE message:
USAGE message:
# ./profile -h
# ./profile -h
usage: profile [-h] [-p PID] [-U | -K] [-F FREQUENCY
] [-d] [-a] [-f
]
usage: profile [-h] [-p PID] [-U | -K] [-F FREQUENCY
| -c COUNT] [-d] [-a
]
[--stack-storage-size STACK_STORAGE_SIZE]
[-
f] [-
-stack-storage-size STACK_STORAGE_SIZE]
[duration]
[duration]
Profile CPU stack traces at a timed interval
Profile CPU stack traces at a timed interval
...
@@ -723,7 +723,9 @@ optional arguments:
...
@@ -723,7 +723,9 @@ optional arguments:
show stacks from kernel space only (no user space
show stacks from kernel space only (no user space
stacks)
stacks)
-F FREQUENCY, --frequency FREQUENCY
-F FREQUENCY, --frequency FREQUENCY
sample frequency, Hertz (default 49)
sample frequency, Hertz
-c COUNT, --count COUNT
sample period, number of events
-d, --delimited insert delimiter between kernel/user stacks
-d, --delimited insert delimiter between kernel/user stacks
-a, --annotations add _[k] annotations to kernel frames
-a, --annotations add _[k] annotations to kernel frames
-f, --folded output folded format, one line per stack (for flame
-f, --folded output folded format, one line per stack (for flame
...
@@ -735,6 +737,7 @@ optional arguments:
...
@@ -735,6 +737,7 @@ optional arguments:
examples:
examples:
./profile # profile stack traces at 49 Hertz until Ctrl-C
./profile # profile stack traces at 49 Hertz until Ctrl-C
./profile -F 99 # profile stack traces at 99 Hertz
./profile -F 99 # profile stack traces at 99 Hertz
./profile -c 1000000 # profile stack traces every 1 in a million events
./profile 5 # profile at 49 Hertz for 5 seconds only
./profile 5 # profile at 49 Hertz for 5 seconds only
./profile -f 5 # output in folded format for flame graphs
./profile -f 5 # output in folded format for flame graphs
./profile -p 185 # only profile threads for PID 185
./profile -p 185 # only profile threads for PID 185
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment