例如只关注telnetd的调度情况
116 echo "comm == 'telnetd'" > events/sched/sched_wakeup/filter
119 echo "prev_comm == 'telnetd' || next_comm == 'telnetd'" > events/sched/sched_switch/filter
123 echo 1 > events/sched/sched_wakeup/enable
124 echo 1 > events/sched/sched_switch/enable
抓取telnetd被抢占的点, 0为R
echo "prev_comm == 'telnetd' && prev_state == 0" > events/sched/sched_switch/filter
其他
echo "(prev_comm == 'telnetd' && prev_state == 0) || next_comm == 'telnetd'" > events/sched/sched_switch/filter
如下脚本统计调度延时,运行时间,被抢占情况
-
#!/usr/bin/python3
-
# -*- coding:UTF-8 -*-
-
import sys
-
import os
-
import glob
-
import re
-
import subprocess
-
#
-
#taskname in trace.txt must all, include wakeup, switch in, switchout
-
#
-
if len(sys.argv) < 3:
-
print("Usage: ./xx.py trace.txt taskname")
-
sys.exit()
-
-
-
print("script name:", sys.argv[0])
-
for i in range(1, len(sys.argv)):
-
print("para",i,":", sys.argv[i])
-
-
para_f=sys.argv[1]
-
taskname=sys.argv[2]
-
-
-
file_o=open(para_f)
-
list1=file_o.readlines()
-
l_index=1
-
l_begin=0
-
dict_l=[]
-
d_index=0
-
key0="sched_wakeup: comm="+taskname
-
key1="prev_comm="+taskname
-
key2="next_comm="+taskname
-
key3="prev_state=R"
-
-
print("key0:", key0)
-
print("key1:",key1)
-
print("key2:",key2)
-
print("key3:",key3)
-
-
for c in list1:
-
#print(c)
-
-
#print("preempted:")
-
if key1 in c and key3 in c:
-
c = c.rstrip()
-
#print(c)
-
-
if key0 in c or key1 in c or key2 in c:
-
#print(c)
-
c = c.rstrip()
-
dict={}
-
dict['index']=d_index
-
dict['line']=l_index
-
# <idle>-0 [000] dN.h3.. 144697.812693: sched_wakeup: comm=testTask pid=1203 prio=30 target_cpu=000
-
#<idle>-0 [000] d...2.. 141970.032847: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=testTask next_pid=1203 next_prio=30
-
#Group : 0 Range: [0, 162]
-
#0: <idle>-0 [000] d...2.. 141970.032847: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=testTask next_pid=1203 next_prio=30
-
#1: <idle>
-
#2: 141970
-
#3: 032847
-
#4: sched_switch
-
#5: swapper/0
-
#6: testTask
-
#7: 30
-
#groups:
-
#
-
if key0 in c:
-
mo = re.search(r'\s{0,20}(\S{1,50})-[0-9]{1,4}\s{0,10}\[[0-9]{3}\]\s[0-9a-zA-Z_.]{7}\s([0-9]{6}).([0-9]{6}):\s(sched_wakeup):\scomm=(\S{1,20})\s',c)
-
dict['name']=mo.group(4)
-
dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))
-
if key1 in c:
-
mo = re.search(r'\s{0,20}(\S{1,50})-[0-9]{1,4}\s{0,10}\[[0-9]{3}\]\s[0-9a-zA-Z_.]{7}\s([0-9]{6}).([0-9]{6}):\s(sched_switch):\sprev_comm=(\S{1,20})\s[\S*\s]*next_comm=(\S{1,20})\s[\S*\s]*next_prio=(\d{1,3})',c)
-
dict['name']=mo.group(4)+"_out"
-
dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))
-
dict['next']=mo.group(6)
-
dict['next_prio']=mo.group(7)
-
if key2 in c:
-
mo = re.search(r'\s{0,20}(\S{1,50})-[0-9]{1,4}\s{0,10}\[[0-9]{3}\]\s[0-9a-zA-Z_.]{7}\s([0-9]{6}).([0-9]{6}):\s(sched_switch):\sprev_comm=(\S{1,20})\s',c)
-
dict['name']=mo.group(4)+"_in"
-
dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))
-
-
dict['index']=d_index
-
dict['line']=l_index
-
dict_l.append(dict)
-
-
-
d_index = d_index + 1
-
-
-
-
l_index = l_index + 1
-
total=0
-
-
'''
-
for dic in dict_l:
-
print(dic)
-
'''
-
-
head_flag=0
-
first_wakeup_index=0
-
for i in range(0, len(dict_l)):
-
dic=dict_l[i]
-
-
#skip head lines which is not sched_wakeup
-
if dic['name'] != "sched_wakeup" and head_flag==0:
-
print(dic)
-
print("skip head which is not wakeup")
-
first_wakeup_index=i+1
-
continue
-
else:
-
head_flag=1
-
-
#cal the wakeup interval
-
if dic['name'] == "sched_wakeup" and i!=first_wakeup_index:
-
pre_wakeup={}
-
#find the last wakeup
-
for j in range(i-1, 0, -1):
-
if dict_l[j]['name'] == "sched_wakeup":
-
pre_wakeup=dict_l[j]
-
break
-
if 'time' in pre_wakeup:
-
dict_l[i]['last_wake+'] = int(dict_l[i]['time']) - int(pre_wakeup['time'])
-
-
#cal the sched lat
-
if dic['name'] == "sched_switch_in":
-
if dict_l[i-1]['name'] == "sched_wakeup":
-
dict_l[i]['sched_lat'] = int(dic['time'])-int(dict_l[i-1]['time'])
-
elif dict_l[i-1]['name'] == "sched_switch_out":
-
#cal the preempted count in this wakeup period
-
preempt_count=0
-
for j in range(i-1, 0, -1):
-
if dict_l[j]['name'] == "sched_wakeup":
-
pre_wakeup=dict_l[j]
-
break
-
if dict_l[j]['name'] == "sched_switch_out":
-
preempt_count = preempt_count+1
-
dict_l[i]['***preempted_time***'] = int(dic['time'])-int(dict_l[i-1]['time'])
-
dict_l[i]['***preempted_count***'] = preempt_count
-
-
#cal the run time
-
if dic['name'] == "sched_switch_out":
-
if dict_l[i-1]['name'] == "sched_switch_in":
-
dict_l[i]['run_time'] = int(dic['time'])-int(dict_l[i-1]['time'])
-
-
#print out org data
-
for dic in dict_l:
-
print(dic)
-
-
-
#should be set by user
-
last_wake_threshold=300
-
sched_lat_threashold=100
-
run_time_threashold=200
-
-
print("#print out wakeup interval > set:", last_wake_threshold)
-
for dic in dict_l:
-
if dic['name'] == "sched_wakeup":
-
if 'last_wake+' in dic and int(dic['last_wake+']) > last_wake_threshold:
-
print(dic)
-
-
print("#print out sched_lat > set:", sched_lat_threashold)
-
for dic in dict_l:
-
if dic['name'] == "sched_switch_in":
-
if 'sched_lat' in dic and int(dic['sched_lat']) > sched_lat_threashold:
-
print(dic)
-
-
print("#print out run_time > set:", run_time_threashold)
-
for dic in dict_l:
-
if dic['name'] == "sched_switch_out":
-
if 'run_time' in dic and int(dic['run_time']) > run_time_threashold:
-
print(dic)
-
-
print("#print out when this task is preepmed, and when preempted, how long be preempted")
-
for i in range(0, len(dict_l)):
-
dic=dict_l[i]
-
if dic['name'] == "sched_switch_in":
-
if '***preempted_time***' in dic:
-
print(dict_l[i-1])
-
print(dic)
-
print("----------")
阅读(873) | 评论(0) | 转发(0) |