首页 > 解决方案 > 在 perf 中了解内核符号与我的应用程序的关系

问题描述

我正在尝试分析程序中的瓶颈。
我正在使用perfsudo perf record -agi -F 10000 -p $(pidof myapp)
是我看到的输出的一部分sudo perf report -g graph,0.01

+   63.68%     0.00%  my_thread    [kernel.kallsyms]    [k] entry_SYSCALL_64_after_hwframe
+   63.60%     0.49%  my_thread    [kernel.kallsyms]    [k] do_syscall_64
+   49.35%     0.14%  my_thread    libpthread-2.27.so   [.] __libc_write
+   49.08%     0.04%  my_thread    [kernel.kallsyms]    [k] __x64_sys_write
+   49.04%     0.02%  my_thread    [kernel.kallsyms]    [k] ksys_write
+   48.92%     0.07%  my_thread    [kernel.kallsyms]    [k] vfs_write
+   48.78%     0.03%  my_thread    [kernel.kallsyms]    [k] __vfs_write
+   48.67%     0.12%  my_thread    [kernel.kallsyms]    [k] sock_write_iter
+   48.65%     0.07%  my_thread    [kernel.kallsyms]    [k] new_sync_write
+   48.53%     0.01%  my_thread    [kernel.kallsyms]    [k] sock_sendmsg
+   48.44%     0.07%  my_thread    [kernel.kallsyms]    [k] inet_sendmsg

这似乎是内核中的网络堆栈。根据我的应用程序的功能,这是非常合理的。
稍后在下面我看到我的用户空间函数对接收到的数据进行处理。

但是我在任何地方都看不到连接-我的意思是:我看不到我的用户空间函数调用了一些read()/ write()

void func1() {
  // ...
  read();
  // ...
}
void func2() {
  // ...
  write();
  // ...
}
void func3() {
  // ...
  write();
  // ...
}

--- 更新 ---
我正在使用-g,但仍然看不到与我的代码的连接:

-   43.68%     0.86%  my_thread       [kernel.kallsyms]    [k] do_syscall_64
   - 42.81% do_syscall_64
      - 25.34% __x64_sys_write
         - 25.31% ksys_write
            - 25.18% vfs_write
               - 24.99% __vfs_write
                  - 24.79% new_sync_write
                     - sock_write_iter
                        - 24.60% sock_sendmsg
                           - 24.42% inet_sendmsg
                              - 24.32% tcp_sendmsg
                                 - 23.85% tcp_sendmsg_locked
                                    - 22.09% tcp_push
                                       - 21.98% __tcp_push_pending_frames
                                          - 21.87% tcp_write_xmit
                                             - 21.25% __tcp_transmit_skb
                                                - 20.70% ip_queue_xmit
                                                   - 20.61% __ip_queue_xmit
                                                      - 20.45% ip_local_out
                                                         - 20.27% ip_output
                                                            - 20.16% ip_finish_output
                                                               - 20.01% ip_finish_output2
                                                                  - 18.50% __local_bh_enable_ip
                                                                     - do_softirq.part.21
                                                                        - do_softirq_own_stack
                                                                           - 18.37% __softirqentry_text_start
                                                                              - 18.07% net_rx_action
                                                                                 - 17.92% process_backlog
                                                                                    - 17.78% __netif_receive_skb
                                                                                       - 17.74% __netif_receive_skb_one_core
                                                                                          - 17.53% ip_rcv
                                                                                             - 17.44% ip_rcv_finish
                                                                                                - 17.40% ip_local_deliver
                                                                                                   - 17.37% ip_local_deliver_finish
                                                                                                      - 17.27% ip_protocol_deliver_rcu
                                                                                                         - 17.10% tcp_v4_rcv
                                                                                                            - 16.42% tcp_v4_do_rcv
                                                                                                               - 16.27% tcp_rcv_established
                                                                                                                  - 14.49% tcp_data_queue
                                                                                                                     - 14.28% sock_def_readable
                                                                                                                        - __wake_up_sync_key
                                                                                                                          __wake_up_common_lock
                                                                                                                          _raw_spin_unlock_irqrestore

标签: linuxperformancenetworkingperf

解决方案


推荐阅读