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
06a1c85f
Commit
06a1c85f
authored
Feb 13, 2017
by
Brendan Gregg
Committed by
GitHub
Feb 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #920 from pchaigno/pid-filter-gethostlatency
gethostlatency: Filter by process ID
parents
5472dbcd
edca17a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
6 deletions
+44
-6
man/man8/gethostlatency.8
man/man8/gethostlatency.8
+4
-0
tools/gethostlatency.py
tools/gethostlatency.py
+24
-6
tools/gethostlatency_example.txt
tools/gethostlatency_example.txt
+16
-0
No files found.
man/man8/gethostlatency.8
View file @
06a1c85f
...
...
@@ -21,6 +21,10 @@ and may need modifications to match your software and processor architecture.
Since this uses BPF, only the root user can use this tool.
.SH REQUIREMENTS
CONFIG_BPF and bcc.
.SH OPTIONS
.TP
\-p PID
Trace this process ID only.
.SH EXAMPLES
.TP
Trace host lookups (getaddrinfo/gethostbyname[2]) system wide:
...
...
tools/gethostlatency.py
View file @
06a1c85f
...
...
@@ -18,8 +18,21 @@
from
__future__
import
print_function
from
bcc
import
BPF
from
time
import
strftime
import
argparse
import
ctypes
as
ct
examples
=
"""examples:
./gethostlatency # trace all TCP accept()s
./gethostlatency -p 181 # only trace PID 181
"""
parser
=
argparse
.
ArgumentParser
(
description
=
"Show latency for getaddrinfo/gethostbyname[2] calls"
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
epilog
=
examples
)
parser
.
add_argument
(
"-p"
,
"--pid"
,
help
=
"trace this PID only"
,
type
=
int
,
default
=-
1
)
args
=
parser
.
parse_args
()
# load BPF program
bpf_text
=
"""
#include <uapi/linux/ptrace.h>
...
...
@@ -82,12 +95,17 @@ int do_return(struct pt_regs *ctx) {
}
"""
b
=
BPF
(
text
=
bpf_text
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"getaddrinfo"
,
fn_name
=
"do_entry"
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"gethostbyname"
,
fn_name
=
"do_entry"
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"gethostbyname2"
,
fn_name
=
"do_entry"
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"getaddrinfo"
,
fn_name
=
"do_return"
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"gethostbyname"
,
fn_name
=
"do_return"
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"gethostbyname2"
,
fn_name
=
"do_return"
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"getaddrinfo"
,
fn_name
=
"do_entry"
,
pid
=
args
.
pid
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"gethostbyname"
,
fn_name
=
"do_entry"
,
pid
=
args
.
pid
)
b
.
attach_uprobe
(
name
=
"c"
,
sym
=
"gethostbyname2"
,
fn_name
=
"do_entry"
,
pid
=
args
.
pid
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"getaddrinfo"
,
fn_name
=
"do_return"
,
pid
=
args
.
pid
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"gethostbyname"
,
fn_name
=
"do_return"
,
pid
=
args
.
pid
)
b
.
attach_uretprobe
(
name
=
"c"
,
sym
=
"gethostbyname2"
,
fn_name
=
"do_return"
,
pid
=
args
.
pid
)
TASK_COMM_LEN
=
16
# linux/sched.h
...
...
tools/gethostlatency_example.txt
View file @
06a1c85f
...
...
@@ -19,3 +19,19 @@ TIME PID COMM LATms HOST
In this example, the first call to lookup "www.iovisor.org" took 90 ms, and
the second took 0 ms (cached). The slowest call in this example was to "foo",
which was an unsuccessful lookup.
USAGE message:
# ./gethostlatency -h
usage: gethostlatency [-h] [-p PID]
Show latency for getaddrinfo/gethostbyname[2] calls
optional arguments:
-h, --help show this help message and exit
-p PID, --pid PID trace this PID only
examples:
./gethostlatency # trace all TCP accept()s
./gethostlatency -p 181 # only trace PID 181
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