-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.bt
More file actions
41 lines (36 loc) · 1.12 KB
/
Copy pathcommon.bt
File metadata and controls
41 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* common.bt
*
* Shared preamble for process monitoring scripts. Provides timestamp
* macros, process-tree tracking, and lifecycle management.
*
* Not intended to be run standalone. Combined with tracer modules by
* monitor-process.sh (or manually via cat):
*
* cat common.bt trace-files.bt cleanup.bt | sudo bpftrace - <PID>
*
* Requires: kernel BTF support (CONFIG_DEBUG_INFO_BTF=y), bpftrace >= 0.25
*/
// Timestamp: HH:MM:SS string and milliseconds within the current second
macro ts_str(t) { strftime("%H:%M:%S", t) }
macro ts_ms(t) { (t % 1000000000) / 1000000 }
// Network to host byte order for 16-bit values
macro ntohs(raw) { ((raw >> 8) | ((raw & 0xff) << 8)) }
BEGIN
{
if ($1 == 0) {
printf("Usage: sudo bpftrace <script> <PID>\n");
exit();
}
printf("Monitoring PID %d (and their children)...\n", $1);
printf("%-20s %-10s %s\n", "TIME", "EVENT", "DETAILS");
printf("%-20s %-10s %s\n", "----", "-----", "-------");
@root_pid = $1;
@watched[($1)] = 1;
}
tracepoint:sched:sched_process_fork
{
if (@watched[(int64)pid]) {
@watched[args.child_pid] = 1;
}
}