目次
strace コマンド
インストール
# opkg update && opkg install strace
Downloading https://fw.gl-inet.com/releases/kmod-3.2/ar71xx/nand/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_core Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/sync_kmod-3.2/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_sync Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/base/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_base Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/gli_pub/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_gli_pub Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/packages/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_packages Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/luci/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_luci Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/routing/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_routing Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/telephony/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_telephony Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/glinet/Packages.gz Updated list of available packages in /var/opkg-lists/glinet_glinet Installing strace (4.20-1) to root... Downloading https://fw.gl-inet.com/releases/packages-3.x/ar71xx/base/strace_4.20-1_mips_24kc.ipk Configuring strace.
動作確認
# strace -h
usage: strace [-CdffhiqrtttTvVwxxy] [-I n] [-e expr]...
[-a column] [-o file] [-s strsize] [-P path]...
-p pid... / [-D] [-E var=val]... [-u username] PROG [ARGS]
or: strace -c[dfw] [-I n] [-e expr]... [-O overhead] [-S sortby]
-p pid... / [-D] [-E var=val]... [-u username] PROG [ARGS]
Output format:
-a column alignment COLUMN for printing syscall results (default 40)
-i print instruction pointer at time of syscall
-o file send trace output to FILE instead of stderr
-q suppress messages about attaching, detaching, etc.
-r print relative timestamp
-s strsize limit length of print strings to STRSIZE chars (default 32)
-t print absolute timestamp
-tt print absolute timestamp with usecs
-T print time spent in each syscall
-x print non-ascii strings in hex
-xx print all strings in hex
-y print paths associated with file descriptor arguments
-yy print protocol specific information associated with socket file descriptors
Statistics:
-c count time, calls, and errors for each syscall and report summary
-C like -c but also print regular output
-O overhead set overhead for tracing syscalls to OVERHEAD usecs
-S sortby sort syscall counts by: time, calls, name, nothing (default time)
-w summarise syscall latency (default is system time)
Filtering:
-e expr a qualifying expression: option=[!]all or option=[!]val1[,val2]...
options: trace, abbrev, verbose, raw, signal, read, write, fault
-P path trace accesses to path
Tracing:
-b execve detach on execve syscall
-D run tracer process as a detached grandchild, not as parent
-f follow forks
-ff follow forks with output into separate files
-I interruptible
1: no signals are blocked
2: fatal signals are blocked while decoding syscall (default)
3: fatal signals are always blocked (default if '-o FILE PROG')
4: fatal signals and SIGTSTP (^Z) are always blocked
(useful to make 'strace -o FILE PROG' not stop on ^Z)
Startup:
-E var remove var from the environment for command
-E var=val put var=val in the environment for command
-p pid trace process with process id PID, may be repeated
-u username run command as username handling setuid and/or setgid
Miscellaneous:
-d enable debug output to stderr
-v verbose mode: print unabbreviated argv, stat, termios, etc. args
-h print help message
-V print version
実行
strace [プロセス(コマンド等)]
実行例:
# strace ls
execve("/bin/ls", ["ls"], 0x7faec570 /* 13 vars */) = 0 set_thread_area(0x77cc1da0) = 0 set_tid_address(0x77cbad08) = 2290 open("/etc/ld-musl-mips-sf.path", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("/lib/libgcc_s.so.1", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=87624, ...}) = 0 read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0(0\0\0\0004"..., 936) = 936 mmap2(NULL, 155648, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x77be2000 mmap2(0x77c07000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x15000) = 0x77c07000 close(3) = 0 mprotect(0x45f000, 4096, PROT_READ) = 0 prctl(PR_SET_NAME, "ls") = 0 getuid() = 0 clock_gettime(CLOCK_REALTIME, {tv_sec=1584324418, tv_nsec=689099805}) = 0 ioctl(0, TIOCGWINSZ, 0x7fd4acd8) = 0 ioctl(1, TIOCGWINSZ, 0x7fd4ad10) = 0 ioctl(1, TIOCGWINSZ, 0x7fd4ad10) = 0 stat64(".", {st_mode=S_IFDIR|0755, st_size=3, ...}) = 0 open(".", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 getdents64(3, /* 2 entries */, 2048) = 48 getdents64(3, /* 0 entries */, 2048) = 0 close(3) = 0 exit_group(0) = ? +++ exited with 0 +++