最終更新:2016-12-19 (月) 16:18:14 (1090d)  

strace はてなブックマークを見る
Top / strace

straceはシステムコールトレーサで、すでに実行されているプログラムによって発せられたコールを追跡する(straceを既存のPIDにバインドする)ことも、テストしたいプロセスをstraceに開始させることもできる。

インストール

yum install strace

引数

  • -T: システムコールの所要時間(秒.マイクロ秒)を出力 ※マイクロ秒=1/1,000,000秒
  • -tt: タイムスタンプをマイクロ秒で出力
  • -o: トレースを指定したファイルに出力
  • -c: 回数をカウント
  • -e expr: A qualifying expression which modifies which events to trace or how to trace them.
  • -e trace=set: Trace only the specified set of system calls.
    trace=open,close,read,write
  • -e trace=file: Trace all system calls which take a file name as an argument.
  • -e trace=process: Trace all system calls which involve process management. This is useful for watching the fork, wait, and exec steps of a process.
  • -e trace=network: Trace all the network related system calls.
  • -e trace=signal: Trace all signal related system calls.
  • -e trace=ipc: Trace all IPC related system calls.
  • -e trace=desc: Trace all file descriptor related system calls.
  • -e trace=memory: Trace all memory mapping related system calls.

メモ

  • strace gcc 2>&1 | grep -i spec

/* hello_world.c */
#include <stdio.h>

int main(void)
{
    printf("Hello world!\n");
    return 0;
}
# strace ./hello
execve("./hello", ["./hello"], [/* 46 vars */]) = 0
brk(0)                                  = 0x8f3000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffd146ec000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=53125, ...}) = 0
mmap(NULL, 53125, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffd146df000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY)      = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\355\301Z:\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1922112, ...}) = 0
mmap(0x3a5ac00000, 3745960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a5ac00000
mprotect(0x3a5ad89000, 2097152, PROT_NONE) = 0
mmap(0x3a5af89000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x189000) = 0x3a5af89000
mmap(0x3a5af8e000, 18600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3a5af8e000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffd146de000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffd146dd000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffd146dc000
arch_prctl(ARCH_SET_FS, 0x7ffd146dd700) = 0
mprotect(0x3a5af89000, 16384, PROT_READ) = 0
mprotect(0x3a5aa1f000, 4096, PROT_READ) = 0
munmap(0x7ffd146df000, 53125)           = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 8), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffd146eb000
write(1, "Hello world!\n", 13Hello world!
)          = 13
exit_group(0)                           = ?

関連コマンド

関連

関連

参考