如何计算进程切换的花费时间?
假设系统有P1,P2二个进程,P1正在运行,P2是等待运行,系统调度会切换进程以及处理相关环境,让P1进入等待或者挂起状态,P2运行。
如何用程序去计算这个时间。
youiou
10 years, 8 months ago
Answers
[root@linux tracing]# pwd
/sys/kernel/debug/tracing
[root@linux tracing]# echo 0 > tracing_enabled
[root@linux tracing]# echo 1 > /proc/sys/kernel/ftrace_enabled
[root@linux tracing]# echo sched_switch > current_tracer
[root@linux tracing]# echo 1 > tracing_on
[root@linux tracing]# echo 1 > tracing_enabled
# 让内核运行一段时间,这样 ftrace 可以收集一些跟踪信息,之后再停止跟踪
[root@linux tracing]# echo 0 > tracing_enabled
[root@linux tracing]# cat trace | head -10
# tracer: sched_switch
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |
bash-1408 [000] 26208.816058: 1408:120:S + [000] 1408:120:S bash
bash-1408 [000] 26208.816070: 1408:120:S + [000] 1408:120:S bash
bash-1408 [000] 26208.816921: 1408:120:R + [000] 9:120:R events/0
bash-1408 [000] 26208.816939: 1408:120:R ==> [000] 9:120:R events/0
events/0-9 [000] 26208.817081: 9:120:R + [000] 1377:120:R gnome-terminal
events/0-9 [000] 26208.817088: 9:120:S ==> [000] 1377:120:R gnome-terminal
欲知详情,请移步这个问题: http://segmentfault.com/q/1010000000259208/a-1020000000270128 。
咏梦D沙发君
answered 10 years, 8 months ago