script:ftrace: Analyze suspend resume time of each driver
Alankrita [Wed, 4 Feb 2015 13:28:57 +0000 (18:28 +0530)]
- This adds python script to analyze suspend-resume time of each driver.
(on execution,it reads ftrace data and parses and stores the result
 in res<date>.txt)
-The result can be viewed on 10.24.228.59/suspend-resume
-Supposed to run weekly and store results

Bug 200071658

Change-Id: I30e024c8122a46f889b02a5a6c510f154f64d775
Signed-off-by: Alankrita G <alankritag@nvidia.com>
Reviewed-on: http://git-master/r/681157
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>

scripts/parse_suspend_resume_ftrace.py [new file with mode: 0644]

diff --git a/scripts/parse_suspend_resume_ftrace.py b/scripts/parse_suspend_resume_ftrace.py
new file mode 100644 (file)
index 0000000..6eda468
--- /dev/null
@@ -0,0 +1,139 @@
+import subprocess
+import os
+import time
+from datetime import datetime
+
+
+cycle =0
+str1 = ""
+
+date = datetime.now()
+fp = open('/var/www/suspend-resume/res' + str(date)+'.txt','w')
+
+#open file for reading suspend-resume details
+with open("ftrace.txt", "r") as file:
+    for line in file:
+        if line.startswith('#'):
+            continue
+
+        if "suspend_enter[3] begin" in line:
+             cycle = cycle + 1
+             fp.write("*******************Cycle " +str(cycle) +" starts******************\n")
+             cycle_start_time = float(line.split(" ...1   ")[1].split(":")[0])
+        if "suspend_enter[3] end" in line:
+             suspend_enter_end_time = float(line.split(" ...1   ")[1].split(":")[0])
+             fp.write("     Suspend enter took       "+str((suspend_enter_end_time-cycle_start_time)*1000000) +" us\n")
+             str1=str1 + "SUSPEND_ENTER took " + str(suspend_enter_end_time-cycle_start_time) +" secs\n"
+
+        if "suspend_resume: dpm" in line:
+            if "begin" in line:
+                try:
+                    statestart= float(line.split(" ...1   ")[1].split(":")[0])
+                    statestartname=line.split("suspend_resume: ")[1].split('[')[0]
+                except IndexError:
+                    statestart= float(line.split("N.1   ")[1].split(":")[0])
+                    statestartname=line.split("suspend_resume: ")[1].split('[')[0]
+
+            elif "end" in line:
+                try :
+                     stateend = float(line.split(" ...1   ")[1].split(":")[0])
+                     stateendname=line.split("suspend_resume: ")[1].split('[')[0]
+                except IndexError:
+                     stateend = float(line.split("N.1   ")[1].split(":")[0])
+                     stateendname=line.split("suspend_resume: ")[1].split('[')[0]
+                if stateendname == statestartname:
+                   str1 = str1 + stateendname.upper() + " took "+str(stateend - statestart) + " sec \n";
+            try:
+                fp.write(line.split("..1")[1].upper() + " \n")
+            except IndexError:
+                fp.write(line.split("N.1")[1].upper() + " \n")
+        #elif "suspend_resume:" in line:
+        #    try:
+        #        fp.write(line.split("..1")[1] + "\n")
+        #    except IndexError:
+        #        fp.write(line.split("N.1")[1].upper() + " \n")
+
+        if "device_pm_callback_start:" in line:
+            try:
+                 dpm_start = float(line.split(" ...1   ")[1].split(":")[0])
+            except IndexError:
+                 dpm_start = float(line.split(" .N.1   ")[1].split(":")[0])
+            driver_sname = line.split("device_pm_callback_start: ")[1].split(",")[0]
+        if "device_pm_callback_end:" in line:
+            try:
+                 dpm_end = float(line.split(" ...1   ")[1].split(":")[0])
+            except:
+                 dpm_end = float(line.split(" .N.1   ")[1].split(":")[0])
+            driver_ename = line.split("device_pm_callback_end: ")[1].split(",")[0]
+            if driver_ename == driver_sname:
+                fp.write("      " +driver_ename.ljust(50) + " ------>       " + str((dpm_end - dpm_start)*1000000) + " us \n")
+
+        if "thaw_processes[0] end" in line:
+            cycle_end_time = float(line.split(" ...1   ")[1].split(":")[0])
+            fp.write("********************* Cycle " +str(cycle) +" ends***************\n")
+            fp.write("Cycle " + str(cycle) + " took " + str(cycle_end_time - cycle_start_time) + " sec \n")
+            fp.write(str1+"\n\n\n\n")
+            str1 = ""
+        if "CPU_OFF"  in line:
+            if "begin" in line:
+                 try:
+                     cpuoffstart=  float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     cpuoffstart =float(line.split("N.1   ")[1].split(":")[0])
+            elif "end" in line:
+                 try:
+                    cpuoffend= float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     cpuoffend =float(line.split("N.1   ")[1].split(":")[0])
+                 str1 = str1 + "CPUOFF took " +str(cpuoffend-cpuoffstart) +" secs\n"
+
+        if "machine_suspend"  in line:
+            if "begin" in line:
+                 try:
+                     mcsusstart=  float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     mcsusstart =float(line.split("N.1   ")[1].split(":")[0])
+            elif "end" in line:
+                 try:
+                    mcsusend= float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     mcsusend =float(line.split("N.1   ")[1].split(":")[0])
+                 str1 = str1 + "MACHINE SUSPEND  took " +str(mcsusend-mcsusstart) +" secs\n"
+
+        if "CPU_ON" in line:
+            if "begin" in line:
+                 try:
+                     cpuonstart=  float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     cpuonstart =float(line.split("N.1   ")[1].split(":")[0])
+            elif "end" in line:
+                 try:
+                    cpuonend= float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     cpuonend =float(line.split("N.1   ")[1].split(":")[0])
+                 str1 = str1 + "CPU_ON took " +str(cpuonend-cpuonstart) +" secs\n"
+
+        if "syscore_resume"  in line:
+            if "begin" in line:
+                 try:
+                     sysresstart=  float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     sysresstart =float(line.split("N.1   ")[1].split(":")[0])
+            elif "end" in line:
+                 try:
+                    sysresend= float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     sysresend =float(line.split("N.1   ")[1].split(":")[0])
+                 str1 = str1 + "SYSTEM CORE RESUME took " +str(sysresend-sysresstart) +" secs\n"
+        if "syscore_suspend"  in line:
+            if "begin" in line:
+                 try:
+                     syssusstart=  float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     syssusstart =float(line.split("N.1   ")[1].split(":")[0])
+            elif "end" in line:
+                 try:
+                    syssusend= float(line.split("..1   ")[1].split(":")[0])
+                 except IndexError:
+                     syssusend =float(line.split("N.1   ")[1].split(":")[0])
+                 str1 = str1 + "SYSTEM CORE SUSPEND took " +str(syssusend-syssusstart) +" secs\n"