简体   繁体   English

性能记录如何获取目标进程的指令的虚拟内存地址以及性能用于存储的数据结构

[英]how perf record get the virtual memory address of instruction of the target process and what data struct does perf use to store it

I'm reading source code of perf and try to make sense of how perf record get the the virtual memory address of an Instruction of the target process that trigger perf to count(for example the virtual address of call test ,which is assembly code watched by perf report 's annotation). 我正在阅读perf的源代码,并尝试理解perf record如何获取触发perf计数的目标进程的指令的虚拟内存地址(例如, call test的虚拟地址,该代码是受监视的汇编代码)通过性能perf report的注释)。 And what data structure does perf use to store the virtual address of the instruction that make perf-event happen and trigger counter? perf使用什么数据结构来存储使perf事件发生并触发计数器的指令的虚拟地址?

In order to get the instruction pointers for samples, you must include PERF_SAMPLE_IP in perf_attr.sample_type for the perf_event_open call. 为了得到样品的指令指针,你必须包括PERF_SAMPLE_IPperf_attr.sample_typeperf_event_open电话。 This will include the ip field in the struct for PERF_RECORD_SAMPLE events that you can read from the mmap ringbuffer. 这将包含可从mmap环形缓冲区读取的PERF_RECORD_SAMPLE事件的结构中的ip字段。 See the manpage for details. 有关详细信息,请参见手册页。

PERF_RECORD_SAMPLE
    This record indicates a sample.

       struct {
            struct perf_event_header header;
            u64    sample_id;   /* if PERF_SAMPLE_IDENTIFIER */
            u64    ip;          /* if PERF_SAMPLE_IP */
            u32    pid, tid;    /* if PERF_SAMPLE_TID */
            u64    time;        /* if PERF_SAMPLE_TIME */
            ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM