[英]How to interpret strace output?
I need to profile the performance of an application for which I am using strace.我需要分析我正在使用 strace 的应用程序的性能。 However, I do not really know how to interpret the various system calls the strace emits.
但是,我真的不知道如何解释 strace 发出的各种系统调用。 Examples of a few of them are below:
其中一些示例如下:
(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.我浏览了 strace 的手册页,但仍然不是很自信。 If you any other pointers for me to read, that would be great.
如果您有任何其他建议让我阅读,那就太好了。
I have some background on Operating Systems and understand what system calls, memory, virtual memory, Scheduling, etc. are.我有一些操作系统的背景知识,并且了解系统调用、memory、虚拟 memory、调度等是什么。
In order to understand these, you have to get familiar with the POSIX system calls.为了理解这些,你必须熟悉 POSIX 系统调用。 They are the interface a user-space program uses to interact with the kernel.
它们是用户空间程序用来与 kernel 交互的接口。
lseek
, write
, close
, mmap
, munmap
and fstat
are all system calls and 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).简而言之,
lseek
将提供的文件描述符的内部指针移动到第二个参数指向的 position 字节,从SEEK_SET
(开始)、 SEEK_CUR
(当前位置)或SEEK_END
(结束)开始。 Any consecutive read
and write
calls on the same descriptor will start their action from this position.对同一描述符的任何连续
read
和write
调用都将从该 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
并非针对所有类型的描述符都实现 - 它对磁盘上的文件有意义,但不适用于套接字或 pipe。
write
copies the supplied buffer to kernelspace and returns the number of bytes actually written. write
将提供的缓冲区复制到内核空间并返回实际写入的字节数。 Depending on the kind of the descriptor, the kernel may write the data to disk or send it through the network.根据描述符的种类,kernel 可以将数据写入磁盘或通过网络发送。 This is generally a costly operation because it involves transferring this buffer to the kernel.
这通常是一项昂贵的操作,因为它涉及将此缓冲区传输到 kernel。
close
closes the supplied descriptor and any associated resources with it in the kernel are freed. close
关闭提供的描述符,并释放 kernel 中与其相关的任何资源。 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.请注意,每个进程对同时打开的描述符的数量都有限制,因此有时需要关闭描述符才能达到此限制。
mmap
is a complex system call and is used for many purposes including shared memory. mmap
是一个复杂的系统调用,用于多种用途,包括共享 memory。 The general usage however is to allocate more memory for the process.然而,一般用法是为进程分配更多的 memory。 The
malloc
and calloc
library functions usually use it internally. malloc
和calloc
库函数通常在内部使用它。
munmap
frees the mmap
'ped memory. munmap
释放mmap
'ped memory。
fstat
returns various information that the filesystem keeps about a file - size, last modified, permissions, etc. fstat
返回文件系统保存的有关文件的各种信息 - 大小、上次修改时间、权限等。
For each command there is a manual page, you can read it by typing man
and the name of C function, eg man lseek
(also check apropos
).对于每个命令,都有一个手册页,您可以通过键入
man
和 C function 的名称来阅读它,例如man lseek
(也检查apropos
)。 They also have description of passed parameters.他们也有传递参数的描述。
Here are short summaries:以下是简短的摘要:
lseek
- reposition read/write file offset of the file descriptor lseek
- 重新定位文件描述符的读/写文件偏移量write
- write to a file descriptor from the buffer write
- 从缓冲区写入文件描述符close
- delete a descriptor from the per-process object reference table close
- 从每个进程 object 参考表中删除一个描述符mmap
- allocate memory, or map files or devices into memory mmap
- 将 memory 或 map 文件或设备分配到 memorymunmap
- remove a mapping for the specified address range munmap
- 删除指定地址范围的映射fstat
- get file status pointed to by path 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.要测试这些系统调用的性能重要性,您应该使用
-c
参数,该参数可以计算每个系统调用的时间、调用和错误并报告摘要。 Then you can read more about these which are taking the longest time.然后你可以阅读更多关于这些花费时间最长的内容。
To learn more about output and strace
parameters, check man strace
.要了解有关 output 和
strace
参数的更多信息,请查看man strace
。
See also: How to parse strace in shell into plain text?另请参阅:如何将 shell 中的 strace 解析为纯文本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.