global traced_cpu; probe begin { traced_cpu = $1 printf("Tracing CPU%d...\n", traced_cpu); }
probe kernel.function("inc_nr_running") { if(cpu() != traced_cpu) next; printf("current is inc_nr and nr is %d \n", @var("rq")->nr_running); }
负责产生 load 触发 enqueue 操作的代码。
1 2 3 4 5 6 7 8
intmain() { int var = 0; while(1){ var = 1+1 ; } return0; }
我开了 tmux,在另一个窗口运行如下代码,然后切好换回产生 enqueue 的代码,反复运行。
1
# stap -v 1.stp 6
在另一个 terminal 里面观察 nr_running 有时候会变成 0。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 10 current is inc_nr and nr is 0 current is inc_nr and nr is 10 current is inc_nr and nr is 0 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9 current is inc_nr and nr is 9