Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cbc301
commit f021967
Showing
4 changed files
with
113 additions
and
0 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
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,60 @@ | ||
.TH threadsnoop 8 "2019-07-02" "USER COMMANDS" | ||
.SH NAME | ||
threadsnoop.bt \- Trace thread creation via pthread_create(). Uses bpftrace/eBPF. | ||
.SH SYNOPSIS | ||
.B threadsnoop.bt | ||
.SH DESCRIPTION | ||
threadsnoop traces calls to pthread_create(), showing this path of thread | ||
creation. This can be used for workload characterization and discovery, and is | ||
a companion to execsnoop(8) which traces execve(2). | ||
|
||
This works by tracing the pthread_create() from libpthread.so.0. The path | ||
to this library may need adjusting in the tool source to match your system. | ||
|
||
Since this uses BPF, only the root user can use this tool. | ||
.SH REQUIREMENTS | ||
CONFIG_BPF and bpftrace. | ||
.SH EXAMPLES | ||
.TP | ||
Trace calls pthread_create(): | ||
# | ||
.B threadsnoop.bt | ||
.SH FIELDS | ||
.TP | ||
TIME(ms) | ||
Elapsed time since the tool began tracing (in milliseconds). | ||
.TP | ||
PID | ||
The process ID. | ||
.TP | ||
COMM | ||
The process (thread) name. | ||
.TP | ||
FUNC | ||
The name of the start routine, if the symbol is available, else a hex address | ||
for the start routine address. | ||
.SH OVERHEAD | ||
Thread creation is expected to be low (<< 1000/s), so the overhead of this | ||
tool is expected to be negligible. | ||
.SH SOURCE | ||
This tool originated from the book "BPF Performance Tools", published by | ||
Addison Wesley (2019): | ||
.IP | ||
http://www.brendangregg.com/bpf-performance-tools-book.html | ||
.PP | ||
See the book for more documentation on this tool. | ||
.PP | ||
This version is in the bpftrace repository: | ||
.IP | ||
https://github.com/iovisor/bpftrace | ||
.PP | ||
Also look in the bpftrace distribution for a companion _examples.txt file | ||
containing example usage, output, and commentary for this tool. | ||
.SH OS | ||
Linux | ||
.SH STABILITY | ||
Unstable - in development. | ||
.SH AUTHOR | ||
Brendan Gregg | ||
.SH SEE ALSO | ||
execsnoop(8) |
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,25 @@ | ||
#!/usr/local/bin/bpftrace | ||
/* | ||
* threadsnoop - List new thread creation. | ||
* | ||
* See BPF Performance Tools, Chapter 13, for an explanation of this tool. | ||
* | ||
* Copyright (c) 2019 Brendan Gregg. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* This was originally created for the BPF Performance Tools book | ||
* published by Addison Wesley. ISBN-13: 9780136554820 | ||
* When copying or porting, include this comment. | ||
* | ||
* 15-Feb-2019 Brendan Gregg Created this. | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
printf("%-10s %-6s %-16s %s\n", "TIME(ms)", "PID", "COMM", "FUNC"); | ||
} | ||
|
||
uprobe:/lib/x86_64-linux-gnu/libpthread.so.0:pthread_create | ||
{ | ||
printf("%-10u %-6d %-16s %s\n", elapsed / 1000000, pid, comm, | ||
usym(arg2)); | ||
} |
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,27 @@ | ||
Demonstrations of threadsnoop, the Linux bpftrace/eBPF version. | ||
|
||
|
||
Tracing new threads via phtread_create(): | ||
|
||
# ./threadsnoop.bt | ||
Attaching 2 probes... | ||
TIME(ms) PID COMM FUNC | ||
1938 28549 dockerd threadentry | ||
1939 28549 dockerd threadentry | ||
1939 28549 dockerd threadentry | ||
1940 28549 dockerd threadentry | ||
1949 28549 dockerd threadentry | ||
1958 28549 dockerd threadentry | ||
1939 28549 dockerd threadentry | ||
1950 28549 dockerd threadentry | ||
2013 28579 docker-containe 0x562f30f2e710 | ||
2036 28549 dockerd threadentry | ||
2083 28579 docker-containe 0x562f30f2e710 | ||
2116 629 systemd-journal 0x7fb7114955c0 | ||
2116 629 systemd-journal 0x7fb7114955c0 | ||
[...] | ||
|
||
The output shows a dockerd process creating several threads with the start | ||
routine threadentry(), and docker-containe (truncated) and systemd-journal | ||
also starting threads: in their cases, the function had no symbol information | ||
available, so their addresses are printed in hex. |