Linux效能測試 strace命令

2021-06-19 20:26:10 字數 2637 閱讀 2632

1  功能說明

strace 命令是一種強大的工具 ,  能夠顯示任何由使用者空間程式發出的系統呼叫 .  strace 顯示這些呼叫的引數並返回符號形式的值 .  strace 從核心接收資訊 ,  而且無需以任何特別的方式來構建核心 .  strace 的每一行輸出包括系統呼叫名稱,   然後是引數和返回值.

下面記錄幾個常用option :

-f -f選項告訴strace同時跟蹤fork和vfork出來的程序

-o ***.txt 輸出到某個文件 . 

-e execve 只記錄 execve 這類系統呼叫 .

2  詳細用法

usage: strace [-dffhiqrttttvvxx] [-a column] [-e expr] ... [-o file]

[-p pid] ... [-s strsize] [-u username] [-e var=val] ...

[command [arg ...]]

or: strace -c [-e expr] ... [-o overhead] [-s sortby] [-e var=val] ...

[command [arg ...]]

-c -- count time, calls, and errors for each syscall and report summary

-f -- follow forks, -ff -- with output into separate files

-f -- attempt to follow vforks, -h -- print help message

-i -- print instruction pointer at time of syscall

-q -- suppress messages about attaching, detaching, etc.

-r -- print relative timestamp, -t -- absolute timestamp, -tt -- with usecs

-t -- print time spent in each syscall, -v -- print version

-v -- verbose mode: print unabbreviated argv, stat, termio[s], etc. args

-x -- print non-ascii strings in hex, -xx -- print all strings in hex

-a column -- alignment column for printing syscall results (default 40)

-e expr -- a qualifying expression: option=[!]all or option=[!]val1[,val2]...

options: trace, abbrev, verbose, raw, signal, read, or write

-o file -- send trace output to file instead of stderr

-o overhead -- set overhead for tracing syscalls to overhead usecs

-p pid -- trace process with process id pid, may be repeated

-s strsize -- limit length of print strings to strsize chars (default 32)

-s sortby -- sort syscall counts by: time, calls, name, nothing (default time)

-u username -- run command as username handling setuid and/or setgid

-e var=val -- put var=val in the environment for command

-e var -- remove var from the environment for command

當你嘗試/"ls -l/" 乙個不存在的檔案時,會有:

lstat(/foot/ball/",0xb004) = -1 enoent (no such file or directory)

char*將作為c的字串型別輸出.沒有字串輸出時一般是char* 是乙個轉義字元,只輸出字串的長度.

當字串過長是會使用/".../"省略.如在/"ls -l/"會有乙個gepwuid呼叫讀取password檔案:

read(3,/"root::0:0:system administrator://"...,1024) = 422

當引數是結構陣列時,將按照簡單的指標和陣列輸出如:

getgroups(4,[0,2,4,5]) = 4

關於bit作為引數的情形,也是使用方括號,並且用空格將每一項引數隔開.如:

sigprocmask(sig_block,[chld ttou],) = 0

這裡第二個引數代表兩個訊號sigchld 和 sigttou.如果bit型引數全部置位,則有如下的輸出:

sigprocmask(sig_unblock,~,null) = 0

Linux效能測試命令系列(5) strace

功能 trace system calls and signals strace能夠跟蹤程序使用的系統呼叫,並顯示呼叫過程資訊。本文章只給出比較常用的命令。注 1 a.out表示要被strace跟蹤的使用者可執行程式,2 pidof a.out 表示要被strace跟蹤的正在執行的a.out對應的程...

strace 除錯linux 程式

strace常用引數 c 統計每種系統呼叫執行的時間 呼叫次數 出錯次數,程式退出時給出報告 p pid 跟蹤指定的程序,可以使用多個 p同時跟蹤多個程序 o filename strace預設輸出到stdout,o可以將輸出寫入到指定的檔案 f 跟蹤由fork產生的子程序的系統呼叫 ff 常與 o...

linux磁碟效能測試

120 test apt get install hdparm 真實機器120上測試結果 測試磁碟效能 不cache 120 test home lai hdparm t dev sda dev sda timing buffered disk reads 346 mb in 3.02 second...