Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 部分程序的性能统计_Linux_Perf_Likwid - Fatal编程技术网

Linux 部分程序的性能统计

Linux 部分程序的性能统计,linux,perf,likwid,Linux,Perf,Likwid,perf是否可以仅为程序执行的一部分收集硬件计数器统计信息?如果是,怎么做 likwid提供了能够定义命名区域的功能,但是如果在只安装了perf的系统上可以这样做,那就太好了 前面的一些问题已经给出了相关答案,但仍存在一些不足: 我得到了同样的错误,我正在使用一个稍新的内核(3.13)。这些修复程序是否有更新版本 我希望保持在命令行上定义事件的灵活性。我还浏览了perf stat的代码,但它似乎没有通过调用perf_event_open来设置 生成一个子进程以运行性能统计。 将perf sta

perf是否可以仅为程序执行的一部分收集硬件计数器统计信息?如果是,怎么做

likwid提供了能够定义命名区域的功能,但是如果在只安装了perf的系统上可以这样做,那就太好了

前面的一些问题已经给出了相关答案,但仍存在一些不足:

  • 我得到了同样的错误,我正在使用一个稍新的内核(3.13)。这些修复程序是否有更新版本
  • 我希望保持在命令行上定义事件的灵活性。我还浏览了perf stat的代码,但它似乎没有通过调用perf_event_open来设置

生成一个子进程以运行性能统计。
perf stat
附加到父级。
根据需要从父进程终止子进程

#include <unistd.h>
#include <stdio.h>
#include <signal.h>

int main()
{

    int pid= getpid();
    int cpid = fork();


    if( cpid == 0)
    {
        // child process .  Run your perf stat
        char buf[50];
        sprintf(buf, "perf stat -p %d   > stat.log 2>&1",pid);
        execl("/bin/sh", "sh", "-c", buf, NULL);

    }
    else
    {
        // set the child the leader of its process group
        setpgid(cpid, 0);

        //////////////////////////////////////////////
        // part of program you wanted to perf stat
        sleep(3);
        ////////////////////////////////////////////////


        ////////////////////////////////////////////////////////////////
        // stop perf stat by killing child process and all its descendants(sh, perf stat etc )
        kill(-cpid, SIGINT);
        ////////////////////////////////////////////////////////////////////


        // rest of the program
        sleep(2);
     }
}
#包括
#包括
#包括
int main()
{
int pid=getpid();
int cpid=fork();
如果(cpid==0)
{
//子进程。运行性能统计
char-buf[50];
sprintf(buf,“性能统计-p%d>stat.log 2>&1”,pid);
execl(“/bin/sh”、“sh”、“-c”、buf、NULL);
}
其他的
{
//将子进程设置为其进程组的负责人
setpgid(cpid,0);
//////////////////////////////////////////////
//您想要执行的程序的一部分
睡眠(3);
////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//通过杀死子进程及其所有子进程(sh、perf stat等)停止perf stat
kill(-cpid,SIGINT);
////////////////////////////////////////////////////////////////////
//节目的其余部分
睡眠(2);
}
}
您可以使用或两者都是Linux兼容的库,允许在userland程序的任意点通过
rdpmc
编程和读取性能计数器


这对您在命令行上指定事件的请求没有直接帮助,但是您可以根据ocperf.py代码或libpfm4将某些内容一起备份

是的,您可以在性能事件打开的情况下运行它。perf stat确实调用它(run_perf_stat→ __运行性能统计→ 创建性能统计计数器→ 每线程执行evsel打开→ __perf_evsel_uopen)。perf没有库来将计数器集成到程序中或在程序中定义区域(它只是最近才获得比
/tmp/perf-$pid.map
文件更好的正常JIT代理接口)。您可以尝试使用诸如或(可能使用libpfm4)之类的库从程序中计算硬件性能。它们将为您编程perf_event_open,libpfm4还具有事件名称表,并且有一些编程方法可以使用env vars/cmdline args指定事件名称。