Lines Matching +full:self +full:- +full:power

2 # SPDX-License-Identifier: GPL-2.0-only
21 # https://www.intel.com/content/www/us/en/developer/topic-technology/open/pm-graph/overview.html
23 # [email protected]:intel/pm-graph
51 # ----------------- LIBRARIES --------------------
74 print('[%09.3f] %s' % (time.time()-mystarttime, msg))
82 # ----------------- CLASSES --------------------
86 # A global, single-instance container used to
108 cgtest = -1
126 epath = '/sys/kernel/tracing/events/power/'
127 pmdpath = '/sys/power/pm_debug_messages'
141 powerfile = '/sys/power/state'
142 mempowerfile = '/sys/power/mem_sleep'
143 diskpowerfile = '/sys/power/disk'
183 tmstart = 'SUSPEND START %Y%m%d-%H:%M:%S.%f'
184 tmend = 'RESUME COMPLETE %Y%m%d-%H:%M:%S.%f'
299 [0, 'sysinfo', 'uname', '-a'],
300 [0, 'cpuinfo', 'head', '-7', '/proc/cpuinfo'],
303 [0, 'pcidevices', 'lspci', '-tv'],
304 [0, 'usbdevices', 'lsusb', '-tv'],
305 [0, 'acpidevices', 'sh', '-c', 'ls -l /sys/bus/acpi/devices/*/physical_node'],
312 [2, 'gpecounts', 'sh', '-c', 'grep -v invalid /sys/firmware/acpi/interrupts/*'],
313 [2, 'suspendstats', 'sh', '-c', 'grep -v invalid /sys/power/suspend_stats/*'],
314 …[2, 'cpuidle', 'sh', '-c', 'grep -v invalid /sys/devices/system/cpu/cpu*/cpuidle/state*/s2idle/*'],
315 [2, 'battery', 'sh', '-c', 'grep -v invalid /sys/class/power_supply/*/*'],
316 [2, 'thermal', 'sh', '-c', 'grep . /sys/class/thermal/thermal_zone*/temp'],
324 def __init__(self): argument
325 self.archargs = 'args_'+platform.machine()
326 self.hostname = platform.node()
327 if(self.hostname == ''):
328 self.hostname = 'localhost'
335 self.rtcpath = rtc
337 self.ansi = True
338 self.testdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S')
341 self.sudouser = os.environ['SUDO_USER']
342 def resetlog(self): argument
343 self.logmsg = ''
344 self.platinfo = []
345 def vprint(self, msg): argument
346 self.logmsg += msg+'\n'
347 if self.verbose or msg.startswith('WARNING:'):
349 def signalHandler(self, signum, frame): argument
350 signame = self.signames[signum] if signum in self.signames else 'UNKNOWN'
354 self.outputResult({'stack':stack})
359 self.outputResult({'error':msg})
362 def signalHandlerInit(self): argument
365 self.signames = dict()
370 signal.signal(signum, self.signalHandler)
373 self.signames[signum] = s
374 def rootCheck(self, fatal=True): argument
375 if(os.access(self.powerfile, os.W_OK)):
380 self.outputResult({'error':msg})
383 def rootUser(self, fatal=False): argument
389 self.outputResult({'error':msg})
392 def usable(self, file, ishtml=False): argument
405 def getExec(self, cmd): argument
420 def setPrecision(self, num): argument
423 self.timeformat = '%.{0}f'.format(num)
424 def setOutputFolder(self, value): argument
429 args['hostname'] = args['host'] = self.hostname
430 args['mode'] = self.suspendmode
432 def setOutputFile(self): argument
433 if self.dmesgfile != '':
434 m = re.match(r'(?P<name>.*)_dmesg\.txt.*', self.dmesgfile)
436 self.htmlfile = m.group('name')+'.html'
437 if self.ftracefile != '':
438 m = re.match(r'(?P<name>.*)_ftrace\.txt.*', self.ftracefile)
440 self.htmlfile = m.group('name')+'.html'
441 def systemInfo(self, info): argument
443 if 'baseboard-manufacturer' in info:
444 m = info['baseboard-manufacturer']
445 elif 'system-manufacturer' in info:
446 m = info['system-manufacturer']
447 if 'system-product-name' in info:
448 p = info['system-product-name']
449 elif 'baseboard-product-name' in info:
450 p = info['baseboard-product-name']
451 if m[:5].lower() == 'intel' and 'baseboard-product-name' in info:
452 p = info['baseboard-product-name']
453 c = info['processor-version'] if 'processor-version' in info else ''
454 b = info['bios-version'] if 'bios-version' in info else ''
455 r = info['bios-release-date'] if 'bios-release-date' in info else ''
456self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | biosdate:%s | numcpu:%d | memsz…
457 (m, p, c, b, r, self.cpucount, self.memtotal, self.memfree)
458 if self.osversion:
459 self.sysstamp += ' | os:%s' % self.osversion
460 def printSystemInfo(self, fatal=False): argument
461 self.rootCheck(True)
462 out = dmidecode(self.mempath, fatal)
465 fmt = '%-24s: %s'
466 if self.osversion:
467 print(fmt % ('os-version', self.osversion))
470 print(fmt % ('cpucount', ('%d' % self.cpucount)))
471 print(fmt % ('memtotal', ('%d kB' % self.memtotal)))
472 print(fmt % ('memfree', ('%d kB' % self.memfree)))
473 def cpuInfo(self): argument
474 self.cpucount = 0
478 if re.match(r'^processor[ \t]*:[ \t]*[0-9]*', line):
479 self.cpucount += 1
483 m = re.match(r'^MemTotal:[ \t]*(?P<sz>[0-9]*) *kB', line)
485 self.memtotal = int(m.group('sz'))
486 m = re.match(r'^MemFree:[ \t]*(?P<sz>[0-9]*) *kB', line)
488 self.memfree = int(m.group('sz'))
489 if os.path.exists('/etc/os-release'):
490 with open('/etc/os-release', 'r') as fp:
493 self.osversion = line[12:].strip().replace('"', '')
494 def initTestOutput(self, name): argument
495 self.prefix = self.hostname
498 fmt = name+'-%m%d%y-%H%M%S'
500 self.teststamp = \
501 '# '+testtime+' '+self.prefix+' '+self.suspendmode+' '+kver
503 if self.gzip:
505 self.dmesgfile = \
506 self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'+ext
507 self.ftracefile = \
508 self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'+ext
509 self.htmlfile = \
510 self.testdir+'/'+self.prefix+'_'+self.suspendmode+'.html'
511 if not os.path.isdir(self.testdir):
512 os.makedirs(self.testdir)
513 self.sudoUserchown(self.testdir)
514 def getValueList(self, value): argument
520 def setDeviceFilter(self, value): argument
521 self.devicefilter = self.getValueList(value)
522 def setCallgraphFilter(self, value): argument
523 self.cgfilter = self.getValueList(value)
524 def skipKprobes(self, value): argument
525 for k in self.getValueList(value):
526 if k in self.tracefuncs:
527 del self.tracefuncs[k]
528 if k in self.dev_tracefuncs:
529 del self.dev_tracefuncs[k]
530 def setCallgraphBlacklist(self, file): argument
531 self.cgblacklist = self.listFromFile(file)
532 def rtcWakeAlarmOn(self): argument
533 call('echo 0 > '+self.rtcpath+'/wakealarm', shell=True)
534 nowtime = open(self.rtcpath+'/since_epoch', 'r').read().strip()
540 alarm = nowtime + self.rtcwaketime
541 call('echo %d > %s/wakealarm' % (alarm, self.rtcpath), shell=True)
542 def rtcWakeAlarmOff(self): argument
543 call('echo 0 > %s/wakealarm' % self.rtcpath, shell=True)
544 def initdmesg(self): argument
553 m = re.match(r'[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
557 self.dmesgstart = float(ktime)
558 def getdmesg(self, testdata): argument
559 op = self.writeDatafileHeader(self.dmesgfile, testdata)
567 m = re.match(r'[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
571 if ktime > self.dmesgstart:
575 def listFromFile(self, file): argument
584 def addFtraceFilterFunctions(self, file): argument
585 for i in self.listFromFile(file):
588 self.tracefuncs[i] = dict()
589 def getFtraceFilterFunctions(self, current): argument
590 self.rootCheck(True)
592 call('cat '+self.tpath+'available_filter_functions', shell=True)
594 master = self.listFromFile(self.tpath+'available_filter_functions')
595 for i in sorted(self.tracefuncs):
596 if 'func' in self.tracefuncs[i]:
597 i = self.tracefuncs[i]['func']
601 print(self.colorText(i))
602 def setFtraceFilterFunctions(self, list): argument
603 master = self.listFromFile(self.tpath+'available_filter_functions')
612 fp = open(self.tpath+'set_graph_function', 'w')
615 def basicKprobe(self, name): argument
616 self.kprobes[name] = {'name': name,'func': name,'args': dict(),'format': name}
617 def defaultKprobe(self, name, kdata): argument
622 if self.archargs in k:
623 k['args'] = k[self.archargs]
627 self.kprobes[name] = k
628 def kprobeColor(self, name): argument
629 if name not in self.kprobes or 'color' not in self.kprobes[name]:
631 return self.kprobes[name]['color']
632 def kprobeDisplayName(self, name, dataraw): argument
633 if name not in self.kprobes:
634 self.basicKprobe(name)
645 fmt, args = self.kprobes[name]['format'], self.kprobes[name]['args']
660 def kprobeText(self, kname, kprobe): argument
669 if self.archargs in kprobe:
670 args = kprobe[self.archargs]
673 if re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', func):
675 for arg in re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', fmt):
683 def addKprobes(self, output=False): argument
684 if len(self.kprobes) < 1:
690 # sort kprobes: trace, ub-dev, custom, dev
692 linesout = len(self.kprobes)
693 for name in sorted(self.kprobes):
694 res = self.colorText('YES', 32)
695 if not self.testKprobe(name, self.kprobes[name]):
696 res = self.colorText('NO')
699 if name in self.tracefuncs:
701 elif name in self.dev_tracefuncs:
702 if 'ub' in self.dev_tracefuncs[name]:
713 self.kprobes.pop(name)
715 self.fsetVal('', 'kprobe_events')
718 kprobeevents += self.kprobeText(kp, self.kprobes[kp])
719 self.fsetVal(kprobeevents, 'kprobe_events')
721 check = self.fgetVal('kprobe_events')
722 linesack = (len(check.split('\n')) - 1) // 2
724 self.fsetVal('1', 'events/kprobes/enable')
725 def testKprobe(self, kname, kprobe): argument
726 self.fsetVal('0', 'events/kprobes/enable')
727 kprobeevents = self.kprobeText(kname, kprobe)
731 self.fsetVal(kprobeevents, 'kprobe_events')
732 check = self.fgetVal('kprobe_events')
740 def setVal(self, val, file): argument
751 def fsetVal(self, val, path): argument
752 if not self.useftrace:
754 return self.setVal(val, self.tpath+path)
755 def getVal(self, file): argument
766 def fgetVal(self, path): argument
767 if not self.useftrace:
769 return self.getVal(self.tpath+path)
770 def cleanupFtrace(self): argument
771 if self.useftrace:
772 self.fsetVal('0', 'events/kprobes/enable')
773 self.fsetVal('', 'kprobe_events')
774 self.fsetVal('1024', 'buffer_size_kb')
775 def setupAllKprobes(self): argument
776 for name in self.tracefuncs:
777 self.defaultKprobe(name, self.tracefuncs[name])
778 for name in self.dev_tracefuncs:
779 self.defaultKprobe(name, self.dev_tracefuncs[name])
780 def isCallgraphFunc(self, name): argument
781 if len(self.tracefuncs) < 1 and self.suspendmode == 'command':
783 for i in self.tracefuncs:
784 if 'func' in self.tracefuncs[i]:
785 f = self.tracefuncs[i]['func']
791 def initFtrace(self, quiet=False): argument
792 if not self.useftrace:
798 self.fsetVal('0', 'tracing_on')
799 self.cleanupFtrace()
801 self.fsetVal('global', 'trace_clock')
802 self.fsetVal('nop', 'current_tracer')
804 cpus = max(1, self.cpucount)
805 if self.bufsize > 0:
806 tgtsize = self.bufsize
807 elif self.usecallgraph or self.usedevsrc:
808 bmax = (1*1024*1024) if self.suspendmode in ['disk', 'command'] \
810 tgtsize = min(self.memfree, bmax)
813 while not self.fsetVal('%d' % (tgtsize // cpus), 'buffer_size_kb'):
815 tgtsize -= 65536
817 tgtsize = int(self.fgetVal('buffer_size_kb')) * cpus
819 self.vprint('Setting trace buffers to %d kB (%d kB per cpu)' % (tgtsize, tgtsize/cpus))
821 if(self.usecallgraph):
823 self.fsetVal('function_graph', 'current_tracer')
824 self.fsetVal('', 'set_ftrace_filter')
826 fp = open(self.tpath+'set_ftrace_notrace', 'w')
830 self.fsetVal('print-parent', 'trace_options')
831 self.fsetVal('funcgraph-abstime', 'trace_options')
832 self.fsetVal('funcgraph-cpu', 'trace_options')
833 self.fsetVal('funcgraph-duration', 'trace_options')
834 self.fsetVal('funcgraph-proc', 'trace_options')
835 self.fsetVal('funcgraph-tail', 'trace_options')
836 self.fsetVal('nofuncgraph-overhead', 'trace_options')
837 self.fsetVal('context-info', 'trace_options')
838 self.fsetVal('graph-time', 'trace_options')
839 self.fsetVal('%d' % self.max_graph_depth, 'max_graph_depth')
841 if(self.usetraceevents):
843 for fn in self.tracefuncs:
844 if 'func' in self.tracefuncs[fn]:
845 cf.append(self.tracefuncs[fn]['func'])
848 if self.ftop:
849 self.setFtraceFilterFunctions([self.ftopfunc])
851 self.setFtraceFilterFunctions(cf)
853 elif self.usekprobes:
854 for name in self.tracefuncs:
855 self.defaultKprobe(name, self.tracefuncs[name])
856 if self.usedevsrc:
857 for name in self.dev_tracefuncs:
858 self.defaultKprobe(name, self.dev_tracefuncs[name])
861 self.addKprobes(self.verbose)
862 if(self.usetraceevents):
864 events = iter(self.traceevents)
866 self.fsetVal('1', 'events/power/'+e+'/enable')
868 self.fsetVal('', 'trace')
869 def verifyFtrace(self): argument
874 if not os.path.exists(self.tpath+'trace'):
875 self.tpath = '/sys/kernel/debug/tracing/'
876 if not os.path.exists(self.epath):
877 self.epath = '/sys/kernel/debug/tracing/events/power/'
879 tp = self.tpath
880 if(self.usecallgraph):
890 def verifyKprobes(self): argument
893 tp = self.tpath
898 def colorText(self, str, color=31): argument
899 if not self.ansi:
902 def writeDatafileHeader(self, filename, testdata): argument
903 fp = self.openlog(filename, 'w')
904 fp.write('%s\n%s\n# command | %s\n' % (self.teststamp, self.sysstamp, self.cmdline))
919 def sudoUserchown(self, dir): argument
920 if os.path.exists(dir) and self.sudouser:
921 cmd = 'chown -R {0}:{0} {1} > /dev/null 2>&1'
922 call(cmd.format(self.sudouser, dir), shell=True)
923 def outputResult(self, testdata, num=0): argument
924 if not self.result:
929 fp = open(self.result, 'a')
935 self.sudoUserchown(self.result)
953 self.sudoUserchown(self.result)
954 def configFile(self, file): argument
963 def openlog(self, filename, mode): argument
964 isgz = self.gzip
975 def putlog(self, filename, text): argument
976 with self.openlog(filename, 'a') as fp:
979 def dlog(self, text): argument
980 if not self.dmesgfile:
982 self.putlog(self.dmesgfile, '# %s\n' % text)
983 def flog(self, text): argument
984 self.putlog(self.ftracefile, text)
985 def b64unzip(self, data): argument
991 def b64zip(self, data): argument
994 def platforminfo(self, cmdafter): argument
996 if not os.path.exists(self.ftracefile):
1001 if self.suspendmode == 'command' and self.testcommand:
1002 footer += '# platform-testcmd: %s\n' % (self.testcommand)
1007 tf = self.openlog(self.ftracefile, 'r')
1009 if tp.stampInfo(line, self):
1025 if(re.match(r'.*/power', dirname) and 'async' in filenames):
1026 dev = dirname.split('/')[-2]
1028 props[dev].syspath = dirname[:-6]
1036 if os.path.exists(dirname+'/power/async'):
1037 fp = open(dirname+'/power/async')
1069 footer += '# platform-devinfo: %s\n' % self.b64zip(out)
1073 footer += '# platform-%s: %s | %s\n' % (name, cmdline, self.b64zip(info))
1074 self.flog(footer)
1076 def commonPrefix(self, list): argument
1082 prefix = prefix[:len(prefix)-1]
1085 if '/' in prefix and prefix[-1] != '/':
1088 def dictify(self, text, format): argument
1105 def cmdinfovar(self, arg): argument
1108 cmd = [self.getExec('ip'), '-4', '-o', '-br', 'addr']
1119 def cmdinfo(self, begin, debug=False): argument
1122 self.cmd1 = dict()
1123 for cargs in self.infocmds:
1126 if args[i][0] == '{' and args[i][-1] == '}':
1127 args[i] = self.cmdinfovar(args[i][1:-1])
1128 cmdline, cmdpath = ' '.join(args[0:]), self.getExec(args[0])
1131 self.dlog('[%s]' % cmdline)
1139 self.cmd1[name] = self.dictify(info, delta)
1140 elif not debug and delta and name in self.cmd1:
1141 before, after = self.cmd1[name], self.dictify(info, delta)
1143 prefix = self.commonPrefix(list(before.keys()))
1148 dinfo += '\t%s : %s -> %s\n' % \
1158 def testVal(self, file, fmt='basic', value=''): argument
1160 for f in self.cfgdef:
1163 fp.write(self.cfgdef[f])
1165 self.cfgdef = dict()
1171 self.cfgdef[file] = m.group('v')
1173 line = fp.read().strip().split('\n')[-1]
1174 m = re.match(r'.* (?P<v>[0-9A-Fx]*) .*', line)
1176 self.cfgdef[file] = m.group('v')
1178 self.cfgdef[file] = fp.read().strip()
1181 def s0ixSupport(self): argument
1182 if not os.path.exists(self.s0ixres) or not os.path.exists(self.mempowerfile):
1190 def haveTurbostat(self): argument
1191 if not self.tstat:
1193 cmd = self.getExec('turbostat')
1196 fp = Popen([cmd, '-v'], stdout=PIPE, stderr=PIPE).stderr
1200 self.vprint(out)
1203 def turbostat(self, s0ixready): argument
1204 cmd = self.getExec('turbostat')
1206 fullcmd = '%s -q -S echo freeze > %s' % (cmd, self.powerfile)
1207 fp = Popen(['sh', '-c', fullcmd], stdout=PIPE, stderr=PIPE)
1220 self.vprint(errmsg)
1221 if not self.verbose:
1224 if self.verbose:
1234 def netfixon(self, net='both'): argument
1235 cmd = self.getExec('netfix')
1238 fp = Popen([cmd, '-s', net, 'on'], stdout=PIPE, stderr=PIPE).stdout
1242 def wifiDetails(self, dev): argument
1250 vals.append(prop.split('=')[-1])
1252 def checkWifi(self, dev=''): argument
1258 m = re.match(r' *(?P<dev>.*): (?P<stat>[0-9a-f]*) .*', line)
1263 def pollWifi(self, dev, timeout=10): argument
1265 while (time.time() - start) < timeout:
1266 w = self.checkWifi(dev)
1269 (self.wifiDetails(dev), max(0, time.time() - start))
1271 return '%s timeout %d' % (self.wifiDetails(dev), timeout)
1272 def errorSummary(self, errinfo, msg): argument
1277 if self.hostname not in entry['urls']:
1278 entry['urls'][self.hostname] = [self.htmlfile]
1279 elif self.htmlfile not in entry['urls'][self.hostname]:
1280 entry['urls'][self.hostname].append(self.htmlfile)
1287 if re.match(r'^[0-9,\-\.]*$', arr[j]):
1288 arr[j] = r'[0-9,\-\.]*'
1300 'urls': {self.hostname: [self.htmlfile]}
1303 def multistat(self, start, idx, finish): argument
1304 if 'time' in self.multitest:
1305 id = '%d Duration=%dmin' % (idx+1, self.multitest['time'])
1307 id = '%d/%d' % (idx+1, self.multitest['count'])
1309 if 'start' not in self.multitest:
1310 self.multitest['start'] = self.multitest['last'] = t
1311 self.multitest['total'] = 0.0
1314 dt = t - self.multitest['last']
1316 if idx == 0 and self.multitest['delay'] > 0:
1317 self.multitest['total'] += self.multitest['delay']
1318 pprint('TEST (%s) COMPLETE -- Duration %.1fs' % (id, dt))
1320 self.multitest['total'] += dt
1321 self.multitest['last'] = t
1322 avg = self.multitest['total'] / idx
1323 if 'time' in self.multitest:
1324 left = finish - datetime.now()
1325 left -= timedelta(microseconds=left.microseconds)
1327 left = timedelta(seconds=((self.multitest['count'] - idx) * int(avg)))
1328 pprint('TEST (%s) START - Avg Duration %.1fs, Time left %s' % \
1330 def multiinit(self, c, d): argument
1333 sz, unit, c = 'time', c[-1], c[:-1]
1334 self.multitest['run'] = True
1335 self.multitest[sz] = getArgInt('multi: n d (exec count)', c, 1, 1000000, False)
1336 self.multitest['delay'] = getArgInt('multi: n d (delay between tests)', d, 0, 3600, False)
1338 self.multitest[sz] *= 1440
1340 self.multitest[sz] *= 60
1341 def displayControl(self, cmd): argument
1342 xset, ret = 'timeout 10 xset -d :0.0 {0}', 0
1343 if self.sudouser:
1344 xset = 'sudo -u %s %s' % (self.sudouser, xset)
1352 b4 = self.displayControl('stat')
1355 curr = self.displayControl('stat')
1356 self.vprint('Display Switched: %s -> %s' % (b4, curr))
1358 self.vprint('WARNING: Display failed to change to %s' % cmd)
1360 self.vprint('WARNING: Display failed to change to %s with xset' % cmd)
1373 def setRuntimeSuspend(self, before=True): argument
1376 if self.rs > 0:
1377 self.rstgt, self.rsval, self.rsdir = 'on', 'auto', 'enabled'
1379 self.rstgt, self.rsval, self.rsdir = 'auto', 'on', 'disabled'
1381 self.rslist = deviceInfo(self.rstgt)
1382 for i in self.rslist:
1383 self.setVal(self.rsval, i)
1384 pprint('runtime suspend %s on all devices (%d changed)' % (self.rsdir, len(self.rslist)))
1388 # runtime suspend re-enable or re-disable
1389 for i in self.rslist:
1390 self.setVal(self.rstgt, i)
1391 pprint('runtime suspend settings restored on %d devices' % len(self.rslist))
1392 def start(self, pm): argument
1393 if self.useftrace:
1394 self.dlog('start ftrace tracing')
1395 self.fsetVal('1', 'tracing_on')
1396 if self.useprocmon:
1397 self.dlog('start the process monitor')
1399 def stop(self, pm): argument
1400 if self.useftrace:
1401 if self.useprocmon:
1402 self.dlog('stop the process monitor')
1404 self.dlog('stop ftrace tracing')
1405 self.fsetVal('0', 'tracing_on')
1422 def __init__(self): argument
1423 self.syspath = ''
1424 self.altname = ''
1425 self.isasync = True
1426 self.xtraclass = ''
1427 self.xtrainfo = ''
1428 def out(self, dev): argument
1429 return '%s,%s,%d;' % (dev, self.altname, self.isasync)
1430 def debug(self, dev): argument
1431 pprint('%s:\n\taltname = %s\n\t async = %s' % (dev, self.altname, self.isasync))
1432 def altName(self, dev): argument
1433 if not self.altname or self.altname == dev:
1435 return '%s [%s]' % (self.altname, dev)
1436 def xtraClass(self): argument
1437 if self.xtraclass:
1438 return ' '+self.xtraclass
1439 if not self.isasync:
1442 def xtraInfo(self): argument
1443 if self.xtraclass:
1444 return ' '+self.xtraclass
1445 if self.isasync:
1454 def __init__(self, nodename, nodedepth): argument
1455 self.name = nodename
1456 self.children = []
1457 self.depth = nodedepth
1465 # 10 sequential, non-overlapping phases of S/R
1507 'ACPI' : r'.*\bACPI *(?P<b>[A-Za-z]*) *Error[: ].*',
1509 'USBERR' : r'.*usb .*device .*, error [0-9-]*',
1510 'ATAERR' : r' *ata[0-9\.]*: .*failed.*',
1512 'TPMERR' : r'(?i) *tpm *tpm[0-9]*: .*error.*',
1514 def __init__(self, num): argument
1516 self.start = 0.0 # test start
1517 self.end = 0.0 # test end
1518 self.hwstart = 0 # rtc test start
1519 self.hwend = 0 # rtc test end
1520 self.tSuspended = 0.0 # low-level suspend start
1521 self.tResumed = 0.0 # low-level resume start
1522 self.tKernSus = 0.0 # kernel level suspend start
1523 self.tKernRes = 0.0 # kernel level resume end
1524 self.fwValid = False # is firmware data available
1525 self.fwSuspend = 0 # time spent in firmware suspend
1526 self.fwResume = 0 # time spent in firmware resume
1527 self.html_device_id = 0
1528 self.stamp = 0
1529 self.outfile = ''
1530 self.kerror = False
1531 self.wifi = dict()
1532 self.turbostat = 0
1533 self.enterfail = ''
1534 self.currphase = ''
1535 self.pstl = dict() # process timeline
1536 self.testnumber = num
1537 self.idstr = idchar[num]
1538 self.dmesgtext = [] # dmesg text file in memory
1539 self.dmesg = dict() # root data structure
1540 self.errorinfo = {'suspend':[],'resume':[]}
1541 self.tLow = [] # time spent in low-level suspends (standby/freeze)
1542 self.devpids = []
1543 self.devicegroups = 0
1544 def sortedPhases(self): argument
1545 return sorted(self.dmesg, key=lambda k:self.dmesg[k]['order'])
1546 def initDevicegroups(self): argument
1548 for phase in sorted(self.dmesg.keys()):
1552 self.dmesg[pnew] = self.dmesg.pop(phase)
1553 self.devicegroups = []
1554 for phase in self.sortedPhases():
1555 self.devicegroups.append([phase])
1556 def nextPhase(self, phase, offset): argument
1557 order = self.dmesg[phase]['order'] + offset
1558 for p in self.dmesg:
1559 if self.dmesg[p]['order'] == order:
1562 def lastPhase(self, depth=1): argument
1563 plist = self.sortedPhases()
1566 return plist[-1*depth]
1567 def turbostatInfo(self): argument
1570 for line in self.dmesgtext:
1576 out['syslpi'] = i.split('=')[-1]+'%'
1578 out['pkgpc10'] = i.split('=')[-1]+'%'
1581 def extractErrorInfo(self): argument
1582 lf = self.dmesgtext
1583 if len(self.dmesgtext) < 1 and sysvals.dmesgfile:
1592 m = re.match(r'[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
1596 if t < self.start or t > self.end:
1598 dir = 'suspend' if t < self.tSuspended else 'resume'
1602 for err in self.errlist:
1603 if re.match(self.errlist[err], msg):
1605 self.kerror = True
1610 self.errorinfo[dir].append((type, t, idx1, idx2))
1611 if self.kerror:
1613 if len(self.dmesgtext) < 1 and sysvals.dmesgfile:
1616 def setStart(self, time, msg=''): argument
1617 self.start = time
1620 self.hwstart = datetime.strptime(msg, sysvals.tmstart)
1622 self.hwstart = 0
1623 def setEnd(self, time, msg=''): argument
1624 self.end = time
1627 self.hwend = datetime.strptime(msg, sysvals.tmend)
1629 self.hwend = 0
1630 def isTraceEventOutsideDeviceCalls(self, pid, time): argument
1631 for phase in self.sortedPhases():
1632 list = self.dmesg[phase]['list']
1639 def sourcePhase(self, start): argument
1640 for phase in self.sortedPhases():
1643 pend = self.dmesg[phase]['end']
1646 return 'resume_complete' if 'resume_complete' in self.dmesg else ''
1647 def sourceDevice(self, phaselist, start, end, pid, type): argument
1650 list = self.dmesg[phase]['list']
1671 def addDeviceFunctionCall(self, displayname, kprobename, proc, pid, start, end, cdata, rdata): argument
1673 phases = self.sortedPhases()
1674 tgtdev = self.sourceDevice(phases, start, end, pid, 'device')
1677 if not tgtdev and pid in self.devpids:
1681 tgtdev = self.sourceDevice(phases, start, end, pid, 'thread')
1685 threadname = 'kthread-%d' % (pid)
1687 threadname = '%s-%d' % (proc, pid)
1688 tgtphase = self.sourcePhase(start)
1691 self.newAction(tgtphase, threadname, pid, '', start, end, '', ' kth', '')
1692 return self.addDeviceFunctionCall(displayname, kprobename, proc, pid, start, end, cdata, rdata)
1695 sysvals.vprint('[%f - %f] %s-%d %s %s %s' % \
1723 def overflowDevices(self): argument
1726 for phase in self.sortedPhases():
1727 list = self.dmesg[phase]['list']
1730 if dev['end'] > self.end:
1733 def mergeOverlapDevices(self, devlist): argument
1737 for phase in self.sortedPhases():
1738 list = self.dmesg[phase]['list']
1742 o = min(dev['end'], tdev['end']) - max(dev['start'], tdev['start'])
1750 def usurpTouchingThread(self, name, dev): argument
1752 for phase in self.sortedPhases():
1753 list = self.dmesg[phase]['list']
1756 if tdev['start'] - dev['end'] < 0.1:
1764 def stitchTouchingThreads(self, testlist): argument
1766 for phase in self.sortedPhases():
1767 list = self.dmesg[phase]['list']
1774 def optimizeDevSrc(self): argument
1776 for phase in self.sortedPhases():
1777 list = self.dmesg[phase]['list']
1789 p.length = p.end - p.time
1792 def trimTimeVal(self, t, t0, dT, left): argument
1795 if(t - dT < t0):
1797 return t - dT
1807 def trimTime(self, t0, dT, left): argument
1808 self.tSuspended = self.trimTimeVal(self.tSuspended, t0, dT, left)
1809 self.tResumed = self.trimTimeVal(self.tResumed, t0, dT, left)
1810 self.start = self.trimTimeVal(self.start, t0, dT, left)
1811 self.tKernSus = self.trimTimeVal(self.tKernSus, t0, dT, left)
1812 self.tKernRes = self.trimTimeVal(self.tKernRes, t0, dT, left)
1813 self.end = self.trimTimeVal(self.end, t0, dT, left)
1814 for phase in self.sortedPhases():
1815 p = self.dmesg[phase]
1816 p['start'] = self.trimTimeVal(p['start'], t0, dT, left)
1817 p['end'] = self.trimTimeVal(p['end'], t0, dT, left)
1821 d['start'] = self.trimTimeVal(d['start'], t0, dT, left)
1822 d['end'] = self.trimTimeVal(d['end'], t0, dT, left)
1823 d['length'] = d['end'] - d['start']
1826 cg.start = self.trimTimeVal(cg.start, t0, dT, left)
1827 cg.end = self.trimTimeVal(cg.end, t0, dT, left)
1829 line.time = self.trimTimeVal(line.time, t0, dT, left)
1832 e.time = self.trimTimeVal(e.time, t0, dT, left)
1833 e.end = self.trimTimeVal(e.end, t0, dT, left)
1834 e.length = e.end - e.time
1839 c0 = self.trimTimeVal(c0, t0, dT, left)
1840 cN = self.trimTimeVal(cN, t0, dT, left)
1845 for e in self.errorinfo[dir]:
1847 tm = self.trimTimeVal(tm, t0, dT, left)
1849 self.errorinfo[dir] = list
1850 def trimFreezeTime(self, tZero): argument
1853 for phase in self.sortedPhases():
1855 tS, tR = self.dmesg[lp]['end'], self.dmesg[phase]['start']
1856 tL = tR - tS
1860 self.trimTime(tS, tL, left)
1861 if 'waking' in self.dmesg[lp]:
1862 tCnt = self.dmesg[lp]['waking'][0]
1863 if self.dmesg[lp]['waking'][1] >= 0.001:
1864 tTry = '%.0f' % (round(self.dmesg[lp]['waking'][1] * 1000))
1866 tTry = '%.3f' % (self.dmesg[lp]['waking'][1] * 1000)
1870 self.tLow.append(text)
1872 def getMemTime(self): argument
1873 if not self.hwstart or not self.hwend:
1875 stime = (self.tSuspended - self.start) * 1000000
1876 rtime = (self.end - self.tResumed) * 1000000
1877 hws = self.hwstart + timedelta(microseconds=stime)
1878 hwr = self.hwend - timedelta(microseconds=rtime)
1879 self.tLow.append('%.0f'%((hwr - hws).total_seconds() * 1000))
1880 def getTimeValues(self): argument
1881 s = (self.tSuspended - self.tKernSus) * 1000
1882 r = (self.tKernRes - self.tResumed) * 1000
1884 def setPhase(self, phase, ktime, isbegin, order=-1): argument
1887 if self.currphase:
1888 if 'resume_machine' not in self.currphase:
1889 sysvals.vprint('WARNING: phase %s failed to end' % self.currphase)
1890 self.dmesg[self.currphase]['end'] = ktime
1891 phases = self.dmesg.keys()
1892 color = self.phasedef[phase]['color']
1897 self.dmesg[phase] = {'list': dict(), 'start': -1.0, 'end': -1.0,
1899 self.dmesg[phase]['start'] = ktime
1900 self.currphase = phase
1903 if phase not in self.currphase:
1904 if self.currphase:
1905 sysvals.vprint('WARNING: %s ended instead of %s, ftrace corruption?' % (phase, self.currphase))
1909 phase = self.currphase
1910 self.dmesg[phase]['end'] = ktime
1911 self.currphase = ''
1913 def sortedDevices(self, phase): argument
1914 list = self.dmesg[phase]['list']
1916 def fixupInitcalls(self, phase): argument
1918 phaselist = self.dmesg[phase]['list']
1922 for p in self.sortedPhases():
1923 if self.dmesg[p]['end'] > dev['start']:
1924 dev['end'] = self.dmesg[p]['end']
1927 def deviceFilter(self, devicefilter): argument
1928 for phase in self.sortedPhases():
1929 list = self.dmesg[phase]['list']
1941 def fixupInitcallsThatDidntReturn(self): argument
1943 for phase in self.sortedPhases():
1944 self.fixupInitcalls(phase)
1945 def phaseOverlap(self, phases): argument
1948 for group in self.devicegroups:
1958 self.devicegroups.remove(group)
1959 self.devicegroups.append(newgroup)
1960 def newActionGlobal(self, name, start, end, pid=-1, color=''): argument
1962 phases = self.sortedPhases()
1968 pstart = self.dmesg[phase]['start']
1969 pend = self.dmesg[phase]['end']
1971 o = max(0, min(end, pend) - max(start, pstart))
1982 p0start = self.dmesg[phases[0]]['start']
1986 targetphase = phases[-1]
1987 if pid == -2:
1989 elif pid == -3:
1993 self.phaseOverlap(myphases)
1995 newname = self.newAction(targetphase, name, pid, '', start, end, '', htmlclass, color)
1998 def newAction(self, phase, name, pid, parent, start, end, drv, htmlclass='', color=''): argument
2000 self.html_device_id += 1
2001 devid = '%s%d' % (self.idstr, self.html_device_id)
2002 list = self.dmesg[phase]['list']
2003 length = -1.0
2005 length = end - start
2006 if pid >= -2:
2019 def findDevice(self, phase, name): argument
2020 list = self.dmesg[phase]['list']
2023 if name == devname or re.match(r'^%s\[(?P<num>[0-9]*)\]$' % name, devname):
2028 def deviceChildren(self, devname, phase): argument
2030 list = self.dmesg[phase]['list']
2035 def maxDeviceNameSize(self, phase): argument
2037 for name in self.dmesg[phase]['list']:
2041 def printDetails(self): argument
2043 sysvals.vprint(' test start: %f' % self.start)
2044 sysvals.vprint('kernel suspend start: %f' % self.tKernSus)
2046 for phase in self.sortedPhases():
2047 devlist = self.dmesg[phase]['list']
2048 dc, ps, pe = len(devlist), self.dmesg[phase]['start'], self.dmesg[phase]['end']
2049 if not tS and ps >= self.tSuspended:
2050 sysvals.vprint(' machine suspended: %f' % self.tSuspended)
2052 if not tR and ps >= self.tResumed:
2053 sysvals.vprint(' machine resumed: %f' % self.tResumed)
2055 sysvals.vprint('%20s: %f - %f (%d devices)' % (phase, ps, pe, dc))
2057 sysvals.vprint(''.join('-' for i in range(80)))
2058 maxname = '%d' % self.maxDeviceNameSize(phase)
2059 fmt = '%3d) %'+maxname+'s - %f - %f'
2066 sysvals.vprint(''.join('-' for i in range(80)))
2067 sysvals.vprint(' kernel resume end: %f' % self.tKernRes)
2068 sysvals.vprint(' test end: %f' % self.end)
2069 def deviceChildrenAllPhases(self, devname): argument
2071 for phase in self.sortedPhases():
2072 list = self.deviceChildren(devname, phase)
2077 def masterTopology(self, name, list, depth): argument
2083 clist = self.deviceChildrenAllPhases(cname)
2084 cnode = self.masterTopology(cname, clist, depth+1)
2087 def printTopology(self, node): argument
2092 for phase in self.sortedPhases():
2093 list = self.dmesg[phase]['list']
2099 info += ('<li>%s: %.3fms</li>' % (phase, (e-s)*1000))
2107 html += self.printTopology(cnode)
2110 def rootDeviceList(self): argument
2113 for phase in self.sortedPhases():
2114 list = self.dmesg[phase]['list']
2118 # list of top-most root devices
2120 for phase in self.sortedPhases():
2121 list = self.dmesg[phase]['list']
2125 if(pid < 0 or re.match(r'[0-9]*-[0-9]*\.[0-9]*[\.0-9]*\:[\.0-9]*$', pdev)):
2130 def deviceTopology(self): argument
2131 rootlist = self.rootDeviceList()
2132 master = self.masterTopology('', rootlist, 0)
2133 return self.printTopology(master)
2134 def selectTimelineDevices(self, widfmt, tTotal, mindevlen): argument
2136 self.tdevlist = dict()
2137 for phase in self.dmesg:
2139 list = self.dmesg[phase]['list']
2141 length = (list[dev]['end'] - list[dev]['start']) * 1000
2142 width = widfmt % (((list[dev]['end']-list[dev]['start'])*100)/tTotal)
2145 self.tdevlist[phase] = devlist
2146 def addHorizontalDivider(self, devname, devend): argument
2148 self.newAction(phase, devname, -2, '', \
2149 self.start, devend, '', ' sec', '')
2150 if phase not in self.tdevlist:
2151 self.tdevlist[phase] = []
2152 self.tdevlist[phase].append(devname)
2153 d = DevItem(0, phase, self.dmesg[phase]['list'][devname])
2155 def addProcessUsageEvent(self, name, times): argument
2158 tlast = start = end = -1
2163 if name in self.pstl[t] and self.pstl[t][name] > 0:
2167 maxj = (t - tlast) * 1024.0
2168 cpuexec[key] = min(1.0, float(self.pstl[t][name]) / maxj)
2173 out = self.newActionGlobal(name, start, end, -3)
2176 dev = self.dmesg[phase]['list'][devname]
2178 def createProcessUsageEvents(self): argument
2182 for t in sorted(self.pstl):
2183 dir = 'sus' if t < self.tSuspended else 'res'
2184 for ps in sorted(self.pstl[t]):
2193 self.addProcessUsageEvent(ps, tdata[dir])
2194 def handleEndMarker(self, time, msg=''): argument
2195 dm = self.dmesg
2196 self.setEnd(time, msg)
2197 self.initDevicegroups()
2203 np = self.nextPhase('resume_machine', 1)
2207 if self.tKernRes == 0.0:
2208 self.tKernRes = time
2210 if self.tKernSus == 0.0:
2211 self.tKernSus = time
2215 def initcall_debug_call(self, line, quick=False): argument
2216 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) .* (?P<f>.*)\: '+\
2219 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) .* (?P<f>.*)\: '+\
2222 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) calling '+\
2227 def initcall_debug_return(self, line, quick=False): argument
2228 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) .* (?P<f>.*)\: PM: '+\
2229 r'.* returned (?P<r>[0-9]*) after (?P<dt>[0-9]*) usecs', line)
2231 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) .* (?P<f>.*)\: '+\
2232 r'.* returned (?P<r>[0-9]*) after (?P<dt>[0-9]*) usecs', line)
2234 m = re.match(r'.*(\[ *)(?P<t>[0-9\.]*)(\]) call '+\
2239 def debugPrint(self): argument
2240 for p in self.sortedPhases():
2241 list = self.dmesg[p]['list']
2251 def __init__(self, name, args, caller, ret, start, end, u, proc, pid, color): argument
2252 self.row = 0
2253 self.count = 1
2254 self.name = name
2255 self.args = args
2256 self.caller = caller
2257 self.ret = ret
2258 self.time = start
2259 self.length = end - start
2260 self.end = end
2261 self.ubiquitous = u
2262 self.proc = proc
2263 self.pid = pid
2264 self.color = color
2265 def title(self): argument
2267 if self.count > 1:
2268 cnt = '(x%d)' % self.count
2269 l = '%0.3fms' % (self.length * 1000)
2270 if self.ubiquitous:
2271 title = '%s(%s)%s <- %s, %s(%s)' % \
2272 (self.name, self.args, cnt, self.caller, self.ret, l)
2274 title = '%s(%s) %s%s(%s)' % (self.name, self.args, self.ret, cnt, l)
2276 def text(self): argument
2277 if self.count > 1:
2278 text = '%s(x%d)' % (self.name, self.count)
2280 text = self.name
2282 def repeat(self, tgt): argument
2284 dt = self.time - tgt.end
2285 # only combine calls if -all- attributes are identical
2286 if tgt.caller == self.caller and \
2287 tgt.name == self.name and tgt.args == self.args and \
2288 tgt.proc == self.proc and tgt.pid == self.pid and \
2289 tgt.ret == self.ret and dt >= 0 and \
2291 self.length < sysvals.callloopmaxlen:
2307 def __init__(self, t, m='', d=''): argument
2308 self.length = 0.0
2309 self.fcall = False
2310 self.freturn = False
2311 self.fevent = False
2312 self.fkprobe = False
2313 self.depth = 0
2314 self.name = ''
2315 self.type = ''
2316 self.time = float(t)
2331 self.name = emm.group('msg')
2332 self.type = emm.group('call')
2334 self.name = msg
2335 km = re.match(r'^(?P<n>.*)_cal$', self.type)
2337 self.fcall = True
2338 self.fkprobe = True
2339 self.type = km.group('n')
2341 km = re.match(r'^(?P<n>.*)_ret$', self.type)
2343 self.freturn = True
2344 self.fkprobe = True
2345 self.type = km.group('n')
2347 self.fevent = True
2351 self.length = float(d)/1000000
2356 self.depth = self.getDepth(match.group('d'))
2360 self.freturn = True
2365 self.name = match.group('n').strip()
2368 self.fcall = True
2370 if(m[-1] == '{'):
2373 self.name = match.group('n').strip()
2375 elif(m[-1] == ';'):
2376 self.freturn = True
2379 self.name = match.group('n').strip()
2382 self.name = m
2383 def isCall(self): argument
2384 return self.fcall and not self.freturn
2385 def isReturn(self): argument
2386 return self.freturn and not self.fcall
2387 def isLeaf(self): argument
2388 return self.fcall and self.freturn
2389 def getDepth(self, str): argument
2391 def debugPrint(self, info=''): argument
2392 if self.isLeaf():
2393 pprint(' -- %12.6f (depth=%02d): %s(); (%.3f us) %s' % (self.time, \
2394 self.depth, self.name, self.length*1000000, info))
2395 elif self.freturn:
2396 pprint(' -- %12.6f (depth=%02d): %s} (%.3f us) %s' % (self.time, \
2397 self.depth, self.name, self.length*1000000, info))
2399 pprint(' -- %12.6f (depth=%02d): %s() { (%.3f us) %s' % (self.time, \
2400 self.depth, self.name, self.length*1000000, info))
2401 def startMarker(self): argument
2403 if not self.fevent:
2406 if(self.name.startswith('SUSPEND START')):
2410 if(self.type == 'suspend_resume' and
2411 re.match(r'suspend_enter\[.*\] begin', self.name)):
2414 def endMarker(self): argument
2416 if not self.fevent:
2419 if(self.name.startswith('RESUME COMPLETE')):
2423 if(self.type == 'suspend_resume' and
2424 re.match(r'thaw_processes\[.*\] end', self.name)):
2436 def __init__(self, pid, sv): argument
2437 self.id = ''
2438 self.invalid = False
2439 self.name = ''
2440 self.partial = False
2441 self.ignore = False
2442 self.start = -1.0
2443 self.end = -1.0
2444 self.list = []
2445 self.depth = 0
2446 self.pid = pid
2447 self.sv = sv
2448 def addLine(self, line): argument
2450 if(self.invalid):
2455 if(self.depth < 0):
2456 self.invalidate(line)
2459 if self.ignore:
2460 if line.depth > self.depth:
2463 self.list[-1].freturn = True
2464 self.list[-1].length = line.time - self.list[-1].time
2465 self.ignore = False
2466 # if this is a return at self.depth, no more work is needed
2467 if line.depth == self.depth and line.isReturn():
2469 self.end = line.time
2472 # compare current depth with this lines pre-call depth
2478 if len(self.list) > 0:
2479 last = self.list[-1]
2484 mismatch = prelinedep - self.depth
2485 warning = self.sv.verbose and abs(mismatch) > 1
2490 while prelinedep < self.depth:
2491 self.depth -= 1
2494 last.depth = self.depth
2496 last.length = line.time - last.time
2501 vline.depth = self.depth
2502 vline.name = self.vfname
2504 self.list.append(vline)
2518 while prelinedep > self.depth:
2522 prelinedep -= 1
2527 vline.depth = self.depth
2528 vline.name = self.vfname
2530 self.list.append(vline)
2531 self.depth += 1
2533 self.start = vline.time
2547 md = self.sv.max_graph_depth
2550 if (md and self.depth >= md - 1) or (line.name in self.sv.cgblacklist):
2551 self.ignore = True
2553 self.depth += 1
2555 self.depth -= 1
2559 (line.name in self.sv.cgblacklist):
2560 while len(self.list) > 0 and self.list[-1].depth > line.depth:
2561 self.list.pop(-1)
2562 if len(self.list) == 0:
2563 self.invalid = True
2565 self.list[-1].freturn = True
2566 self.list[-1].length = line.time - self.list[-1].time
2567 self.list[-1].name = line.name
2569 if len(self.list) < 1:
2570 self.start = line.time
2573 if mismatch < 0 and self.list[-1].depth == 0 and self.list[-1].freturn:
2574 line = self.list[-1]
2576 res = -1
2578 self.list.append(line)
2580 if(self.start < 0):
2581 self.start = line.time
2582 self.end = line.time
2584 self.end += line.length
2585 if self.list[0].name == self.vfname:
2586 self.invalid = True
2587 if res == -1:
2588 self.partial = True
2591 def invalidate(self, line): argument
2592 if(len(self.list) > 0):
2593 first = self.list[0]
2594 self.list = []
2595 self.list.append(first)
2596 self.invalid = True
2597 id = 'task %s' % (self.pid)
2598 window = '(%f - %f)' % (self.start, line.time)
2599 if(self.depth < 0):
2605 def slice(self, dev): argument
2606 minicg = FTraceCallGraph(dev['pid'], self.sv)
2607 minicg.name = self.name
2608 mydepth = -1
2610 for l in self.list:
2620 l.depth -= mydepth
2625 def repair(self, enddepth): argument
2628 last = self.list[-1]
2633 fixed = self.addLine(t)
2635 self.end = last.time
2638 def postProcess(self): argument
2639 if len(self.list) > 0:
2640 self.name = self.list[0].name
2644 for l in self.list:
2648 if last.length > l.time - last.time:
2649 last.length = l.time - last.time
2655 if self.sv.verbose:
2661 cl.length = l.time - cl.time
2662 if cl.name == self.vfname:
2666 cnt -= 1
2672 if self.sv.verbose:
2676 return self.repair(cnt)
2677 def deviceMatch(self, pid, data): argument
2684 if(self.name in borderphase):
2685 p = borderphase[self.name]
2690 self.start <= dev['start'] and
2691 self.end >= dev['end']):
2692 cg = self.slice(dev)
2698 if(data.dmesg[p]['start'] <= self.start and
2699 self.start <= data.dmesg[p]['end']):
2704 self.start <= dev['start'] and
2705 self.end >= dev['end']):
2706 dev['ftrace'] = self
2711 def newActionFromFunction(self, data): argument
2712 name = self.name
2715 fs = self.start
2716 fe = self.end
2721 if(data.dmesg[p]['start'] <= self.start and
2722 self.start < data.dmesg[p]['end']):
2727 out = data.newActionGlobal(name, fs, fe, -2)
2730 data.dmesg[phase]['list'][myname]['ftrace'] = self
2731 def debugPrint(self, info=''): argument
2732 pprint('%s pid=%d [%f - %f] %.3f us' % \
2733 (self.name, self.pid, self.start, self.end,
2734 (self.end - self.start)*1000000))
2735 for l in self.list:
2748 def __init__(self, test, phase, dev): argument
2749 self.test = test
2750 self.phase = phase
2751 self.dev = dev
2752 def isa(self, cls): argument
2753 if 'htmlclass' in self.dev and cls in self.dev['htmlclass']:
2767 def __init__(self, rowheight, scaleheight): argument
2768 self.html = ''
2769 self.height = 0 # total timeline height
2770 self.scaleH = scaleheight # timescale (top) row height
2771 self.rowH = rowheight # device row height
2772 self.bodyH = 0 # body height
2773 self.rows = 0 # total timeline rows
2774 self.rowlines = dict()
2775 self.rowheight = dict()
2776 def createHeader(self, sv, stamp): argument
2779 self.html += '<div class="version"><a href="https://www.intel.com/content/www/'+\
2780 'us/en/developer/topic-technology/open/pm-graph/overview.html">%s v%s</a></div>' \
2783 self.html += '<button id="showtest" class="logbtn btnfmt">log</button>'
2785 self.html += '<button id="showdmesg" class="logbtn btnfmt">dmesg</button>'
2787 self.html += '<button id="showftrace" class="logbtn btnfmt">ftrace</button>'
2789 self.html += headline_stamp.format(stamp['host'], stamp['kernel'],
2794 self.html += headline_sysinfo.format(stamp['man'], stamp['plat'], stamp['cpu'])
2803 def getDeviceRows(self, rawlist): argument
2807 item.row = -1
2833 remaining -= 1
2844 def getPhaseRows(self, devlist, row=0, sortby='length'): argument
2850 # initialize all device rows to -1 and calculate devrows
2856 dev['row'] = -1
2859 sortdict[item] = (-1*float(dev['start']), float(dev['end']) - float(dev['start']))
2862 sortdict[item] = (float(dev['end']) - float(dev['start']), item.dev['name'])
2864 dev['devrows'] = self.getDeviceRows(dev['src'])
2869 if item.dev['pid'] == -2:
2895 remaining -= 1
2899 if t not in self.rowlines or t not in self.rowheight:
2900 self.rowlines[t] = dict()
2901 self.rowheight[t] = dict()
2902 if p not in self.rowlines[t] or p not in self.rowheight[t]:
2903 self.rowlines[t][p] = dict()
2904 self.rowheight[t][p] = dict()
2905 rh = self.rowH
2911 self.rowlines[t][p][row] = rowheight
2912 self.rowheight[t][p][row] = rowheight * rh
2914 if(row > self.rows):
2915 self.rows = int(row)
2917 def phaseRowHeight(self, test, phase, row): argument
2918 return self.rowheight[test][phase][row]
2919 def phaseRowTop(self, test, phase, row): argument
2921 for i in sorted(self.rowheight[test][phase]):
2924 top += self.rowheight[test][phase][i]
2926 def calcTotalRows(self): argument
2930 for t in self.rowlines:
2931 for p in self.rowlines[t]:
2933 for i in sorted(self.rowlines[t][p]):
2934 total += self.rowlines[t][p][i]
2937 if total == len(self.rowlines[t][p]):
2939 self.height = self.scaleH + (maxrows*self.rowH)
2940 self.bodyH = self.height - self.scaleH
2943 for i in sorted(self.rowheight[t][p]):
2944 self.rowheight[t][p][i] = float(self.bodyH)/len(self.rowlines[t][p])
2945 def createZoomBox(self, mode='command', testcount=1): argument
2947 …html_zoombox = '<center><button id="zoomin">ZOOM IN +</button><button id="zoomout">ZOOM OUT -</but…
2953 self.html += html_devlist2
2954 self.html += html_devlist1.format('1')
2956 self.html += html_devlist1.format('')
2957 self.html += html_zoombox
2958 self.html += html_timeline.format('dmesg', self.height)
2969 def createTimeScale(self, m0, mMax, tTotal, mode): argument
2971 rline = '<div class="t" style="left:0;border-left:1px solid black;border-right:0;">{0}</div>\n'
2974 mTotal = mMax - m0
2981 divEdge = (mTotal - tS*(divTotal-1))*100/mTotal
2985 pos = '%0.3f' % (100 - ((float(i)*tS*100)/mTotal) - divEdge)
2986 val = '%0.fms' % (float(i-divTotal+1)*tS*1000)
2987 if(i == divTotal - 1):
2991 pos = '%0.3f' % (100 - ((float(i)*tS*100)/mTotal))
2997 self.html += output+'</div>\n'
3003 stampfmt = r'# [a-z]*-(?P<m>[0-9]{2})(?P<d>[0-9]{2})(?P<y>[0-9]{2})-'+\
3004 r'(?P<H>[0-9]{2})(?P<M>[0-9]{2})(?P<S>[0-9]{2})'+\
3006 wififmt = r'^# wifi *(?P<d>\S*) *(?P<s>\S*) *(?P<t>[0-9\.]+).*'
3013 pinfofmt = r'# platform-(?P<val>[a-z,A-Z,0-9,_]*): (?P<info>.*)'
3015 firmwarefmt = r'# fwsuspend (?P<s>[0-9]*) fwresume (?P<r>[0-9]*)$'
3016 procexecfmt = r'ps - (?P<ps>.*)$'
3017 procmultifmt = r'@(?P<n>[0-9]*)\|(?P<ps>.*)$'
3019 r'^ *(?P<time>[0-9\.]*) *\| *(?P<cpu>[0-9]*)\)'+\
3020 r' *(?P<proc>.*)-(?P<pid>[0-9]*) *\|'+\
3021 r'[ +!#\*@$]*(?P<dur>[0-9\.]*) .*\| (?P<msg>.*)'
3023 r' *(?P<proc>.*)-(?P<pid>[0-9]*) *\[(?P<cpu>[0-9]*)\] *'+\
3024 r'(?P<flags>\S*) *(?P<time>[0-9\.]*): *'+\
3030 def __init__(self): argument
3031 self.stamp = ''
3032 self.sysinfo = ''
3033 self.cmdline = ''
3034 self.testerror = []
3035 self.turbostat = []
3036 self.wifi = []
3037 self.fwdata = []
3038 self.ftrace_line_fmt = self.ftrace_line_fmt_nop
3039 self.cgformat = False
3040 self.data = 0
3041 self.ktemp = dict()
3042 def setTracerType(self, tracer): argument
3044 self.cgformat = True
3045 self.ftrace_line_fmt = self.ftrace_line_fmt_fg
3047 self.ftrace_line_fmt = self.ftrace_line_fmt_nop
3050 def stampInfo(self, line, sv): argument
3051 if re.match(self.stampfmt, line):
3052 self.stamp = line
3054 elif re.match(self.sysinfofmt, line):
3055 self.sysinfo = line
3057 elif re.match(self.tstatfmt, line):
3058 self.turbostat.append(line)
3060 elif re.match(self.wififmt, line):
3061 self.wifi.append(line)
3063 elif re.match(self.testerrfmt, line):
3064 self.testerror.append(line)
3066 elif re.match(self.firmwarefmt, line):
3067 self.fwdata.append(line)
3069 elif(re.match(self.devpropfmt, line)):
3070 self.parseDevprops(line, sv)
3072 elif(re.match(self.pinfofmt, line)):
3073 self.parsePlatformInfo(line, sv)
3075 m = re.match(self.cmdlinefmt, line)
3077 self.cmdline = m.group('cmd')
3079 m = re.match(self.tracertypefmt, line)
3081 self.setTracerType(m.group('t'))
3084 def parseStamp(self, data, sv): argument
3086 m = re.match(self.stampfmt, self.stamp)
3087 if not self.stamp or not m:
3097 if re.match(self.sysinfofmt, self.sysinfo):
3098 for f in self.sysinfo.split('|'):
3108 self.machinesuspend = r'timekeeping_freeze\[.*'
3110 self.machinesuspend = r'machine_suspend\[.*'
3121 sv.cmdline = self.cmdline
3125 if sv.suspendmode == 'mem' and len(self.fwdata) > data.testnumber:
3126 m = re.match(self.firmwarefmt, self.fwdata[data.testnumber])
3132 if len(self.turbostat) > data.testnumber:
3133 m = re.match(self.tstatfmt, self.turbostat[data.testnumber])
3137 if len(self.wifi) > data.testnumber:
3138 m = re.match(self.wififmt, self.wifi[data.testnumber])
3144 if len(self.testerror) > data.testnumber:
3145 m = re.match(self.testerrfmt, self.testerror[data.testnumber])
3148 def devprops(self, data): argument
3163 def parseDevprops(self, line, sv): argument
3167 props = self.devprops(line[idx:])
3171 def parsePlatformInfo(self, line, sv): argument
3172 m = re.match(self.pinfofmt, line)
3177 sv.devprops = self.devprops(sv.b64unzip(info))
3194 def __init__(self, dataobj): argument
3195 self.data = dataobj
3196 self.ftemp = dict()
3197 self.ttemp = dict()
3201 def __init__(self): argument
3202 self.proclist = dict()
3203 self.running = False
3204 def procstat(self): argument
3205 c = ['cat /proc/[1-9]*/stat 2>/dev/null']
3215 if pid not in self.proclist:
3216 self.proclist[pid] = {'name' : name, 'user' : user, 'kern' : kern}
3218 val = self.proclist[pid]
3219 ujiff = user - val['user']
3220 kjiff = kern - val['kern']
3229 val = self.proclist[pid]
3230 if len(out[-1]) > self.maxchars:
3232 elif len(out[-1]) > 0:
3233 out[-1] += ','
3234 out[-1] += '%s-%s %d' % (val['name'], pid, jiffies)
3237 sysvals.fsetVal('ps - @%d|%s' % (len(out), line), 'trace_marker')
3239 sysvals.fsetVal('ps - %s' % out[0], 'trace_marker')
3240 def processMonitor(self, tid): argument
3241 while self.running:
3242 self.procstat()
3243 def start(self): argument
3244 self.thread = Thread(target=self.processMonitor, args=(0,))
3245 self.running = True
3246 self.thread.start()
3247 def stop(self): argument
3248 self.running = False
3250 # ----------------- FUNCTIONS --------------------
3354 cg = testrun[testidx].ftemp[pid][-1]
3358 if(res == -1):
3359 testrun[testidx].ftemp[pid][-1].addLine(t)
3366 if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
3516 name = val[0].replace('--', '-')
3534 testrun.ttemp['thaw_processes'][-1]['end'] = t.time
3555 # -- phase changes --
3595 t.time - data.dmesg[lp]['start']
3643 testrun.ttemp[name][-1]['end'] = t.time
3644 testrun.ttemp[name][-1]['loop'] += 1
3657 testrun.ttemp[name][-1]['end'] = t.time
3670 data.newAction(phase, n, pid, p, t.time, -1, drv)
3683 dev['length'] = t.time - dev['start']
3701 'end': -1,
3716 if (t.time - e['begin']) * 1000 < sysvals.mindevlen:
3735 cg = testrun.ftemp[key][-1]
3739 if(res == -1):
3740 testrun.ftemp[key][-1].addLine(t)
3777 if i < len(testruns) - 1:
3787 if event['end'] - event['begin'] <= 0:
3802 if ke - kb < 0.000001 or tlb > kb or tle <= kb:
3814 if ke - kb < 0.000001 or tlb > kb or tle <= kb:
3824 if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
3846 …sysvals.vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name…
3866 terr = 'test%s did not enter %s power mode' % (tn, sm)
3900 for i in range(tc - 1):
3920 tp.stamp = datetime.now().strftime('# suspend-%m%d%y-%H%M%S localhost mem unknown')
3931 m = re.match(r'[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
3943 m = re.match(r'.* *(?P<k>[0-9]\.[0-9]{2}\.[0-9]-.*) .*', msg)
3999 'suspend': ['PM: Entering [a-z]* sleep.*', 'Suspending console.*',
4005 'suspend_machine': ['PM: suspend-to-idle',
4009 'ACPI: Low-level resume complete.*',
4011 r'Suspended for [0-9\.]* seconds'],
4012 'resume_noirq': ['PM: resume from suspend-to-idle',
4027 'emsg': 'PM: Preparing system for[a-z]* sleep.*' },
4039 'emsg': 'Disabling non-boot CPUs .*' },
4042 t0 = -1.0
4043 cpu_start = -1.0
4044 prevktime = -1.0
4048 m = re.match(r'[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
4145 # -- device callbacks --
4150 data.newAction(phase, f, int(n), p, ktime, -1, '')
4169 if(a in actions and actions[a][-1]['begin'] == actions[a][-1]['end']):
4170 actions[a][-1]['end'] = ktime
4172 if(re.match(r'Disabling non-boot CPUs .*', msg)):
4175 elif(re.match(r'Enabling non-boot CPUs .*', msg)):
4178 elif(re.match(r'smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg) \
4179 or re.match(r'psci: CPU(?P<cpu>[0-9]*) killed.*', msg)):
4181 m = re.match(r'smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg)
4183 m = re.match(r'psci: CPU(?P<cpu>[0-9]*) killed.*', msg)
4189 elif(re.match(r'CPU(?P<cpu>[0-9]*) is up', msg)):
4191 m = re.match(r'CPU(?P<cpu>[0-9]*) is up', msg)
4245 cglen = (cg.end - cg.start) * 1000
4308 tdcenter = 'text-align:center;' if center else ''
4310 <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
4313 ….stamp {width: 100%;text-align:center;background:#888;line-height:30px;color:white;font: 25px Aria…
4314 table {width:100%;border-collapse: collapse;border:1px solid;}\n\
4318 tr.alt {background-color:#ddd;}\n\
4320 .minval {background-color:#BBFFBB;}\n\
4321 .medval {background-color:#BBBBFF;}\n\
4322 .maxval {background-color:#FFBBBB;}\n\
4323 .head a {color:#000;text-decoration: none;}\n\
4334 html = summaryCSS('Summary - SleepGraph')
4372 idx = len(list[mode]['data']) - 1
4457 iMin = iMed = iMax = [-1, -1, -1]
4460 # row classes - alternate row color
4504 html = summaryCSS('Device Summary - SleepGraph', False)
4550 # row classes - alternate row color
4571 html = summaryCSS('Issues Summary - SleepGraph', False)
4594 # row classes - alternate row color
4641 data.trimFreezeTime(testruns[-1].tSuspended)
4647 …lass="traceevent{6}" style="left:{1}%;top:{2}px;height:{3}px;width:{4}%;line-height:{3}px;{7}">{5}…
4655 …'<td class="gray" title="time spent in low-power mode with clock running">'+sysvals.suspendmode+' …
4680 tTotal = data.end - data.start
4704 rtot += data.end - data.tKernRes + (data.wifi['time'] * 1000.0)
4736 wtime = '%.0f ms'%(data.end - data.tKernRes + (data.wifi['time'] * 1000.0))
4747 tMax = testruns[-1].end
4748 tTotal = tMax - t0
4781 d = testruns[0].addHorizontalDivider(msg, testruns[-1].end)
4785 d = testruns[0].addHorizontalDivider('asynchronous kernel threads', testruns[-1].end)
4807 left = '%f' % (((m0-t0)*100.0)/tTotal)
4814 left = '%f' % ((((m0-t0)*100.0)+sysvals.srgap/2)/tTotal)
4815 mTotal = mMax - m0
4819 width = '%f' % (((mTotal*100.0)-sysvals.srgap/2)/tTotal)
4824 length = phase['end']-phase['start']
4825 left = '%f' % (((phase['start']-m0)*100.0)/mTotal)
4834 right = '%f' % (((mMax-t)*100.0)/mTotal)
4858 left = '%f' % (((dev['start']-m0)*100)/mTotal)
4859 width = '%f' % (((dev['end']-dev['start'])*100)/mTotal)
4860 length = ' (%0.3f ms) ' % ((dev['end']-dev['start'])*1000)
4879 left = '%f' % (((start-m0)*100)/mTotal)
4880 width = '%f' % ((end-start)*100/mTotal)
4892 left = '%f' % (((e.time-m0)*100)/mTotal)
4909 phasedef = testruns[-1].phasedef
4932 pscolor = 'linear-gradient(to top left, #ccc, #eee)'
4937 length = phase['end']-phase['start']
4938 left = '%.3f' % (((phase['start']-t0)*100.0)/tTotal)
4953 data = testruns[-1]
4999 hoverZ = 'z-index:8;'
5013 <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
5016 body {overflow-y:scroll;}\n\
5017 ….stamp {width:100%;text-align:center;background:gray;line-height:30px;color:white;font:25px Arial;…
5019 .callgraph {margin-top:30px;box-shadow:5px 5px 20px black;}\n\
5020 .callgraph article * {padding-left:28px;}\n\
5025 t3 {color:black;font:20px Times;white-space:nowrap;}\n\
5026 t4 {color:black;font:bold 30px Times;line-height:60px;white-space:nowrap;}\n\
5035 .time2 {font:15px Arial;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;}\n\
5037 td {text-align:center;}\n\
5043-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:black;stroke-width:0"…
5044 …troke="black" stroke-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:b…
5045 .pf:'+cgchk+' ~ *:not(:nth-child(2)) {display:none;}\n\
5046 …oombox {position:relative;width:100%;overflow-x:scroll;-webkit-user-select:none;-moz-user-select:n…
5047 ….timeline {position:relative;font-size:14px;cursor:pointer;width:100%; overflow:hidden;background:…
5048 …bsolute;height:0%;overflow:hidden;z-index:7;line-height:30px;font-size:14px;border:1px solid;text-
5049 .thread.ps {border-radius:3px;background:linear-gradient(to top, #ccc, #eee);}\n\
5051 ….thread.sec,.thread.sec:hover {background:black;border:0;color:white;line-height:15px;font-size:10…
5055 .jiffie {position:absolute;pointer-events: none;z-index:8;}\n\
5056 …font-size:10px;z-index:7;overflow:hidden;color:black;text-align:center;white-space:nowrap;border-r…
5057 .traceevent:hover {color:white;font-weight:bold;border:1px solid white;}\n\
5058 .phase {position:absolute;overflow:hidden;border:0px;text-align:center;}\n\
5059 ….phaselet {float:left;overflow:hidden;border:0px;text-align:center;min-height:100px;font-size:24px…
5060 ….t {position:absolute;line-height:'+('%d'%scaleTH)+'px;pointer-events:none;top:0;height:100%;borde…
5061 …err {position:absolute;top:0%;height:100%;border-right:3px solid red;color:red;font:bold 14px Time…
5062 .legend {position:relative; width:100%; height:40px; text-align:center;margin-bottom:20px}\n\
5063 …ion:absolute;cursor:pointer;top:10px; width:0px;height:20px;border:1px solid;padding-left:20px;}\n\
5064 button {height:40px;width:200px;margin-bottom:20px;margin-top:20px;font-size:24px;}\n\
5065 …ion:relative;float:right;height:25px;width:auto;margin-top:3px;margin-bottom:0;font-size:10px;text
5067 a:link {color:white;text-decoration:none;}\n\
5071 ….version {position:relative;float:left;color:white;font-size:10px;line-height:30px;margin-left:10p…
5072 #devicedetail {min-height:100px;box-shadow:5px 5px 20px black;}\n\
5074 .tback {position:absolute;width:100%;background:linear-gradient(#ccc, #ddd);}\n\
5075 .bg {z-index:1;}\n\
5088 tMax = testruns[-1].end * 1000
5098 script_code = r""" var resolution = -1;
5101 var rline = '<div class="t" style="left:0;border-left:1px solid black;border-right:0;">';
5102 var tTotal = tMax - t0;
5112 var divEdge = (mTotal - tS*(divTotal-1))*100/mTotal;
5118 pos = 100 - (((j)*tS*100)/mTotal) - divEdge;
5119 val = (j-divTotal+1)*tS;
5120 if(j == divTotal - 1)
5125 pos = 100 - (((j)*tS*100)/mTotal);
5150 zoombox.scrollLeft = ((left + sh) * newval / val) - sh;
5155 zoombox.scrollLeft = ((left + sh) * newval / val) - sh;
5163 var tTotal = tMax - t0;
5167 if(i >= tS.length) i = tS.length - 1;
5180 var cpu = -1;
5181 if(name.match("CPU_ON\[[0-9]*\]"))
5183 else if(name.match("CPU_OFF\[[0-9]*\]"))
5235 var cpu = -1;
5236 if(name.match("CPU_ON\[[0-9]*\]"))
5238 else if(name.match("CPU_OFF\[[0-9]*\]"))
5264 var pname = info[info.length-1];
5265 var length = parseFloat(info[info.length-3].slice(1));
5293 var time = "<t4 style=\"font-size:"+fs+"px\">"+pd[phases[i].id].toFixed(3)+" ms<br></t4>";
5294 …var pname = "<t3 style=\"font-size:"+fs2+"px\">"+phases[i].id.replace(new RegExp("_", "g"), " ")+"…
5322 var name = tmp[0], phase = tmp[tmp.length-1];
5342 var html = '<div style="padding-top:'+pad+'px"><t3> <b>'+name+':</b>';
5351 html += '<table class=fstat style="padding-top:'+(maxlen*5)+'px;"><tr><th>Function</th>';
5386 " ul {list-style-type:circle;padding-left:10px;margin-left:10px;}"+
5430 zoombox.scrollLeft = dragval[1] + dragval[0] - e.clientX;
5621 return os.readlink(file).split('/')[-1]
5655 '---------------------------------------------------------------------------------------------\n'\
5660 '---------------------------------------------------------------------------------------------\n'\
5662 '---------------------------------------------------------------------------------------------')
5668 if(not re.match(r'.*/power', dirname) or
5673 dirname = dirname[:-6]
5674 device = dirname.split('/')[-1]
5675 power = dict()
5676 power[tgtval] = readFile('%s/power/%s' % (dirname, tgtval))
5678 if power[tgtval] not in ['active', 'suspended', 'suspending']:
5689 power[i] = readFile('%s/power/%s' % (dirname, i))
5691 if power['control'] == output:
5692 res.append('%s/power/control' % dirname)
5694 lines[dirname] = '%-26s %-26s %1s %1s %1s %1s %1s %10s %10s' % \
5696 yesno(power['async']), \
5697 yesno(power['control']), \
5698 yesno(power['runtime_status']), \
5699 power['runtime_usage'], \
5700 power['runtime_active_kids'], \
5701 ms2nice(power['runtime_active_time']), \
5702 ms2nice(power['runtime_suspended_time']))
5709 # Determine the supported power modes on this system
5726 modes.append('mem-%s' % memmode)
5733 modes.append('disk-%s' % m.strip('[]'))
5739 'bios-vendor': 'bios_vendor',
5740 'bios-version': 'bios_version',
5741 'bios-release-date': 'bios_date',
5742 'system-manufacturer': 'sys_vendor',
5743 'system-product-name': 'product_name',
5744 'system-version': 'product_version',
5745 'system-serial-number': 'product_serial',
5746 'baseboard-manufacturer': 'board_vendor',
5747 'baseboard-product-name': 'board_name',
5748 'baseboard-version': 'board_version',
5749 'baseboard-serial-number': 'board_serial',
5750 'chassis-manufacturer': 'chassis_vendor',
5751 'chassis-version': 'chassis_version',
5752 'chassis-serial-number': 'chassis_serial',
5759 if 'processor-version' not in out and os.path.exists(cpath):
5764 out['processor-version'] = m.group('c').strip()
5786 'bios-vendor': (0, 4),
5787 'bios-version': (0, 5),
5788 'bios-release-date': (0, 8),
5789 'system-manufacturer': (1, 4),
5790 'system-product-name': (1, 5),
5791 'system-version': (1, 6),
5792 'system-serial-number': (1, 7),
5793 'baseboard-manufacturer': (2, 4),
5794 'baseboard-product-name': (2, 5),
5795 'baseboard-version': (2, 6),
5796 'baseboard-serial-number': (2, 7),
5797 'chassis-manufacturer': (3, 4),
5798 'chassis-version': (3, 6),
5799 'chassis-serial-number': (3, 7),
5800 'processor-manufacturer': (4, 7),
5801 'processor-version': (4, 16),
5832 if buf[i:i+4] == b'_SM_' and i < memsize - 16:
5855 while(count < num and i <= len(buf) - 4):
5858 while n < len(buf) - 1:
5867 if idx > 0 and idx < len(data) - 1:
5868 s = data[idx-1].decode('utf-8')
5964 recdata = fp.read(rechead[1]-8)
5996 fwData[0] = record[1] - record[0]
6048 pprint(' is "%s" a valid power mode: %s' % (sysvals.suspendmode, res))
6050 pprint(' valid power modes are: %s' % modes)
6051 pprint(' please choose one with -m')
6061 status = efmt.format('-f')
6063 status = efmt.format('-dev')
6065 status = efmt.format('-proc')
6149 doError(name+': non-integer value given', True)
6168 doError(name+': non-numerical value given', True)
6198 sysvals.vprint(' %-8s : %s' % (key.upper(), sysvals.stamp[key]))
6214 sysvals.vprint('[%s - %s]' % (info[0], info[1]))
6312 num = re.search(r'[-+]?\d*\.\d+|\d+', str)
6343 m = re.match(r'[a-z0-9]* failed in (?P<p>\S*).*', error)
6381 m = re.match(r'.* -m (?P<m>\S*).*', line)
6393 m = re.match(r'.*waking *(?P<n>[0-9]*) *times.*', low)
6411 m = re.match(r' *<div id=\"[a,0-9]*\" *title=\"(?P<title>.*)\" class=\"thread.*', line)
6414 m = re.match(r'(?P<n>.*) \((?P<t>[0-9,\.]*) ms\) (?P<p>.*)', m.group('title'))
6421 name = ' '.join(name.split(' ')[:-1])
6463 for arg in ['-multi ', '-info ']:
6489 # create a summary of tests in a sub-directory
6519 pprint(' summary.html - tabular list of test data found')
6520 createHTMLDeviceSummary(testruns, os.path.join(outpath, 'summary-devices.html'), title)
6521 pprint(' summary-devices.html - kernel device list sorted by total execution time')
6522 createHTMLIssuesSummary(testruns, issues, os.path.join(outpath, 'summary-issues.html'), title)
6523 pprint(' summary-issues.html - kernel issues found sorted by frequency')
6533 doError('invalid boolean --> (%s: %s), use "true/false" or "1/0"' % (name, value), True)
6563 elif(option == 'override-timeline-functions'):
6565 elif(option == 'override-dev-timeline-functions'):
6574 sysvals.rs = -1
6578 doError('invalid value --> (%s: %s), use "enable/disable"' % (option, value), True)
6582 doError('invalid value --> (%s: %s), use %s' % (option, value, disopt), True)
6600 doError('invalid phase --> (%s: %s), valid phases are %s'\
6644 elif(option == 'callloop-maxgap'):
6645 sysvals.callloopmaxgap = getArgFloat('callloop-maxgap', value, 0.0, 1.0, False)
6646 elif(option == 'callloop-maxlen'):
6647 sysvals.callloopmaxgap = getArgFloat('callloop-maxlen', value, 0.0, 1.0, False)
6652 elif(option == 'output-dir'):
6660 doError('-dev is not compatible with -f')
6662 doError('-proc is not compatible with -f')
6693 if val[0] == '[' and val[-1] == ']':
6694 for prop in val[1:-1].split(','):
6713 for arg in re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', format):
6751 ' Generates output files in subdirectory: suspend-yymmdd-HHMMSS\n'\
6757 ' -h Print this help text\n'\
6758 ' -v Print the current tool version\n'\
6759 ' -config fn Pull arguments and config options from file fn\n'\
6760 ' -verbose Print extra information during execution and analysis\n'\
6761 ' -m mode Mode to initiate for suspend (default: %s)\n'\
6762 ' -o name Overrides the output subdirectory name when running a new test\n'\
6763 ' default: suspend-{date}-{time}\n'\
6764 ' -rtcwake t Wakeup t seconds after suspend, set t to "off" to disable (default: 15)\n'\
6765 ' -addlogs Add the dmesg and ftrace logs to the html output\n'\
6766 ' -noturbostat Dont use turbostat in freeze mode (default: disabled)\n'\
6767 ' -srgap Add a visible gap in the timeline between sus/res (default: disabled)\n'\
6768 …' -skiphtml Run the test and capture the trace logs, but skip the timeline (default: disabled…
6769 ' -result fn Export a results table to a text file for parsing.\n'\
6770 ' -wifi If a wifi connection is available, check that it reconnects after resume.\n'\
6771 ' -wifitrace Trace kernel execution through wifi reconnect.\n'\
6772 ' -netfix Use netfix to reset the network in the event it fails to resume.\n'\
6773 ' -debugtiming Add timestamp to each printed line\n'\
6775 ' -sync Sync the filesystems before starting the test\n'\
6776 ' -rs on/off Enable/disable runtime suspend for all devices, restore all after test\n'\
6777 ' -display m Change the display mode to m for the test (on/off/standby/suspend)\n'\
6779 ' -gzip Gzip the trace and dmesg logs to save space\n'\
6780 ' -cmd {s} Run the timeline over a custom command, e.g. "sync -d"\n'\
6781 ' -proc Add usermode process info into the timeline (default: disabled)\n'\
6782 ' -dev Add kernel function calls and threads to the timeline (default: disabled)\n'\
6783 ' -x2 Run two suspend/resumes back to back (default: disabled)\n'\
6784 ' -x2delay t Include t ms delay between multiple test runs (default: 0 ms)\n'\
6785 ' -predelay t Include t ms delay before 1st suspend (default: 0 ms)\n'\
6786 ' -postdelay t Include t ms delay after last resume (default: 0 ms)\n'\
6787 ' -mindev ms Discard all device blocks shorter than ms milliseconds (e.g. 0.001 for us)\n'\
6788 ' -multi n d Execute <n> consecutive tests at <d> seconds intervals. If <n> is followed\n'\
6791 ' -maxfail n Abort a -multi run after n consecutive fails (default is 0 = never abort)\n'\
6793 ' -f Use ftrace to create device callgraphs (default: disabled)\n'\
6794 ' -ftop Use ftrace on the top level call: "%s" (default: disabled)\n'\
6795 ' -maxdepth N limit the callgraph data to N call levels (default: 0=all)\n'\
6796 ' -expandcg pre-expand the callgraph data in the html output (default: disabled)\n'\
6797 ' -fadd file Add functions to be graphed in the timeline from a list in a text file\n'\
6798 ' -filter "d1,d2,..." Filter out all but this comma-delimited list of device names\n'\
6799 ' -mincg ms Discard all callgraphs shorter than ms milliseconds (e.g. 0.001 for us)\n'\
6800 ' -cgphase P Only show callgraph data for phase P (e.g. suspend_late)\n'\
6801 ' -cgtest N Only show callgraph data for test N (e.g. 0 or 1 in an x2 run)\n'\
6802 ' -timeprec N Number of significant digits in timestamps (0:S, [3:ms], 6:us)\n'\
6803 ' -cgfilter S Filter the callgraph output in the timeline\n'\
6804 ' -cgskip file Callgraph functions to skip, off to disable (default: cgskip.txt)\n'\
6805 ' -bufsize N Set trace buffer size to N kilo-bytes (default: all of free memory)\n'\
6806 ' -devdump Print out all the raw device data for each phase\n'\
6807 ' -cgdump Print out all the raw callgraph data\n'\
6810 ' -modes List available suspend modes\n'\
6811 ' -status Test to see if the system is enabled to run this tool\n'\
6812 ' -fpdt Print out the contents of the ACPI Firmware Performance Data Table\n'\
6813 ' -wificheck Print out wifi connection info\n'\
6814 ' -x<mode> Test xset by toggling the given mode (on/off/standby/suspend)\n'\
6815 ' -sysinfo Print out system info extracted from BIOS\n'\
6816 ' -devinfo Print out the pm settings of all devices which support runtime suspend\n'\
6817 ' -cmdinfo Print out all the platform info collected before and after suspend/resume\n'\
6818 ' -flist Print the list of functions currently being captured in ftrace\n'\
6819 ' -flistall Print all functions capable of being captured in ftrace\n'\
6820 ' -summary dir Create a summary of tests in this dir [-genhtml builds missing html]\n'\
6822 ' -ftrace ftracefile Create HTML output using ftrace input (used with -dmesg)\n'\
6823 ' -dmesg dmesgfile Create HTML output using dmesg (used with -ftrace)\n'\
6827 # ----------------- MAIN --------------------
6832 simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall',
6833 '-devinfo', '-status', '-xon', '-xoff', '-xstandby', '-xsuspend',
6834 '-xinit', '-xreset', '-xstat', '-wificheck', '-cmdinfo']
6835 if '-f' in sys.argv:
6840 if(arg == '-m'):
6850 elif(arg == '-h'):
6853 elif(arg == '-v'):
6856 elif(arg == '-debugtiming'):
6858 elif(arg == '-x2'):
6860 elif(arg == '-x2delay'):
6861 sysvals.x2delay = getArgInt('-x2delay', args, 0, 60000)
6862 elif(arg == '-predelay'):
6863 sysvals.predelay = getArgInt('-predelay', args, 0, 60000)
6864 elif(arg == '-postdelay'):
6865 sysvals.postdelay = getArgInt('-postdelay', args, 0, 60000)
6866 elif(arg == '-f'):
6868 elif(arg == '-ftop'):
6872 elif(arg == '-skiphtml'):
6874 elif(arg == '-cgdump'):
6876 elif(arg == '-devdump'):
6878 elif(arg == '-genhtml'):
6880 elif(arg == '-addlogs'):
6882 elif(arg == '-nologs'):
6884 elif(arg == '-addlogdmesg'):
6886 elif(arg == '-addlogftrace'):
6888 elif(arg == '-noturbostat'):
6890 elif(arg == '-verbose'):
6892 elif(arg == '-proc'):
6894 elif(arg == '-dev'):
6896 elif(arg == '-sync'):
6898 elif(arg == '-wifi'):
6900 elif(arg == '-wifitrace'):
6902 elif(arg == '-netfix'):
6904 elif(arg == '-gzip'):
6906 elif(arg == '-info'):
6910 doError('-info requires one string argument', True)
6911 elif(arg == '-desc'):
6915 doError('-desc requires one string argument', True)
6916 elif(arg == '-rs'):
6920 doError('-rs requires "enable" or "disable"', True)
6923 sysvals.rs = -1
6928 elif(arg == '-display'):
6932 doError('-display requires an mode value', True)
6937 elif(arg == '-maxdepth'):
6938 sysvals.max_graph_depth = getArgInt('-maxdepth', args, 0, 1000)
6939 elif(arg == '-rtcwake'):
6948 sysvals.rtcwaketime = getArgInt('-rtcwake', val, 0, 3600, False)
6949 elif(arg == '-timeprec'):
6950 sysvals.setPrecision(getArgInt('-timeprec', args, 0, 6))
6951 elif(arg == '-mindev'):
6952 sysvals.mindevlen = getArgFloat('-mindev', args, 0.0, 10000.0)
6953 elif(arg == '-mincg'):
6954 sysvals.mincglen = getArgFloat('-mincg', args, 0.0, 10000.0)
6955 elif(arg == '-bufsize'):
6956 sysvals.bufsize = getArgInt('-bufsize', args, 1, 1024*1024*8)
6957 elif(arg == '-cgtest'):
6958 sysvals.cgtest = getArgInt('-cgtest', args, 0, 1)
6959 elif(arg == '-cgphase'):
6966 doError('invalid phase --> (%s: %s), valid phases are %s'\
6969 elif(arg == '-cgfilter'):
6975 elif(arg == '-skipkprobe'):
6981 elif(arg == '-cgskip'):
6992 elif(arg == '-callloop-maxgap'):
6993 sysvals.callloopmaxgap = getArgFloat('-callloop-maxgap', args, 0.0, 1.0)
6994 elif(arg == '-callloop-maxlen'):
6995 sysvals.callloopmaxlen = getArgFloat('-callloop-maxlen', args, 0.0, 1.0)
6996 elif(arg == '-cmd'):
7003 elif(arg == '-expandcg'):
7005 elif(arg == '-srgap'):
7007 elif(arg == '-maxfail'):
7008 sysvals.maxfail = getArgInt('-maxfail', args, 0, 1000000)
7009 elif(arg == '-multi'):
7013 doError('-multi requires two values', True)
7015 elif(arg == '-o'):
7021 elif(arg == '-config'):
7030 elif(arg == '-fadd'):
7039 elif(arg == '-dmesg'):
7048 elif(arg == '-ftrace'):
7057 elif(arg == '-summary'):
7067 elif(arg == '-filter'):
7073 elif(arg == '-result'):
7084 doError('-dev is not compatible with -f')
7086 doError('-proc is not compatible with -f')
7136 print('[%s - %s]\n%s\n' % out)
7139 # if instructed, re-analyze existing data files
7153 memmode = mode.split('-', 1)[-1] if '-' in mode else 'deep'
7162 if mode.startswith('disk-'):
7163 sysvals.diskmode = mode.split('-', 1)[-1]
7172 s = '-%dm' % sysvals.multitest['time']
7174 s = '-x%d' % sysvals.multitest['count']
7175 sysvals.outdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S'+s)
7187 fmt = 'suspend-%y%m%d-%H%M%S'