pm-graph: AnalyzeSuspend v5.0
Changes
2 files changed · +1053 −619
| File | Status | Add | Del | Content |
|---|---|---|---|---|
| tools/power/pm-graph/sleepgraph.8 | modified | +41 | −6 | View file |
| tools/power/pm-graph/sleepgraph.py | modified | +1012 | −613 | View file |
Only the first 600 diff lines are shown. Download the complete patch.
tools/power/pm-graph/sleepgraph.8
View filediff --git a/tools/power/pm-graph/sleepgraph.8 b/tools/power/pm-graph/sleepgraph.8
index fbe7bd3..18baaf6 100644
--- a/tools/power/pm-graph/sleepgraph.8
+++ b/tools/power/pm-graph/sleepgraph.8
@@ -52,9 +52,32 @@ disable rtcwake and require a user keypress to resume.
\fB-addlogs\fR
Add the dmesg and ftrace logs to the html output. They will be viewable by
clicking buttons in the timeline.
+.TP
+\fB-result \fIfile\fR
+Export a results table to a text file for parsing.
+.TP
+\fB-sync\fR
+Sync the filesystems before starting the test. This reduces the size of
+the sys_sync call which happens in the suspend_prepare phase.
+.TP
+\fB-rs \fIenable/disable\fR
+During test, enable/disable runtime suspend for all devices. The test is delayed
+by 5 seconds to allow runtime suspend changes to occur. The settings are restored
+after the test is complete.
+.TP
+\fB-display \fIon/off\fR
+Turn the display on or off for the test using the xset command. This helps
+maintain the consistecy of test data for better comparison.
+.TP
+\fB-skiphtml\fR
+Run the test and capture the trace logs, but skip the timeline generation.
.SS "advanced"
.TP
+\fB-gzip\fR
+Gzip the trace and dmesg logs to save space. The tool can also read in gzipped
+logs for processing.
+.TP
\fB-cmd \fIstr\fR
Run the timeline over a custom suspend command, e.g. pm-suspend. By default
the tool forces suspend via /sys/power/state so this allows testing over
@@ -114,6 +137,18 @@ This reduces the html file size as there can be many tiny callgraphs
which are barely visible in the timeline.
The value is a float: e.g. 0.001 represents 1 us.
.TP
+\fB-cgfilter \fI"func1,func2,..."\fR
+Reduce callgraph output in the timeline by limiting it to a list of calls. The
+argument can be a single function name or a comma delimited list.
+(default: none)
+.TP
+\fB-cgskip \fIfile\fR
+Reduce callgraph timeline size by skipping over uninteresting functions
+in the trace, e.g. printk or console_unlock. The functions listed
+in this file will show up as empty leaves in the callgraph with only the start/end
+times displayed. cgskip.txt is used automatically if found in the path, so
+use "off" to disable completely (default: cgskip.txt)
+.TP
\fB-cgphase \fIp\fR
Only show callgraph data for phase \fIp\fR (e.g. suspend_late).
.TP
@@ -122,6 +157,9 @@ In an x2 run, only show callgraph data for test \fIn\fR (e.g. 0 or 1).
.TP
\fB-timeprec \fIn\fR
Number of significant digits in timestamps (0:S, [3:ms], 6:us).
+.TP
+\fB-bufsize \fIN\fR
+Set trace buffer size to N kilo-bytes (default: all of free memory up to 3GB)
.SH COMMANDS
.TP
@@ -144,11 +182,8 @@ Print out the contents of the ACPI Firmware Performance Data Table.
\fB-sysinfo\fR
Print out system info extracted from BIOS. Reads /dev/mem directly instead of going through dmidecode.
.TP
-\fB-usbtopo\fR
-Print out the current USB topology with power info.
-.TP
-\fB-usbauto\fR
-Enable autosuspend for all connected USB devices.
+\fB-devinfo\fR
+Print out the pm settings of all devices which support runtime suspend.
.TP
\fB-flist\fR
Print the list of ftrace functions currently being captured. Functions
@@ -198,7 +233,7 @@ Execute a mem suspend with a 15 second wakeup. Include the logs in the html.
.PP
Execute a standby with a 15 second wakeup. Change the output folder name.
.IP
-\f(CW$ sudo sleepgraph -m standby -rtcwake 15 -o "standby-{hostname}-{date}-{time}"\fR
+\f(CW$ sudo sleepgraph -m standby -rtcwake 15 -o "standby-{host}-{date}-{time}"\fR
.PP
Execute a freeze with no wakeup (require keypress). Change output folder name.
.IP
tools/power/pm-graph/sleepgraph.py
View filediff --git a/tools/power/pm-graph/sleepgraph.py b/tools/power/pm-graph/sleepgraph.py
index 1b60fe2..266409f 100755
--- a/tools/power/pm-graph/sleepgraph.py
+++ b/tools/power/pm-graph/sleepgraph.py
@@ -19,7 +19,7 @@
# Home Page
# https://01.org/suspendresume
# Source repo
-# https://github.com/01org/pm-graph
+# [email protected]:01org/pm-graph
#
# Description:
# This tool is designed to assist kernel and OS developers in optimizing
@@ -57,6 +57,7 @@ import platform
from datetime import datetime
import struct
import ConfigParser
+import gzip
from threading import Thread
from subprocess import call, Popen, PIPE
@@ -68,8 +69,12 @@ from subprocess import call, Popen, PIPE
# store system values and test parameters
class SystemValues:
title = 'SleepGraph'
- version = '4.7'
+ version = '5.0'
ansi = False
+ rs = 0
+ display = 0
+ gzip = False
+ sync = False
verbose = False
testlog = True
dmesglog = False
@@ -78,14 +83,19 @@ class SystemValues:
mincglen = 0.0
cgphase = ''
cgtest = -1
+ cgskip = ''
+ multitest = {'run': False, 'count': 0, 'delay': 0}
max_graph_depth = 0
callloopmaxgap = 0.0001
callloopmaxlen = 0.005
+ bufsize = 0
cpucount = 0
memtotal = 204800
+ memfree = 204800
srgap = 0
cgexp = False
testdir = ''
+ outdir = ''
tpath = '/sys/kernel/debug/tracing/'
fpdtpath = '/sys/firmware/acpi/tables/FPDT'
epath = '/sys/kernel/debug/tracing/events/power/'
@@ -109,22 +119,24 @@ class SystemValues:
dmesgfile = ''
ftracefile = ''
htmlfile = 'output.html'
- embedded = False
+ result = ''
rtcwake = True
rtcwaketime = 15
rtcpath = ''
devicefilter = []
+ cgfilter = []
stamp = 0
execcount = 1
x2delay = 0
+ skiphtml = False
usecallgraph = False
usetraceevents = False
- usetraceeventsonly = False
usetracemarkers = True
usekprobes = True
usedevsrc = False
useprocmon = False
notestrun = False
+ cgdump = False
mixedphaseheight = True
devprops = dict()
predelay = 0
@@ -134,24 +146,33 @@ class SystemValues:
tracertypefmt = '# tracer: (?P<t>.*)'
firmwarefmt = '# fwsuspend (?P<s>[0-9]*) fwresume (?P<r>[0-9]*)$'
tracefuncs = {
- 'sys_sync': dict(),
- 'pm_prepare_console': dict(),
- 'pm_notifier_call_chain': dict(),
- 'freeze_processes': dict(),
- 'freeze_kernel_threads': dict(),
- 'pm_restrict_gfp_mask': dict(),
- 'acpi_suspend_begin': dict(),
- 'suspend_console': dict(),
- 'acpi_pm_prepare': dict(),
- 'syscore_suspend': dict(),
- 'arch_enable_nonboot_cpus_end': dict(),
- 'syscore_resume': dict(),
- 'acpi_pm_finish': dict(),
- 'resume_console': dict(),
- 'acpi_pm_end': dict(),
- 'pm_restore_gfp_mask': dict(),
- 'thaw_processes': dict(),
- 'pm_restore_console': dict(),
+ 'sys_sync': {},
+ '__pm_notifier_call_chain': {},
+ 'pm_prepare_console': {},
+ 'pm_notifier_call_chain': {},
+ 'freeze_processes': {},
+ 'freeze_kernel_threads': {},
+ 'pm_restrict_gfp_mask': {},
+ 'acpi_suspend_begin': {},
+ 'acpi_hibernation_begin': {},
+ 'acpi_hibernation_enter': {},
+ 'acpi_hibernation_leave': {},
+ 'acpi_pm_freeze': {},
+ 'acpi_pm_thaw': {},
+ 'hibernate_preallocate_memory': {},
+ 'create_basic_memory_bitmaps': {},
+ 'swsusp_write': {},
+ 'suspend_console': {},
+ 'acpi_pm_prepare': {},
+ 'syscore_suspend': {},
+ 'arch_enable_nonboot_cpus_end': {},
+ 'syscore_resume': {},
+ 'acpi_pm_finish': {},
+ 'resume_console': {},
+ 'acpi_pm_end': {},
+ 'pm_restore_gfp_mask': {},
+ 'thaw_processes': {},
+ 'pm_restore_console': {},
'CPU_OFF': {
'func':'_cpu_down',
'args_x86_64': {'cpu':'%di:s32'},
@@ -173,56 +194,54 @@ class SystemValues:
'mutex_lock_slowpath': { 'func':'__mutex_lock_slowpath', 'ub': 1 },
'acpi_os_stall': {'ub': 1},
# ACPI
- 'acpi_resume_power_resources': dict(),
- 'acpi_ps_parse_aml': dict(),
+ 'acpi_resume_power_resources': {},
+ 'acpi_ps_parse_aml': {},
# filesystem
- 'ext4_sync_fs': dict(),
+ 'ext4_sync_fs': {},
# 80211
- 'iwlagn_mac_start': dict(),
- 'iwlagn_alloc_bcast_station': dict(),
- 'iwl_trans_pcie_start_hw': dict(),
- 'iwl_trans_pcie_start_fw': dict(),
- 'iwl_run_init_ucode': dict(),
- 'iwl_load_ucode_wait_alive': dict(),
- 'iwl_alive_start': dict(),
- 'iwlagn_mac_stop': dict(),
- 'iwlagn_mac_suspend': dict(),
- 'iwlagn_mac_resume': dict(),
- 'iwlagn_mac_add_interface': dict(),
- 'iwlagn_mac_remove_interface': dict(),
- 'iwlagn_mac_change_interface': dict(),
- 'iwlagn_mac_config': dict(),
- 'iwlagn_configure_filter': dict(),
- 'iwlagn_mac_hw_scan': dict(),
- 'iwlagn_bss_info_changed': dict(),
- 'iwlagn_mac_channel_switch': dict(),
- 'iwlagn_mac_flush': dict(),
+ 'iwlagn_mac_start': {},
+ 'iwlagn_alloc_bcast_station': {},
+ 'iwl_trans_pcie_start_hw': {},
+ 'iwl_trans_pcie_start_fw': {},
+ 'iwl_run_init_ucode': {},
+ 'iwl_load_ucode_wait_alive': {},
+ 'iwl_alive_start': {},
+ 'iwlagn_mac_stop': {},
+ 'iwlagn_mac_suspend': {},
+ 'iwlagn_mac_resume': {},
+ 'iwlagn_mac_add_interface': {},
+ 'iwlagn_mac_remove_interface': {},
+ 'iwlagn_mac_change_interface': {},
+ 'iwlagn_mac_config': {},
+ 'iwlagn_configure_filter': {},
+ 'iwlagn_mac_hw_scan': {},
+ 'iwlagn_bss_info_changed': {},
+ 'iwlagn_mac_channel_switch': {},
+ 'iwlagn_mac_flush': {},
# ATA
'ata_eh_recover': { 'args_x86_64': {'port':'+36(%di):s32'} },
# i915
- 'i915_gem_resume': dict(),
- 'i915_restore_state': dict(),
- 'intel_opregion_setup': dict(),
- 'g4x_pre_enable_dp': dict(),
- 'vlv_pre_enable_dp': dict(),
- 'chv_pre_enable_dp': dict(),
- 'g4x_enable_dp': dict(),
- 'vlv_enable_dp': dict(),
- 'intel_hpd_init': dict(),
- 'intel_opregion_register': dict(),
- 'intel_dp_detect': dict(),
- 'intel_hdmi_detect': dict(),
- 'intel_opregion_init': dict(),
- 'intel_fbdev_set_suspend': dict(),
+ 'i915_gem_resume': {},
+ 'i915_restore_state': {},
+ 'intel_opregion_setup': {},
+ 'g4x_pre_enable_dp': {},
+ 'vlv_pre_enable_dp': {},
+ 'chv_pre_enable_dp': {},
+ 'g4x_enable_dp': {},
+ 'vlv_enable_dp': {},
+ 'intel_hpd_init': {},
+ 'intel_opregion_register': {},
+ 'intel_dp_detect': {},
+ 'intel_hdmi_detect': {},
+ 'intel_opregion_init': {},
+ 'intel_fbdev_set_suspend': {},
}
+ cgblacklist = []
kprobes = dict()
timeformat = '%.3f'
+ cmdline = '%s %s' % \
+ (os.path.basename(sys.argv[0]), string.join(sys.argv[1:], ' '))
def __init__(self):
- # if this is a phoronix test run, set some default options
- if('LOG_FILE' in os.environ and 'TEST_RESULTS_IDENTIFIER' in os.environ):
- self.embedded = True
- self.dmesglog = self.ftracelog = True
- self.htmlfile = os.environ['LOG_FILE']
self.archargs = 'args_'+platform.machine()
self.hostname = platform.node()
if(self.hostname == ''):
@@ -237,18 +256,36 @@ class SystemValues:
if (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()):
self.ansi = True
self.testdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S')
+ def vprint(self, msg):
+ self.logmsg += msg+'\n'
+ if(self.verbose):
+ print(msg)
def rootCheck(self, fatal=True):
if(os.access(self.powerfile, os.W_OK)):
return True
if fatal:
- doError('This command requires sysfs mount and root access')
+ msg = 'This command requires sysfs mount and root access'
+ print('ERROR: %s\n') % msg
+ self.outputResult({'error':msg})
+ sys.exit()
return False
def rootUser(self, fatal=False):
if 'USER' in os.environ and os.environ['USER'] == 'root':
return True
if fatal:
- doError('This command must be run as root')
+ msg = 'This command must be run as root'
+ print('ERROR: %s\n') % msg
+ self.outputResult({'error':msg})
+ sys.exit()
return False
+ def getExec(self, cmd):
+ dirlist = ['/sbin', '/bin', '/usr/sbin', '/usr/bin',
+ '/usr/local/sbin', '/usr/local/bin']
+ for path in dirlist:
+ cmdfull = os.path.join(path, cmd)
+ if os.path.exists(cmdfull):
+ return cmdfull
+ return ''
def setPrecision(self, num):
if num < 0 or num > 6:
return
@@ -258,15 +295,15 @@ class SystemValues:
n = datetime.now()
args['date'] = n.strftime('%y%m%d')
args['time'] = n.strftime('%H%M%S')
- args['hostname'] = self.hostname
+ args['hostname'] = args['host'] = self.hostname
return value.format(**args)
def setOutputFile(self):
if self.dmesgfile != '':
- m = re.match('(?P<name>.*)_dmesg\.txt$', self.dmesgfile)
+ m = re.match('(?P<name>.*)_dmesg\.txt.*', self.dmesgfile)
if(m):
self.htmlfile = m.group('name')+'.html'
if self.ftracefile != '':
- m = re.match('(?P<name>.*)_ftrace\.txt$', self.ftracefile)
+ m = re.match('(?P<name>.*)_ftrace\.txt.*', self.ftracefile)
if(m):
self.htmlfile = m.group('name')+'.html'
def systemInfo(self, info):
@@ -283,16 +320,19 @@ class SystemValues:
c = info['processor-version']
if 'bios-version' in info:
b = info['bios-version']
- self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | numcpu:%d | memsz:%d' % \
- (m, p, c, b, self.cpucount, self.memtotal)
- def printSystemInfo(self):
+ self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | numcpu:%d | memsz:%d | memfr:%d' % \
+ (m, p, c, b, self.cpucount, self.memtotal, self.memfree)
+ def printSystemInfo(self, fatal=False):
self.rootCheck(True)
- out = dmidecode(self.mempath, True)
+ out = dmidecode(self.mempath, fatal)
+ if len(out) < 1:
+ return
fmt = '%-24s: %s'
for name in sorted(out):
print fmt % (name, out[name])
print fmt % ('cpucount', ('%d' % self.cpucount))
print fmt % ('memtotal', ('%d kB' % self.memtotal))
+ print fmt % ('memfree', ('%d kB' % self.memfree))
def cpuInfo(self):
self.cpucount = 0
fp = open('/proc/cpuinfo', 'r')
@@ -305,7 +345,9 @@ class SystemValues:
m = re.match('^MemTotal:[ \t]*(?P<sz>[0-9]*) *kB', line)
if m:
self.memtotal = int(m.group('sz'))
- break
+ m = re.match('^MemFree:[ \t]*(?P<sz>[0-9]*) *kB', line)
+ if m:
+ self.memfree = int(m.group('sz'))
fp.close()
def initTestOutput(self, name):
self.prefix = self.hostname
@@ -315,39 +357,34 @@ class SystemValues:
testtime = datetime.now().strftime(fmt)
self.teststamp = \
'# '+testtime+' '+self.prefix+' '+self.suspendmode+' '+kver
- if(self.embedded):
- self.dmesgfile = \
- '/tmp/'+testtime+'_'+self.suspendmode+'_dmesg.txt'
- self.ftracefile = \
- '/tmp/'+testtime+'_'+self.suspendmode+'_ftrace.txt'
- return
+ ext = ''
+ if self.gzip:
+ ext = '.gz'
self.dmesgfile = \
- self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'
+ self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'+ext
self.ftracefile = \
- self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'
+ self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'+ext
self.htmlfile = \
self.testdir+'/'+self.prefix+'_'+self.suspendmode+'.html'
if not os.path.isdir(self.testdir):
os.mkdir(self.testdir)
+ def getValueList(self, value):
+ out = []
+ for i in value.split(','):
+ if i.strip():
+ out.append(i.strip())
+ return out
def setDeviceFilter(self, value):
- self.devicefilter = []
- if value:
- value = value.split(',')
- for i in value:
- self.devicefilter.append(i.strip())
+ self.devicefilter = self.getValueList(value)
+ def setCallgraphFilter(self, value):
+ self.cgfilter = self.getValueList(value)
+ def setCallgraphBlacklist(self, file):
+ self.cgblacklist = self.listFromFile(file)
def rtcWakeAlarmOn(self):
call('echo 0 > '+self.rtcpath+'/wakealarm', shell=True)
- outD = open(self.rtcpath+'/date', 'r').read().strip()
- outT = open(self.rtcpath+'/time', 'r').read().strip()
- mD = re.match('^(?P<y>[0-9]*)-(?P<m>[0-9]*)-(?P<d>[0-9]*)', outD)
- mT = re.match('^(?P<h>[0-9]*):(?P<m>[0-9]*):(?P<s>[0-9]*)', outT)
- if(mD and mT):
- # get the current time from hardware
- utcoffset = int((datetime.now() - datetime.utcnow()).total_seconds())
- dt = datetime(\
- int(mD.group('y')), int(mD.group('m')), int(mD.group('d')),
- int(mT.group('h')), int(mT.group('m')), int(mT.group('s')))
- nowtime = int(dt.strftime('%s')) + utcoffset
+ nowtime = open(self.rtcpath+'/since_epoch', 'r').read().strip()
+ if nowtime:
+ nowtime = int(nowtime)
else:
# if hardware time fails, use the software time
nowtime = int(datetime.now().strftime('%s'))
@@ -369,10 +406,10 @@ class SystemValues:
ktime = m.group('ktime')
fp.close()
self.dmesgstart = float(ktime)
- def getdmesg(self):
+ def getdmesg(self, fwdata=[]):
+ op = self.writeDatafileHeader(sysvals.dmesgfile, fwdata)
# store all new dmesg lines since initdmesg was called
fp = Popen('dmesg', stdout=PIPE).stdout
- op = open(self.dmesgfile, 'a')
for line in fp:
line = line.replace('\r\n', '')
idx = line.find('[')
@@ -386,11 +423,17 @@ class SystemValues:
op.write(line)
fp.close()
op.close()
- def addFtraceFilterFunctions(self, file):
+ def listFromFile(self, file):
+ list = []
fp = open(file)
- list = fp.read().split('\n')
+ for i in fp.read().split('\n'):
+ i = i.strip()
+ if i and i[0] != '#':
+ list.append(i)
fp.close()
- for i in list:
+ return list
+ def addFtraceFilterFunctions(self, file):
+ for i in self.listFromFile(file):
if len(i) < 2:
continue
self.tracefuncs[i] = dict()
@@ -399,9 +442,7 @@ class SystemValues:
if not current:
call('cat '+self.tpath+'available_filter_functions', shell=True)
return
- fp = open(self.tpath+'available_filter_functions')
- master = fp.read().split('\n')
- fp.close()
+ master = self.listFromFile(self.tpath+'available_filter_functions')
for i in self.tracefuncs:
if 'func' in self.tracefuncs[i]:
i = self.tracefuncs[i]['func']
@@ -410,9 +451,7 @@ class SystemValues:
else:
print self.colorText(i)
def setFtraceFilterFunctions(self, list):
- fp = open(self.tpath+'available_filter_functions')
- master = fp.read().split('\n')
- fp.close()
+ master = self.listFromFile(self.tpath+'available_filter_functions')
flist = ''
for i in list:
if i not in master:
@@ -501,6 +540,7 @@ class SystemValues:
rejects = []
# sort kprobes: trace, ub-dev, custom, dev
kpl = [[], [], [], []]
+ linesout = len(self.kprobes)
for name in sorted(self.kprobes):
res = self.colorText('YES', 32)
if not self.testKprobe(name, self.kprobes[name]):
@@ -528,17 +568,10 @@ class SystemValues:
for kp in kplist:
kprobeevents += self.kprobeText(kp, self.kprobes[kp])
self.fsetVal(kprobeevents, 'kprobe_events')
- # verify that the kprobes were set as ordered
- check = self.fgetVal('kprobe_events')
- linesout = len(kprobeevents.split('\n')) - 1
- linesack = len(check.split('\n')) - 1
if output:
- res = '%d/%d' % (linesack, linesout)
- if linesack < linesout:
- res = self.colorText(res, 31)
- else:
- res = self.colorText(res, 32)
- print(' working kprobe functions enabled: %s' % res)
+ check = self.fgetVal('kprobe_events')
+ linesack = (len(check.split('\n')) - 1) / 2
+ print(' kprobe functions enabled: %d/%d' % (linesack, linesout))
self.fsetVal('1', 'events/kprobes/enable')
def testKprobe(self, kname, kprobe):
self.fsetVal('0', 'events/kprobes/enable')
@@ -555,8 +588,7 @@ class SystemValues:
if linesack < linesout:
return False
return True
- def fsetVal(self, val, path, mode='w'):
- file = self.tpath+path
+ def setVal(self, val, file, mode='w'):
if not os.path.exists(file):
return False
try:
@@ -567,8 +599,9 @@ class SystemValues:
except:
return False
return True
- def fgetVal(self, path):
- file = self.tpath+path
+ def fsetVal(self, val, path, mode='w'):
+ return self.setVal(val, self.tpath+path, mode)
+ def getVal(self, file):
res = ''
if not os.path.exists(file):
return res
@@ -579,10 +612,13 @@ class SystemValues:
except:
pass
return res
+ def fgetVal(self, path):
+ return self.getVal(self.tpath+path)
def cleanupFtrace(self):
- if(self.usecallgraph or self.usetraceevents):
+ if(self.usecallgraph or self.usetraceevents or self.usedevsrc):
self.fsetVal('0', 'events/kprobes/enable')
self.fsetVal('', 'kprobe_events')
+ self.fsetVal('1024', 'buffer_size_kb')
def setupAllKprobes(self):
for name in self.tracefuncs:
self.defaultKprobe(name, self.tracefuncs[name])
@@ -599,7 +635,8 @@ class SystemValues:
if name == f:
return True
return False
- def initFtrace(self, testing=False):
+ def initFtrace(self):
+ self.printSystemInfo(False)
This diff is incomplete. Download the complete patch.