-
Notifications
You must be signed in to change notification settings - Fork 480
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
script: Add report-open-files.py #286
base: master
Are you sure you want to change the base?
Conversation
ebc159a
to
f676cdc
Compare
Hmm.. I don't get what is the purpose of this script. Is it just for an example? Current output doesn't seem to have much difference than the plain replay with |
f676cdc
to
7fa4ab2
Compare
I think it can better handle enum types rather than manually writing options for
Especially |
You can use |
You need to reconsider open mode flag processing. IIRC the last 2 bits is used to mask the read-write mode and |
Something like this ? diff --git a/scripts/report-open-files.py b/scripts/report-open-files.py
index c188c96a..ccdd3db7 100644
--- a/scripts/report-open-files.py
+++ b/scripts/report-open-files.py
@@ -9,10 +9,10 @@ import os
UFTRACE_FUNC = [ "open" ]
+UFT_OPEN_MODE_MASK = 0x3
+uft_open_mode = [ "O_RDONLY", "O_WRONLY", "O_RDWR", "O_XXX" ]
+
uft_open_flag = {
- "O_RDONLY": 00,
- "O_WRONLY": 01,
- "O_RDWR": 02,
"O_CREAT": 0100,
"O_EXCL": 0200,
"O_NOCTTY": 0400,
@@ -77,11 +77,10 @@ def uftrace_end():
print("")
def get_mode_str(mode):
- mode_str = ""
+ mode_str = uft_open_mode[mode & UFT_OPEN_MODE_MASK]
+
for key, value in uft_open_flag.items():
- if mode == 0:
- mode_str = "O_RDONLY"
- elif mode & uft_open_flag[key] > 0:
+ if mode & uft_open_flag[key] > 0:
if mode_str == "":
mode_str = key
else: |
7fa4ab2
to
c6a709d
Compare
Thanks for the fix. I've updated including the change. |
It seems that adding |
Or you can use |
|
c6a709d
to
8f3bf55
Compare
Updated with handling |
An example output is as follows:
|
8f3bf55
to
a44a07f
Compare
Hmm.. I tried to remove some functions that returned -1 because there's no such file, but python return value is a bit tricky. def uftrace_exit(ctx):
global open_pathname
if ctx.has_key("retval"):
#if "retval" in ctx:
if ctx["name"] == "open":
#if ctx["retval"] == -1:
if ctx["retval"] == 18446744073709551615:
del open_set[open_pathname]
elif ctx["name"] == "openat":
#if ctx["retval"] == -1:
if ctx["retval"] == 18446744073709551615:
del openat_set[open_pathname]
elif ctx["name"] == "fopen":
if ctx["retval"] == 0:
del fopen_set[open_pathname]
|
After removing failed open files, the number of open files are reduced a lot from 161 to 41.
|
59c4b02
to
bbeaede
Compare
The manual (
Also glibc added following extensions:
|
Thanks for the useful info, but I just wanted to leave |
Hmm.. it can be combination with other characters in |
fopen_map = {} | ||
open_pathname = "" | ||
|
||
def uftrace_begin(): |
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.
One small nitpicking.. please add a 'ctx' argument
scripts/report-open-files.py
Outdated
if ctx.has_key("retval"): | ||
if ctx["name"] == "open": | ||
#if ctx["retval"] == -1: | ||
if ctx["retval"] == 18446744073709551615: |
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.
This is because python deals with big numbers more than 64 bit. It's hex: 0xffffffffffffffff
. I don't know what's the best way to handle this.
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 this?
minus_one = (1 << 64) - 1
...
if ctx["retval"] == minus_one:
This patch adds report-open-files.py that collects all the open files based on open, openat, and fopen calls and shows its summary at the end of execution. An example output of this script is as follows: $ uftrace record -S scripts/report-open-files.py /usr/bin/gcc -save-temps ~/hello.c # 161 files are opened by 'cc1' (pid: 176695) open mode pathname ================== ================================================ O_RDONLY|O_NOCTTY /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/bits/types.h O_RDONLY|O_NOCTTY /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/stdlib.h O_RDONLY|O_NOCTTY /usr/include/x86_64-linux-gnu/bits/waitstatus.h O_RDONLY|O_NOCTTY /usr/local/include/bits/types.h ... ... w hello.i # 3 files are opened by 'cc1' (pid: 176696) open mode pathname ================== ================================================ O_RDONLY /dev/urandom O_RDONLY|O_NOCTTY hello.i w hello.s # 1 files are opened by 'as' (pid: 176697) open mode pathname ================= ================================================ r hello.s # 12 files are opened by 'ld' (pid: 176699) open mode pathname ================= ================================================ O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o O_RDONLY /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so O_RDONLY /usr/lib/x86_64-linux-gnu/libc_nonshared.a O_RDONLY /lib/x86_64-linux-gnu/libc.so.6 O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.so O_RDONLY hello.o O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crtn.o O_RDONLY /usr/lib/gcc/x86_64-linux-gnu/5/crtend.o r /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.so # 4 files are opened by 'collect2' (pid: 176698) open mode pathname ========================= ================================================ O_WRONLY|O_TRUNC|O_CREAT /tmp/ccVDJ3He.le O_WRONLY|O_TRUNC|O_CREAT /tmp/cciG4DMx.ld r /tmp/cciG4DMx.ld r /tmp/ccVDJ3He.le # 0 files are opened by 'gcc' (pid: 176684) Signed-off-by: Honggyu Kim <[email protected]>
bbeaede
to
6d31a62
Compare
This patch adds report-open-files.py that collects all the open files
based on open() calls and shows its summary at the end of execution.
The output of this script is as follows:
Signed-off-by: Honggyu Kim [email protected]