-
Notifications
You must be signed in to change notification settings - Fork 4k
tools/filetop: Add --recursive for directory filter #5400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
tools/filetop.py
Outdated
| if args.recursive: | ||
| print(f'Tracing directory recursively: {args.directory} (Inode: {directory_inode})') | ||
| directory_filter = ("({ struct dentry *pde = de; int found = 0; " | ||
| "for (int i = 0; i < 50; i++) { " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Please replace the magic number 50 with a macro or constant for clarity and maintainability.
-
Is there a specific reason why 50 is chosen as the max depth? Could you also include your thoughts on performance, BPF instruction count, and verifier safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1、done
2、I switched the bound to 32 and made it a macro FILETOP_MAX_DENTRY_DEPTH. 32 aligns with existing path-walking limits in this repo (e.g., libbpf-tools uses MAX_PATH_DEPTH=32) and is well above typical directory depths we see in practice.
tools/filetop.py
Outdated
| bpf_text = bpf_text.replace('DIRECTORY_FILTER', 'file->f_path.dentry->d_parent->d_inode->i_ino != %d' % directory_inode) | ||
| if args.recursive: | ||
| print(f'Tracing directory recursively: {args.directory} (Inode: {directory_inode})') | ||
| directory_filter = ("({ struct dentry *pde = de; int found = 0; " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory_filter code for the recursive case is hard to read.
Could you please refactor it for better readability and maintainability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tools/filetop.py
Outdated
| // Limit dentry parent walk depth to satisfy eBPF verifier loop | ||
| #ifndef FILETOP_MAX_DENTRY_DEPTH | ||
| #define FILETOP_MAX_DENTRY_DEPTH 32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While FILETOP_MAX_DENTRY_DEPTH is below 32 in most cases, there is still a chance that it could exceed this limit in certain scenarios. If that happens, the tool's behavior might deviate from the user's expectations. Would it be worth notifying users about this limitation to avoid potential confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, add max depth log in --help and Tracing directory recursively log
Signed-off-by: abushwang <[email protected]>
| { | ||
| struct dentry *pde = de; | ||
| int found = 0; | ||
| #pragma unroll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line after the variable declaration section.
| exit(1) | ||
| else: | ||
| if args.recursive: | ||
| print("Error: --recursive can only be used with -d/--directory option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about -R/--recursive?
| parser.add_argument("-d", "--directory", type=str, | ||
| help="trace this directory only") | ||
| parser.add_argument("-R", "--recursive", action="store_true", | ||
| help=f"when used with -d, also trace files in subdirectories (max depth {MAX_DENTRY_DEPTH_VAL})") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to make it clearer that this is only available when using -d. The current wording makes it seem like there could be cases where it's possible to use without -d.
For example, "This feature is only supported when used with the -d option, tracing files inside subdirectories."
| { | ||
| struct dentry *pde = de; | ||
| int found = 0; | ||
| #pragma unroll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is #pragma unroll (and __always_inline) intended?
please refer to:
https://lwn.net/Articles/1017116/
The commit 137bd5f introduced a directory filter. However, files under subdirectories were not being traced.
This PR adds a --recursive option which, while remaining backward-compatible, enables recursive filtering so that files in subdirectories are also matched.