4 from datetime import datetime
14 fp = open('res.txt','w')
16 #open file for reading suspend-resume details
17 with open("ftrace.txt", "r") as file:
19 if line.startswith('#'):
22 if "suspend_enter[3] begin" in line:
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"
31 if "suspend_resume: dpm" in line:
34 statestart= float(line.split(" ...1")[1].replace(" ","").split(":")[0])
35 statestartname=line.split("suspend_resume: ")[1].split('[')[0]
37 statestart= float(line.split("N.1")[1].replace(" ","").split(":")[0])
38 statestartname=line.split("suspend_resume: ")[1].split('[')[0]
42 stateend = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
43 stateendname=line.split("suspend_resume: ")[1].split('[')[0]
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";
50 fp.write(line.split("..1")[1].upper() + " \n")
52 fp.write(line.split("N.1")[1].upper() + " \n")
53 #elif "suspend_resume:" in line:
55 # fp.write(line.split("..1")[1] + "\n")
57 # fp.write(line.split("N.1")[1].upper() + " \n")
59 if "device_pm_callback_start:" in line:
61 dpm_start = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
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:
67 dpm_end = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
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")
74 if "thaw_processes[0] end" in line:
76 cycle_end_time = float(line.split(" ...1")[1].replace(" ","").split(":")[0])
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")
86 cpuoffstart= float(line.split("..1")[1].replace(" ","").split(":")[0])
88 cpuoffstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
91 cpuoffend= float(line.split("..1")[1].replace(" ","").split(":")[0])
93 cpuoffend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
94 str1 = str1 + "CPUOFF took " +str(cpuoffend-cpuoffstart) +" secs\n"
96 if "machine_suspend" in line:
99 mcsusstart= float(line.split("..1")[1].replace(" ","").split(":")[0])
101 mcsusstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
104 mcsusend= float(line.split("..1")[1].replace(" ","").split(":")[0])
106 mcsusend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
107 str1 = str1 + "MACHINE SUSPEND took " +str(mcsusend-mcsusstart) +" secs\n"
112 cpuonstart= float(line.split("..1")[1].replace(" ","").split(":")[0])
114 cpuonstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
117 cpuonend= float(line.split("..1")[1].replace(" ","").split(":")[0])
119 cpuonend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
120 str1 = str1 + "CPU_ON took " +str(cpuonend-cpuonstart) +" secs\n"
122 if "syscore_resume" in line:
125 sysresstart= float(line.split("..1")[1].replace(" ","").split(":")[0])
127 sysresstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
130 sysresend= float(line.split("..1")[1].replace(" ","").split(":")[0])
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:
137 syssusstart= float(line.split("..1")[1].replace(" ","").split(":")[0])
139 syssusstart =float(line.split("N.1")[1].replace(" ","").split(":")[0])
142 syssusend= float(line.split("..1")[1].replace(" ","").split(":")[0])
144 syssusend =float(line.split("N.1")[1].replace(" ","").split(":")[0])
145 str1 = str1 + "SYSTEM CORE SUSPEND took " +str(syssusend-syssusstart) +" secs\n"
150 with open('res.txt', "r") as file:
154 matchObj = re.match( r'Cycle (.*?) took (.*?) sec.*', line, re.M|re.I)
156 digit = re.findall(r'\d+', line)
158 #matchObj1 = re.match( r'\n', line, re.M|re.I)
159 if line == "\n" and flag:
162 cycle1.append(int(digit[0]))
166 matchObj1 = re.match( r'(.*)\n', line, re.M|re.I)
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:
174 matchObj1 = re.match( r'(.*)Cycle ' + str(cycle1[i]) + ' starts(.*)', line, re.M|re.I)
177 matchObj = re.match( r'(.*)Cycle ' + str(cycle1[i] + 1) + ' starts(.*)', line, re.M|re.I)