如何解释strace输出? [英] How to interpret strace output?

查看:572
本文介绍了如何解释strace输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要分析我正在使用strace的应用程序的性能.但是,我真的不知道如何解释strace发出的各种系统调用.下面是其中一些示例:

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:

(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

如果有人能用简单的英文简短地解释从(A)到(F)的这些行在I/O,数据传输,性能重要性等方面的真正含义,我将不胜感激.

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.

我浏览了strace的手册页,但仍然不是很自信.如果您还有其他指针需要我阅读,那就太好了.

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.

我对操作系统有一定的了解,并且了解什么是系统调用,内存,虚拟内存,调度等.

I have some background on Operating Systems and understand what system calls, memory, virtual memory, Scheduling, etc. are.

推荐答案

为了理解这些内容,您必须熟悉POSIX系统调用.它们是用户空间程序用来与内核进行交互的接口.

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.

lseekwriteclosemmapmunmapfstat都是

lseek, write, close, mmap, munmap and fstat are all system calls and are documented in section 2 of the linux manual.

简而言之,lseek将提供的文件描述符的内部指针移动到第二个参数指向的位置的字节,从SEEK_SET(开始),SEEK_CUR(当前位置)或SEEK_END开始(结束).对同一描述符的任何连续readwrite调用都将从该位置开始其动作.请注意,lseek并非针对所有类型的描述符都实现-它对于磁盘上的文件有意义,但对于套接字或管道则没有意义.

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.

write将提供的缓冲区复制到内核空间,并返回实际写入的字节数.根据描述符的类型,内核可以将数据写入磁盘或通过网络发送.通常这是一项昂贵的操作,因为它涉及将该缓冲区传输到内核.

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.

close关闭提供的描述符,并释放内核中与其相关的任何资源.请注意,每个进程对同时打开的描述符的数量都有限制,因此有时有必要关闭描述符以达到此限制.

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.

mmap是一个复杂的系统调用,用于许多目的,包括共享内存.但是,一般用法是为该进程分配更多的内存. malloccalloc库函数通常在内部使用它.

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.

munmap释放mmap'ped的内存.

munmap frees the mmap'ped memory.

fstat返回文件系统保留的有关文件的各种信息-大小,最后修改时间,权限等.

fstat returns various information that the filesystem keeps about a file - size, last modified, permissions, etc.

这篇关于如何解释strace输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆