-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopentrace.bt
executable file
·35 lines (30 loc) · 1.12 KB
/
opentrace.bt
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
#!/usr/bin/env bpftrace
tracepoint:syscalls:sys_enter_openat*
{
// TODO: pass partial string name as argument instead of fucking grepping
// $filename = str(args->filename);
// $string = str($1);
// if ( strncmp($filename, $string, 3) ) {
@filename[tid] = args->filename;
@flags[tid] = args->flags;
@start[tid] = nsecs;
@dfd[tid] = args->dfd;
// }
}
tracepoint:syscalls:sys_exit_openat* /@filename[tid]/
{
$ret = args->ret;
$fd = $ret >= 0 ? $ret : -1;
$errno = $ret >= 0 ? 0 : - $ret;
$usecs = (nsecs - @start[tid]) / 1000;
// AT_FDCWD = -100 dfd, i.e. in current working directory of the calling process
// printf("%d usec %s:%d:%d fd:%d dfd:%d err:%d flags:%d %s %s\n",
// $usecs, comm, pid, tid, $fd, @dfd[tid], $errno, @flags[tid], str(@filename[tid]), strftime("%H:%M:%S:%f",nsecs));
// just a different format, and actually prints the latency
printf("%s:%d:%d %s fd:%d dfd:%d err:%d flags:%d %s\n",
comm, pid, tid, str(@filename[tid]), $fd, @dfd[tid], $errno, @flags[tid], strftime("%H:%M:%S:%f",nsecs));
delete(@filename[tid]);
delete(@start[tid]);
delete(@flags[tid]);
delete(@dfd[tid]);
}