Linux 如何解释 strace 输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6334515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to interpret strace output?
提问by mkc
I need to profile the performance of an application for which I am using strace. However, I do not really know how to interpret the various system calls the strace emits. Examples of a few of them are below:
我需要分析我使用 strace 的应用程序的性能。但是,我真的不知道如何解释 strace 发出的各种系统调用。其中一些示例如下:
(A) lseek(3, 1600, SEEK_SET) = 1600
(B) write(3, "G_DATA 300 0 "..., 800) = 800
(C) close(3) = 0
(D) mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b600b179000
(E) munmap(0x2b600b179000, 4096) = 0
(F) fstat(3, {st_mode=S_IFREG|0644, st_size=1600, ...}) = 0
I would be grateful if someone could briefly explain in plain English what these lines from (A) to (F) really means in terms of I/O, data transferred, significance on performance etc.
如果有人能用简单的英语简要解释从 (A) 到 (F) 的这些行在 I/O、数据传输、性能重要性等方面的真正含义,我将不胜感激。
I went through the man pages of strace but still am not very very confident. If you any other pointers for me to read, that would be great.
我浏览了 strace 的手册页,但仍然不是很自信。如果您有任何其他指示供我阅读,那就太好了。
I have some background on Operating Systems and understand what system calls, memory, virtual memory, Scheduling, etc. are.
我对操作系统有一定的了解,了解什么是系统调用、内存、虚拟内存、调度等。
采纳答案by Blagovest Buyukliev
In order to understand these, you have to get familiar with the POSIX system calls. They are the interface a user-space program uses to interact with the kernel.
为了理解这些,您必须熟悉 POSIX 系统调用。它们是用户空间程序用来与内核交互的接口。
lseek
, write
, close
, mmap
, munmap
and fstat
are all system callsand are documented in section 2 of the linux manual.
lseek
, write
, close
, mmap
,munmap
和fstat
都是系统调用,并在 linux 手册的第 2 节中记录。
Briefly, lseek
moves the internal pointer of the supplied file descriptor to the byte with position pointed to by the second argument, starting from SEEK_SET
(the beginning), SEEK_CUR
(current position) or SEEK_END
(the end). Any consecutive read
and write
calls on the same descriptor will start their action from this position. Note that lseek
is not implemented for all kinds of descriptors - it makes sense for a file on disk, but not for a socket or a pipe.
简而言之,lseek
将提供的文件描述符的内部指针移动到具有第二个参数指向的位置的字节,从SEEK_SET
(开始)、SEEK_CUR
(当前位置)或SEEK_END
(结束)开始。对同一描述符的任何连续read
和write
调用将从该位置开始它们的操作。请注意,这lseek
不是为所有类型的描述符实现的——它对磁盘上的文件有意义,但对套接字或管道没有意义。
write
copies the supplied buffer to kernelspace and returns the number of bytes actually written. Depending on the kind of the descriptor, the kernel may write the data to disk or send it through the network. This is generally a costly operation because it involves transferring this buffer to the kernel.
write
将提供的缓冲区复制到内核空间并返回实际写入的字节数。根据描述符的类型,内核可能会将数据写入磁盘或通过网络发送。这通常是一个代价高昂的操作,因为它涉及将此缓冲区传输到内核。
close
closes the supplied descriptor and any associated resources with it in the kernel are freed. Note that each process has a limit on the number of simultaneously open descriptors, so it's sometimes necessary to close descriptors to not reach this limit.
close
关闭提供的描述符,并释放内核中与它相关的任何资源。请注意,每个进程对同时打开的描述符数量都有限制,因此有时需要关闭描述符才能不达到此限制。
mmap
is a complex system call and is used for many purposes including shared memory. The general usage however is to allocate more memory for the process. The malloc
and calloc
library functions usually use it internally.
mmap
是一个复杂的系统调用,用于多种用途,包括共享内存。然而,一般用法是为进程分配更多内存。在malloc
和calloc
库函数通常在内部使用。
munmap
frees the mmap
'ped memory.
munmap
释放mmap
'ped 内存。
fstat
returns various information that the filesystem keeps about a file - size, last modified, permissions, etc.
fstat
返回文件系统保存的有关文件的各种信息 - 大小、最后修改时间、权限等。
回答by kenorb
For each command there is a manual page, you can read it by typing man
and the name of C function, e.g. man lseek
(also check apropos
). They also have description of passed parameters.
对于每个命令都有一个手册页,您可以通过键入man
和 C 函数的名称来阅读它,例如man lseek
(也检查apropos
)。他们也有传递参数的描述。
Here are short summaries:
以下是简短摘要:
lseek
- reposition read/write file offset of the file descriptorwrite
- write to a file descriptor from the bufferclose
- delete a descriptor from the per-process object reference tablemmap
- allocate memory, or map files or devices into memorymunmap
- remove a mapping for the specified address rangefstat
- get file status pointed to by path
lseek
- 重新定位文件描述符的读/写文件偏移量write
- 从缓冲区写入文件描述符close
- 从每个进程的对象引用表中删除一个描述符mmap
- 分配内存,或将文件或设备映射到内存中munmap
- 删除指定地址范围的映射fstat
- 获取路径指向的文件状态
Please note that interpreting single/random syscals won't be meaningful in terms performance. To test significance on performance of these syscalls, you should use -c
parameter which can count time, calls, and errors for each syscall and report the summary. Then you can read more about these which are taking the longest time.
请注意,解释单个/随机系统在性能方面没有意义。要测试这些系统调用的性能的重要性,您应该使用-c
可以计算每个系统调用的时间、调用和错误并报告摘要的参数。然后你可以阅读更多关于这些花费时间最长的内容。
To learn more about output and strace
parameters, check man strace
.
要了解有关输出和strace
参数的更多信息,请查看man strace
。