-fno-omit-frame-pointer로 컴파일했는데도 perf_event의 성능 보고서에 스택 기호가 누락되었습니다.

-fno-omit-frame-pointer로 컴파일했는데도 perf_event의 성능 보고서에 스택 기호가 누락되었습니다.

해당 주제에 대한 많은 튜토리얼을 읽고 필요한 모든 작업을 수행했음에도 불구하고 기호가 포함된 스택 추적을 제공하는 perf_events를 얻는 데 여전히 어려움을 겪고 있습니다. 로컬에 설치된 성능(자세한 내용은 아래 참조)에 어떤 방식으로든 결함이 있을 수 있습니까? 어쨌든, 내가 한 일은 다음과 같다.

main.cpp는 동일한 파일에 정의된 몇 가지 함수를 호출하고 일부 메모리를 할당하고 해제한 다음 무언가를 인쇄하는 간단한 C++ 프로그램입니다.

컴파일 명령:

gcc -std=c++11 -lstdc++ main.cpp -Og -fno-omit-frame-pointer -fno-inline -o arr_test

구성 파일 명령:

perf record -a -g -- ./arr_test && perf report --stdio

커널 기호에 대해 다음과 같은 경고가 표시되지만 지금은 애플리케이션의 기호에만 관심이 있으므로 문제가 되지 않는다고 생각합니다.

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.052 MB perf.data (~2285 samples) ]
[kernel.kallsyms] with build id e22966849c48748782a1be4fe0ce94db6838b806 not found, continuing without symbols
[kernel.kallsyms] with build id e22966849c48748782a1be4fe0ce94db6838b806 not found, continuing without symbols
Warning:
Kernel address maps (/proc/{kallsyms,modules}) were restricted.

Check /proc/sys/kernel/kptr_restrict before running 'perf record'.

As no suitable kallsyms nor vmlinux was found, kernel samples
can't be resolved.

Samples in kernel modules can't be resolved as well.

다음은 출력의 일부입니다.

# Overhead   Command      Shared Object
# ........  ........  .................
#
    83.27%  arr_test  arr_test         
            |          
            |--34.12%-- 0x400908
            |          0x7fe72b381ec5
            |          
            |--10.48%-- 0x400903
            |          0x7fe72b381ec5
            |          
            |--10.08%-- 0x4008b8
            |          0x7fe72b381ec5
            |          
            |--9.22%-- 0x4008e5
            |          0x7fe72b381ec5
            |          
            |--9.05%-- 0x4008da
            |          0x7fe72b381ec5
            |          
            |--8.49%-- 0x4008f0
            |          0x7fe72b381ec5
            |          
            |--6.87%-- 0x4008d5
            |          0x7fe72b381ec5
            |          
            |--6.23%-- 0x4008c2
            |          0x7fe72b381ec5
            |          
            |--4.76%-- 0x4008fd
            |          0x7fe72b381ec5
             --0.70%-- [...]

     8.02%  arr_test  [kernel.kallsyms]
            |          
            |--4.87%-- 0xffffffff81140b64
            |          0xffffffff81146646
            |          0xffffffff81182751
            |          0xffffffff811829eb
            |          0xffffffff8173317d
            |          0x7fe72bab86a7
            |          0x7fe72baa7e00

파일 정보("제거되지 않음" 표시):

$ file arr_test 
arr_test: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, not stripped

내 성능 설치에 대한 세부 정보(이러한 경고로 인해 스택의 기호가 표시되지 않습니까?)

Auto-detecting system features:
...                     backtrace: [ on  ]
...                         dwarf: [ OFF ]
...                fortify-source: [ on  ]
...                         glibc: [ on  ]
...                          gtk2: [ on  ]
...                  gtk2-infobar: [ on  ]
...                      libaudit: [ OFF ]
...                        libbfd: [ OFF ]
...                        libelf: [ OFF ]
...             libelf-getphdrnum: [ OFF ]
...                   libelf-mmap: [ OFF ]
...                       libnuma: [ on  ]
...                       libperl: [ on  ]
...                     libpython: [ on  ]
...             libpython-version: [ on  ]
...                      libslang: [ on  ]
...                     libunwind: [ OFF ]
...                       on-exit: [ on  ]
...                stackprotector: [ on  ]
...            stackprotector-all: [ on  ]
...                       timerfd: [ on  ]

config/Makefile:264: No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev
config/Makefile:329: No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1
config/Makefile:354: No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev

perf에서 내 기호를 어떻게 찾을 수 있나요?

답변1

더 많은 디버깅 옵션을 사용하여 컴파일하고 있습니다.

-Og -ggdb3 -fno-omit-frame-pointer

그런 다음 로그할 때 -a 옵션을 사용하지 않고(모든 시스템 프로세스를 모니터링해야 함) 다음을 사용하고 있습니다.

perf record -e cycles -g --call-graph fp -- ./your_app your_args

마지막으로, 내가 사용하고 있는 결과를 보여주기 위해

perf report -g graph

출력은 예상한 대로 보입니다(참고로 저는 debian 9를 사용하고 있으며 성능 보고서 출력은 ncurses를 기반으로 합니다).

-   92.18%     0.00%  stsm     stsm                  [.] main                                                                                                ◆
   - main                                                                                                                                                    ▒
      - 91.77% STSM::run                                                                                                                                     ▒
         + 56.86% STSM::generateCandidates                                                                                                                   ▒
         - 25.22% STSM::detectBlocksOfAllSolidSequences                                                                                                      ▒
            + 23.42% STSM::detectSolidSequenceBlocksFromSolidSequence                                                                                        ▒
              0.81% Segment::unify                                                                                                                           ▒
         + 5.25% STSM::updateKernelsOfAllCandidates                                                                                                          ▒
           1.80% RangedSequence::range                                                                                                                       ▒
         + 1.45% STSM::updateMatchingPositions                                                                                                               ▒
           0.99% Segment::intersects                                                                                                                         ▒
+   92.18%     0.00%  stsm     libc-2.24.so          [.] __libc_start_main                                                                                   ▒
+   92.18%     0.00%  stsm     [unknown]             [k] 0x4d96258d4c544155                                                                                  ▒
+   91.77%     0.00%  stsm     stsm                  [.] STSM::run                                                                                           ▒
+   56.86%     6.74%  stsm     stsm                  [.] STSM::generateCandidates                                                                            ▒
+   49.99%    49.99%  stsm     stsm                  [.] Segment::intersects                                                                                 ▒
+   25.22%     0.00%  stsm     stsm                  [.] STSM::detectBlocksOfAllSolidSequences 

답변2

이것은 오래된 주제이지만 여전히 수백 명의 사람들에게 발생하고 있다고 확신하며 이 StackExchange 질문은 여전히 ​​Google 검색 결과에서 상위에 표시되므로 StackOverflow에서 저에게 도움이 된 답변을 공유하고 있습니다.https://stackoverflow.com/questions/33137543/linux-perf-top-kernel-symbol-not-found

원래:

연주 녹음을 시작하기 전에

echo 0 > /proc/sys/kernel/kptr_restrict

다음을 설정해야 할 수도 있습니다.

RHEL/CentOS/Fedora/etc에 적용 가능합니다.

yum install -y elfutils-libelf-devel libunwind-devel audit-libs-devel slang-devel

또는 데비안/우분투/등의 경우

apt-get install libelf-dev libunwind-dev libaudit-dev libslang-dev

관련 정보