Skip to content

tools/filetop: Add directory filter #5300

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srivathsa729
Copy link

@srivathsa729 srivathsa729 commented May 7, 2025

Add support to filetop to filter by directory.

Signed-off-by: Srivathsa Dara [email protected]

Add support to filtop to filter by directory.

Signed-off-by: Srivathsa Dara <[email protected]>
@srivathsa729 srivathsa729 force-pushed the filetop-dir-filter branch from 6c8f442 to ac91de6 Compare May 7, 2025 14:35
@@ -163,6 +173,16 @@
bpf_text = bpf_text.replace('TYPE_FILTER', '0')
else:
bpf_text = bpf_text.replace('TYPE_FILTER', '!S_ISREG(mode)')
if args.directory:
try:
directory_inode = os.lstat(args.directory)[stat.ST_INO]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target directory is a symbolic link, the directory_inode might differ from the target's inode. Does this behave as intended?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I used os.lstat, which doesn't follow symlinks, so currently if a symlink is provided as an argument, it doesn't report any activity. Switching to os.stat should fix this by properly following the symlink to its target. I'll update the PR accordingly.

from subprocess import call

# arguments
examples = """examples:
./filetop # file I/O top, 1 second refresh
./filetop -C # don't clear the screen
./filetop -p 181 # PID 181 only
./filetop -d /home/user # trace files in /home/user directory only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current functionality is good, but adding support for including subdirectories would make it even more powerful.
Thank you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense. I'll work on adding support for subdirectories.

Thanks for the input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants