File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 18
18
from bcc import BPF
19
19
from time import sleep , strftime
20
20
import argparse
21
+ import os
22
+ import stat
21
23
from subprocess import call
22
24
23
25
# arguments
55
57
help = "number of outputs" )
56
58
parser .add_argument ("--ebpf" , action = "store_true" ,
57
59
help = argparse .SUPPRESS )
60
+ parser .add_argument ("-d" , "--directory" , type = str ,
61
+ help = "trace this directory only" )
62
+
58
63
args = parser .parse_args ()
59
64
interval = int (args .interval )
60
65
countdown = int (args .count )
109
114
if (d_name.len == 0 || TYPE_FILTER)
110
115
return 0;
111
116
117
+ // skip if not in the specified directory
118
+ if (DIRECTORY_FILTER)
119
+ return 0;
120
+
112
121
// store counts and sizes by pid & file
113
122
struct info_t info = {
114
123
.pid = pid,
163
172
bpf_text = bpf_text .replace ('TYPE_FILTER' , '0' )
164
173
else :
165
174
bpf_text = bpf_text .replace ('TYPE_FILTER' , '!S_ISREG(mode)' )
175
+ if args .directory :
176
+ try :
177
+ directory_inode = os .lstat (args .directory )[stat .ST_INO ]
178
+ print (f'Tracing directory: { args .directory } (Inode: { directory_inode } )' )
179
+ bpf_text = bpf_text .replace ('DIRECTORY_FILTER' , 'file->f_path.dentry->d_parent->d_inode->i_ino != %d' % directory_inode )
180
+ except (FileNotFoundError , PermissionError ) as e :
181
+ print (f'Error accessing directory { args .directory } : { e } ' )
182
+ exit (1 )
183
+ else :
184
+ bpf_text = bpf_text .replace ('DIRECTORY_FILTER' , '0' )
166
185
167
186
if debug or args .ebpf :
168
187
print (bpf_text )
You can’t perform that action at this time.
0 commit comments