]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - scripts/parse_suspend_resume_ftrace.py
arm64: config: Enable CDC-ACM driver in kernel
[hercules2020/nv-tegra/linux-4.4.git] / scripts / parse_suspend_resume_ftrace.py
1 import subprocess
2 import os,re
3 import time
4 from datetime import datetime
5
6
7 cycle1 =[]
8 str1 = ""
9 cycle=0;
10 flag = 0;
11 COUNT = 13;
12
13 date = datetime.now()
14 fp = open('res.txt','w')
15
16 #open file for reading suspend-resume details
17 with open("ftrace.txt", "r") as file:
18     for line in file:
19         if line.startswith('#'):
20             continue
21
22         if "suspend_enter[3] begin" in line:
23              cycle = cycle + 1
24              fp.write("*******************Cycle " +str(cycle) +" starts******************\n")
25              cycle_start_time = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
26         if "suspend_enter[3] end" in line:
27              suspend_enter_end_time = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
28              fp.write("     Suspend enter took       "+str((suspend_enter_end_time-cycle_start_time)*1000000) +" us\n")
29              str1=str1 + "SUSPEND_ENTER took " + str(suspend_enter_end_time-cycle_start_time) +" secs\n"
30
31         if "suspend_resume: dpm" in line:
32             if "begin" in line:
33                 try:
34                     statestart= float(line.split(" ...1")[1].replace(" ","").split(":")[0])
35                     statestartname=line.split("suspend_resume: ")[1].split('[')[0]
36                 except IndexError:
37                     statestart= float(line.split("N.1")[1].replace(" ","").split(":")[0])
38                     statestartname=line.split("suspend_resume: ")[1].split('[')[0]
39
40             elif "end" in line:
41                 try :
42                      stateend = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
43                      stateendname=line.split("suspend_resume: ")[1].split('[')[0]
44                 except IndexError:
45                      stateend = float(line.split("N.1")[1].replace(" ","").split(":")[0])
46                      stateendname=line.split("suspend_resume: ")[1].split('[')[0]
47                 if stateendname == statestartname:
48                    str1 = str1 + stateendname.upper() + " took "+str(stateend - statestart) + " sec \n";
49             try:
50                 fp.write(line.split("..1")[1].upper() + " \n")
51             except IndexError:
52                 fp.write(line.split("N.1")[1].upper() + " \n")
53         #elif "suspend_resume:" in line:
54         #    try:
55         #        fp.write(line.split("..1")[1] + "\n")
56         #    except IndexError:
57         #        fp.write(line.split("N.1")[1].upper() + " \n")
58
59         if "device_pm_callback_start:" in line:
60             try:
61                  dpm_start = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
62             except IndexError:
63                  dpm_start = float(line.split(" .N.1")[1].replace(" ","").split(":")[0])
64             driver_sname = line.split("device_pm_callback_start: ")[1].split(",")[0]
65         if "device_pm_callback_end:" in line:
66             try:
67                  dpm_end = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
68             except:
69                  dpm_end = float(line.split(" .N.1")[1].replace(" ","").split(":")[0])
70             driver_ename = line.split("device_pm_callback_end: ")[1].split(",")[0]
71             if driver_ename == driver_sname:
72                 fp.write("      " +driver_ename.ljust(50) + " ------>       " + str(int((dpm_end - dpm_start)*1000000)) + " us \n")
73
74         if "thaw_processes[0] end" in line:
75             try:
76                   cycle_end_time = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
77             except IndexError:
78                   cycle_end_time = float(line.split(" .N.1")[1].replace(" ","").split(":")[0])
79             fp.write("********************* Cycle " +str(cycle) +" ends***************\n")
80             fp.write("Cycle " + str(cycle) + " took " + str(cycle_end_time - cycle_start_time) + " sec \n")
81             fp.write(str1+"\n\n\n\n")
82             str1 = ""
83         if "CPU_OFF"  in line:
84             if "begin" in line:
85                  try:
86                      cpuoffstart=  float(line.split("..1")[1].replace(" ","").split(":")[0])
87                  except IndexError:
88                      cpuoffstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
89             elif "end" in line:
90                  try:
91                     cpuoffend= float(line.split("..1")[1].replace(" ","").split(":")[0])
92                  except IndexError:
93                      cpuoffend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
94                  str1 = str1 + "CPUOFF took " +str(cpuoffend-cpuoffstart) +" secs\n"
95
96         if "machine_suspend"  in line:
97             if "begin" in line:
98                  try:
99                      mcsusstart=  float(line.split("..1")[1].replace(" ","").split(":")[0])
100                  except IndexError:
101                      mcsusstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
102             elif "end" in line:
103                  try:
104                     mcsusend= float(line.split("..1")[1].replace(" ","").split(":")[0])
105                  except IndexError:
106                      mcsusend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
107                  str1 = str1 + "MACHINE SUSPEND  took " +str(mcsusend-mcsusstart) +" secs\n"
108
109         if "CPU_ON" in line:
110             if "begin" in line:
111                  try:
112                      cpuonstart=  float(line.split("..1")[1].replace(" ","").split(":")[0])
113                  except IndexError:
114                      cpuonstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
115             elif "end" in line:
116                  try:
117                     cpuonend= float(line.split("..1")[1].replace(" ","").split(":")[0])
118                  except IndexError:
119                      cpuonend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
120                  str1 = str1 + "CPU_ON took " +str(cpuonend-cpuonstart) +" secs\n"
121
122         if "syscore_resume"  in line:
123             if "begin" in line:
124                  try:
125                      sysresstart=  float(line.split("..1")[1].replace(" ","").split(":")[0])
126                  except IndexError:
127                      sysresstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
128             elif "end" in line:
129                  try:
130                     sysresend= float(line.split("..1")[1].replace(" ","").split(":")[0])
131                  except IndexError:
132                      sysresend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
133                  str1 = str1 + "SYSTEM CORE RESUME took " +str(sysresend-sysresstart) +" secs\n"
134         if "syscore_suspend"  in line:
135             if "begin" in line:
136                  try:
137                      syssusstart=  float(line.split("..1")[1].replace(" ","").split(":")[0])
138                  except IndexError:
139                      syssusstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
140             elif "end" in line:
141                  try:
142                     syssusend= float(line.split("..1")[1].replace(" ","").split(":")[0])
143                  except IndexError:
144                      syssusend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
145                  str1 = str1 + "SYSTEM CORE SUSPEND took " +str(syssusend-syssusstart) +" secs\n"
146 fp.close();
147
148 lines=0;
149
150 with open('res.txt', "r") as file:
151      length = 0
152      for line in file:
153           lines +=1;
154           matchObj = re.match( r'Cycle (.*?) took (.*?) sec.*', line, re.M|re.I)
155           if matchObj:
156               digit = re.findall(r'\d+', line)
157               flag = 1;
158           #matchObj1 = re.match( r'\n', line, re.M|re.I)
159           if line == "\n" and flag:
160               flag = 0;
161               if length >= COUNT:
162                    cycle1.append(int(digit[0]))
163               length = 0;
164
165           if flag:
166                matchObj1 = re.match( r'(.*)\n', line, re.M|re.I)
167                if matchObj1:
168                    length = length + 1;
169
170 fp = open('/var/www/suspend-resume/result' + str(date) + '.txt','w')
171 for i in range(len(cycle1)):
172     with open('res.txt', "r") as file:
173         for line in file:
174              matchObj1 = re.match( r'(.*)Cycle ' + str(cycle1[i]) + ' starts(.*)', line, re.M|re.I)
175              if matchObj1:
176                 flag = 1;
177              matchObj = re.match( r'(.*)Cycle ' + str(cycle1[i] + 1) + ' starts(.*)',  line, re.M|re.I)
178              if matchObj:
179                  flag = 0;
180              if flag:
181                  fp.write(line);