linux - 在 perf 中了解内核符号与我的应用程序的关系
问题描述
我正在尝试分析程序中的瓶颈。
我正在使用perf
这sudo 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()
。
read()
有没有办法查看在/上花费了多少时间write()
(以防套接字阻塞)?- 有没有办法通过我的应用程序从内核网络堆栈中查看堆栈跟踪?所以我会知道究竟是哪个功能在做繁重的网络负载?例如,一直看谁
write()
?
进一步来说; 假设我有 3 个功能,哪一个是导致所有这些 perf 输出的原因?
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
解决方案
推荐阅读
- python-3.x - 从上面的文件夹导入python文件时出现问题
- gitlab - 我如何在 2020 年离开 GitLab 项目/组
- c++ - C++ 枚举类作为可变模板参数
- sql - 如何使用 DML 命令从两个不同的表中更新表中的列
- c++ - 错误:我的班级的“操作员>>”不匹配
- vb.net - 从文本中读取文件并创建循环
- tensorflow - 如何使用 TensorFlow 2 自定义 CNN 层,在 CNN 的密集层提供新输入
- javascript - 未捕获的类型错误:无法读取创建的 VueJ 中未定义的属性“0”
- php - 用户提交收据后删除购物车中的项目
- python - Python通过循环登录不同的帐户