Chinaunix首页 | 论坛 | 博客
  • 博客访问: 307074
  • 博文数量: 65
  • 博客积分: 185
  • 博客等级: 入伍新兵
  • 技术积分: 609
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-06 21:41
个人简介

好好学习,天天向上

文章分类

全部博文(65)

文章存档

2022年(3)

2021年(25)

2020年(1)

2019年(3)

2016年(2)

2015年(3)

2014年(14)

2013年(7)

2012年(7)

我的朋友

分类: 嵌入式

2022-01-12 16:37:38

例如只关注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


如下脚本统计调度延时,运行时间,被抢占情况

点击(此处)折叠或打开

  1. #!/usr/bin/python3
  2. # -*- coding:UTF-8 -*-
  3. import sys
  4. import os
  5. import glob
  6. import re
  7. import subprocess
  8. #
  9. #taskname in trace.txt must all, include wakeup, switch in, switchout
  10. #
  11. if len(sys.argv) < 3:
  12.         print("Usage: ./xx.py trace.txt taskname")
  13.         sys.exit()


  14. print("script name:", sys.argv[0])
  15. for i in range(1, len(sys.argv)):
  16.   print("para",i,":", sys.argv[i])

  17. para_f=sys.argv[1]
  18. taskname=sys.argv[2]


  19. file_o=open(para_f)
  20. list1=file_o.readlines()
  21. l_index=1
  22. l_begin=0
  23. dict_l=[]
  24. d_index=0
  25. key0="sched_wakeup: comm="+taskname
  26. key1="prev_comm="+taskname
  27. key2="next_comm="+taskname
  28. key3="prev_state=R"

  29. print("key0:", key0)
  30. print("key1:",key1)
  31. print("key2:",key2)
  32. print("key3:",key3)

  33. for c in list1:
  34.     #print(c)
  35.     
  36.     #print("preempted:")
  37.     if key1 in c and key3 in c:
  38.         c = c.rstrip()
  39.         #print(c)

  40.     if key0 in c or key1 in c or key2 in c:
  41.         #print(c)
  42.         c = c.rstrip()
  43.         dict={}
  44.         dict['index']=d_index
  45.         dict['line']=l_index
  46. # <idle>-0 [000] dN.h3.. 144697.812693: sched_wakeup: comm=testTask pid=1203 prio=30 target_cpu=000
  47. #<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
  48. #Group : 0 Range: [0, 162]
  49. #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
  50. #1:    <idle>
  51. #2:    141970
  52. #3:    032847
  53. #4:    sched_switch
  54. #5:    swapper/0
  55. #6:    testTask
  56. #7:    30
  57. #groups:    
  58. #
  59.         if key0 in c:
  60.             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)
  61.             dict['name']=mo.group(4)
  62.             dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))
  63.         if key1 in c:
  64.             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)
  65.             dict['name']=mo.group(4)+"_out"
  66.             dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))
  67.             dict['next']=mo.group(6)
  68.             dict['next_prio']=mo.group(7)
  69.         if key2 in c:
  70.             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)
  71.             dict['name']=mo.group(4)+"_in"
  72.             dict['time']=int(mo.group(2))*1000000 + int(mo.group(3))

  73.         dict['index']=d_index
  74.         dict['line']=l_index
  75.         dict_l.append(dict)

  76.             
  77.         d_index = d_index + 1
  78.         
  79.         

  80.     l_index = l_index + 1
  81. total=0

  82. '''
  83. for dic in dict_l:
  84.     print(dic)
  85. '''

  86. head_flag=0
  87. first_wakeup_index=0
  88. for i in range(0, len(dict_l)):
  89.     dic=dict_l[i]

  90.     #skip head lines which is not sched_wakeup
  91.     if dic['name'] != "sched_wakeup" and head_flag==0:
  92.         print(dic)
  93.         print("skip head which is not wakeup")
  94.         first_wakeup_index=i+1
  95.         continue
  96.     else:
  97.         head_flag=1
  98.     
  99.     #cal the wakeup interval
  100.     if dic['name'] == "sched_wakeup" and i!=first_wakeup_index:
  101.         pre_wakeup={}
  102.         #find the last wakeup
  103.         for j in range(i-1, 0, -1):
  104.             if dict_l[j]['name'] == "sched_wakeup":
  105.                 pre_wakeup=dict_l[j]
  106.                 break
  107.         if 'time' in pre_wakeup:
  108.             dict_l[i]['last_wake+'] = int(dict_l[i]['time']) - int(pre_wakeup['time'])
  109.             
  110.     #cal the sched lat
  111.     if dic['name'] == "sched_switch_in":
  112.         if dict_l[i-1]['name'] == "sched_wakeup":
  113.             dict_l[i]['sched_lat'] = int(dic['time'])-int(dict_l[i-1]['time'])            
  114.         elif dict_l[i-1]['name'] == "sched_switch_out":
  115.             #cal the preempted count in this wakeup period
  116.             preempt_count=0
  117.             for j in range(i-1, 0, -1):
  118.                 if dict_l[j]['name'] == "sched_wakeup":
  119.                     pre_wakeup=dict_l[j]
  120.                     break
  121.                 if dict_l[j]['name'] == "sched_switch_out":
  122.                     preempt_count = preempt_count+1
  123.             dict_l[i]['***preempted_time***'] = int(dic['time'])-int(dict_l[i-1]['time'])
  124.             dict_l[i]['***preempted_count***'] = preempt_count

  125.     #cal the run time
  126.     if dic['name'] == "sched_switch_out":
  127.         if dict_l[i-1]['name'] == "sched_switch_in":
  128.             dict_l[i]['run_time'] = int(dic['time'])-int(dict_l[i-1]['time'])

  129. #print out org data
  130. for dic in dict_l:
  131.     print(dic)


  132. #should be set by user
  133. last_wake_threshold=300
  134. sched_lat_threashold=100
  135. run_time_threashold=200

  136. print("#print out wakeup interval > set:", last_wake_threshold)
  137. for dic in dict_l:
  138.     if dic['name'] == "sched_wakeup":
  139.         if 'last_wake+' in dic and int(dic['last_wake+']) > last_wake_threshold:
  140.             print(dic)

  141. print("#print out sched_lat > set:", sched_lat_threashold)        
  142. for dic in dict_l:
  143.     if dic['name'] == "sched_switch_in":
  144.         if 'sched_lat' in dic and int(dic['sched_lat']) > sched_lat_threashold:
  145.             print(dic)

  146. print("#print out run_time > set:", run_time_threashold)
  147. for dic in dict_l:
  148.     if dic['name'] == "sched_switch_out":
  149.         if 'run_time' in dic and int(dic['run_time']) > run_time_threashold:
  150.             print(dic)

  151. print("#print out when this task is preepmed, and when preempted, how long be preempted")            
  152. for i in range(0, len(dict_l)):
  153.     dic=dict_l[i]
  154.     if dic['name'] == "sched_switch_in":
  155.         if '***preempted_time***' in dic:
  156.             print(dict_l[i-1])
  157.             print(dic)
  158.             print("----------")

阅读(895) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~