【问题标题】:perf mem doesn't records mem load on heapperf mem 不记录堆上的 mem 负载
【发布时间】:2022-10-26 04:09:42
【问题描述】:

我在我的测试 C 程序中使用了 perf mem,因为我想在同一页面上获取 mem 加载(和存储)的次数。

一个。我的 C 程序在这里:

“测试.c”

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

const int TESTSIZE = 1024*10;

int main(){
    int* ptr_obj = (int*)malloc(sizeof(int)*TESTSIZE);
    int count = 0;
    while(count < 1000){
            for (int i=0; i< TESTSIZE; i++) {
                ptr_obj[i] = 12;
            }

            for (int i=1; i < TESTSIZE-1; i++) {
                ptr_obj[i] = ptr_obj[i-1] + ptr_obj[i+1] - ptr_obj[i] + 1;
            }
            
            count ++;
            sleep(1);
    }
return 0;
}

湾。然后我用这个命令构建它:

gcc -O0 -o stest stest.c

C。接下来由 perf mem 记录使用此命令:

perf 内存记录 ./test

大约 5 秒后,我通过 CTRL + C 中断了该过程。

d。我使用此命令获取报告:

perf mem 报告 --stdio -d 测试

这是输出。(仅内存加载)

# To display the perf.data header info, please use --header/--header-only options.
#
# dso: stest
#
# Total Lost Samples: 0
#
# Samples: 94  of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 5792
# Sort order   : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked
#
# Overhead       Samples  Local Weight  Memory access             Symbol    Data Symbol             Data Object  Snoop         TLB access              Locked
# ........  ............  ............  ........................  ........  ......................  ...........  ............  ......................  ......
#
     6.22%             8  45            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     5.92%             7  49            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     5.28%             6  51            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     4.87%             6  47            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     4.45%             6  43            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     3.97%             5  46            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     3.45%             4  50            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     2.75%             3  53            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     2.69%             3  52            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     2.49%             3  48            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     2.21%             4  32            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     2.07%             3  40            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.93%             2  56            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.90%             2  55            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.86%             2  54            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.81%             3  35            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.76%             3  34            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.71%             3  33            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.52%             2  44            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.45%             2  42            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.42%             2  41            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.35%             2  39            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     1.00%             1  58            LFB or LFB hit            [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     0.66%             1  38            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     0.64%             1  37            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No
     0.62%             1  36            L1 or L1 hit              [.] main  [.] 0x00007ffd193dbd50  [stack]      None          L1 or L2 hit            No


显然,这里没有堆记录。

我的问题是

    a. why no heap record?
    b. how to get the record.
    c. or maybe my test C program has something wrong

【问题讨论】:

    标签: c linux perf


    【解决方案1】:

    您正在分配非常小的内存(10k)。将其增加到更大的值。

    $ head ./stest.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    const int TESTSIZE = 1024*1024*1024;
    
    int main(){
    

    perf record之后,

    $ perf mem report --stdio -d stest
    # Sort order   : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked,blocked,local_ins_lat,p_stage_cyc
    ...
      0.16%             1  4583          Local RAM or RAM hit      [.] main  [.] 0x00007ff5b2808580  anon         Hit           L1 or L2 hit            No       N/A        0        
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-10
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 2015-01-27
      • 1970-01-01
      相关资源
      最近更新 更多