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
fff792df
Commit
fff792df
authored
Aug 04, 2017
by
Iago López Galeiras
Committed by
Brenden Blanco
Aug 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools/tcptracer: print ns timestamps with -v
parent
6426cd4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
tools/tcptracer.py
tools/tcptracer.py
+25
-16
No files found.
tools/tcptracer.py
View file @
fff792df
...
@@ -49,7 +49,7 @@ bpf_text = """
...
@@ -49,7 +49,7 @@ bpf_text = """
#define TCP_EVENT_TYPE_CLOSE 3
#define TCP_EVENT_TYPE_CLOSE 3
struct tcp_ipv4_event_t {
struct tcp_ipv4_event_t {
u64 ts_
u
s;
u64 ts_
n
s;
u32 type;
u32 type;
u32 pid;
u32 pid;
char comm[TASK_COMM_LEN];
char comm[TASK_COMM_LEN];
...
@@ -63,7 +63,7 @@ struct tcp_ipv4_event_t {
...
@@ -63,7 +63,7 @@ struct tcp_ipv4_event_t {
BPF_PERF_OUTPUT(tcp_ipv4_event);
BPF_PERF_OUTPUT(tcp_ipv4_event);
struct tcp_ipv6_event_t {
struct tcp_ipv6_event_t {
u64 ts_
u
s;
u64 ts_
n
s;
u32 type;
u32 type;
u32 pid;
u32 pid;
char comm[TASK_COMM_LEN];
char comm[TASK_COMM_LEN];
...
@@ -308,7 +308,7 @@ int trace_tcp_set_state_entry(struct pt_regs *ctx, struct sock *sk, int state)
...
@@ -308,7 +308,7 @@ int trace_tcp_set_state_entry(struct pt_regs *ctx, struct sock *sk, int state)
}
}
struct tcp_ipv4_event_t evt4 = { };
struct tcp_ipv4_event_t evt4 = { };
evt4.ts_
us = bpf_ktime_get_ns() / 1000
;
evt4.ts_
ns = bpf_ktime_get_ns()
;
evt4.type = TCP_EVENT_TYPE_CONNECT;
evt4.type = TCP_EVENT_TYPE_CONNECT;
evt4.pid = p->pid >> 32;
evt4.pid = p->pid >> 32;
evt4.ip = ipver;
evt4.ip = ipver;
...
@@ -344,7 +344,7 @@ int trace_tcp_set_state_entry(struct pt_regs *ctx, struct sock *sk, int state)
...
@@ -344,7 +344,7 @@ int trace_tcp_set_state_entry(struct pt_regs *ctx, struct sock *sk, int state)
}
}
struct tcp_ipv6_event_t evt6 = { };
struct tcp_ipv6_event_t evt6 = { };
evt6.ts_
us = bpf_ktime_get_ns() / 1000
;
evt6.ts_
ns = bpf_ktime_get_ns()
;
evt6.type = TCP_EVENT_TYPE_CONNECT;
evt6.type = TCP_EVENT_TYPE_CONNECT;
evt6.pid = p->pid >> 32;
evt6.pid = p->pid >> 32;
evt6.ip = ipver;
evt6.ip = ipver;
...
@@ -395,7 +395,7 @@ int trace_close_entry(struct pt_regs *ctx, struct sock *sk)
...
@@ -395,7 +395,7 @@ int trace_close_entry(struct pt_regs *ctx, struct sock *sk)
}
}
struct tcp_ipv4_event_t evt4 = { };
struct tcp_ipv4_event_t evt4 = { };
evt4.ts_
us = bpf_ktime_get_ns() / 1000
;
evt4.ts_
ns = bpf_ktime_get_ns()
;
evt4.type = TCP_EVENT_TYPE_CLOSE;
evt4.type = TCP_EVENT_TYPE_CLOSE;
evt4.pid = pid >> 32;
evt4.pid = pid >> 32;
evt4.ip = ipver;
evt4.ip = ipver;
...
@@ -415,7 +415,7 @@ int trace_close_entry(struct pt_regs *ctx, struct sock *sk)
...
@@ -415,7 +415,7 @@ int trace_close_entry(struct pt_regs *ctx, struct sock *sk)
}
}
struct tcp_ipv6_event_t evt6 = { };
struct tcp_ipv6_event_t evt6 = { };
evt6.ts_
us = bpf_ktime_get_ns() / 1000
;
evt6.ts_
ns = bpf_ktime_get_ns()
;
evt6.type = TCP_EVENT_TYPE_CLOSE;
evt6.type = TCP_EVENT_TYPE_CLOSE;
evt6.pid = pid >> 32;
evt6.pid = pid >> 32;
evt6.ip = ipver;
evt6.ip = ipver;
...
@@ -468,7 +468,7 @@ int trace_accept_return(struct pt_regs *ctx)
...
@@ -468,7 +468,7 @@ int trace_accept_return(struct pt_regs *ctx)
struct tcp_ipv4_event_t evt4 = { 0 };
struct tcp_ipv4_event_t evt4 = { 0 };
evt4.ts_
us = bpf_ktime_get_ns() / 1000
;
evt4.ts_
ns = bpf_ktime_get_ns()
;
evt4.type = TCP_EVENT_TYPE_ACCEPT;
evt4.type = TCP_EVENT_TYPE_ACCEPT;
evt4.netns = net_ns_inum;
evt4.netns = net_ns_inum;
evt4.pid = pid >> 32;
evt4.pid = pid >> 32;
...
@@ -493,7 +493,7 @@ int trace_accept_return(struct pt_regs *ctx)
...
@@ -493,7 +493,7 @@ int trace_accept_return(struct pt_regs *ctx)
struct tcp_ipv6_event_t evt6 = { 0 };
struct tcp_ipv6_event_t evt6 = { 0 };
evt6.ts_
us = bpf_ktime_get_ns() / 1000
;
evt6.ts_
ns = bpf_ktime_get_ns()
;
evt6.type = TCP_EVENT_TYPE_ACCEPT;
evt6.type = TCP_EVENT_TYPE_ACCEPT;
evt6.netns = net_ns_inum;
evt6.netns = net_ns_inum;
evt6.pid = pid >> 32;
evt6.pid = pid >> 32;
...
@@ -525,7 +525,7 @@ TASK_COMM_LEN = 16 # linux/sched.h
...
@@ -525,7 +525,7 @@ TASK_COMM_LEN = 16 # linux/sched.h
class
TCPIPV4Evt
(
ctypes
.
Structure
):
class
TCPIPV4Evt
(
ctypes
.
Structure
):
_fields_
=
[
_fields_
=
[
(
"ts_
u
s"
,
ctypes
.
c_ulonglong
),
(
"ts_
n
s"
,
ctypes
.
c_ulonglong
),
(
"type"
,
ctypes
.
c_uint
),
(
"type"
,
ctypes
.
c_uint
),
(
"pid"
,
ctypes
.
c_uint
),
(
"pid"
,
ctypes
.
c_uint
),
(
"comm"
,
ctypes
.
c_char
*
TASK_COMM_LEN
),
(
"comm"
,
ctypes
.
c_char
*
TASK_COMM_LEN
),
...
@@ -540,7 +540,7 @@ class TCPIPV4Evt(ctypes.Structure):
...
@@ -540,7 +540,7 @@ class TCPIPV4Evt(ctypes.Structure):
class
TCPIPV6Evt
(
ctypes
.
Structure
):
class
TCPIPV6Evt
(
ctypes
.
Structure
):
_fields_
=
[
_fields_
=
[
(
"ts_
u
s"
,
ctypes
.
c_ulonglong
),
(
"ts_
n
s"
,
ctypes
.
c_ulonglong
),
(
"type"
,
ctypes
.
c_uint
),
(
"type"
,
ctypes
.
c_uint
),
(
"pid"
,
ctypes
.
c_uint
),
(
"pid"
,
ctypes
.
c_uint
),
(
"comm"
,
ctypes
.
c_char
*
TASK_COMM_LEN
),
(
"comm"
,
ctypes
.
c_char
*
TASK_COMM_LEN
),
...
@@ -560,10 +560,14 @@ verbose_types = {"C": "connect", "A": "accept",
...
@@ -560,10 +560,14 @@ verbose_types = {"C": "connect", "A": "accept",
def
print_ipv4_event
(
cpu
,
data
,
size
):
def
print_ipv4_event
(
cpu
,
data
,
size
):
event
=
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
TCPIPV4Evt
)).
contents
event
=
ctypes
.
cast
(
data
,
ctypes
.
POINTER
(
TCPIPV4Evt
)).
contents
global
start_ts
global
start_ts
if
args
.
timestamp
:
if
args
.
timestamp
:
if
start_ts
==
0
:
if
start_ts
==
0
:
start_ts
=
event
.
ts_us
start_ts
=
event
.
ts_ns
print
(
"%-9.3f"
%
((
float
(
event
.
ts_us
)
-
start_ts
)
/
1000000
),
end
=
""
)
if
args
.
verbose
:
print
(
"%-14d"
%
(
event
.
ts_ns
-
start_ts
),
end
=
""
)
else
:
print
(
"%-9.3f"
%
((
float
(
event
.
ts_ns
)
-
start_ts
)
/
1000000000
),
end
=
""
)
if
event
.
type
==
1
:
if
event
.
type
==
1
:
type_str
=
"C"
type_str
=
"C"
elif
event
.
type
==
2
:
elif
event
.
type
==
2
:
...
@@ -596,8 +600,11 @@ def print_ipv6_event(cpu, data, size):
...
@@ -596,8 +600,11 @@ def print_ipv6_event(cpu, data, size):
global
start_ts
global
start_ts
if
args
.
timestamp
:
if
args
.
timestamp
:
if
start_ts
==
0
:
if
start_ts
==
0
:
start_ts
=
event
.
ts_us
start_ts
=
event
.
ts_ns
print
(
"%-9.3f"
%
((
float
(
event
.
ts_us
)
-
start_ts
)
/
1000000
),
end
=
""
)
if
args
.
verbose
:
print
(
"%-14d"
%
(
event
.
ts_ns
-
start_ts
),
end
=
""
)
else
:
print
(
"%-9.3f"
%
((
float
(
event
.
ts_ns
)
-
start_ts
)
/
1000000000
),
end
=
""
)
if
event
.
type
==
1
:
if
event
.
type
==
1
:
type_str
=
"C"
type_str
=
"C"
elif
event
.
type
==
2
:
elif
event
.
type
==
2
:
...
@@ -649,15 +656,17 @@ b.attach_kretprobe(event="inet_csk_accept", fn_name="trace_accept_return")
...
@@ -649,15 +656,17 @@ b.attach_kretprobe(event="inet_csk_accept", fn_name="trace_accept_return")
print
(
"Tracing TCP established connections. Ctrl-C to end."
)
print
(
"Tracing TCP established connections. Ctrl-C to end."
)
# header
# header
if
args
.
timestamp
:
print
(
"%-9s"
%
(
"TIME(s)"
),
end
=
""
)
if
args
.
verbose
:
if
args
.
verbose
:
if
args
.
timestamp
:
print
(
"%-14s"
%
(
"TIME(ns)"
),
end
=
""
)
print
(
"%-12s %-6s %-16s %-2s %-16s %-16s %-6s %-7s"
%
(
"TYPE"
,
print
(
"%-12s %-6s %-16s %-2s %-16s %-16s %-6s %-7s"
%
(
"TYPE"
,
"PID"
,
"COMM"
,
"IP"
,
"SADDR"
,
"DADDR"
,
"SPORT"
,
"DPORT"
),
end
=
""
)
"PID"
,
"COMM"
,
"IP"
,
"SADDR"
,
"DADDR"
,
"SPORT"
,
"DPORT"
),
end
=
""
)
if
not
args
.
netns
:
if
not
args
.
netns
:
print
(
"%-8s"
%
"NETNS"
,
end
=
""
)
print
(
"%-8s"
%
"NETNS"
,
end
=
""
)
print
()
print
()
else
:
else
:
if
args
.
timestamp
:
print
(
"%-9s"
%
(
"TIME(s)"
),
end
=
""
)
print
(
"%-2s %-6s %-16s %-2s %-16s %-16s %-6s %-6s"
%
print
(
"%-2s %-6s %-16s %-2s %-16s %-16s %-6s %-6s"
%
(
"T"
,
"PID"
,
"COMM"
,
"IP"
,
"SADDR"
,
"DADDR"
,
"SPORT"
,
"DPORT"
))
(
"T"
,
"PID"
,
"COMM"
,
"IP"
,
"SADDR"
,
"DADDR"
,
"SPORT"
,
"DPORT"
))
...
...
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