【问题标题】:Generating Raw Intel Processor Trace With Perf使用 Perf 生成原始英特尔处理器跟踪
【发布时间】:2017-08-02 18:49:46
【问题描述】:

我的任务是生成一个原始英特尔处理器跟踪。通过原始,我的意思是跟踪符合文件头:

struct pt_logfile_header {
    unsigned int magic;
    unsigned int version;
};

然后是各种进程、线程、xpage和缓冲区结构:

/* logitem header */
struct pt_logitem_header {
    enum pt_logitem_kind kind;
    unsigned int size;
};
/* type process */
struct pt_logitem_process {
    struct pt_logitem_header header;
    unsigned long tgid;                 // process id
    unsigned long cmd_size;             // the size of command string followed to launch this process
};
/* type thread */
struct pt_logitem_thread {
    struct pt_logitem_header header;
    unsigned long tgid;                 // process id
    unsigned long pid;                  // thread id
};
/* type xpage */
struct pt_logitem_xpage {
    struct pt_logitem_header header;
    unsigned long tgid; // process id
    unsigned long base; // the base address where executable pages were mapped
    unsigned long size; // the total size of the executable pages
};
/* type buffer */
struct pt_logitem_buffer {
    struct pt_logitem_header header;
    unsigned long tgid; // process id
    unsigned long pid; // thread id
    unsigned long sequence; // a per-thread sequence number
    unsigned long size; // the total size of PT packets followed
};

perf record 是否能够创建这种类型的跟踪或非常类似的东西?

【问题讨论】:

  • 您从哪里获得 pt_logfile_header 和其他标头?这种跟踪模式的确切名称是什么(来自英特尔软件开发人员文档)?

标签: debugging intel trace processor perf


【解决方案1】:

计划在 4.1(内核部分)和 4.3(用户空间部分)Linux 内核版本:https://lwn.net/Articles/648154/“向 Linux 添加处理器跟踪支持”,2015 年 7 月:

处理器跟踪 (PT) 是一种用于 Intel CPU 的新跟踪机制,它跟踪 CPU 上执行的分支,它允许重建所有已执行代码的控制流。 Intel CPU 有一种称为 BTS(Branch Trace Store)的旧机制,它也允许进行分支跟踪,但速度很慢并且没有被广泛使用。 PT 允许以更好的性能进行跟踪并收集额外的信息,例如时间。 Broadwell CPU 支持英特尔处理器跟踪。更多信息可以在英特尔架构软件开发人员手册第 3 卷第 36 章中的处理器跟踪规范中找到。

4.1 内核在内核的 perf_events 子系统中实现了处理器跟踪,允许通过 perf 接口使用 PT。用户工具支持尚未完全合并,但预计将用于 4.2。该代码由 Alex Shishkin 和 Adrian Hunter 开发,并由 Emmanuel Lucet 测试。 ...

这里是一个例子,记录一个简单程序的执行情况

% perf record -e intel_pt//u ls
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.190 MB perf.data ]

应该有某种方式使用perf script/perf script -D或修改性能源或perf.data的其他解析来提取原始PT日志。

还可以查看 https://www.halobates.de/pt-tracing-summit15.pdf 来自 Andi Kleen 和 Beeman Strong 的 Tracing Summit 2015 的“Linux 上的英特尔® 处理器跟踪”。它显示了 perf script -D 输出(最后一张幻灯片),其中包含 PERF_RECORD_AUXTRACE 记录中的原始 PT 转储。

还有一些简单的英特尔工具可以与 PT 配合使用:https://github.com/andikleen/simple-pt

simple-pt 是 Linux 上英特尔处理器跟踪 (PT) 的简单实验参考实现。 PT 可以在硬件级别跟踪 CPU 执行的所有分支,开销适中。然后,PT 解码器使用边带跟踪数据对分支跟踪进行解码。

% sptcmd  -c tcall taskset -c 0 ./tcall
cpu   0 offset 1027688,  1003 KB, writing to ptout.0
...
Wrote sideband to ptout.sideband
% sptdecode --sideband ptout.sideband --pt ptout.0 | less
TIME      DELTA    INSNs   OPERATION

simple-pt 由一个

简单的 PT 不支持:

  • 它不支持长期跟踪超过缓冲区容量的数据(无中断)(使用perf
  • 不支持任何采样(使用perf或VTune)
  • 收集数据需要root权限(使用perf
  • 不支持交互式调试(使用gdb [7.10+] 或硬件调试器)

【讨论】:

猜你喜欢
  • 2020-05-24
  • 2015-09-25
  • 1970-01-01
  • 2018-04-20
  • 2015-08-14
  • 2017-03-31
  • 2012-08-26
  • 2023-03-12
  • 2011-01-08
相关资源
最近更新 更多