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
03c2bc5d
Commit
03c2bc5d
authored
Jan 28, 2016
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #323 from iovisor/strlen
Add uprobe strlen histogram example
parents
f7ee4e83
7adab964
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
examples/tracing/strlen_hist.py
examples/tracing/strlen_hist.py
+59
-0
No files found.
examples/tracing/strlen_hist.py
0 → 100755
View file @
03c2bc5d
#!/usr/bin/python
#
# strlen_hist.py Histogram of system-wide strlen return values
#
# A basic example of using uprobes along with a histogram to show
# distributions.
#
# Runs until ctrl-c is pressed.
#
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# Example output:
# $ sudo ./strlen_hist.py
# 22:12:52
# strlen return: : count distribution
# 0 -> 1 : 2106 |**************** |
# 2 -> 3 : 1172 |********* |
# 4 -> 7 : 3892 |****************************** |
# 8 -> 15 : 5096 |****************************************|
# 16 -> 31 : 2201 |***************** |
# 32 -> 63 : 547 |**** |
# 64 -> 127 : 106 | |
# 128 -> 255 : 13 | |
# 256 -> 511 : 27 | |
# 512 -> 1023 : 6 | |
# 1024 -> 2047 : 10 | |
# ^C$
#
from
__future__
import
print_function
import
bcc
import
time
text
=
"""
#include <uapi/linux/ptrace.h>
BPF_HISTOGRAM(dist);
int count(struct pt_regs *ctx) {
dist.increment(bpf_log2l(ctx->ax));
return 0;
}
"""
b
=
bcc
.
BPF
(
text
=
text
)
sym
=
"strlen"
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
sym
,
fn_name
=
"count"
)
dist
=
b
[
"dist"
]
try
:
while
True
:
time
.
sleep
(
1
)
print
(
"%-8s
\
n
"
%
time
.
strftime
(
"%H:%M:%S"
),
end
=
""
)
dist
.
print_log2_hist
(
sym
+
" return:"
)
dist
.
clear
()
except
KeyboardInterrupt
:
pass
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