-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Python USDT API Code from @vmg * Basic USDT example * retire procstat.py * improve/fix USDT exceptions
- Loading branch information
1 parent
f4bf275
commit 4f88a94
Showing
10 changed files
with
150 additions
and
632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/python | ||
# | ||
# nodejs_http_server Basic example of node.js USDT tracing. | ||
# For Linux, uses BCC, BPF. Embedded C. | ||
# | ||
# USAGE: nodejs_http_server PID | ||
# | ||
# Copyright 2016 Netflix, Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License") | ||
|
||
from __future__ import print_function | ||
from bcc import BPF, USDT | ||
import sys | ||
|
||
if len(sys.argv) < 2: | ||
print("USAGE: nodejs_http_server PID") | ||
exit() | ||
pid = sys.argv[1] | ||
debug = 0 | ||
|
||
# load BPF program | ||
bpf_text = """ | ||
#include <uapi/linux/ptrace.h> | ||
int do_trace(struct pt_regs *ctx) { | ||
uint64_t addr; | ||
char path[128]; | ||
bpf_usdt_readarg(6, ctx, &addr); | ||
bpf_probe_read(&path, sizeof(path), (void *)addr); | ||
bpf_trace_printk("path:%s\\n", path); | ||
return 0; | ||
}; | ||
""" | ||
|
||
# enable USDT probe from given PID | ||
u = USDT(pid=int(pid)) | ||
u.enable_probe(probe="http__server__request", fn_name="do_trace") | ||
if debug: | ||
print(u.get_text()) | ||
print(bpf_text) | ||
|
||
# initialize BPF | ||
b = BPF(text=bpf_text, usdt=u) | ||
|
||
# header | ||
print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "ARGS")) | ||
|
||
# format output | ||
while 1: | ||
try: | ||
(task, pid, cpu, flags, ts, msg) = b.trace_fields() | ||
except ValueError: | ||
print("value error") | ||
continue | ||
print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.