Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) #!/usr/bin/env python3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) # Tool for analyzing suspend/resume timing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) # Copyright (c) 2013, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) # This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) # under the terms and conditions of the GNU General Public License,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) # version 2, as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) # This program is distributed in the hope it will be useful, but WITHOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) # more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) # Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #	 Todd Brandt <todd.e.brandt@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) # Links:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #	 Home Page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #	   https://01.org/pm-graph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #	 Source repo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #	   git@github.com:intel/pm-graph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #	 This tool is designed to assist kernel and OS developers in optimizing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #	 their linux stack's suspend/resume time. Using a kernel image built
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #	 with a few extra options enabled, the tool will execute a suspend and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #	 will capture dmesg and ftrace data until resume is complete. This data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #	 is transformed into a device timeline and a callgraph to give a quick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #	 and detailed view of which devices and callbacks are taking the most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #	 time in suspend/resume. The output is a single html file which can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #	 viewed in firefox or chrome.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #	 The following kernel build options are required:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #		 CONFIG_DEVMEM=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #		 CONFIG_PM_DEBUG=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #		 CONFIG_PM_SLEEP_DEBUG=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #		 CONFIG_FTRACE=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #		 CONFIG_FUNCTION_TRACER=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #		 CONFIG_FUNCTION_GRAPH_TRACER=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #		 CONFIG_KPROBES=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #		 CONFIG_KPROBES_ON_FTRACE=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #	 For kernel versions older than 3.15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #	 The following additional kernel parameters are required:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #		 (e.g. in file /etc/default/grub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #		 GRUB_CMDLINE_LINUX_DEFAULT="... initcall_debug log_buf_len=16M ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) # ----------------- LIBRARIES --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) import sys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) import time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) import os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) import string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) import re
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) import platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) import signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) import codecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) from datetime import datetime, timedelta
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) import struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) import configparser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) import gzip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) from threading import Thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) from subprocess import call, Popen, PIPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) import base64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) def pprint(msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	print(msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	sys.stdout.flush()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) def ascii(text):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	return text.decode('ascii', 'ignore')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) # ----------------- CLASSES --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) # Class: SystemValues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #	 A global, single-instance container used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #	 store system values and test parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) class SystemValues:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	title = 'SleepGraph'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	version = '5.7'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	ansi = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	rs = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	display = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	gzip = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	sync = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	wifi = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	verbose = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	testlog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	dmesglog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	ftracelog = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	tstat = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	mindevlen = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	mincglen = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	cgphase = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	cgtest = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	cgskip = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	maxfail = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	multitest = {'run': False, 'count': 1000000, 'delay': 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	max_graph_depth = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	callloopmaxgap = 0.0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	callloopmaxlen = 0.005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	bufsize = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	cpucount = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	memtotal = 204800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	memfree = 204800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	srgap = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	cgexp = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	testdir = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	outdir = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	tpath = '/sys/kernel/debug/tracing/'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	fpdtpath = '/sys/firmware/acpi/tables/FPDT'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	epath = '/sys/kernel/debug/tracing/events/power/'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	pmdpath = '/sys/power/pm_debug_messages'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	traceevents = [
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		'suspend_resume',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		'wakeup_source_activate',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		'wakeup_source_deactivate',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		'device_pm_callback_end',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		'device_pm_callback_start'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	logmsg = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	testcommand = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	mempath = '/dev/mem'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	powerfile = '/sys/power/state'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	mempowerfile = '/sys/power/mem_sleep'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	diskpowerfile = '/sys/power/disk'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	suspendmode = 'mem'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	memmode = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	diskmode = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	hostname = 'localhost'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	prefix = 'test'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	teststamp = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	sysstamp = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	dmesgstart = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	dmesgfile = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	ftracefile = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	htmlfile = 'output.html'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	result = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	rtcwake = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	rtcwaketime = 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	rtcpath = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	devicefilter = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	cgfilter = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	stamp = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	execcount = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	x2delay = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	skiphtml = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	usecallgraph = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	ftopfunc = 'pm_suspend'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	ftop = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	usetraceevents = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	usetracemarkers = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	usekprobes = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	usedevsrc = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	useprocmon = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	notestrun = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	cgdump = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	devdump = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	mixedphaseheight = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	devprops = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	platinfo = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	predelay = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	postdelay = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	pmdebug = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	tmstart = 'SUSPEND START %Y%m%d-%H:%M:%S.%f'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	tmend = 'RESUME COMPLETE %Y%m%d-%H:%M:%S.%f'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	tracefuncs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		'sys_sync': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		'ksys_sync': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		'pm_notifier_call_chain_robust': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		'pm_prepare_console': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		'pm_notifier_call_chain': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		'freeze_processes': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		'freeze_kernel_threads': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		'pm_restrict_gfp_mask': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		'acpi_suspend_begin': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		'acpi_hibernation_begin': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		'acpi_hibernation_enter': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		'acpi_hibernation_leave': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		'acpi_pm_freeze': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		'acpi_pm_thaw': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		'acpi_s2idle_end': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		'acpi_s2idle_sync': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		'acpi_s2idle_begin': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		'acpi_s2idle_prepare': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		'acpi_s2idle_prepare_late': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		'acpi_s2idle_wake': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		'acpi_s2idle_wakeup': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		'acpi_s2idle_restore': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		'acpi_s2idle_restore_early': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		'hibernate_preallocate_memory': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		'create_basic_memory_bitmaps': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		'swsusp_write': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		'suspend_console': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		'acpi_pm_prepare': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		'syscore_suspend': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		'arch_enable_nonboot_cpus_end': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		'syscore_resume': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		'acpi_pm_finish': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		'resume_console': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		'acpi_pm_end': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		'pm_restore_gfp_mask': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		'thaw_processes': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		'pm_restore_console': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		'CPU_OFF': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			'func':'_cpu_down',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			'args_x86_64': {'cpu':'%di:s32'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			'format': 'CPU_OFF[{cpu}]'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		'CPU_ON': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			'func':'_cpu_up',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 			'args_x86_64': {'cpu':'%di:s32'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 			'format': 'CPU_ON[{cpu}]'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	dev_tracefuncs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		# general wait/delay/sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		'msleep': { 'args_x86_64': {'time':'%di:s32'}, 'ub': 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		'schedule_timeout': { 'args_x86_64': {'timeout':'%di:s32'}, 'ub': 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		'udelay': { 'func':'__const_udelay', 'args_x86_64': {'loops':'%di:s32'}, 'ub': 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		'usleep_range': { 'args_x86_64': {'min':'%di:s32', 'max':'%si:s32'}, 'ub': 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		'mutex_lock_slowpath': { 'func':'__mutex_lock_slowpath', 'ub': 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		'acpi_os_stall': {'ub': 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		'rt_mutex_slowlock': {'ub': 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		# ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		'acpi_resume_power_resources': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		'acpi_ps_execute_method': { 'args_x86_64': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			'fullpath':'+0(+40(%di)):string',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		}},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		# mei_me
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		'mei_reset': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		# filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		'ext4_sync_fs': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		# 80211
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		'ath10k_bmi_read_memory': { 'args_x86_64': {'length':'%cx:s32'} },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		'ath10k_bmi_write_memory': { 'args_x86_64': {'length':'%cx:s32'} },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		'ath10k_bmi_fast_download': { 'args_x86_64': {'length':'%cx:s32'} },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		'iwlagn_mac_start': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		'iwlagn_alloc_bcast_station': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		'iwl_trans_pcie_start_hw': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		'iwl_trans_pcie_start_fw': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		'iwl_run_init_ucode': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		'iwl_load_ucode_wait_alive': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		'iwl_alive_start': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		'iwlagn_mac_stop': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		'iwlagn_mac_suspend': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		'iwlagn_mac_resume': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		'iwlagn_mac_add_interface': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		'iwlagn_mac_remove_interface': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		'iwlagn_mac_change_interface': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		'iwlagn_mac_config': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		'iwlagn_configure_filter': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		'iwlagn_mac_hw_scan': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		'iwlagn_bss_info_changed': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		'iwlagn_mac_channel_switch': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		'iwlagn_mac_flush': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		# ATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		'ata_eh_recover': { 'args_x86_64': {'port':'+36(%di):s32'} },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		# i915
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		'i915_gem_resume': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		'i915_restore_state': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		'intel_opregion_setup': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		'g4x_pre_enable_dp': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		'vlv_pre_enable_dp': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		'chv_pre_enable_dp': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		'g4x_enable_dp': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		'vlv_enable_dp': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		'intel_hpd_init': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		'intel_opregion_register': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		'intel_dp_detect': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		'intel_hdmi_detect': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		'intel_opregion_init': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		'intel_fbdev_set_suspend': {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	infocmds = [
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		[0, 'kparams', 'cat', '/proc/cmdline'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		[0, 'mcelog', 'mcelog'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		[0, 'pcidevices', 'lspci', '-tv'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		[0, 'usbdevices', 'lsusb', '-t'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		[1, 'interrupts', 'cat', '/proc/interrupts'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		[1, 'wakeups', 'cat', '/sys/kernel/debug/wakeup_sources'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		[2, 'gpecounts', 'sh', '-c', 'grep -v invalid /sys/firmware/acpi/interrupts/*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		[2, 'suspendstats', 'sh', '-c', 'grep -v invalid /sys/power/suspend_stats/*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		[2, 'cpuidle', 'sh', '-c', 'grep -v invalid /sys/devices/system/cpu/cpu*/cpuidle/state*/s2idle/*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		[2, 'battery', 'sh', '-c', 'grep -v invalid /sys/class/power_supply/*/*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	cgblacklist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	kprobes = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	timeformat = '%.3f'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	cmdline = '%s %s' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			(os.path.basename(sys.argv[0]), ' '.join(sys.argv[1:]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	sudouser = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		self.archargs = 'args_'+platform.machine()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		self.hostname = platform.node()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		if(self.hostname == ''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			self.hostname = 'localhost'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		rtc = "rtc0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		if os.path.exists('/dev/rtc'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			rtc = os.readlink('/dev/rtc')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		rtc = '/sys/class/rtc/'+rtc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		if os.path.exists(rtc) and os.path.exists(rtc+'/date') and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			os.path.exists(rtc+'/time') and os.path.exists(rtc+'/wakealarm'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			self.rtcpath = rtc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		if (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			self.ansi = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		self.testdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		if os.getuid() == 0 and 'SUDO_USER' in os.environ and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			os.environ['SUDO_USER']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			self.sudouser = os.environ['SUDO_USER']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	def resetlog(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		self.logmsg = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		self.platinfo = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	def vprint(self, msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		self.logmsg += msg+'\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		if self.verbose or msg.startswith('WARNING:'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			pprint(msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	def signalHandler(self, signum, frame):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		if not self.result:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		signame = self.signames[signum] if signum in self.signames else 'UNKNOWN'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		msg = 'Signal %s caused a tool exit, line %d' % (signame, frame.f_lineno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		self.outputResult({'error':msg})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		sys.exit(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	def signalHandlerInit(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		capture = ['BUS', 'SYS', 'XCPU', 'XFSZ', 'PWR', 'HUP', 'INT', 'QUIT',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			'ILL', 'ABRT', 'FPE', 'SEGV', 'TERM']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		self.signames = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		for i in capture:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			s = 'SIG'+i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 				signum = getattr(signal, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 				signal.signal(signum, self.signalHandler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			self.signames[signum] = s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	def rootCheck(self, fatal=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		if(os.access(self.powerfile, os.W_OK)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		if fatal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			msg = 'This command requires sysfs mount and root access'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			pprint('ERROR: %s\n' % msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			self.outputResult({'error':msg})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			sys.exit(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	def rootUser(self, fatal=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		if 'USER' in os.environ and os.environ['USER'] == 'root':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		if fatal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			msg = 'This command must be run as root'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			pprint('ERROR: %s\n' % msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			self.outputResult({'error':msg})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			sys.exit(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	def usable(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		return (os.path.exists(file) and os.path.getsize(file) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	def getExec(self, cmd):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			fp = Popen(['which', cmd], stdout=PIPE, stderr=PIPE).stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			out = ascii(fp.read()).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			out = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		if out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		for path in ['/sbin', '/bin', '/usr/sbin', '/usr/bin',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			'/usr/local/sbin', '/usr/local/bin']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			cmdfull = os.path.join(path, cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			if os.path.exists(cmdfull):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 				return cmdfull
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	def setPrecision(self, num):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		if num < 0 or num > 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		self.timeformat = '%.{0}f'.format(num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	def setOutputFolder(self, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		args = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		n = datetime.now()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		args['date'] = n.strftime('%y%m%d')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		args['time'] = n.strftime('%H%M%S')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		args['hostname'] = args['host'] = self.hostname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		args['mode'] = self.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		return value.format(**args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	def setOutputFile(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		if self.dmesgfile != '':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			m = re.match('(?P<name>.*)_dmesg\.txt.*', self.dmesgfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 				self.htmlfile = m.group('name')+'.html'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		if self.ftracefile != '':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			m = re.match('(?P<name>.*)_ftrace\.txt.*', self.ftracefile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				self.htmlfile = m.group('name')+'.html'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	def systemInfo(self, info):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		p = m = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		if 'baseboard-manufacturer' in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			m = info['baseboard-manufacturer']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		elif 'system-manufacturer' in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 			m = info['system-manufacturer']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		if 'system-product-name' in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			p = info['system-product-name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		elif 'baseboard-product-name' in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 			p = info['baseboard-product-name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		if m[:5].lower() == 'intel' and 'baseboard-product-name' in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 			p = info['baseboard-product-name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		c = info['processor-version'] if 'processor-version' in info else ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		b = info['bios-version'] if 'bios-version' in info else ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		r = info['bios-release-date'] if 'bios-release-date' in info else ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | biosdate:%s | numcpu:%d | memsz:%d | memfr:%d' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			(m, p, c, b, r, self.cpucount, self.memtotal, self.memfree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	def printSystemInfo(self, fatal=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		self.rootCheck(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		out = dmidecode(self.mempath, fatal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		if len(out) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		fmt = '%-24s: %s'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		for name in sorted(out):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			print(fmt % (name, out[name]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		print(fmt % ('cpucount', ('%d' % self.cpucount)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		print(fmt % ('memtotal', ('%d kB' % self.memtotal)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		print(fmt % ('memfree', ('%d kB' % self.memfree)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	def cpuInfo(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		self.cpucount = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		fp = open('/proc/cpuinfo', 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 			if re.match('^processor[ \t]*:[ \t]*[0-9]*', line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 				self.cpucount += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		fp = open('/proc/meminfo', 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			m = re.match('^MemTotal:[ \t]*(?P<sz>[0-9]*) *kB', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 				self.memtotal = int(m.group('sz'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			m = re.match('^MemFree:[ \t]*(?P<sz>[0-9]*) *kB', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 				self.memfree = int(m.group('sz'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	def initTestOutput(self, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		self.prefix = self.hostname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		v = open('/proc/version', 'r').read().strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		kver = v.split()[2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		fmt = name+'-%m%d%y-%H%M%S'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		testtime = datetime.now().strftime(fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		self.teststamp = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			'# '+testtime+' '+self.prefix+' '+self.suspendmode+' '+kver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		ext = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		if self.gzip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			ext = '.gz'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		self.dmesgfile = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'+ext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		self.ftracefile = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'+ext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		self.htmlfile = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			self.testdir+'/'+self.prefix+'_'+self.suspendmode+'.html'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		if not os.path.isdir(self.testdir):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			os.makedirs(self.testdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		self.sudoUserchown(self.testdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	def getValueList(self, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		out = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		for i in value.split(','):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			if i.strip():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 				out.append(i.strip())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	def setDeviceFilter(self, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		self.devicefilter = self.getValueList(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	def setCallgraphFilter(self, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		self.cgfilter = self.getValueList(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	def skipKprobes(self, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		for k in self.getValueList(value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			if k in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 				del self.tracefuncs[k]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			if k in self.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 				del self.dev_tracefuncs[k]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	def setCallgraphBlacklist(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		self.cgblacklist = self.listFromFile(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	def rtcWakeAlarmOn(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		call('echo 0 > '+self.rtcpath+'/wakealarm', shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		nowtime = open(self.rtcpath+'/since_epoch', 'r').read().strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		if nowtime:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			nowtime = int(nowtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			# if hardware time fails, use the software time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			nowtime = int(datetime.now().strftime('%s'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		alarm = nowtime + self.rtcwaketime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		call('echo %d > %s/wakealarm' % (alarm, self.rtcpath), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	def rtcWakeAlarmOff(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		call('echo 0 > %s/wakealarm' % self.rtcpath, shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	def initdmesg(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		# get the latest time stamp from the dmesg log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		fp = Popen('dmesg', stdout=PIPE).stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		ktime = '0'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			line = ascii(line).replace('\r\n', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			idx = line.find('[')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			if idx > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				line = line[idx:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 				ktime = m.group('ktime')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		self.dmesgstart = float(ktime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	def getdmesg(self, testdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		op = self.writeDatafileHeader(self.dmesgfile, testdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		# store all new dmesg lines since initdmesg was called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		fp = Popen('dmesg', stdout=PIPE).stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			line = ascii(line).replace('\r\n', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			idx = line.find('[')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			if idx > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 				line = line[idx:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			ktime = float(m.group('ktime'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			if ktime > self.dmesgstart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 				op.write(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		op.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	def listFromFile(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		fp = open(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		for i in fp.read().split('\n'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			i = i.strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			if i and i[0] != '#':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 				list.append(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		return list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	def addFtraceFilterFunctions(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		for i in self.listFromFile(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			if len(i) < 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			self.tracefuncs[i] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	def getFtraceFilterFunctions(self, current):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		self.rootCheck(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		if not current:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 			call('cat '+self.tpath+'available_filter_functions', shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		master = self.listFromFile(self.tpath+'available_filter_functions')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		for i in sorted(self.tracefuncs):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			if 'func' in self.tracefuncs[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 				i = self.tracefuncs[i]['func']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			if i in master:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 				print(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 				print(self.colorText(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	def setFtraceFilterFunctions(self, list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		master = self.listFromFile(self.tpath+'available_filter_functions')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		flist = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		for i in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			if i not in master:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 			if ' [' in i:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 				flist += i.split(' ')[0]+'\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 				flist += i+'\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		fp = open(self.tpath+'set_graph_function', 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		fp.write(flist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	def basicKprobe(self, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		self.kprobes[name] = {'name': name,'func': name,'args': dict(),'format': name}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	def defaultKprobe(self, name, kdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		k = kdata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		for field in ['name', 'format', 'func']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			if field not in k:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 				k[field] = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		if self.archargs in k:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 			k['args'] = k[self.archargs]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 			k['args'] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 			k['format'] = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		self.kprobes[name] = k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	def kprobeColor(self, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		if name not in self.kprobes or 'color' not in self.kprobes[name]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		return self.kprobes[name]['color']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	def kprobeDisplayName(self, name, dataraw):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		if name not in self.kprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			self.basicKprobe(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		data = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		quote=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		# first remvoe any spaces inside quotes, and the quotes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		for c in dataraw:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			if c == '"':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 				quote = (quote + 1) % 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 			if quote and c == ' ':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 				data += '_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			elif c != '"':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 				data += c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		fmt, args = self.kprobes[name]['format'], self.kprobes[name]['args']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		arglist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		# now process the args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		for arg in sorted(args):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			arglist[arg] = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			m = re.match('.* '+arg+'=(?P<arg>.*) ', data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 				arglist[arg] = m.group('arg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 				m = re.match('.* '+arg+'=(?P<arg>.*)', data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 				if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 					arglist[arg] = m.group('arg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		out = fmt.format(**arglist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		out = out.replace(' ', '_').replace('"', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	def kprobeText(self, kname, kprobe):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		name = fmt = func = kname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		args = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		if 'name' in kprobe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			name = kprobe['name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if 'format' in kprobe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			fmt = kprobe['format']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		if 'func' in kprobe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			func = kprobe['func']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		if self.archargs in kprobe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			args = kprobe[self.archargs]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		if 'args' in kprobe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			args = kprobe['args']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', func):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			doError('Kprobe "%s" has format info in the function name "%s"' % (name, func))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		for arg in re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', fmt):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			if arg not in args:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 				doError('Kprobe "%s" is missing argument "%s"' % (name, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		val = 'p:%s_cal %s' % (name, func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		for i in sorted(args):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			val += ' %s=%s' % (i, args[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		val += '\nr:%s_ret %s $retval\n' % (name, func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		return val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	def addKprobes(self, output=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		if len(self.kprobes) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		if output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			pprint('    kprobe functions in this kernel:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		# first test each kprobe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		rejects = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		# sort kprobes: trace, ub-dev, custom, dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		kpl = [[], [], [], []]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		linesout = len(self.kprobes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		for name in sorted(self.kprobes):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			res = self.colorText('YES', 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			if not self.testKprobe(name, self.kprobes[name]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 				res = self.colorText('NO')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 				rejects.append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 				if name in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 					kpl[0].append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 				elif name in self.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 					if 'ub' in self.dev_tracefuncs[name]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 						kpl[1].append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 						kpl[3].append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 					kpl[2].append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 			if output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 				pprint('         %s: %s' % (name, res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		kplist = kpl[0] + kpl[1] + kpl[2] + kpl[3]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		# remove all failed ones from the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		for name in rejects:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			self.kprobes.pop(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		# set the kprobes all at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		self.fsetVal('', 'kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		kprobeevents = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		for kp in kplist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 			kprobeevents += self.kprobeText(kp, self.kprobes[kp])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		self.fsetVal(kprobeevents, 'kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		if output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			check = self.fgetVal('kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 			linesack = (len(check.split('\n')) - 1) // 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			pprint('    kprobe functions enabled: %d/%d' % (linesack, linesout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		self.fsetVal('1', 'events/kprobes/enable')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	def testKprobe(self, kname, kprobe):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		self.fsetVal('0', 'events/kprobes/enable')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		kprobeevents = self.kprobeText(kname, kprobe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		if not kprobeevents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 			self.fsetVal(kprobeevents, 'kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			check = self.fgetVal('kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		linesout = len(kprobeevents.split('\n'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		linesack = len(check.split('\n'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		if linesack < linesout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	def setVal(self, val, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		if not os.path.exists(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			fp = open(file, 'wb', 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			fp.write(val.encode())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			fp.flush()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	def fsetVal(self, val, path):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		return self.setVal(val, self.tpath+path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	def getVal(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		res = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		if not os.path.exists(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			return res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			fp = open(file, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			res = fp.read()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		return res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	def fgetVal(self, path):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		return self.getVal(self.tpath+path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	def cleanupFtrace(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		if(self.usecallgraph or self.usetraceevents or self.usedevsrc):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			self.fsetVal('0', 'events/kprobes/enable')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			self.fsetVal('', 'kprobe_events')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			self.fsetVal('1024', 'buffer_size_kb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		if self.pmdebug:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			self.setVal(self.pmdebug, self.pmdpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	def setupAllKprobes(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		for name in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			self.defaultKprobe(name, self.tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		for name in self.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			self.defaultKprobe(name, self.dev_tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	def isCallgraphFunc(self, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		if len(self.tracefuncs) < 1 and self.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		for i in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			if 'func' in self.tracefuncs[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 				f = self.tracefuncs[i]['func']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				f = i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			if name == f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	def initFtrace(self, quiet=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			sysvals.printSystemInfo(False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			pprint('INITIALIZING FTRACE...')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		# turn trace off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		self.fsetVal('0', 'tracing_on')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		self.cleanupFtrace()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		# pm debug messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		pv = self.getVal(self.pmdpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		if pv != '1':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			self.setVal('1', self.pmdpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			self.pmdebug = pv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		# set the trace clock to global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		self.fsetVal('global', 'trace_clock')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		self.fsetVal('nop', 'current_tracer')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		# set trace buffer to an appropriate value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		cpus = max(1, self.cpucount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		if self.bufsize > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 			tgtsize = self.bufsize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		elif self.usecallgraph or self.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			bmax = (1*1024*1024) if self.suspendmode in ['disk', 'command'] \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 				else (3*1024*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			tgtsize = min(self.memfree, bmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			tgtsize = 65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		while not self.fsetVal('%d' % (tgtsize // cpus), 'buffer_size_kb'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			# if the size failed to set, lower it and keep trying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 			tgtsize -= 65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 			if tgtsize < 65536:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 				tgtsize = int(self.fgetVal('buffer_size_kb')) * cpus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		self.vprint('Setting trace buffers to %d kB (%d kB per cpu)' % (tgtsize, tgtsize/cpus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		# initialize the callgraph trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		if(self.usecallgraph):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			# set trace type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 			self.fsetVal('function_graph', 'current_tracer')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			self.fsetVal('', 'set_ftrace_filter')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			# set trace format options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 			self.fsetVal('print-parent', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 			self.fsetVal('funcgraph-abstime', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			self.fsetVal('funcgraph-cpu', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			self.fsetVal('funcgraph-duration', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			self.fsetVal('funcgraph-proc', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			self.fsetVal('funcgraph-tail', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			self.fsetVal('nofuncgraph-overhead', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			self.fsetVal('context-info', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			self.fsetVal('graph-time', 'trace_options')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 			self.fsetVal('%d' % self.max_graph_depth, 'max_graph_depth')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			cf = ['dpm_run_callback']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 			if(self.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 				cf += ['dpm_prepare', 'dpm_complete']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			for fn in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 				if 'func' in self.tracefuncs[fn]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 					cf.append(self.tracefuncs[fn]['func'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 					cf.append(fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			if self.ftop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 				self.setFtraceFilterFunctions([self.ftopfunc])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 				self.setFtraceFilterFunctions(cf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		# initialize the kprobe trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		elif self.usekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			for name in self.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 				self.defaultKprobe(name, self.tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			if self.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 				for name in self.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 					self.defaultKprobe(name, self.dev_tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 				pprint('INITIALIZING KPROBES...')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			self.addKprobes(self.verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		if(self.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			# turn trace events on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			events = iter(self.traceevents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			for e in events:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 				self.fsetVal('1', 'events/power/'+e+'/enable')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		# clear the trace buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		self.fsetVal('', 'trace')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	def verifyFtrace(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		# files needed for any trace data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		files = ['buffer_size_kb', 'current_tracer', 'trace', 'trace_clock',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				 'trace_marker', 'trace_options', 'tracing_on']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		# files needed for callgraph trace data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		tp = self.tpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		if(self.usecallgraph):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			files += [
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 				'available_filter_functions',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 				'set_ftrace_filter',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				'set_graph_function'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		for f in files:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			if(os.path.exists(tp+f) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 				return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	def verifyKprobes(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		# files needed for kprobes to work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		files = ['kprobe_events', 'events']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		tp = self.tpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		for f in files:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			if(os.path.exists(tp+f) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 				return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	def colorText(self, str, color=31):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		if not self.ansi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			return str
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		return '\x1B[%d;40m%s\x1B[m' % (color, str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	def writeDatafileHeader(self, filename, testdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		fp = self.openlog(filename, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		fp.write('%s\n%s\n# command | %s\n' % (self.teststamp, self.sysstamp, self.cmdline))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		for test in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			if 'fw' in test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 				fw = test['fw']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 				if(fw):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 					fp.write('# fwsuspend %u fwresume %u\n' % (fw[0], fw[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			if 'turbo' in test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 				fp.write('# turbostat %s\n' % test['turbo'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			if 'wifi' in test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 				fp.write('# wifi %s\n' % test['wifi'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			if test['error'] or len(testdata) > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 				fp.write('# enter_sleep_error %s\n' % test['error'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		return fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	def sudoUserchown(self, dir):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		if os.path.exists(dir) and self.sudouser:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			cmd = 'chown -R {0}:{0} {1} > /dev/null 2>&1'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			call(cmd.format(self.sudouser, dir), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	def outputResult(self, testdata, num=0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		if not self.result:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		n = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		if num > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			n = '%d' % num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		fp = open(self.result, 'a')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		if 'error' in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			fp.write('result%s: fail\n' % n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			fp.write('error%s: %s\n' % (n, testdata['error']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			fp.write('result%s: pass\n' % n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		for v in ['suspend', 'resume', 'boot', 'lastinit']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			if v in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 				fp.write('%s%s: %.3f\n' % (v, n, testdata[v]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		for v in ['fwsuspend', 'fwresume']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			if v in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 				fp.write('%s%s: %.3f\n' % (v, n, testdata[v] / 1000000.0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		if 'bugurl' in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			fp.write('url%s: %s\n' % (n, testdata['bugurl']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		self.sudoUserchown(self.result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	def configFile(self, file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		dir = os.path.dirname(os.path.realpath(__file__))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		if os.path.exists(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			return file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		elif os.path.exists(dir+'/'+file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			return dir+'/'+file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		elif os.path.exists(dir+'/config/'+file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			return dir+'/config/'+file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	def openlog(self, filename, mode):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		isgz = self.gzip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		if mode == 'r':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 				with gzip.open(filename, mode+'t') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 					test = fp.read(64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 				isgz = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 				isgz = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		if isgz:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			return gzip.open(filename, mode+'t')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		return open(filename, mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	def b64unzip(self, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			out = codecs.decode(base64.b64decode(data), 'zlib').decode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			out = data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	def b64zip(self, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		out = base64.b64encode(codecs.encode(data.encode(), 'zlib')).decode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	def platforminfo(self, cmdafter):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		# add platform info on to a completed ftrace file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		if not os.path.exists(self.ftracefile):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		footer = '#\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		# add test command string line if need be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		if self.suspendmode == 'command' and self.testcommand:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 			footer += '# platform-testcmd: %s\n' % (self.testcommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		# get a list of target devices from the ftrace file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		props = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		tf = self.openlog(self.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		for line in tf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 			if tp.stampInfo(line, self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			# parse only valid lines, if this is not one move on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 			m = re.match(tp.ftrace_line_fmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 			if(not m or 'device_pm_callback_start' not in line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			m = re.match('.*: (?P<drv>.*) (?P<d>.*), parent: *(?P<p>.*), .*', m.group('msg'));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			dev = m.group('d')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 			if dev not in props:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 				props[dev] = DevProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		tf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		# now get the syspath for each target device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		for dirname, dirnames, filenames in os.walk('/sys/devices'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 			if(re.match('.*/power', dirname) and 'async' in filenames):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 				dev = dirname.split('/')[-2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 				if dev in props and (not props[dev].syspath or len(dirname) < len(props[dev].syspath)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 					props[dev].syspath = dirname[:-6]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		# now fill in the properties for our target devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		for dev in sorted(props):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			dirname = props[dev].syspath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			if not dirname or not os.path.exists(dirname):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			with open(dirname+'/power/async') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 				text = fp.read()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 				props[dev].isasync = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				if 'enabled' in text:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 					props[dev].isasync = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			fields = os.listdir(dirname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			if 'product' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 				with open(dirname+'/product', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 					props[dev].altname = ascii(fp.read())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			elif 'name' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 				with open(dirname+'/name', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 					props[dev].altname = ascii(fp.read())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			elif 'model' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 				with open(dirname+'/model', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 					props[dev].altname = ascii(fp.read())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			elif 'description' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 				with open(dirname+'/description', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 					props[dev].altname = ascii(fp.read())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			elif 'id' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 				with open(dirname+'/id', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 					props[dev].altname = ascii(fp.read())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			elif 'idVendor' in fields and 'idProduct' in fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 				idv, idp = '', ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 				with open(dirname+'/idVendor', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 					idv = ascii(fp.read()).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 				with open(dirname+'/idProduct', 'rb') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 					idp = ascii(fp.read()).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 				props[dev].altname = '%s:%s' % (idv, idp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			if props[dev].altname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 				out = props[dev].altname.strip().replace('\n', ' ')\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 					.replace(',', ' ').replace(';', ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 				props[dev].altname = out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		# add a devinfo line to the bottom of ftrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		out = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		for dev in sorted(props):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			out += props[dev].out(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		footer += '# platform-devinfo: %s\n' % self.b64zip(out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		# add a line for each of these commands with their outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		for name, cmdline, info in cmdafter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			footer += '# platform-%s: %s | %s\n' % (name, cmdline, self.b64zip(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		with self.openlog(self.ftracefile, 'a') as fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			fp.write(footer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	def commonPrefix(self, list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		if len(list) < 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		prefix = list[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		for s in list[1:]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			while s[:len(prefix)] != prefix and prefix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 				prefix = prefix[:len(prefix)-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			if not prefix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		if '/' in prefix and prefix[-1] != '/':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			prefix = prefix[0:prefix.rfind('/')+1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		return prefix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	def dictify(self, text, format):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		out = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		header = True if format == 1 else False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		delim = ' ' if format == 1 else ':'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		for line in text.split('\n'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 			if header:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 				header, out['@'] = False, line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			line = line.strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			if delim in line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				data = line.split(delim, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				num = re.search(r'[\d]+', data[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				if format == 2 and num:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 					out[data[0].strip()] = num.group()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 					out[data[0].strip()] = data[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	def cmdinfo(self, begin, debug=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		out = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		if begin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			self.cmd1 = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		for cargs in self.infocmds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			delta, name = cargs[0], cargs[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			cmdline, cmdpath = ' '.join(cargs[2:]), self.getExec(cargs[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			if not cmdpath or (begin and not delta):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				fp = Popen([cmdpath]+cargs[3:], stdout=PIPE, stderr=PIPE).stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				info = ascii(fp.read()).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 				fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			if not debug and begin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 				self.cmd1[name] = self.dictify(info, delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 			elif not debug and delta and name in self.cmd1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 				before, after = self.cmd1[name], self.dictify(info, delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 				dinfo = ('\t%s\n' % before['@']) if '@' in before else ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 				prefix = self.commonPrefix(list(before.keys()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 				for key in sorted(before):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 					if key in after and before[key] != after[key]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 						title = key.replace(prefix, '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 						if delta == 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 							dinfo += '\t%s : %s -> %s\n' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 								(title, before[key].strip(), after[key].strip())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 						else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 							dinfo += '%10s (start) : %s\n%10s (after) : %s\n' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 								(title, before[key], title, after[key])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 				dinfo = '\tnothing changed' if not dinfo else dinfo.rstrip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 				out.append((name, cmdline, dinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				out.append((name, cmdline, '\tnothing' if not info else info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	def haveTurbostat(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		if not self.tstat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		cmd = self.getExec('turbostat')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		if not cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		fp = Popen([cmd, '-v'], stdout=PIPE, stderr=PIPE).stderr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		out = ascii(fp.read()).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		if re.match('turbostat version .*', out):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			self.vprint(out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	def turbostat(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		cmd = self.getExec('turbostat')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		rawout = keyline = valline = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		fullcmd = '%s -q -S echo freeze > %s' % (cmd, self.powerfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		fp = Popen(['sh', '-c', fullcmd], stdout=PIPE, stderr=PIPE).stderr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 			line = ascii(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 			rawout += line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			if keyline and valline:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 			if re.match('(?i)Avg_MHz.*', line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 				keyline = line.strip().split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 			elif keyline:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 				valline = line.strip().split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		if not keyline or not valline or len(keyline) != len(valline):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			errmsg = 'unrecognized turbostat output:\n'+rawout.strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 			self.vprint(errmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			if not self.verbose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 				pprint(errmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		if self.verbose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 			pprint(rawout.strip())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		out = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		for key in keyline:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			idx = keyline.index(key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			val = valline[idx]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			out.append('%s=%s' % (key, val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		return '|'.join(out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	def wifiDetails(self, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			info = open('/sys/class/net/%s/device/uevent' % dev, 'r').read().strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			return dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		vals = [dev]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		for prop in info.split('\n'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			if prop.startswith('DRIVER=') or prop.startswith('PCI_ID='):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 				vals.append(prop.split('=')[-1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		return ':'.join(vals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	def checkWifi(self, dev=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 			w = open('/proc/net/wireless', 'r').read().strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 			return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		for line in reversed(w.split('\n')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 			m = re.match(' *(?P<dev>.*): (?P<stat>[0-9a-f]*) .*', w.split('\n')[-1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 			if not m or (dev and dev != m.group('dev')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			return m.group('dev')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	def pollWifi(self, dev, timeout=60):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		start = time.time()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		while (time.time() - start) < timeout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			w = self.checkWifi(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			if w:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 				return '%s reconnected %.2f' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 					(self.wifiDetails(dev), max(0, time.time() - start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 			time.sleep(0.01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		return '%s timeout %d' % (self.wifiDetails(dev), timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	def errorSummary(self, errinfo, msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		found = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		for entry in errinfo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 			if re.match(entry['match'], msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 				entry['count'] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 				if self.hostname not in entry['urls']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 					entry['urls'][self.hostname] = [self.htmlfile]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 				elif self.htmlfile not in entry['urls'][self.hostname]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 					entry['urls'][self.hostname].append(self.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 				found = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		if found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		arr = msg.split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		for j in range(len(arr)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			if re.match('^[0-9,\-\.]*$', arr[j]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 				arr[j] = '[0-9,\-\.]*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 				arr[j] = arr[j]\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 					.replace('\\', '\\\\').replace(']', '\]').replace('[', '\[')\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 					.replace('.', '\.').replace('+', '\+').replace('*', '\*')\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 					.replace('(', '\(').replace(')', '\)').replace('}', '\}')\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 					.replace('{', '\{')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		mstr = ' *'.join(arr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		entry = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			'line': msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 			'match': mstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			'count': 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			'urls': {self.hostname: [self.htmlfile]}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		errinfo.append(entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	def multistat(self, start, idx, finish):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		if 'time' in self.multitest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 			id = '%d Duration=%dmin' % (idx+1, self.multitest['time'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 			id = '%d/%d' % (idx+1, self.multitest['count'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		t = time.time()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		if 'start' not in self.multitest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			self.multitest['start'] = self.multitest['last'] = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 			self.multitest['total'] = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 			pprint('TEST (%s) START' % id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		dt = t - self.multitest['last']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		if not start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 			if idx == 0 and self.multitest['delay'] > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 				self.multitest['total'] += self.multitest['delay']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 			pprint('TEST (%s) COMPLETE -- Duration %.1fs' % (id, dt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		self.multitest['total'] += dt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		self.multitest['last'] = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		avg = self.multitest['total'] / idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		if 'time' in self.multitest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			left = finish - datetime.now()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			left -= timedelta(microseconds=left.microseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 			left = timedelta(seconds=((self.multitest['count'] - idx) * int(avg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		pprint('TEST (%s) START - Avg Duration %.1fs, Time left %s' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			(id, avg, str(left)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	def multiinit(self, c, d):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		sz, unit = 'count', 'm'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		if c.endswith('d') or c.endswith('h') or c.endswith('m'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			sz, unit, c = 'time', c[-1], c[:-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		self.multitest['run'] = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		self.multitest[sz] = getArgInt('multi: n d (exec count)', c, 1, 1000000, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		self.multitest['delay'] = getArgInt('multi: n d (delay between tests)', d, 0, 3600, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		if unit == 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 			self.multitest[sz] *= 1440
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		elif unit == 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			self.multitest[sz] *= 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) sysvals = SystemValues()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) switchvalues = ['enable', 'disable', 'on', 'off', 'true', 'false', '1', '0']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) switchoff = ['disable', 'off', 'false', '0']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) suspendmodename = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	'freeze': 'Freeze (S0)',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	'standby': 'Standby (S1)',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	'mem': 'Suspend (S3)',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	'disk': 'Hibernate (S4)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) # Class: DevProps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) #	 Simple class which holds property values collected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) #	 for all the devices used in the timeline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) class DevProps:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		self.syspath = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		self.altname = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		self.isasync = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		self.xtraclass = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 		self.xtrainfo = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	def out(self, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		return '%s,%s,%d;' % (dev, self.altname, self.isasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	def debug(self, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		pprint('%s:\n\taltname = %s\n\t  async = %s' % (dev, self.altname, self.isasync))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	def altName(self, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		if not self.altname or self.altname == dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 			return dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		return '%s [%s]' % (self.altname, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	def xtraClass(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		if self.xtraclass:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 			return ' '+self.xtraclass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		if not self.isasync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 			return ' sync'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	def xtraInfo(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		if self.xtraclass:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 			return ' '+self.xtraclass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		if self.isasync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 			return ' (async)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		return ' (sync)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) # Class: DeviceNode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) #	 A container used to create a device hierachy, with a single root node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) #	 and a tree of child nodes. Used by Data.deviceTopology()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) class DeviceNode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	def __init__(self, nodename, nodedepth):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		self.name = nodename
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		self.children = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 		self.depth = nodedepth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) # Class: Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) #	 The primary container for suspend/resume test data. There is one for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) #	 each test run. The data is organized into a cronological hierarchy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) #	 Data.dmesg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) #		phases {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) #			10 sequential, non-overlapping phases of S/R
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) #			contents: times for phase start/end, order/color data for html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) #			devlist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) #				device callback or action list for this phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) #				device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) #					a single device callback or generic action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) #					contents: start/stop times, pid/cpu/driver info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) #						parents/children, html id for timeline/callgraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) #						optionally includes an ftrace callgraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) #						optionally includes dev/ps data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) #				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) #			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) #		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) #	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) class Data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	phasedef = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		'suspend_prepare': {'order': 0, 'color': '#CCFFCC'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		        'suspend': {'order': 1, 'color': '#88FF88'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		   'suspend_late': {'order': 2, 'color': '#00AA00'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		  'suspend_noirq': {'order': 3, 'color': '#008888'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		'suspend_machine': {'order': 4, 'color': '#0000FF'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		 'resume_machine': {'order': 5, 'color': '#FF0000'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		   'resume_noirq': {'order': 6, 'color': '#FF9900'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		   'resume_early': {'order': 7, 'color': '#FFCC00'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		         'resume': {'order': 8, 'color': '#FFFF88'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		'resume_complete': {'order': 9, 'color': '#FFFFCC'},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	errlist = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		'HWERROR' : r'.*\[ *Hardware Error *\].*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		'FWBUG'   : r'.*\[ *Firmware Bug *\].*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		'BUG'     : r'(?i).*\bBUG\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		'ERROR'   : r'(?i).*\bERROR\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		'WARNING' : r'(?i).*\bWARNING\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		'FAULT'   : r'(?i).*\bFAULT\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		'FAIL'    : r'(?i).*\bFAILED\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		'INVALID' : r'(?i).*\bINVALID\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		'CRASH'   : r'(?i).*\bCRASHED\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		'TIMEOUT' : r'(?i).*\bTIMEOUT\b.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		'IRQ'     : r'.*\bgenirq: .*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		'TASKFAIL': r'.*Freezing of tasks *.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		'ACPI'    : r'.*\bACPI *(?P<b>[A-Za-z]*) *Error[: ].*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		'DISKFULL': r'.*\bNo space left on device.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		'USBERR'  : r'.*usb .*device .*, error [0-9-]*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		'ATAERR'  : r' *ata[0-9\.]*: .*failed.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		'MEIERR'  : r' *mei.*: .*failed.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		'TPMERR'  : r'(?i) *tpm *tpm[0-9]*: .*error.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	def __init__(self, num):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		idchar = 'abcdefghij'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		self.start = 0.0 # test start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		self.end = 0.0   # test end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		self.hwstart = 0 # rtc test start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		self.hwend = 0   # rtc test end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		self.tSuspended = 0.0 # low-level suspend start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		self.tResumed = 0.0   # low-level resume start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		self.tKernSus = 0.0   # kernel level suspend start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		self.tKernRes = 0.0   # kernel level resume end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		self.fwValid = False  # is firmware data available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		self.fwSuspend = 0    # time spent in firmware suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		self.fwResume = 0     # time spent in firmware resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		self.html_device_id = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		self.stamp = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		self.outfile = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		self.kerror = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		self.wifi = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		self.turbostat = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		self.enterfail = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		self.currphase = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		self.pstl = dict()    # process timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		self.testnumber = num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		self.idstr = idchar[num]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		self.dmesgtext = []   # dmesg text file in memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		self.dmesg = dict()   # root data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		self.errorinfo = {'suspend':[],'resume':[]}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		self.tLow = []        # time spent in low-level suspends (standby/freeze)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		self.devpids = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		self.devicegroups = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	def sortedPhases(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return sorted(self.dmesg, key=lambda k:self.dmesg[k]['order'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	def initDevicegroups(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		# called when phases are all finished being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		for phase in sorted(self.dmesg.keys()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			if '*' in phase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 				p = phase.split('*')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 				pnew = '%s%d' % (p[0], len(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 				self.dmesg[pnew] = self.dmesg.pop(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		self.devicegroups = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			self.devicegroups.append([phase])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	def nextPhase(self, phase, offset):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		order = self.dmesg[phase]['order'] + offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		for p in self.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 			if self.dmesg[p]['order'] == order:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 				return p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	def lastPhase(self, depth=1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		plist = self.sortedPhases()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		if len(plist) < depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		return plist[-1*depth]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	def turbostatInfo(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		out = {'syslpi':'N/A','pkgpc10':'N/A'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		for line in self.dmesgtext:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			m = re.match(tp.tstatfmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			if not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			for i in m.group('t').split('|'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 				if 'SYS%LPI' in i:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 					out['syslpi'] = i.split('=')[-1]+'%'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 				elif 'pc10' in i:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 					out['pkgpc10'] = i.split('=')[-1]+'%'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 			break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	def extractErrorInfo(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 		lf = self.dmesgtext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		if len(self.dmesgtext) < 1 and sysvals.dmesgfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			lf = sysvals.openlog(sysvals.dmesgfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		i = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		for line in lf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			i += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			if tp.stampInfo(line, sysvals):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 			m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 			if not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			t = float(m.group('ktime'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			if t < self.start or t > self.end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			dir = 'suspend' if t < self.tSuspended else 'resume'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 			msg = m.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 			if re.match('capability: warning: .*', msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 			for err in self.errlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 				if re.match(self.errlist[err], msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 					list.append((msg, err, dir, t, i, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 					self.kerror = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 					break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		tp.msglist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		for msg, type, dir, t, idx1, idx2 in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			tp.msglist.append(msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			self.errorinfo[dir].append((type, t, idx1, idx2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		if self.kerror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			sysvals.dmesglog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		if len(self.dmesgtext) < 1 and sysvals.dmesgfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			lf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		return tp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	def setStart(self, time, msg=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		self.start = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		if msg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 				self.hwstart = datetime.strptime(msg, sysvals.tmstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				self.hwstart = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	def setEnd(self, time, msg=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		self.end = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		if msg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 				self.hwend = datetime.strptime(msg, sysvals.tmend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 				self.hwend = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	def isTraceEventOutsideDeviceCalls(self, pid, time):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			for dev in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 				d = list[dev]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 				if(d['pid'] == pid and time >= d['start'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 					time < d['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 					return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	def sourcePhase(self, start):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 			if 'machine' in phase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			pend = self.dmesg[phase]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 			if start <= pend:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 				return phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		return 'resume_complete'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	def sourceDevice(self, phaselist, start, end, pid, type):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		tgtdev = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		for phase in phaselist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 			for devname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 				dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 				# pid must match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 				if dev['pid'] != pid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 				devS = dev['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 				devE = dev['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 				if type == 'device':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 					# device target event is entirely inside the source boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 					if(start < devS or start >= devE or end <= devS or end > devE):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 				elif type == 'thread':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 					# thread target event will expand the source boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 					if start < devS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 						dev['start'] = start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 					if end > devE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 						dev['end'] = end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 				tgtdev = dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		return tgtdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	def addDeviceFunctionCall(self, displayname, kprobename, proc, pid, start, end, cdata, rdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		# try to place the call in a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		phases = self.sortedPhases()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		tgtdev = self.sourceDevice(phases, start, end, pid, 'device')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		# calls with device pids that occur outside device bounds are dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		# TODO: include these somehow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		if not tgtdev and pid in self.devpids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		# try to place the call in a thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		if not tgtdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			tgtdev = self.sourceDevice(phases, start, end, pid, 'thread')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		# create new thread blocks, expand as new calls are found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		if not tgtdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 			if proc == '<...>':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 				threadname = 'kthread-%d' % (pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 				threadname = '%s-%d' % (proc, pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			tgtphase = self.sourcePhase(start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 			self.newAction(tgtphase, threadname, pid, '', start, end, '', ' kth', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 			return self.addDeviceFunctionCall(displayname, kprobename, proc, pid, start, end, cdata, rdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		# this should not happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		if not tgtdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 			sysvals.vprint('[%f - %f] %s-%d %s %s %s' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 				(start, end, proc, pid, kprobename, cdata, rdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 		# place the call data inside the src element of the tgtdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		if('src' not in tgtdev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 			tgtdev['src'] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		dtf = sysvals.dev_tracefuncs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		ubiquitous = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		if kprobename in dtf and 'ub' in dtf[kprobename]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 			ubiquitous = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		title = cdata+' '+rdata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		mstr = '\(.*\) *(?P<args>.*) *\((?P<caller>.*)\+.* arg1=(?P<ret>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		m = re.match(mstr, title)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			c = m.group('caller')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 			a = m.group('args').strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 			r = m.group('ret')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 			if len(r) > 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 				r = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 				r = 'ret=%s ' % r
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 			if ubiquitous and c in dtf and 'ub' in dtf[c]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 				return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		color = sysvals.kprobeColor(kprobename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		e = DevFunction(displayname, a, c, r, start, end, ubiquitous, proc, pid, color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		tgtdev['src'].append(e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	def overflowDevices(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		# get a list of devices that extend beyond the end of this test run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		devlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			for devname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 				dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 				if dev['end'] > self.end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 					devlist.append(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		return devlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	def mergeOverlapDevices(self, devlist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		# merge any devices that overlap devlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		for dev in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 			devname = dev['name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 				list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 				if devname not in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 				tdev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 				o = min(dev['end'], tdev['end']) - max(dev['start'], tdev['start'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 				if o <= 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 				dev['end'] = tdev['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 				if 'src' not in dev or 'src' not in tdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 				dev['src'] += tdev['src']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 				del list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	def usurpTouchingThread(self, name, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		# the caller test has priority of this thread, give it to him
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 			if name in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 				tdev = list[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 				if tdev['start'] - dev['end'] < 0.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 					dev['end'] = tdev['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 					if 'src' not in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 						dev['src'] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 					if 'src' in tdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 						dev['src'] += tdev['src']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 					del list[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	def stitchTouchingThreads(self, testlist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		# merge any threads between tests that touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 			for devname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 				dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 				if 'htmlclass' not in dev or 'kth' not in dev['htmlclass']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 				for data in testlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 					data.usurpTouchingThread(devname, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	def optimizeDevSrc(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		# merge any src call loops to reduce timeline size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			for dev in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 				if 'src' not in list[dev]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 				src = list[dev]['src']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 				p = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 				for e in sorted(src, key=lambda event: event.time):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 					if not p or not e.repeat(p):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 						p = e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 					# e is another iteration of p, move it into p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 					p.end = e.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 					p.length = p.end - p.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 					p.count += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 					src.remove(e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	def trimTimeVal(self, t, t0, dT, left):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		if left:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			if(t > t0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 				if(t - dT < t0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 					return t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 				return t - dT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 				return t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 			if(t < t0 + dT):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 				if(t > t0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 					return t0 + dT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 				return t + dT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 				return t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	def trimTime(self, t0, dT, left):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		self.tSuspended = self.trimTimeVal(self.tSuspended, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		self.tResumed = self.trimTimeVal(self.tResumed, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		self.start = self.trimTimeVal(self.start, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		self.tKernSus = self.trimTimeVal(self.tKernSus, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		self.tKernRes = self.trimTimeVal(self.tKernRes, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		self.end = self.trimTimeVal(self.end, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 			p = self.dmesg[phase]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 			p['start'] = self.trimTimeVal(p['start'], t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 			p['end'] = self.trimTimeVal(p['end'], t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 			list = p['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 			for name in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 				d = list[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 				d['start'] = self.trimTimeVal(d['start'], t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 				d['end'] = self.trimTimeVal(d['end'], t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 				d['length'] = d['end'] - d['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 				if('ftrace' in d):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 					cg = d['ftrace']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 					cg.start = self.trimTimeVal(cg.start, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 					cg.end = self.trimTimeVal(cg.end, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 					for line in cg.list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 						line.time = self.trimTimeVal(line.time, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 				if('src' in d):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 					for e in d['src']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 						e.time = self.trimTimeVal(e.time, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 						e.end = self.trimTimeVal(e.end, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 						e.length = e.end - e.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		for dir in ['suspend', 'resume']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 			list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			for e in self.errorinfo[dir]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 				type, tm, idx1, idx2 = e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 				tm = self.trimTimeVal(tm, t0, dT, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 				list.append((type, tm, idx1, idx2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 			self.errorinfo[dir] = list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	def trimFreezeTime(self, tZero):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		# trim out any standby or freeze clock time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 		lp = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 			if 'resume_machine' in phase and 'suspend_machine' in lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 				tS, tR = self.dmesg[lp]['end'], self.dmesg[phase]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 				tL = tR - tS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 				if tL > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 					left = True if tR > tZero else False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 					self.trimTime(tS, tL, left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 					if 'trying' in self.dmesg[lp] and self.dmesg[lp]['trying'] >= 0.001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 						tTry = round(self.dmesg[lp]['trying'] * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 						text = '%.0f (-%.0f waking)' % (tL * 1000, tTry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 						text = '%.0f' % (tL * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 					self.tLow.append(text)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			lp = phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	def getMemTime(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		if not self.hwstart or not self.hwend:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		stime = (self.tSuspended - self.start) * 1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		rtime = (self.end - self.tResumed) * 1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		hws = self.hwstart + timedelta(microseconds=stime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		hwr = self.hwend - timedelta(microseconds=rtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		self.tLow.append('%.0f'%((hwr - hws).total_seconds() * 1000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	def getTimeValues(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		sktime = (self.tSuspended - self.tKernSus) * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		rktime = (self.tKernRes - self.tResumed) * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		return (sktime, rktime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	def setPhase(self, phase, ktime, isbegin, order=-1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		if(isbegin):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 			# phase start over current phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 			if self.currphase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 				if 'resume_machine' not in self.currphase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 					sysvals.vprint('WARNING: phase %s failed to end' % self.currphase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 				self.dmesg[self.currphase]['end'] = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			phases = self.dmesg.keys()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 			color = self.phasedef[phase]['color']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 			count = len(phases) if order < 0 else order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 			# create unique name for every new phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			while phase in phases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 				phase += '*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			self.dmesg[phase] = {'list': dict(), 'start': -1.0, 'end': -1.0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 				'row': 0, 'color': color, 'order': count}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 			self.dmesg[phase]['start'] = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			self.currphase = phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			# phase end without a start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			if phase not in self.currphase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 				if self.currphase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 					sysvals.vprint('WARNING: %s ended instead of %s, ftrace corruption?' % (phase, self.currphase))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 					sysvals.vprint('WARNING: %s ended without a start, ftrace corruption?' % phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 					return phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			phase = self.currphase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 			self.dmesg[phase]['end'] = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 			self.currphase = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		return phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	def sortedDevices(self, phase):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 		return sorted(list, key=lambda k:list[k]['start'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	def fixupInitcalls(self, phase):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		# if any calls never returned, clip them at system resume end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		phaselist = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		for devname in phaselist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 			dev = phaselist[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 			if(dev['end'] < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 				for p in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 					if self.dmesg[p]['end'] > dev['start']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 						dev['end'] = self.dmesg[p]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 						break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 				sysvals.vprint('%s (%s): callback didnt return' % (devname, phase))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	def deviceFilter(self, devicefilter):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 			rmlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 			for name in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 				keep = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 				for filter in devicefilter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 					if filter in name or \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 						('drv' in list[name] and filter in list[name]['drv']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 						keep = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 				if not keep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 					rmlist.append(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 			for name in rmlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 				del list[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	def fixupInitcallsThatDidntReturn(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		# if any calls never returned, clip them at system resume end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 			self.fixupInitcalls(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	def phaseOverlap(self, phases):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 		rmgroups = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		newgroup = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		for group in self.devicegroups:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 			for phase in phases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 				if phase not in group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 				for p in group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 					if p not in newgroup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 						newgroup.append(p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 				if group not in rmgroups:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 					rmgroups.append(group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		for group in rmgroups:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			self.devicegroups.remove(group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		self.devicegroups.append(newgroup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	def newActionGlobal(self, name, start, end, pid=-1, color=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		# which phase is this device callback or action in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		phases = self.sortedPhases()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		targetphase = 'none'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		htmlclass = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		overlap = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		myphases = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 		for phase in phases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 			pstart = self.dmesg[phase]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			pend = self.dmesg[phase]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 			# see if the action overlaps this phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 			o = max(0, min(end, pend) - max(start, pstart))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 			if o > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 				myphases.append(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 			# set the target phase to the one that overlaps most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 			if o > overlap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 				if overlap > 0 and phase == 'post_resume':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 				targetphase = phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 				overlap = o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		# if no target phase was found, pin it to the edge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		if targetphase == 'none':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 			p0start = self.dmesg[phases[0]]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 			if start <= p0start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 				targetphase = phases[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 				targetphase = phases[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		if pid == -2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 			htmlclass = ' bg'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		elif pid == -3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 			htmlclass = ' ps'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		if len(myphases) > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 			htmlclass = ' bg'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 			self.phaseOverlap(myphases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 		if targetphase in phases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 			newname = self.newAction(targetphase, name, pid, '', start, end, '', htmlclass, color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 			return (targetphase, newname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	def newAction(self, phase, name, pid, parent, start, end, drv, htmlclass='', color=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 		# new device callback for a specific phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		self.html_device_id += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		devid = '%s%d' % (self.idstr, self.html_device_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		length = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 		if(start >= 0 and end >= 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 			length = end - start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		if pid == -2 or name not in sysvals.tracefuncs.keys():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 			i = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 			origname = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 			while(name in list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 				name = '%s[%d]' % (origname, i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 				i += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		list[name] = {'name': name, 'start': start, 'end': end, 'pid': pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 			'par': parent, 'length': length, 'row': 0, 'id': devid, 'drv': drv }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		if htmlclass:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 			list[name]['htmlclass'] = htmlclass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 		if color:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 			list[name]['color'] = color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		return name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	def findDevice(self, phase, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		mydev = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		for devname in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 			if name == devname or re.match('^%s\[(?P<num>[0-9]*)\]$' % name, devname):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 				mydev = devname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		if mydev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 			return list[mydev]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	def deviceChildren(self, devname, phase):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		devlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		for child in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 			if(list[child]['par'] == devname):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 				devlist.append(child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 		return devlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	def maxDeviceNameSize(self, phase):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 		size = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		for name in self.dmesg[phase]['list']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 			if len(name) > size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 				size = len(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		return size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	def printDetails(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 		sysvals.vprint('Timeline Details:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 		sysvals.vprint('          test start: %f' % self.start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 		sysvals.vprint('kernel suspend start: %f' % self.tKernSus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		tS = tR = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 			devlist = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 			dc, ps, pe = len(devlist), self.dmesg[phase]['start'], self.dmesg[phase]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 			if not tS and ps >= self.tSuspended:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 				sysvals.vprint('   machine suspended: %f' % self.tSuspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 				tS = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 			if not tR and ps >= self.tResumed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 				sysvals.vprint('     machine resumed: %f' % self.tResumed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 				tR = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 			sysvals.vprint('%20s: %f - %f (%d devices)' % (phase, ps, pe, dc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 			if sysvals.devdump:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 				sysvals.vprint(''.join('-' for i in range(80)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 				maxname = '%d' % self.maxDeviceNameSize(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 				fmt = '%3d) %'+maxname+'s - %f - %f'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 				c = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 				for name in sorted(devlist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 					s = devlist[name]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 					e = devlist[name]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 					sysvals.vprint(fmt % (c, name, s, e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 					c += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 				sysvals.vprint(''.join('-' for i in range(80)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		sysvals.vprint('   kernel resume end: %f' % self.tKernRes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 		sysvals.vprint('            test end: %f' % self.end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	def deviceChildrenAllPhases(self, devname):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		devlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 			list = self.deviceChildren(devname, phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 			for dev in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 				if dev not in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 					devlist.append(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		return devlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	def masterTopology(self, name, list, depth):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 		node = DeviceNode(name, depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		for cname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			# avoid recursions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 			if name == cname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 			clist = self.deviceChildrenAllPhases(cname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 			cnode = self.masterTopology(cname, clist, depth+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			node.children.append(cnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 		return node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	def printTopology(self, node):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		html = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		if node.name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 			info = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 			drv = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 			for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 				list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 				if node.name in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 					s = list[node.name]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 					e = list[node.name]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 					if list[node.name]['drv']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 						drv = ' {'+list[node.name]['drv']+'}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 					info += ('<li>%s: %.3fms</li>' % (phase, (e-s)*1000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 			html += '<li><b>'+node.name+drv+'</b>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 			if info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 				html += '<ul>'+info+'</ul>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 			html += '</li>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 		if len(node.children) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 			html += '<ul>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 			for cnode in node.children:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 				html += self.printTopology(cnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 			html += '</ul>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		return html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	def rootDeviceList(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 		# list of devices graphed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 		real = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 			for dev in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 				if list[dev]['pid'] >= 0 and dev not in real:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 					real.append(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		# list of top-most root devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		rootlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		for phase in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 			for dev in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 				pdev = list[dev]['par']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 				pid = list[dev]['pid']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 				if(pid < 0 or re.match('[0-9]*-[0-9]*\.[0-9]*[\.0-9]*\:[\.0-9]*$', pdev)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 				if pdev and pdev not in real and pdev not in rootlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 					rootlist.append(pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		return rootlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	def deviceTopology(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 		rootlist = self.rootDeviceList()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		master = self.masterTopology('', rootlist, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		return self.printTopology(master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	def selectTimelineDevices(self, widfmt, tTotal, mindevlen):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 		# only select devices that will actually show up in html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		self.tdevlist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		for phase in self.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 			devlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 			list = self.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 			for dev in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 				length = (list[dev]['end'] - list[dev]['start']) * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 				width = widfmt % (((list[dev]['end']-list[dev]['start'])*100)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 				if width != '0.000000' and length >= mindevlen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 					devlist.append(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 			self.tdevlist[phase] = devlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	def addHorizontalDivider(self, devname, devend):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 		phase = 'suspend_prepare'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 		self.newAction(phase, devname, -2, '', \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 			self.start, devend, '', ' sec', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		if phase not in self.tdevlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 			self.tdevlist[phase] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		self.tdevlist[phase].append(devname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		d = DevItem(0, phase, self.dmesg[phase]['list'][devname])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		return d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	def addProcessUsageEvent(self, name, times):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		# get the start and end times for this process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		maxC = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		tlast = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		start = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		end = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		for t in sorted(times):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 			if tlast == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 				tlast = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 			if name in self.pstl[t]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 				if start == -1 or tlast < start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 					start = tlast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 				if end == -1 or t > end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 					end = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 			tlast = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		if start == -1 or end == -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 			return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		# add a new action for this process and get the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		out = self.newActionGlobal(name, start, end, -3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 		if not out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 			return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		phase, devname = out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		dev = self.dmesg[phase]['list'][devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		# get the cpu exec data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 		tlast = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 		clast = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		cpuexec = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		for t in sorted(times):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			if tlast == 0 or t <= start or t > end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 				tlast = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 			list = self.pstl[t]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 			c = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 			if name in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 				c = list[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 			if c > maxC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 				maxC = c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 			if c != clast:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 				key = (tlast, t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 				cpuexec[key] = c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 				tlast = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 				clast = c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		dev['cpuexec'] = cpuexec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		return maxC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	def createProcessUsageEvents(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 		# get an array of process names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 		proclist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 		for t in sorted(self.pstl):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 			pslist = self.pstl[t]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 			for ps in sorted(pslist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 				if ps not in proclist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 					proclist.append(ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		# get a list of data points for suspend and resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 		tsus = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		tres = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		for t in sorted(self.pstl):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 			if t < self.tSuspended:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 				tsus.append(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 				tres.append(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 		# process the events for suspend and resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 		if len(proclist) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 			sysvals.vprint('Process Execution:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		for ps in proclist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 			c = self.addProcessUsageEvent(ps, tsus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 			if c > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 				sysvals.vprint('%25s (sus): %d' % (ps, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 			c = self.addProcessUsageEvent(ps, tres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 			if c > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 				sysvals.vprint('%25s (res): %d' % (ps, c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	def handleEndMarker(self, time, msg=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 		dm = self.dmesg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 		self.setEnd(time, msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		self.initDevicegroups()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 		# give suspend_prepare an end if needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		if 'suspend_prepare' in dm and dm['suspend_prepare']['end'] < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 			dm['suspend_prepare']['end'] = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 		# assume resume machine ends at next phase start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 		if 'resume_machine' in dm and dm['resume_machine']['end'] < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 			np = self.nextPhase('resume_machine', 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 			if np:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 				dm['resume_machine']['end'] = dm[np]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		# if kernel resume end not found, assume its the end marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		if self.tKernRes == 0.0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 			self.tKernRes = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 		# if kernel suspend start not found, assume its the end marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		if self.tKernSus == 0.0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 			self.tKernSus = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		# set resume complete to end at end marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		if 'resume_complete' in dm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 			dm['resume_complete']['end'] = time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	def debugPrint(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 		for p in self.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 			list = self.dmesg[p]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 			for devname in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 				dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 				if 'ftrace' in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 					dev['ftrace'].debugPrint(' [%s]' % devname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) # Class: DevFunction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) #	 A container for kprobe function data we want in the dev timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) class DevFunction:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	def __init__(self, name, args, caller, ret, start, end, u, proc, pid, color):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		self.row = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		self.count = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		self.name = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		self.args = args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		self.caller = caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 		self.ret = ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		self.time = start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		self.length = end - start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		self.end = end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		self.ubiquitous = u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		self.proc = proc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		self.pid = pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		self.color = color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	def title(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		cnt = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		if self.count > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 			cnt = '(x%d)' % self.count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		l = '%0.3fms' % (self.length * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		if self.ubiquitous:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 			title = '%s(%s)%s <- %s, %s(%s)' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 				(self.name, self.args, cnt, self.caller, self.ret, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 			title = '%s(%s) %s%s(%s)' % (self.name, self.args, self.ret, cnt, l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 		return title.replace('"', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	def text(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		if self.count > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 			text = '%s(x%d)' % (self.name, self.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 			text = self.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		return text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	def repeat(self, tgt):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		# is the tgt call just a repeat of this call (e.g. are we in a loop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 		dt = self.time - tgt.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		# only combine calls if -all- attributes are identical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 		if tgt.caller == self.caller and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 			tgt.name == self.name and tgt.args == self.args and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 			tgt.proc == self.proc and tgt.pid == self.pid and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 			tgt.ret == self.ret and dt >= 0 and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 			dt <= sysvals.callloopmaxgap and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 			self.length < sysvals.callloopmaxlen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) # Class: FTraceLine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) #	 A container for a single line of ftrace data. There are six basic types:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) #		 callgraph line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) #			  call: "  dpm_run_callback() {"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) #			return: "  }"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) #			  leaf: " dpm_run_callback();"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) #		 trace event:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) #			 tracing_mark_write: SUSPEND START or RESUME COMPLETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) #			 suspend_resume: phase or custom exec block data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) #			 device_pm_callback: device callback info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) class FTraceLine:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	def __init__(self, t, m='', d=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 		self.length = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		self.fcall = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		self.freturn = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		self.fevent = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		self.fkprobe = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 		self.depth = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 		self.name = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		self.type = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		self.time = float(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		if not m and not d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 		# is this a trace event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		if(d == 'traceevent' or re.match('^ *\/\* *(?P<msg>.*) \*\/ *$', m)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 			if(d == 'traceevent'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 				# nop format trace event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 				msg = m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 				# function_graph format trace event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 				em = re.match('^ *\/\* *(?P<msg>.*) \*\/ *$', m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 				msg = em.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 			emm = re.match('^(?P<call>.*?): (?P<msg>.*)', msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 			if(emm):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 				self.name = emm.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 				self.type = emm.group('call')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 				self.name = msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 			km = re.match('^(?P<n>.*)_cal$', self.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 			if km:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 				self.fcall = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 				self.fkprobe = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 				self.type = km.group('n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 				return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 			km = re.match('^(?P<n>.*)_ret$', self.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 			if km:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 				self.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 				self.fkprobe = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 				self.type = km.group('n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 				return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 			self.fevent = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		# convert the duration to seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		if(d):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 			self.length = float(d)/1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		# the indentation determines the depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		match = re.match('^(?P<d> *)(?P<o>.*)$', m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 		if(not match):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 		self.depth = self.getDepth(match.group('d'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		m = match.group('o')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		# function return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 		if(m[0] == '}'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 			self.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 			if(len(m) > 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 				# includes comment with function name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 				match = re.match('^} *\/\* *(?P<n>.*) *\*\/$', m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 				if(match):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 					self.name = match.group('n').strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 		# function call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 			self.fcall = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 			# function call with children
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 			if(m[-1] == '{'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 				match = re.match('^(?P<n>.*) *\(.*', m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 				if(match):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 					self.name = match.group('n').strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 			# function call with no children (leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 			elif(m[-1] == ';'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 				self.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 				match = re.match('^(?P<n>.*) *\(.*', m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 				if(match):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 					self.name = match.group('n').strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 			# something else (possibly a trace marker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 				self.name = m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	def isCall(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 		return self.fcall and not self.freturn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	def isReturn(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 		return self.freturn and not self.fcall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	def isLeaf(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		return self.fcall and self.freturn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	def getDepth(self, str):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		return len(str)/2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	def debugPrint(self, info=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		if self.isLeaf():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 			pprint(' -- %12.6f (depth=%02d): %s(); (%.3f us) %s' % (self.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 				self.depth, self.name, self.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		elif self.freturn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 			pprint(' -- %12.6f (depth=%02d): %s} (%.3f us) %s' % (self.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 				self.depth, self.name, self.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 			pprint(' -- %12.6f (depth=%02d): %s() { (%.3f us) %s' % (self.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 				self.depth, self.name, self.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	def startMarker(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		# Is this the starting line of a suspend?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		if not self.fevent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		if sysvals.usetracemarkers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			if(self.name.startswith('SUSPEND START')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 			if(self.type == 'suspend_resume' and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 				re.match('suspend_enter\[.*\] begin', self.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	def endMarker(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		# Is this the ending line of a resume?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 		if not self.fevent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		if sysvals.usetracemarkers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 			if(self.name.startswith('RESUME COMPLETE')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 			if(self.type == 'suspend_resume' and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 				re.match('thaw_processes\[.*\] end', self.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) # Class: FTraceCallGraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) #	 A container for the ftrace callgraph of a single recursive function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) #	 This can be a dpm_run_callback, dpm_prepare, or dpm_complete callgraph
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) #	 Each instance is tied to a single device in a single phase, and is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) #	 comprised of an ordered list of FTraceLine objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) class FTraceCallGraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	vfname = 'missing_function_name'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	def __init__(self, pid, sv):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		self.id = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		self.invalid = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 		self.name = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		self.partial = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		self.ignore = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 		self.start = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 		self.end = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 		self.list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		self.depth = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		self.pid = pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		self.sv = sv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	def addLine(self, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		# if this is already invalid, just leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 		if(self.invalid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 			if(line.depth == 0 and line.freturn):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 				return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 			return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 		# invalidate on bad depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		if(self.depth < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 			self.invalidate(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 			return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		# ignore data til we return to the current depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		if self.ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 			if line.depth > self.depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 				return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 				self.list[-1].freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 				self.list[-1].length = line.time - self.list[-1].time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 				self.ignore = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 				# if this is a return at self.depth, no more work is needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 				if line.depth == self.depth and line.isReturn():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 					if line.depth == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 						self.end = line.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 						return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 					return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 		# compare current depth with this lines pre-call depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		prelinedep = line.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		if line.isReturn():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 			prelinedep += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		last = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		lasttime = line.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		if len(self.list) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 			last = self.list[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 			lasttime = last.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 			if last.isLeaf():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 				lasttime += last.length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		# handle low misalignments by inserting returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		mismatch = prelinedep - self.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		warning = self.sv.verbose and abs(mismatch) > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		info = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		if mismatch < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 			idx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 			# add return calls to get the depth down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 			while prelinedep < self.depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 				self.depth -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 				if idx == 0 and last and last.isCall():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 					# special case, turn last call into a leaf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 					last.depth = self.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 					last.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 					last.length = line.time - last.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 					if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 						info.append(('[make leaf]', last))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 					vline = FTraceLine(lasttime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 					vline.depth = self.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 					vline.name = self.vfname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 					vline.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 					self.list.append(vline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 					if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 						if idx == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 							info.append(('', last))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 						info.append(('[add return]', vline))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 				idx += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 			if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 				info.append(('', line))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		# handle high misalignments by inserting calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 		elif mismatch > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 			idx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 			if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 				info.append(('', last))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 			# add calls to get the depth up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 			while prelinedep > self.depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 				if idx == 0 and line.isReturn():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 					# special case, turn this return into a leaf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 					line.fcall = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 					prelinedep -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 					if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 						info.append(('[make leaf]', line))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 					vline = FTraceLine(lasttime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 					vline.depth = self.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 					vline.name = self.vfname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 					vline.fcall = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 					self.list.append(vline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 					self.depth += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 					if not last:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 						self.start = vline.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 					if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 						info.append(('[add call]', vline))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 				idx += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 			if warning and ('[make leaf]', line) not in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 				info.append(('', line))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		if warning:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 			pprint('WARNING: ftrace data missing, corrections made:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 			for i in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 				t, obj = i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 				if obj:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 					obj.debugPrint(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 		# process the call and set the new depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		skipadd = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 		md = self.sv.max_graph_depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		if line.isCall():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 			# ignore blacklisted/overdepth funcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 			if (md and self.depth >= md - 1) or (line.name in self.sv.cgblacklist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 				self.ignore = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 				self.depth += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		elif line.isReturn():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 			self.depth -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 			# remove blacklisted/overdepth/empty funcs that slipped through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 			if (last and last.isCall() and last.depth == line.depth) or \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 				(md and last and last.depth >= md) or \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 				(line.name in self.sv.cgblacklist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 				while len(self.list) > 0 and self.list[-1].depth > line.depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 					self.list.pop(-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 				if len(self.list) == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 					self.invalid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 					return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 				self.list[-1].freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 				self.list[-1].length = line.time - self.list[-1].time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 				self.list[-1].name = line.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 				skipadd = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 		if len(self.list) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 			self.start = line.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 		# check for a mismatch that returned all the way to callgraph end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		res = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 		if mismatch < 0 and self.list[-1].depth == 0 and self.list[-1].freturn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 			line = self.list[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 			skipadd = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 			res = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		if not skipadd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			self.list.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 		if(line.depth == 0 and line.freturn):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 			if(self.start < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 				self.start = line.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 			self.end = line.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 			if line.fcall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 				self.end += line.length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 			if self.list[0].name == self.vfname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 				self.invalid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 			if res == -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 				self.partial = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 			return res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 		return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	def invalidate(self, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		if(len(self.list) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 			first = self.list[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 			self.list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 			self.list.append(first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 		self.invalid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 		id = 'task %s' % (self.pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 		window = '(%f - %f)' % (self.start, line.time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 		if(self.depth < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 			pprint('Data misalignment for '+id+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 				' (buffer overflow), ignoring this callback')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 			pprint('Too much data for '+id+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 				' '+window+', ignoring this callback')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	def slice(self, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 		minicg = FTraceCallGraph(dev['pid'], self.sv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 		minicg.name = self.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 		mydepth = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		good = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 		for l in self.list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 			if(l.time < dev['start'] or l.time > dev['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 			if mydepth < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 				if l.name == 'mutex_lock' and l.freturn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 					mydepth = l.depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 			elif l.depth == mydepth and l.name == 'mutex_unlock' and l.fcall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 				good = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 			l.depth -= mydepth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 			minicg.addLine(l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		if not good or len(minicg.list) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 			return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 		return minicg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	def repair(self, enddepth):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 		# bring the depth back to 0 with additional returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 		fixed = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 		last = self.list[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 		for i in reversed(range(enddepth)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 			t = FTraceLine(last.time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 			t.depth = i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 			t.freturn = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 			fixed = self.addLine(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 			if fixed != 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 				self.end = last.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 				return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	def postProcess(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 		if len(self.list) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 			self.name = self.list[0].name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		stack = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 		cnt = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 		last = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 		for l in self.list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 			# ftrace bug: reported duration is not reliable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 			# check each leaf and clip it at max possible length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 			if last and last.isLeaf():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 				if last.length > l.time - last.time:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 					last.length = l.time - last.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 			if l.isCall():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 				stack[l.depth] = l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 				cnt += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 			elif l.isReturn():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 				if(l.depth not in stack):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 					if self.sv.verbose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 						pprint('Post Process Error: Depth missing')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 						l.debugPrint()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 					return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 				# calculate call length from call/return lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 				cl = stack[l.depth]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 				cl.length = l.time - cl.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 				if cl.name == self.vfname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 					cl.name = l.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 				stack.pop(l.depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 				l.length = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 				cnt -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 			last = l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		if(cnt == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 			# trace caught the whole call tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 		elif(cnt < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 			if self.sv.verbose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 				pprint('Post Process Error: Depth is less than 0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		# trace ended before call tree finished
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 		return self.repair(cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	def deviceMatch(self, pid, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		found = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		# add the callgraph data to the device hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 		borderphase = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 			'dpm_prepare': 'suspend_prepare',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 			'dpm_complete': 'resume_complete'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 		if(self.name in borderphase):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			p = borderphase[self.name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 			list = data.dmesg[p]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 			for devname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 				dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 				if(pid == dev['pid'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 					self.start <= dev['start'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 					self.end >= dev['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 					cg = self.slice(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 					if cg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 						dev['ftrace'] = cg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 					found = devname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 			return found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		for p in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 			if(data.dmesg[p]['start'] <= self.start and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 				self.start <= data.dmesg[p]['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 				list = data.dmesg[p]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 				for devname in sorted(list, key=lambda k:list[k]['start']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 					dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 					if(pid == dev['pid'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 						self.start <= dev['start'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 						self.end >= dev['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 						dev['ftrace'] = self
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 						found = devname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 						break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		return found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	def newActionFromFunction(self, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 		name = self.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		if name in ['dpm_run_callback', 'dpm_prepare', 'dpm_complete']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		fs = self.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		fe = self.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 		if fs < data.start or fe > data.end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 		phase = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 		for p in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 			if(data.dmesg[p]['start'] <= self.start and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 				self.start < data.dmesg[p]['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 				phase = p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		if not phase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		out = data.newActionGlobal(name, fs, fe, -2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		if out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 			phase, myname = out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 			data.dmesg[phase]['list'][myname]['ftrace'] = self
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	def debugPrint(self, info=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 		pprint('%s pid=%d [%f - %f] %.3f us' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 			(self.name, self.pid, self.start, self.end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 			(self.end - self.start)*1000000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 		for l in self.list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 			if l.isLeaf():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 				pprint('%f (%02d): %s(); (%.3f us)%s' % (l.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 					l.depth, l.name, l.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 			elif l.freturn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 				pprint('%f (%02d): %s} (%.3f us)%s' % (l.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 					l.depth, l.name, l.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 				pprint('%f (%02d): %s() { (%.3f us)%s' % (l.time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 					l.depth, l.name, l.length*1000000, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 		pprint(' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) class DevItem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 	def __init__(self, test, phase, dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 		self.test = test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 		self.phase = phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		self.dev = dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	def isa(self, cls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		if 'htmlclass' in self.dev and cls in self.dev['htmlclass']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) # Class: Timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) #	 A container for a device timeline which calculates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) #	 all the html properties to display it correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) class Timeline:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	html_tblock = '<div id="block{0}" class="tblock" style="left:{1}%;width:{2}%;"><div class="tback" style="height:{3}px"></div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	html_device = '<div id="{0}" title="{1}" class="thread{7}" style="left:{2}%;top:{3}px;height:{4}px;width:{5}%;{8}">{6}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	html_phase = '<div class="phase" style="left:{0}%;width:{1}%;top:{2}px;height:{3}px;background:{4}">{5}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 	html_phaselet = '<div id="{0}" class="phaselet" style="left:{1}%;width:{2}%;background:{3}"></div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 	html_legend = '<div id="p{3}" class="square" style="left:{0}%;background:{1}">&nbsp;{2}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	def __init__(self, rowheight, scaleheight):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 		self.html = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		self.height = 0  # total timeline height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 		self.scaleH = scaleheight # timescale (top) row height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		self.rowH = rowheight     # device row height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 		self.bodyH = 0   # body height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 		self.rows = 0    # total timeline rows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 		self.rowlines = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 		self.rowheight = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	def createHeader(self, sv, stamp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 		if(not stamp['time']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		self.html += '<div class="version"><a href="https://01.org/pm-graph">%s v%s</a></div>' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 			% (sv.title, sv.version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		if sv.logmsg and sv.testlog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 			self.html += '<button id="showtest" class="logbtn btnfmt">log</button>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		if sv.dmesglog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 			self.html += '<button id="showdmesg" class="logbtn btnfmt">dmesg</button>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 		if sv.ftracelog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 			self.html += '<button id="showftrace" class="logbtn btnfmt">ftrace</button>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 		headline_stamp = '<div class="stamp">{0} {1} {2} {3}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 		self.html += headline_stamp.format(stamp['host'], stamp['kernel'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 			stamp['mode'], stamp['time'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 		if 'man' in stamp and 'plat' in stamp and 'cpu' in stamp and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 			stamp['man'] and stamp['plat'] and stamp['cpu']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 			headline_sysinfo = '<div class="stamp sysinfo">{0} {1} <i>with</i> {2}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 			self.html += headline_sysinfo.format(stamp['man'], stamp['plat'], stamp['cpu'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 	# Function: getDeviceRows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	# Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 	#    determine how may rows the device funcs will take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	# Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 	#	 rawlist: the list of devices/actions for a single phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	# Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	#	 The total number of rows needed to display this phase of the timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	def getDeviceRows(self, rawlist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		# clear all rows and set them to undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 		sortdict = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		for item in rawlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 			item.row = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 			sortdict[item] = item.length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 		sortlist = sorted(sortdict, key=sortdict.get, reverse=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		remaining = len(sortlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 		rowdata = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 		row = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 		# try to pack each row with as many ranges as possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		while(remaining > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 			if(row not in rowdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 				rowdata[row] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 			for i in sortlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 				if(i.row >= 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 				s = i.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 				e = i.time + i.length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 				valid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 				for ritem in rowdata[row]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 					rs = ritem.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 					re = ritem.time + ritem.length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 					if(not (((s <= rs) and (e <= rs)) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 						((s >= re) and (e >= re)))):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 						valid = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 						break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 				if(valid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 					rowdata[row].append(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 					i.row = row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 					remaining -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 			row += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		return row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 	# Function: getPhaseRows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	# Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	#	 Organize the timeline entries into the smallest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 	#	 number of rows possible, with no entry overlapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	# Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 	#	 devlist: the list of devices/actions in a group of contiguous phases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	# Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	#	 The total number of rows needed to display this phase of the timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 	def getPhaseRows(self, devlist, row=0, sortby='length'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 		# clear all rows and set them to undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		remaining = len(devlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		rowdata = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		sortdict = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		myphases = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 		# initialize all device rows to -1 and calculate devrows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 		for item in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 			dev = item.dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 			tp = (item.test, item.phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 			if tp not in myphases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 				myphases.append(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 			dev['row'] = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 			if sortby == 'start':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 				# sort by start 1st, then length 2nd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 				sortdict[item] = (-1*float(dev['start']), float(dev['end']) - float(dev['start']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 				# sort by length 1st, then name 2nd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 				sortdict[item] = (float(dev['end']) - float(dev['start']), item.dev['name'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 			if 'src' in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 				dev['devrows'] = self.getDeviceRows(dev['src'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 		# sort the devlist by length so that large items graph on top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 		sortlist = sorted(sortdict, key=sortdict.get, reverse=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		orderedlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 		for item in sortlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 			if item.dev['pid'] == -2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 				orderedlist.append(item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 		for item in sortlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 			if item not in orderedlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 				orderedlist.append(item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 		# try to pack each row with as many devices as possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 		while(remaining > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 			rowheight = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 			if(row not in rowdata):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 				rowdata[row] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 			for item in orderedlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 				dev = item.dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 				if(dev['row'] < 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 					s = dev['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 					e = dev['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 					valid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 					for ritem in rowdata[row]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 						rs = ritem.dev['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 						re = ritem.dev['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 						if(not (((s <= rs) and (e <= rs)) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 							((s >= re) and (e >= re)))):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 							valid = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 							break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 					if(valid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 						rowdata[row].append(item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 						dev['row'] = row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 						remaining -= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 						if 'devrows' in dev and dev['devrows'] > rowheight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 							rowheight = dev['devrows']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 			for t, p in myphases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 				if t not in self.rowlines or t not in self.rowheight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 					self.rowlines[t] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 					self.rowheight[t] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 				if p not in self.rowlines[t] or p not in self.rowheight[t]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 					self.rowlines[t][p] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 					self.rowheight[t][p] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 				rh = self.rowH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 				# section headers should use a different row height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 				if len(rowdata[row]) == 1 and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 					'htmlclass' in rowdata[row][0].dev and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 					'sec' in rowdata[row][0].dev['htmlclass']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 					rh = 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 				self.rowlines[t][p][row] = rowheight
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 				self.rowheight[t][p][row] = rowheight * rh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 			row += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		if(row > self.rows):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 			self.rows = int(row)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 		return row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	def phaseRowHeight(self, test, phase, row):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 		return self.rowheight[test][phase][row]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	def phaseRowTop(self, test, phase, row):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 		top = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 		for i in sorted(self.rowheight[test][phase]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 			if i >= row:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 			top += self.rowheight[test][phase][i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 		return top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	def calcTotalRows(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 		# Calculate the heights and offsets for the header and rows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 		maxrows = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 		standardphases = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		for t in self.rowlines:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 			for p in self.rowlines[t]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 				total = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 				for i in sorted(self.rowlines[t][p]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 					total += self.rowlines[t][p][i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 				if total > maxrows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 					maxrows = total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 				if total == len(self.rowlines[t][p]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 					standardphases.append((t, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		self.height = self.scaleH + (maxrows*self.rowH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 		self.bodyH = self.height - self.scaleH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 		# if there is 1 line per row, draw them the standard way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 		for t, p in standardphases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 			for i in sorted(self.rowheight[t][p]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 				self.rowheight[t][p][i] = float(self.bodyH)/len(self.rowlines[t][p])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	def createZoomBox(self, mode='command', testcount=1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		# Create bounding box, add buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 		html_zoombox = '<center><button id="zoomin">ZOOM IN +</button><button id="zoomout">ZOOM OUT -</button><button id="zoomdef">ZOOM 1:1</button></center>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		html_timeline = '<div id="dmesgzoombox" class="zoombox">\n<div id="{0}" class="timeline" style="height:{1}px">\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 		html_devlist1 = '<button id="devlist1" class="devlist" style="float:left;">Device Detail{0}</button>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		html_devlist2 = '<button id="devlist2" class="devlist" style="float:right;">Device Detail2</button>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 		if mode != 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 			if testcount > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 				self.html += html_devlist2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 				self.html += html_devlist1.format('1')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 				self.html += html_devlist1.format('')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 		self.html += html_zoombox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 		self.html += html_timeline.format('dmesg', self.height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	# Function: createTimeScale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	# Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	#	 Create the timescale for a timeline block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	# Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	#	 m0: start time (mode begin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	#	 mMax: end time (mode end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 	#	 tTotal: total timeline time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	#	 mode: suspend or resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	# Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	#	 The html code needed to display the time scale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 	def createTimeScale(self, m0, mMax, tTotal, mode):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 		timescale = '<div class="t" style="right:{0}%">{1}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		rline = '<div class="t" style="left:0;border-left:1px solid black;border-right:0;">{0}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		output = '<div class="timescale">\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 		# set scale for timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 		mTotal = mMax - m0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 		tS = 0.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 		if(tTotal <= 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 			return output+'</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 		if(tTotal > 4):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 			tS = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 		divTotal = int(mTotal/tS) + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 		divEdge = (mTotal - tS*(divTotal-1))*100/mTotal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 		for i in range(divTotal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 			htmlline = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 			if(mode == 'suspend'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 				pos = '%0.3f' % (100 - ((float(i)*tS*100)/mTotal) - divEdge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 				val = '%0.fms' % (float(i-divTotal+1)*tS*1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 				if(i == divTotal - 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 					val = mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 				htmlline = timescale.format(pos, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 				pos = '%0.3f' % (100 - ((float(i)*tS*100)/mTotal))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 				val = '%0.fms' % (float(i)*tS*1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 				htmlline = timescale.format(pos, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 				if(i == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 					htmlline = rline.format(mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 			output += htmlline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 		self.html += output+'</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) # Class: TestProps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) #	 A list of values describing the properties of these test runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) class TestProps:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	stampfmt = '# [a-z]*-(?P<m>[0-9]{2})(?P<d>[0-9]{2})(?P<y>[0-9]{2})-'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 				'(?P<H>[0-9]{2})(?P<M>[0-9]{2})(?P<S>[0-9]{2})'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 				' (?P<host>.*) (?P<mode>.*) (?P<kernel>.*)$'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	wififmt    = '^# wifi *(?P<d>\S*) *(?P<s>\S*) *(?P<t>[0-9\.]+).*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 	tstatfmt   = '^# turbostat (?P<t>\S*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	testerrfmt = '^# enter_sleep_error (?P<e>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 	sysinfofmt = '^# sysinfo .*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	cmdlinefmt = '^# command \| (?P<cmd>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	kparamsfmt = '^# kparams \| (?P<kp>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	devpropfmt = '# Device Properties: .*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	pinfofmt   = '# platform-(?P<val>[a-z,A-Z,0-9]*): (?P<info>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	tracertypefmt = '# tracer: (?P<t>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	firmwarefmt = '# fwsuspend (?P<s>[0-9]*) fwresume (?P<r>[0-9]*)$'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 	procexecfmt = 'ps - (?P<ps>.*)$'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	ftrace_line_fmt_fg = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 		'^ *(?P<time>[0-9\.]*) *\| *(?P<cpu>[0-9]*)\)'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 		' *(?P<proc>.*)-(?P<pid>[0-9]*) *\|'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 		'[ +!#\*@$]*(?P<dur>[0-9\.]*) .*\|  (?P<msg>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	ftrace_line_fmt_nop = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 		' *(?P<proc>.*)-(?P<pid>[0-9]*) *\[(?P<cpu>[0-9]*)\] *'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 		'(?P<flags>\S*) *(?P<time>[0-9\.]*): *'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 		'(?P<msg>.*)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	machinesuspend = 'machine_suspend\[.*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 		self.stamp = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 		self.sysinfo = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 		self.cmdline = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 		self.testerror = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		self.turbostat = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 		self.wifi = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 		self.fwdata = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 		self.ftrace_line_fmt = self.ftrace_line_fmt_nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 		self.cgformat = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 		self.data = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 		self.ktemp = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	def setTracerType(self, tracer):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 		if(tracer == 'function_graph'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 			self.cgformat = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 			self.ftrace_line_fmt = self.ftrace_line_fmt_fg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 		elif(tracer == 'nop'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 			self.ftrace_line_fmt = self.ftrace_line_fmt_nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 			doError('Invalid tracer format: [%s]' % tracer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	def stampInfo(self, line, sv):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 		if re.match(self.stampfmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 			self.stamp = line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 		elif re.match(self.sysinfofmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 			self.sysinfo = line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 		elif re.match(self.tstatfmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 			self.turbostat.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 		elif re.match(self.wififmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 			self.wifi.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 		elif re.match(self.testerrfmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 			self.testerror.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 		elif re.match(self.firmwarefmt, line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 			self.fwdata.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 		elif(re.match(self.devpropfmt, line)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 			self.parseDevprops(line, sv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 		elif(re.match(self.pinfofmt, line)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 			self.parsePlatformInfo(line, sv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 		m = re.match(self.cmdlinefmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 		if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 			self.cmdline = m.group('cmd')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 		m = re.match(self.tracertypefmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 			self.setTracerType(m.group('t'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 			return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 	def parseStamp(self, data, sv):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 		# global test data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 		m = re.match(self.stampfmt, self.stamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 		if not self.stamp or not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 			doError('data does not include the expected stamp')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 		data.stamp = {'time': '', 'host': '', 'mode': ''}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 		dt = datetime(int(m.group('y'))+2000, int(m.group('m')),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 			int(m.group('d')), int(m.group('H')), int(m.group('M')),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 			int(m.group('S')))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		data.stamp['time'] = dt.strftime('%B %d %Y, %I:%M:%S %p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 		data.stamp['host'] = m.group('host')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 		data.stamp['mode'] = m.group('mode')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		data.stamp['kernel'] = m.group('kernel')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 		if re.match(self.sysinfofmt, self.sysinfo):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 			for f in self.sysinfo.split('|'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 				if '#' in f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 				tmp = f.strip().split(':', 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 				key = tmp[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 				val = tmp[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 				data.stamp[key] = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 		sv.hostname = data.stamp['host']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		sv.suspendmode = data.stamp['mode']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		if sv.suspendmode == 'freeze':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 			self.machinesuspend = 'timekeeping_freeze\[.*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 			self.machinesuspend = 'machine_suspend\[.*'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		if sv.suspendmode == 'command' and sv.ftracefile != '':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 			modes = ['on', 'freeze', 'standby', 'mem', 'disk']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 			fp = sv.openlog(sv.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 			for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 				m = re.match('.* machine_suspend\[(?P<mode>.*)\]', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 				if m and m.group('mode') in ['1', '2', '3', '4']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 					sv.suspendmode = modes[int(m.group('mode'))]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 					data.stamp['mode'] = sv.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 					break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 			fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 		sv.cmdline = self.cmdline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 		if not sv.stamp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 			sv.stamp = data.stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 		# firmware data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		if sv.suspendmode == 'mem' and len(self.fwdata) > data.testnumber:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 			m = re.match(self.firmwarefmt, self.fwdata[data.testnumber])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 				data.fwSuspend, data.fwResume = int(m.group('s')), int(m.group('r'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 				if(data.fwSuspend > 0 or data.fwResume > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 					data.fwValid = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 		# turbostat data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 		if len(self.turbostat) > data.testnumber:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 			m = re.match(self.tstatfmt, self.turbostat[data.testnumber])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 				data.turbostat = m.group('t')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 		# wifi data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 		if len(self.wifi) > data.testnumber:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 			m = re.match(self.wififmt, self.wifi[data.testnumber])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 				data.wifi = {'dev': m.group('d'), 'stat': m.group('s'),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 					'time': float(m.group('t'))}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 				data.stamp['wifi'] = m.group('d')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 		# sleep mode enter errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 		if len(self.testerror) > data.testnumber:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 			m = re.match(self.testerrfmt, self.testerror[data.testnumber])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 			if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 				data.enterfail = m.group('e')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 	def devprops(self, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 		props = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		devlist = data.split(';')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 		for dev in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 			f = dev.split(',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 			if len(f) < 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 			dev = f[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 			props[dev] = DevProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 			props[dev].altname = f[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 			if int(f[2]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 				props[dev].isasync = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 				props[dev].isasync = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 		return props
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 	def parseDevprops(self, line, sv):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		idx = line.index(': ') + 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 		if idx >= len(line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		props = self.devprops(line[idx:])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 		if sv.suspendmode == 'command' and 'testcommandstring' in props:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 			sv.testcommand = props['testcommandstring'].altname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 		sv.devprops = props
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 	def parsePlatformInfo(self, line, sv):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 		m = re.match(self.pinfofmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 		if not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 		name, info = m.group('val'), m.group('info')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 		if name == 'devinfo':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 			sv.devprops = self.devprops(sv.b64unzip(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 		elif name == 'testcmd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 			sv.testcommand = info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 		field = info.split('|')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		if len(field) < 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 		cmdline = field[0].strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 		output = sv.b64unzip(field[1].strip())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 		sv.platinfo.append([name, cmdline, output])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) # Class: TestRun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) #	 A container for a suspend/resume test run. This is necessary as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) #	 there could be more than one, and they need to be separate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) class TestRun:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	def __init__(self, dataobj):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 		self.data = dataobj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 		self.ftemp = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 		self.ttemp = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) class ProcessMonitor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 	def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 		self.proclist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 		self.running = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 	def procstat(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 		c = ['cat /proc/[1-9]*/stat 2>/dev/null']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 		process = Popen(c, shell=True, stdout=PIPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 		running = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 		for line in process.stdout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 			data = ascii(line).split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 			pid = data[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 			name = re.sub('[()]', '', data[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 			user = int(data[13])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 			kern = int(data[14])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 			kjiff = ujiff = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 			if pid not in self.proclist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 				self.proclist[pid] = {'name' : name, 'user' : user, 'kern' : kern}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 				val = self.proclist[pid]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 				ujiff = user - val['user']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 				kjiff = kern - val['kern']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 				val['user'] = user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 				val['kern'] = kern
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 			if ujiff > 0 or kjiff > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 				running[pid] = ujiff + kjiff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 		process.wait()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 		out = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 		for pid in running:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 			jiffies = running[pid]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 			val = self.proclist[pid]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 			if out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 				out += ','
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 			out += '%s-%s %d' % (val['name'], pid, jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 		return 'ps - '+out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	def processMonitor(self, tid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 		while self.running:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 			out = self.procstat()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 			if out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 				sysvals.fsetVal(out, 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	def start(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 		self.thread = Thread(target=self.processMonitor, args=(0,))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 		self.running = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 		self.thread.start()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	def stop(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		self.running = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) # ----------------- FUNCTIONS --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) # Function: doesTraceLogHaveTraceEvents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) #	 Quickly determine if the ftrace log has all of the trace events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) #	 markers, and/or kprobes required for primary parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) def doesTraceLogHaveTraceEvents():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 	kpcheck = ['_cal: (', '_ret: (']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 	techeck = ['suspend_resume', 'device_pm_callback']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	tmcheck = ['SUSPEND START', 'RESUME COMPLETE']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	sysvals.usekprobes = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 	fp = sysvals.openlog(sysvals.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 	for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 		# check for kprobes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 		if not sysvals.usekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 			for i in kpcheck:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 				if i in line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 					sysvals.usekprobes = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 		# check for all necessary trace events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 		check = techeck[:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 		for i in techeck:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 			if i in line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 				check.remove(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		techeck = check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 		# check for all necessary trace markers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 		check = tmcheck[:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 		for i in tmcheck:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 			if i in line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 				check.remove(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 		tmcheck = check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 	fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	sysvals.usetraceevents = True if len(techeck) < 2 else False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 	sysvals.usetracemarkers = True if len(tmcheck) == 0 else False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) # Function: appendIncompleteTraceLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) #	 [deprecated for kernel 3.15 or newer]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) #	 Adds callgraph data which lacks trace event data. This is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) #	 for timelines generated from 3.15 or older
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) #	 testruns: the array of Data objects obtained from parseKernelLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) def appendIncompleteTraceLog(testruns):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	# create TestRun vessels for ftrace parsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	testcnt = len(testruns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 	testidx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	testrun = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 		testrun.append(TestRun(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	# extract the callgraph and traceevent data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	sysvals.vprint('Analyzing the ftrace data (%s)...' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 		os.path.basename(sysvals.ftracefile))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 	tf = sysvals.openlog(sysvals.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	data = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 	for line in tf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 		# remove any latent carriage returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 		line = line.replace('\r\n', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 		if tp.stampInfo(line, sysvals):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 		# parse only valid lines, if this is not one move on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 		m = re.match(tp.ftrace_line_fmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 		if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 		# gather the basic message data from the line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 		m_time = m.group('time')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 		m_pid = m.group('pid')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 		m_msg = m.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 		if(tp.cgformat):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 			m_param3 = m.group('dur')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 			m_param3 = 'traceevent'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 		if(m_time and m_pid and m_msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 			t = FTraceLine(m_time, m_msg, m_param3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 			pid = int(m_pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 		# the line should be a call, return, or event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		if(not t.fcall and not t.freturn and not t.fevent):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 		# look for the suspend start marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 		if(t.startMarker()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 			data = testrun[testidx].data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 			tp.parseStamp(data, sysvals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 			data.setStart(t.time, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 		if(not data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 		# find the end of resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 		if(t.endMarker()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 			data.setEnd(t.time, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 			testidx += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 			if(testidx >= testcnt):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 		# trace event processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 		if(t.fevent):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 		# call/return processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 		elif sysvals.usecallgraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 			# create a callgraph object for the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 			if(pid not in testrun[testidx].ftemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 				testrun[testidx].ftemp[pid] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 				testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid, sysvals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 			# when the call is finished, see which device matches it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 			cg = testrun[testidx].ftemp[pid][-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 			res = cg.addLine(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 			if(res != 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 				testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid, sysvals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 			if(res == -1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 				testrun[testidx].ftemp[pid][-1].addLine(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	tf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 	for test in testrun:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 		# add the callgraph data to the device hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 		for pid in test.ftemp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 			for cg in test.ftemp[pid]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 				if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 				if(not cg.postProcess()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 					id = 'task %s cpu %s' % (pid, m.group('cpu'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 					sysvals.vprint('Sanity check failed for '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 						id+', ignoring this callback')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 				callstart = cg.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 				callend = cg.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 				for p in test.data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 					if(test.data.dmesg[p]['start'] <= callstart and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 						callstart <= test.data.dmesg[p]['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 						list = test.data.dmesg[p]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 						for devname in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 							dev = list[devname]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 							if(pid == dev['pid'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 								callstart <= dev['start'] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 								callend >= dev['end']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 								dev['ftrace'] = cg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 						break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) # Function: parseTraceLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) #	 Analyze an ftrace log output file generated from this app during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) #	 the execution phase. Used when the ftrace log is the primary data source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) #	 and includes the suspend_resume and device_pm_callback trace events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) #	 The ftrace filename is taken from sysvals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) #	 An array of Data objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) def parseTraceLog(live=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 	sysvals.vprint('Analyzing the ftrace data (%s)...' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 		os.path.basename(sysvals.ftracefile))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	if(os.path.exists(sysvals.ftracefile) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 		doError('%s does not exist' % sysvals.ftracefile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 	if not live:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 		sysvals.setupAllKprobes()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 	ksuscalls = ['ksys_sync', 'pm_prepare_console']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	krescalls = ['pm_restore_console']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	tracewatch = ['irq_wakeup']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	if sysvals.usekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 		tracewatch += ['sync_filesystems', 'freeze_processes', 'syscore_suspend',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 			'syscore_resume', 'resume_console', 'thaw_processes', 'CPU_ON',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 			'CPU_OFF', 'acpi_suspend']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 	# extract the callgraph and traceevent data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 	s2idle_enter = hwsus = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 	testruns, testdata = [], []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 	testrun, data, limbo = 0, 0, True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 	tf = sysvals.openlog(sysvals.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	phase = 'suspend_prepare'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 	for line in tf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 		# remove any latent carriage returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 		line = line.replace('\r\n', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 		if tp.stampInfo(line, sysvals):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 		# ignore all other commented lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 		if line[0] == '#':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 		# ftrace line: parse only valid lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 		m = re.match(tp.ftrace_line_fmt, line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 		if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 		# gather the basic message data from the line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 		m_time = m.group('time')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 		m_proc = m.group('proc')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 		m_pid = m.group('pid')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 		m_msg = m.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 		if(tp.cgformat):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 			m_param3 = m.group('dur')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 			m_param3 = 'traceevent'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 		if(m_time and m_pid and m_msg):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 			t = FTraceLine(m_time, m_msg, m_param3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 			pid = int(m_pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 		# the line should be a call, return, or event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 		if(not t.fcall and not t.freturn and not t.fevent):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 		# find the start of suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 		if(t.startMarker()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 			data, limbo = Data(len(testdata)), False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 			testdata.append(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 			testrun = TestRun(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 			testruns.append(testrun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 			tp.parseStamp(data, sysvals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 			data.setStart(t.time, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 			data.first_suspend_prepare = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 			phase = data.setPhase('suspend_prepare', t.time, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 		if(not data or limbo):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 		# process cpu exec line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 		if t.type == 'tracing_mark_write':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 			m = re.match(tp.procexecfmt, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 			if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 				proclist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 				for ps in m.group('ps').split(','):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 					val = ps.split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 					if not val:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 					name = val[0].replace('--', '-')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 					proclist[name] = int(val[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 				data.pstl[t.time] = proclist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 		# find the end of resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 		if(t.endMarker()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 			if data.tKernRes == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 				data.tKernRes = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 			data.handleEndMarker(t.time, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 			if(not sysvals.usetracemarkers):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 				# no trace markers? then quit and be sure to finish recording
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 				# the event we used to trigger resume end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 				if('thaw_processes' in testrun.ttemp and len(testrun.ttemp['thaw_processes']) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 					# if an entry exists, assume this is its end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 					testrun.ttemp['thaw_processes'][-1]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 			limbo = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 		# trace event processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 		if(t.fevent):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 			if(t.type == 'suspend_resume'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 				# suspend_resume trace events have two types, begin and end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 				if(re.match('(?P<name>.*) begin$', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 					isbegin = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 				elif(re.match('(?P<name>.*) end$', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 					isbegin = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 				if '[' in t.name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 					m = re.match('(?P<name>.*)\[.*', t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 					m = re.match('(?P<name>.*) .*', t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 				name = m.group('name')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 				# ignore these events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 				if(name.split('[')[0] in tracewatch):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 				# -- phase changes --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 				# start of kernel suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 				if(re.match('suspend_enter\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 					if(isbegin and data.tKernSus == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 						data.tKernSus = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 				# suspend_prepare start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 				elif(re.match('dpm_prepare\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 					if isbegin and data.first_suspend_prepare:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 						data.first_suspend_prepare = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 						if data.tKernSus == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 							data.tKernSus = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 					phase = data.setPhase('suspend_prepare', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 				# suspend start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 				elif(re.match('dpm_suspend\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 					phase = data.setPhase('suspend', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 				# suspend_late start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 				elif(re.match('dpm_suspend_late\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 					phase = data.setPhase('suspend_late', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 				# suspend_noirq start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 				elif(re.match('dpm_suspend_noirq\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 					phase = data.setPhase('suspend_noirq', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 				# suspend_machine/resume_machine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 				elif(re.match(tp.machinesuspend, t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 					lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 					if(isbegin):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 						hwsus = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 						if lp.startswith('resume_machine'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 							# trim out s2idle loops, track time trying to freeze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 							llp = data.lastPhase(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 							if llp.startswith('suspend_machine'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 								if 'trying' not in data.dmesg[llp]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 									data.dmesg[llp]['trying'] = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 								data.dmesg[llp]['trying'] += \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 									t.time - data.dmesg[lp]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 							data.currphase = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 							del data.dmesg[lp]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 							continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 						phase = data.setPhase('suspend_machine', data.dmesg[lp]['end'], True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 						data.setPhase(phase, t.time, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 						if data.tSuspended == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 							data.tSuspended = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 						if lp.startswith('resume_machine'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 							data.dmesg[lp]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 							continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 						phase = data.setPhase('resume_machine', t.time, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 						if(sysvals.suspendmode in ['mem', 'disk']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 							susp = phase.replace('resume', 'suspend')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 							if susp in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 								data.dmesg[susp]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 							data.tSuspended = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 						data.tResumed = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 				# resume_noirq start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 				elif(re.match('dpm_resume_noirq\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 					phase = data.setPhase('resume_noirq', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 				# resume_early start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 				elif(re.match('dpm_resume_early\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 					phase = data.setPhase('resume_early', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 				# resume start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 				elif(re.match('dpm_resume\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 					phase = data.setPhase('resume', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 				# resume complete start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 				elif(re.match('dpm_complete\[.*', t.name)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 					phase = data.setPhase('resume_complete', t.time, isbegin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 				# skip trace events inside devices calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 				if(not data.isTraceEventOutsideDeviceCalls(pid, t.time)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 				# global events (outside device calls) are graphed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 				if(name not in testrun.ttemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 					testrun.ttemp[name] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 				# special handling for s2idle_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 				if name == 'machine_suspend':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 					if hwsus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 						s2idle_enter = hwsus = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 					elif s2idle_enter and not isbegin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 						if(len(testrun.ttemp[name]) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 							testrun.ttemp[name][-1]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 							testrun.ttemp[name][-1]['loop'] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 					elif not s2idle_enter and isbegin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 						s2idle_enter = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 						testrun.ttemp[name].append({'begin': t.time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 							'end': t.time, 'pid': pid, 'loop': 0})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 				if(isbegin):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 					# create a new list entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 					testrun.ttemp[name].append(\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 						{'begin': t.time, 'end': t.time, 'pid': pid})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 					if(len(testrun.ttemp[name]) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 						# if an entry exists, assume this is its end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 						testrun.ttemp[name][-1]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 			# device callback start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 			elif(t.type == 'device_pm_callback_start'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 				if phase not in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 				m = re.match('(?P<drv>.*) (?P<d>.*), parent: *(?P<p>.*), .*',\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 					t.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 				if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 				drv = m.group('drv')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 				n = m.group('d')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 				p = m.group('p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 				if(n and p):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 					data.newAction(phase, n, pid, p, t.time, -1, drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 					if pid not in data.devpids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 						data.devpids.append(pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 			# device callback finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 			elif(t.type == 'device_pm_callback_end'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 				if phase not in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 				m = re.match('(?P<drv>.*) (?P<d>.*), err.*', t.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 				if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 				n = m.group('d')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 				dev = data.findDevice(phase, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 				if dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 					dev['length'] = t.time - dev['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 					dev['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 		# kprobe event processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 		elif(t.fkprobe):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 			kprobename = t.type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 			kprobedata = t.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 			key = (kprobename, pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 			# displayname is generated from kprobe data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 			displayname = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 			if(t.fcall):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 				displayname = sysvals.kprobeDisplayName(kprobename, kprobedata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 				if not displayname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 				if(key not in tp.ktemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 					tp.ktemp[key] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 				tp.ktemp[key].append({
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 					'pid': pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 					'begin': t.time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 					'end': -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 					'name': displayname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 					'cdata': kprobedata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 					'proc': m_proc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 				})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 				# start of kernel resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 				if(data.tKernSus == 0 and phase == 'suspend_prepare' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 					and kprobename in ksuscalls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 					data.tKernSus = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 			elif(t.freturn):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 				if(key not in tp.ktemp) or len(tp.ktemp[key]) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 				e = next((x for x in reversed(tp.ktemp[key]) if x['end'] < 0), 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 				if not e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 				e['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 				e['rdata'] = kprobedata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 				# end of kernel resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 				if(phase != 'suspend_prepare' and kprobename in krescalls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 					if phase in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 						data.dmesg[phase]['end'] = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 					data.tKernRes = t.time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 		# callgraph processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 		elif sysvals.usecallgraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 			# create a callgraph object for the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 			key = (m_proc, pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 			if(key not in testrun.ftemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 				testrun.ftemp[key] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 				testrun.ftemp[key].append(FTraceCallGraph(pid, sysvals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 			# when the call is finished, see which device matches it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 			cg = testrun.ftemp[key][-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 			res = cg.addLine(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 			if(res != 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 				testrun.ftemp[key].append(FTraceCallGraph(pid, sysvals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 			if(res == -1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 				testrun.ftemp[key][-1].addLine(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	tf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 	if len(testdata) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 		sysvals.vprint('WARNING: ftrace start marker is missing')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 	if data and not data.devicegroups:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 		sysvals.vprint('WARNING: ftrace end marker is missing')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 		data.handleEndMarker(t.time, t.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 	if sysvals.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 		for test in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 			for p in test.data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 				if p == 'suspend_prepare':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 					test.data.dmesg[p]['start'] = test.data.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 					test.data.dmesg[p]['end'] = test.data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 					test.data.dmesg[p]['start'] = test.data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 					test.data.dmesg[p]['end'] = test.data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 			test.data.tSuspended = test.data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 			test.data.tResumed = test.data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 			test.data.fwValid = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 	# dev source and procmon events can be unreadable with mixed phase height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 	if sysvals.usedevsrc or sysvals.useprocmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 		sysvals.mixedphaseheight = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	# expand phase boundaries so there are no gaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 	for data in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		lp = data.sortedPhases()[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 		for p in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 			if(p != lp and not ('machine' in p and 'machine' in lp)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 				data.dmesg[lp]['end'] = data.dmesg[p]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 			lp = p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 	for i in range(len(testruns)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 		test = testruns[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		data = test.data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 		# find the total time range for this test (begin, end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 		tlb, tle = data.start, data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 		if i < len(testruns) - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 			tle = testruns[i+1].data.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 		# add the process usage data to the timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		if sysvals.useprocmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 			data.createProcessUsageEvents()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 		# add the traceevent data to the device hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 		if(sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 			# add actual trace funcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 			for name in sorted(test.ttemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 				for event in test.ttemp[name]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 					if event['end'] - event['begin'] <= 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 					title = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 					if name == 'machine_suspend' and 'loop' in event:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 						title = 's2idle_enter_%dx' % event['loop']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 					data.newActionGlobal(title, event['begin'], event['end'], event['pid'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 			# add the kprobe based virtual tracefuncs as actual devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 			for key in sorted(tp.ktemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 				name, pid = key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 				if name not in sysvals.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 				if pid not in data.devpids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 					data.devpids.append(pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 				for e in tp.ktemp[key]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 					kb, ke = e['begin'], e['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 					if ke - kb < 0.000001 or tlb > kb or tle <= kb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 					color = sysvals.kprobeColor(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 					data.newActionGlobal(e['name'], kb, ke, pid, color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 			# add config base kprobes and dev kprobes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 			if sysvals.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 				for key in sorted(tp.ktemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 					name, pid = key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 					if name in sysvals.tracefuncs or name not in sysvals.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 					for e in tp.ktemp[key]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 						kb, ke = e['begin'], e['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 						if ke - kb < 0.000001 or tlb > kb or tle <= kb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 							continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 						data.addDeviceFunctionCall(e['name'], name, e['proc'], pid, kb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 							ke, e['cdata'], e['rdata'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 		if sysvals.usecallgraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 			# add the callgraph data to the device hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 			sortlist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 			for key in sorted(test.ftemp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 				proc, pid = key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 				for cg in test.ftemp[key]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 					if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 					if(not cg.postProcess()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 						id = 'task %s' % (pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 						sysvals.vprint('Sanity check failed for '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 							id+', ignoring this callback')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 					# match cg data to devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 					devname = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 					if sysvals.suspendmode != 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 						devname = cg.deviceMatch(pid, data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 					if not devname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 						sortkey = '%f%f%d' % (cg.start, cg.end, pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 						sortlist[sortkey] = cg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 					elif len(cg.list) > 1000000 and cg.name != sysvals.ftopfunc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 						sysvals.vprint('WARNING: the callgraph for %s is massive (%d lines)' %\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 							(devname, len(cg.list)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 			# create blocks for orphan cg data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 			for sortkey in sorted(sortlist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 				cg = sortlist[sortkey]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 				name = cg.name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 				if sysvals.isCallgraphFunc(name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 					sysvals.vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 					cg.newActionFromFunction(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 	if sysvals.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 		return (testdata, '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 	# fill in any missing phases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 	error = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 	for data in testdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 		tn = '' if len(testdata) == 1 else ('%d' % (data.testnumber + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 		terr = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 		phasedef = data.phasedef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 		lp = 'suspend_prepare'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 		for p in sorted(phasedef, key=lambda k:phasedef[k]['order']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 			if p not in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 				if not terr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 					ph = p if 'machine' in p else lp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 					terr = '%s%s failed in %s phase' % (sysvals.suspendmode, tn, ph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 					pprint('TEST%s FAILED: %s' % (tn, terr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 					error.append(terr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 					if data.tSuspended == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 						data.tSuspended = data.dmesg[lp]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 					if data.tResumed == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 						data.tResumed = data.dmesg[lp]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 					data.fwValid = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 				sysvals.vprint('WARNING: phase "%s" is missing!' % p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 			lp = p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 		if not terr and 'dev' in data.wifi and data.wifi['stat'] == 'timeout':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 			terr = '%s%s failed in wifi_resume <i>(%s %.0fs timeout)</i>' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 				(sysvals.suspendmode, tn, data.wifi['dev'], data.wifi['time'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 			error.append(terr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 		if not terr and data.enterfail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 			pprint('test%s FAILED: enter %s failed with %s' % (tn, sysvals.suspendmode, data.enterfail))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 			terr = 'test%s failed to enter %s mode' % (tn, sysvals.suspendmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 			error.append(terr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 		if data.tSuspended == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 			data.tSuspended = data.tKernRes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 		if data.tResumed == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 			data.tResumed = data.tSuspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 		if(len(sysvals.devicefilter) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 			data.deviceFilter(sysvals.devicefilter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 		data.fixupInitcallsThatDidntReturn()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 		if sysvals.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 			data.optimizeDevSrc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 	# x2: merge any overlapping devices between test runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 	if sysvals.usedevsrc and len(testdata) > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 		tc = len(testdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 		for i in range(tc - 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 			devlist = testdata[i].overflowDevices()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 			for j in range(i + 1, tc):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 				testdata[j].mergeOverlapDevices(devlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 		testdata[0].stitchTouchingThreads(testdata[1:])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 	return (testdata, ', '.join(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) # Function: loadKernelLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) #	 [deprecated for kernel 3.15.0 or newer]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) #	 load the dmesg file into memory and fix up any ordering issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) #	 The dmesg filename is taken from sysvals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) #	 An array of empty Data objects with only their dmesgtext attributes set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) def loadKernelLog():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 	sysvals.vprint('Analyzing the dmesg data (%s)...' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 		os.path.basename(sysvals.dmesgfile))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 	if(os.path.exists(sysvals.dmesgfile) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 		doError('%s does not exist' % sysvals.dmesgfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 	# there can be multiple test runs in a single file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 	tp = TestProps()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 	tp.stamp = datetime.now().strftime('# suspend-%m%d%y-%H%M%S localhost mem unknown')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 	testruns = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 	data = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 	lf = sysvals.openlog(sysvals.dmesgfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 	for line in lf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 		line = line.replace('\r\n', '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 		idx = line.find('[')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 		if idx > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 			line = line[idx:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 		if tp.stampInfo(line, sysvals):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 		m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 		if(not m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 		msg = m.group("msg")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 		if(re.match('PM: Syncing filesystems.*', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 			if(data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 				testruns.append(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 			data = Data(len(testruns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 			tp.parseStamp(data, sysvals)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 		if(not data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 		m = re.match('.* *(?P<k>[0-9]\.[0-9]{2}\.[0-9]-.*) .*', msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 		if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 			sysvals.stamp['kernel'] = m.group('k')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 		m = re.match('PM: Preparing system for (?P<m>.*) sleep', msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 		if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 			sysvals.stamp['mode'] = sysvals.suspendmode = m.group('m')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 		data.dmesgtext.append(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 	lf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	if data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 		testruns.append(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 	if len(testruns) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 		doError('dmesg log has no suspend/resume data: %s' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 			% sysvals.dmesgfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	# fix lines with same timestamp/function with the call and return swapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 		last = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 		for line in data.dmesgtext:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 			mc = re.match('.*(\[ *)(?P<t>[0-9\.]*)(\]) calling  '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 				'(?P<f>.*)\+ @ .*, parent: .*', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 			mr = re.match('.*(\[ *)(?P<t>[0-9\.]*)(\]) call '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 				'(?P<f>.*)\+ returned .* after (?P<dt>.*) usecs', last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 			if(mc and mr and (mc.group('t') == mr.group('t')) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 				(mc.group('f') == mr.group('f'))):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 				i = data.dmesgtext.index(last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 				j = data.dmesgtext.index(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 				data.dmesgtext[i] = line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 				data.dmesgtext[j] = last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 			last = line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 	return testruns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) # Function: parseKernelLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) #	 [deprecated for kernel 3.15.0 or newer]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) #	 Analyse a dmesg log output file generated from this app during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) #	 the execution phase. Create a set of device structures in memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) #	 for subsequent formatting in the html output file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) #	 This call is only for legacy support on kernels where the ftrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) #	 data lacks the suspend_resume or device_pm_callbacks trace events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) #	 data: an empty Data object (with dmesgtext) obtained from loadKernelLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) #	 The filled Data object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) def parseKernelLog(data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 	phase = 'suspend_runtime'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 	if(data.fwValid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 		sysvals.vprint('Firmware Suspend = %u ns, Firmware Resume = %u ns' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 			(data.fwSuspend, data.fwResume))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 	# dmesg phase match table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 	dm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 		'suspend_prepare': ['PM: Syncing filesystems.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		        'suspend': ['PM: Entering [a-z]* sleep.*', 'Suspending console.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 		   'suspend_late': ['PM: suspend of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 		  'suspend_noirq': ['PM: late suspend of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 		'suspend_machine': ['PM: noirq suspend of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 		 'resume_machine': ['ACPI: Low-level resume complete.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 		   'resume_noirq': ['ACPI: Waking up from system sleep state.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 		   'resume_early': ['PM: noirq resume of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 		         'resume': ['PM: early resume of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 		'resume_complete': ['PM: resume of devices complete after.*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 		    'post_resume': ['.*Restarting tasks \.\.\..*'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 	if(sysvals.suspendmode == 'standby'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 		dm['resume_machine'] = ['PM: Restoring platform NVS memory']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 	elif(sysvals.suspendmode == 'disk'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 		dm['suspend_late'] = ['PM: freeze of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 		dm['suspend_noirq'] = ['PM: late freeze of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 		dm['suspend_machine'] = ['PM: noirq freeze of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 		dm['resume_machine'] = ['PM: Restoring platform NVS memory']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 		dm['resume_early'] = ['PM: noirq restore of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 		dm['resume'] = ['PM: early restore of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 		dm['resume_complete'] = ['PM: restore of devices complete after.*']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 	elif(sysvals.suspendmode == 'freeze'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 		dm['resume_machine'] = ['ACPI: resume from mwait']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 	# action table (expected events that occur and show up in dmesg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 	at = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 		'sync_filesystems': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 			'smsg': 'PM: Syncing filesystems.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 			'emsg': 'PM: Preparing system for mem sleep.*' },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 		'freeze_user_processes': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 			'smsg': 'Freezing user space processes .*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 			'emsg': 'Freezing remaining freezable tasks.*' },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 		'freeze_tasks': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 			'smsg': 'Freezing remaining freezable tasks.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 			'emsg': 'PM: Entering (?P<mode>[a-z,A-Z]*) sleep.*' },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 		'ACPI prepare': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 			'smsg': 'ACPI: Preparing to enter system sleep state.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 			'emsg': 'PM: Saving platform NVS memory.*' },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 		'PM vns': {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 			'smsg': 'PM: Saving platform NVS memory.*',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 			'emsg': 'Disabling non-boot CPUs .*' },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 	t0 = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 	cpu_start = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 	prevktime = -1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	actions = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	for line in data.dmesgtext:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 		# parse each dmesg line into the time and message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 		m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 		if(m):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 			val = m.group('ktime')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 				ktime = float(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 			msg = m.group('msg')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 			# initialize data start to first line time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 			if t0 < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 				data.setStart(ktime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 				t0 = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 		# check for a phase change line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 		phasechange = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 		for p in dm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 			for s in dm[p]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 				if(re.match(s, msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 					phasechange, phase = True, p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 					break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 		# hack for determining resume_machine end for freeze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 		if(not sysvals.usetraceevents and sysvals.suspendmode == 'freeze' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 			and phase == 'resume_machine' and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 			re.match('calling  (?P<f>.*)\+ @ .*, parent: .*', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 			data.setPhase(phase, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 			phase = 'resume_noirq'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 			data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 		if phasechange:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 			if phase == 'suspend_prepare':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 				data.setStart(ktime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 				data.tKernSus = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 			elif phase == 'suspend':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 			elif phase == 'suspend_late':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 			elif phase == 'suspend_noirq':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 			elif phase == 'suspend_machine':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 			elif phase == 'resume_machine':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 				if(sysvals.suspendmode in ['freeze', 'standby']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 					data.tSuspended = prevktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 					if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 						data.setPhase(lp, prevktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 					data.tSuspended = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 					if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 						data.setPhase(lp, prevktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 				data.tResumed = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 			elif phase == 'resume_noirq':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 			elif phase == 'resume_early':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 			elif phase == 'resume':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 			elif phase == 'resume_complete':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 				data.setPhase(phase, ktime, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 			elif phase == 'post_resume':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 				lp = data.lastPhase()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 				if lp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 					data.setPhase(lp, ktime, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 				data.setEnd(ktime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 				data.tKernRes = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 		# -- device callbacks --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 		if(phase in data.sortedPhases()):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 			# device init call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 			if(re.match('calling  (?P<f>.*)\+ @ .*, parent: .*', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 				sm = re.match('calling  (?P<f>.*)\+ @ '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 					'(?P<n>.*), parent: (?P<p>.*)', msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 				f = sm.group('f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 				n = sm.group('n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 				p = sm.group('p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 				if(f and n and p):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 					data.newAction(phase, f, int(n), p, ktime, -1, '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 			# device init return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 			elif(re.match('call (?P<f>.*)\+ returned .* after '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 				'(?P<t>.*) usecs', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 				sm = re.match('call (?P<f>.*)\+ returned .* after '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 					'(?P<t>.*) usecs(?P<a>.*)', msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 				f = sm.group('f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 				t = sm.group('t')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 				list = data.dmesg[phase]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 				if(f in list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 					dev = list[f]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 					dev['length'] = int(t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 					dev['end'] = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 		# if trace events are not available, these are better than nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 		if(not sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 			# look for known actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 			for a in sorted(at):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 				if(re.match(at[a]['smsg'], msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 					if(a not in actions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 						actions[a] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 					actions[a].append({'begin': ktime, 'end': ktime})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 				if(re.match(at[a]['emsg'], msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 					if(a in actions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 						actions[a][-1]['end'] = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 			# now look for CPU on/off events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 			if(re.match('Disabling non-boot CPUs .*', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 				# start of first cpu suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 				cpu_start = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 			elif(re.match('Enabling non-boot CPUs .*', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 				# start of first cpu resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 				cpu_start = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 			elif(re.match('smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 				# end of a cpu suspend, start of the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 				m = re.match('smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 				cpu = 'CPU'+m.group('cpu')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 				if(cpu not in actions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 					actions[cpu] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 				actions[cpu].append({'begin': cpu_start, 'end': ktime})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 				cpu_start = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 			elif(re.match('CPU(?P<cpu>[0-9]*) is up', msg)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 				# end of a cpu resume, start of the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 				m = re.match('CPU(?P<cpu>[0-9]*) is up', msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 				cpu = 'CPU'+m.group('cpu')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 				if(cpu not in actions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 					actions[cpu] = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 				actions[cpu].append({'begin': cpu_start, 'end': ktime})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 				cpu_start = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 		prevktime = ktime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 	data.initDevicegroups()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 	# fill in any missing phases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 	phasedef = data.phasedef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 	terr, lp = '', 'suspend_prepare'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 	for p in sorted(phasedef, key=lambda k:phasedef[k]['order']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 		if p not in data.dmesg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 			if not terr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 				pprint('TEST FAILED: %s failed in %s phase' % (sysvals.suspendmode, lp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 				terr = '%s failed in %s phase' % (sysvals.suspendmode, lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 				if data.tSuspended == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 					data.tSuspended = data.dmesg[lp]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 				if data.tResumed == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 					data.tResumed = data.dmesg[lp]['end']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 			sysvals.vprint('WARNING: phase "%s" is missing!' % p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 		lp = p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 	lp = data.sortedPhases()[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 	for p in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 		if(p != lp and not ('machine' in p and 'machine' in lp)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 			data.dmesg[lp]['end'] = data.dmesg[p]['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 		lp = p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 	if data.tSuspended == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 		data.tSuspended = data.tKernRes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 	if data.tResumed == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 		data.tResumed = data.tSuspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	# fill in any actions we've found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	for name in sorted(actions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 		for event in actions[name]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 			data.newActionGlobal(name, event['begin'], event['end'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	if(len(sysvals.devicefilter) > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 		data.deviceFilter(sysvals.devicefilter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 	data.fixupInitcallsThatDidntReturn()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 	return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) def callgraphHTML(sv, hf, num, cg, title, color, devid):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 	html_func_top = '<article id="{0}" class="atop" style="background:{1}">\n<input type="checkbox" class="pf" id="f{2}" checked/><label for="f{2}">{3} {4}</label>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 	html_func_start = '<article>\n<input type="checkbox" class="pf" id="f{0}" checked/><label for="f{0}">{1} {2}</label>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 	html_func_end = '</article>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	html_func_leaf = '<article>{0} {1}</article>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 	cgid = devid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	if cg.id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 		cgid += cg.id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 	cglen = (cg.end - cg.start) * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 	if cglen < sv.mincglen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		return num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 	fmt = '<r>(%.3f ms @ '+sv.timeformat+' to '+sv.timeformat+')</r>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 	flen = fmt % (cglen, cg.start, cg.end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 	hf.write(html_func_top.format(cgid, color, num, title, flen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 	num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 	for line in cg.list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 		if(line.length < 0.000000001):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 			flen = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 			fmt = '<n>(%.3f ms @ '+sv.timeformat+')</n>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 			flen = fmt % (line.length*1000, line.time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 		if line.isLeaf():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 			hf.write(html_func_leaf.format(line.name, flen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 		elif line.freturn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 			hf.write(html_func_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 			hf.write(html_func_start.format(num, line.name, flen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 			num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 	hf.write(html_func_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 	return num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) def addCallgraphs(sv, hf, data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 	hf.write('<section id="callgraphs" class="callgraph">\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 	# write out the ftrace data converted to html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 	num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 	for p in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 		if sv.cgphase and p != sv.cgphase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 		list = data.dmesg[p]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 		for d in data.sortedDevices(p):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 			if len(sv.cgfilter) > 0 and d not in sv.cgfilter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 			dev = list[d]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 			color = 'white'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 			if 'color' in data.dmesg[p]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 				color = data.dmesg[p]['color']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 			if 'color' in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 				color = dev['color']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 			name = d if '[' not in d else d.split('[')[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 			if(d in sv.devprops):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 				name = sv.devprops[d].altName(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 			if 'drv' in dev and dev['drv']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 				name += ' {%s}' % dev['drv']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 			if sv.suspendmode in suspendmodename:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 				name += ' '+p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 			if('ftrace' in dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 				cg = dev['ftrace']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 				if cg.name == sv.ftopfunc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 					name = 'top level suspend/resume call'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 				num = callgraphHTML(sv, hf, num, cg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 					name, color, dev['id'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 			if('ftraces' in dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 				for cg in dev['ftraces']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 					num = callgraphHTML(sv, hf, num, cg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 						name+' &rarr; '+cg.name, color, dev['id'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 	hf.write('\n\n    </section>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) def summaryCSS(title, center=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 	tdcenter = 'text-align:center;' if center else ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 	out = '<!DOCTYPE html>\n<html>\n<head>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 	<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 	<title>'+title+'</title>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 	<style type=\'text/css\'>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 		.stamp {width: 100%;text-align:center;background:#888;line-height:30px;color:white;font: 25px Arial;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 		table {width:100%;border-collapse: collapse;border:1px solid;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 		th {border: 1px solid black;background:#222;color:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) 		td {font: 14px "Times New Roman";'+tdcenter+'}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 		tr.head td {border: 1px solid black;background:#aaa;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 		tr.alt {background-color:#ddd;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 		tr.notice {color:red;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 		.minval {background-color:#BBFFBB;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) 		.medval {background-color:#BBBBFF;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 		.maxval {background-color:#FFBBBB;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 		.head a {color:#000;text-decoration: none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 	</style>\n</head>\n<body>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 	return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) # Function: createHTMLSummarySimple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) #	 Create summary html file for a series of tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) #	 testruns: array of Data objects from parseTraceLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) def createHTMLSummarySimple(testruns, htmlfile, title):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 	# write the html header first (html head, css code, up to body start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 	html = summaryCSS('Summary - SleepGraph')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 	# extract the test data into list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 	list = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 	tAvg, tMin, tMax, tMed = [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [dict(), dict()]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 	iMin, iMed, iMax = [0, 0], [0, 0], [0, 0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 	num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 	useturbo = usewifi = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 	lastmode = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 	cnt = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 	for data in sorted(testruns, key=lambda v:(v['mode'], v['host'], v['kernel'], v['time'])):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 		mode = data['mode']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 		if mode not in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 			list[mode] = {'data': [], 'avg': [0,0], 'min': [0,0], 'max': [0,0], 'med': [0,0]}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 		if lastmode and lastmode != mode and num > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 			for i in range(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 				s = sorted(tMed[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 				list[lastmode]['med'][i] = s[int(len(s)//2)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 				iMed[i] = tMed[i][list[lastmode]['med'][i]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 			list[lastmode]['avg'] = [tAvg[0] / num, tAvg[1] / num]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 			list[lastmode]['min'] = tMin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 			list[lastmode]['max'] = tMax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 			list[lastmode]['idx'] = (iMin, iMed, iMax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 			tAvg, tMin, tMax, tMed = [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [dict(), dict()]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 			iMin, iMed, iMax = [0, 0], [0, 0], [0, 0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 			num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 		pkgpc10 = syslpi = wifi = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 		if 'pkgpc10' in data and 'syslpi' in data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 			pkgpc10, syslpi, useturbo = data['pkgpc10'], data['syslpi'], True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 		if 'wifi' in data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 			wifi, usewifi = data['wifi'], True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 		res = data['result']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 		tVal = [float(data['suspend']), float(data['resume'])]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 		list[mode]['data'].append([data['host'], data['kernel'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 			data['time'], tVal[0], tVal[1], data['url'], res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 			data['issues'], data['sus_worst'], data['sus_worsttime'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 			data['res_worst'], data['res_worsttime'], pkgpc10, syslpi, wifi])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 		idx = len(list[mode]['data']) - 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 		if res.startswith('fail in'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 			res = 'fail'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 		if res not in cnt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 			cnt[res] = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 			cnt[res] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 		if res == 'pass':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 			for i in range(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 				tMed[i][tVal[i]] = idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 				tAvg[i] += tVal[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 				if tMin[i] == 0 or tVal[i] < tMin[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 					iMin[i] = idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 					tMin[i] = tVal[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 				if tMax[i] == 0 or tVal[i] > tMax[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 					iMax[i] = idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 					tMax[i] = tVal[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 			num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 		lastmode = mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 	if lastmode and num > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 		for i in range(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 			s = sorted(tMed[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 			list[lastmode]['med'][i] = s[int(len(s)//2)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 			iMed[i] = tMed[i][list[lastmode]['med'][i]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 		list[lastmode]['avg'] = [tAvg[0] / num, tAvg[1] / num]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 		list[lastmode]['min'] = tMin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 		list[lastmode]['max'] = tMax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 		list[lastmode]['idx'] = (iMin, iMed, iMax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 	# group test header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 	desc = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 	for ilk in sorted(cnt, reverse=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 		if cnt[ilk] > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 			desc.append('%d %s' % (cnt[ilk], ilk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	html += '<div class="stamp">%s (%d tests: %s)</div>\n' % (title, len(testruns), ', '.join(desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 	th = '\t<th>{0}</th>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 	td = '\t<td>{0}</td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	tdh = '\t<td{1}>{0}</td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 	tdlink = '\t<td><a href="{0}">html</a></td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 	cols = 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 	if useturbo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 		cols += 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 	if usewifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 		cols += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	colspan = '%d' % cols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 	# table header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 	html += '<table>\n<tr>\n' + th.format('#') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 		th.format('Mode') + th.format('Host') + th.format('Kernel') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 		th.format('Test Time') + th.format('Result') + th.format('Issues') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 		th.format('Suspend') + th.format('Resume') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 		th.format('Worst Suspend Device') + th.format('SD Time') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 		th.format('Worst Resume Device') + th.format('RD Time')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 	if useturbo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 		html += th.format('PkgPC10') + th.format('SysLPI')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 	if usewifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 		html += th.format('Wifi')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	html += th.format('Detail')+'</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 	# export list into html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 	head = '<tr class="head"><td>{0}</td><td>{1}</td>'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 		'<td colspan='+colspan+' class="sus">Suspend Avg={2} '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 		'<span class=minval><a href="#s{10}min">Min={3}</a></span> '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 		'<span class=medval><a href="#s{10}med">Med={4}</a></span> '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 		'<span class=maxval><a href="#s{10}max">Max={5}</a></span> '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 		'Resume Avg={6} '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 		'<span class=minval><a href="#r{10}min">Min={7}</a></span> '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 		'<span class=medval><a href="#r{10}med">Med={8}</a></span> '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 		'<span class=maxval><a href="#r{10}max">Max={9}</a></span></td>'+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 		'</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 	headnone = '<tr class="head"><td>{0}</td><td>{1}</td><td colspan='+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 		colspan+'></td></tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 	for mode in sorted(list):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 		# header line for each suspend mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 		num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 		tAvg, tMin, tMax, tMed = list[mode]['avg'], list[mode]['min'],\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 			list[mode]['max'], list[mode]['med']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 		count = len(list[mode]['data'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 		if 'idx' in list[mode]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 			iMin, iMed, iMax = list[mode]['idx']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 			html += head.format('%d' % count, mode.upper(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 				'%.3f' % tAvg[0], '%.3f' % tMin[0], '%.3f' % tMed[0], '%.3f' % tMax[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 				'%.3f' % tAvg[1], '%.3f' % tMin[1], '%.3f' % tMed[1], '%.3f' % tMax[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 				mode.lower()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 			)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 			iMin = iMed = iMax = [-1, -1, -1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 			html += headnone.format('%d' % count, mode.upper())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 		for d in list[mode]['data']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 			# row classes - alternate row color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 			rcls = ['alt'] if num % 2 == 1 else []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 			if d[6] != 'pass':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 				rcls.append('notice')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 			html += '<tr class="'+(' '.join(rcls))+'">\n' if len(rcls) > 0 else '<tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 			# figure out if the line has sus or res highlighted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 			idx = list[mode]['data'].index(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 			tHigh = ['', '']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 			for i in range(2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 				tag = 's%s' % mode if i == 0 else 'r%s' % mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 				if idx == iMin[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 					tHigh[i] = ' id="%smin" class=minval title="Minimum"' % tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 				elif idx == iMax[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 					tHigh[i] = ' id="%smax" class=maxval title="Maximum"' % tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 				elif idx == iMed[i]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 					tHigh[i] = ' id="%smed" class=medval title="Median"' % tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 			html += td.format("%d" % (list[mode]['data'].index(d) + 1)) # row
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 			html += td.format(mode)										# mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 			html += td.format(d[0])										# host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 			html += td.format(d[1])										# kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 			html += td.format(d[2])										# time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 			html += td.format(d[6])										# result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 			html += td.format(d[7])										# issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 			html += tdh.format('%.3f ms' % d[3], tHigh[0]) if d[3] else td.format('')	# suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 			html += tdh.format('%.3f ms' % d[4], tHigh[1]) if d[4] else td.format('')	# resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 			html += td.format(d[8])										# sus_worst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 			html += td.format('%.3f ms' % d[9])	if d[9] else td.format('')		# sus_worst time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 			html += td.format(d[10])									# res_worst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 			html += td.format('%.3f ms' % d[11]) if d[11] else td.format('')	# res_worst time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 			if useturbo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 				html += td.format(d[12])								# pkg_pc10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 				html += td.format(d[13])								# syslpi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 			if usewifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 				html += td.format(d[14])								# wifi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 			html += tdlink.format(d[5]) if d[5] else td.format('')		# url
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 			html += '</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 			num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 	# flush the data to file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 	hf = open(htmlfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 	hf.write(html+'</table>\n</body>\n</html>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 	hf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) def createHTMLDeviceSummary(testruns, htmlfile, title):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 	html = summaryCSS('Device Summary - SleepGraph', False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 	# create global device list from all tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 	devall = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 		host, url, devlist = data['host'], data['url'], data['devlist']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 		for type in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 			if type not in devall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 				devall[type] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 			mdevlist, devlist = devall[type], data['devlist'][type]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 			for name in devlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 				length = devlist[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 				if name not in mdevlist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 					mdevlist[name] = {'name': name, 'host': host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 						'worst': length, 'total': length, 'count': 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 						'url': url}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 					if length > mdevlist[name]['worst']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 						mdevlist[name]['worst'] = length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 						mdevlist[name]['url'] = url
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 						mdevlist[name]['host'] = host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 					mdevlist[name]['total'] += length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 					mdevlist[name]['count'] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 	# generate the html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 	th = '\t<th>{0}</th>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 	td = '\t<td align=center>{0}</td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 	tdr = '\t<td align=right>{0}</td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 	tdlink = '\t<td align=center><a href="{0}">html</a></td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 	limit = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	for type in sorted(devall, reverse=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 		num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 		devlist = devall[type]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 		# table header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 		html += '<div class="stamp">%s (%s devices > %d ms)</div><table>\n' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 			(title, type.upper(), limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 		html += '<tr>\n' + '<th align=right>Device Name</th>' +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 			th.format('Average Time') + th.format('Count') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 			th.format('Worst Time') + th.format('Host (worst time)') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 			th.format('Link (worst time)') + '</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 		for name in sorted(devlist, key=lambda k:(devlist[k]['worst'], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 			devlist[k]['total'], devlist[k]['name']), reverse=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 			data = devall[type][name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 			data['average'] = data['total'] / data['count']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 			if data['average'] < limit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 			# row classes - alternate row color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 			rcls = ['alt'] if num % 2 == 1 else []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 			html += '<tr class="'+(' '.join(rcls))+'">\n' if len(rcls) > 0 else '<tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 			html += tdr.format(data['name'])				# name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 			html += td.format('%.3f ms' % data['average'])	# average
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 			html += td.format(data['count'])				# count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 			html += td.format('%.3f ms' % data['worst'])	# worst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 			html += td.format(data['host'])					# host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 			html += tdlink.format(data['url'])				# url
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 			html += '</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 			num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 		html += '</table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 	# flush the data to file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 	hf = open(htmlfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 	hf.write(html+'</body>\n</html>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 	hf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	return devall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) def createHTMLIssuesSummary(testruns, issues, htmlfile, title, extra=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 	multihost = len([e for e in issues if len(e['urls']) > 1]) > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	html = summaryCSS('Issues Summary - SleepGraph', False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 	total = len(testruns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	# generate the html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 	th = '\t<th>{0}</th>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 	td = '\t<td align={0}>{1}</td>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 	tdlink = '<a href="{1}">{0}</a>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	subtitle = '%d issues' % len(issues) if len(issues) > 0 else 'no issues'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 	html += '<div class="stamp">%s (%s)</div><table>\n' % (title, subtitle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 	html += '<tr>\n' + th.format('Issue') + th.format('Count')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 	if multihost:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 		html += th.format('Hosts')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 	html += th.format('Tests') + th.format('Fail Rate') +\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 		th.format('First Instance') + '</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 	num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 	for e in sorted(issues, key=lambda v:v['count'], reverse=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 		testtotal = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		links = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 		for host in sorted(e['urls']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 			links.append(tdlink.format(host, e['urls'][host][0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 			testtotal += len(e['urls'][host])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 		rate = '%d/%d (%.2f%%)' % (testtotal, total, 100*float(testtotal)/float(total))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 		# row classes - alternate row color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 		rcls = ['alt'] if num % 2 == 1 else []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 		html += '<tr class="'+(' '.join(rcls))+'">\n' if len(rcls) > 0 else '<tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 		html += td.format('left', e['line'])		# issue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 		html += td.format('center', e['count'])		# count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 		if multihost:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 			html += td.format('center', len(e['urls']))	# hosts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 		html += td.format('center', testtotal)		# test count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 		html += td.format('center', rate)			# test rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 		html += td.format('center nowrap', '<br>'.join(links))	# links
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 		html += '</tr>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 		num += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 	# flush the data to file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 	hf = open(htmlfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 	hf.write(html+'</table>\n'+extra+'</body>\n</html>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 	hf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 	return issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) def ordinal(value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 	suffix = 'th'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 	if value < 10 or value > 19:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 		if value % 10 == 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 			suffix = 'st'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 		elif value % 10 == 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 			suffix = 'nd'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 		elif value % 10 == 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 			suffix = 'rd'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 	return '%d%s' % (value, suffix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) # Function: createHTML
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) #	 Create the output html file from the resident test data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) #	 testruns: array of Data objects from parseKernelLog or parseTraceLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) #	 True if the html file was created, false if it failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) def createHTML(testruns, testfail):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 	if len(testruns) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 		pprint('ERROR: Not enough test data to build a timeline')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 	kerror = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 		if data.kerror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 			kerror = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 		if(sysvals.suspendmode in ['freeze', 'standby']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 			data.trimFreezeTime(testruns[-1].tSuspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 			data.getMemTime()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 	# html function templates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 	html_error = '<div id="{1}" title="kernel error/warning" class="err" style="right:{0}%">{2}&rarr;</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 	html_traceevent = '<div title="{0}" class="traceevent{6}" style="left:{1}%;top:{2}px;height:{3}px;width:{4}%;line-height:{3}px;{7}">{5}</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 	html_cpuexec = '<div class="jiffie" style="left:{0}%;top:{1}px;height:{2}px;width:{3}%;background:{4};"></div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 	html_timetotal = '<table class="time1">\n<tr>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 		'<td class="green" title="{3}">{2} Suspend Time: <b>{0} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 		'<td class="yellow" title="{4}">{2} Resume Time: <b>{1} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 		'</tr>\n</table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 	html_timetotal2 = '<table class="time1">\n<tr>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 		'<td class="green" title="{4}">{3} Suspend Time: <b>{0} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 		'<td class="gray" title="time spent in low-power mode with clock running">'+sysvals.suspendmode+' time: <b>{1} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		'<td class="yellow" title="{5}">{3} Resume Time: <b>{2} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 		'</tr>\n</table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 	html_timetotal3 = '<table class="time1">\n<tr>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 		'<td class="green">Execution Time: <b>{0} ms</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		'<td class="yellow">Command: <b>{1}</b></td>'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 		'</tr>\n</table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 	html_fail = '<table class="testfail"><tr><td>{0}</td></tr></table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 	html_kdesc = '<td class="{3}" title="time spent in kernel execution">{0}Kernel {2}: {1} ms</td>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 	html_fwdesc = '<td class="{3}" title="time spent in firmware">{0}Firmware {2}: {1} ms</td>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 	html_wifdesc = '<td class="yellow" title="time for wifi to reconnect after resume complete ({2})">{0}Wifi Resume: {1}</td>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 	# html format variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 	scaleH = 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 	if kerror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 		scaleH = 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 	# device timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 	devtl = Timeline(30, scaleH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 	# write the test title and general info header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 	devtl.createHeader(sysvals, testruns[0].stamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 	# Generate the header for this timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 		tTotal = data.end - data.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 		if(tTotal == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 			doError('No timeline data')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 		if sysvals.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 			run_time = '%.0f' % (tTotal * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 			if sysvals.testcommand:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 				testdesc = sysvals.testcommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 				testdesc = 'unknown'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 			if(len(testruns) > 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 				testdesc = ordinal(data.testnumber+1)+' '+testdesc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 			thtml = html_timetotal3.format(run_time, testdesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 			devtl.html += thtml
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 		# typical full suspend/resume header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 		stot, rtot = sktime, rktime = data.getTimeValues()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 		ssrc, rsrc, testdesc, testdesc2 = ['kernel'], ['kernel'], 'Kernel', ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 		if data.fwValid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 			stot += (data.fwSuspend/1000000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 			rtot += (data.fwResume/1000000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 			ssrc.append('firmware')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 			rsrc.append('firmware')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 			testdesc = 'Total'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 		if 'time' in data.wifi and data.wifi['stat'] != 'timeout':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 			rtot += data.end - data.tKernRes + (data.wifi['time'] * 1000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 			rsrc.append('wifi')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 			testdesc = 'Total'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 		suspend_time, resume_time = '%.3f' % stot, '%.3f' % rtot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 		stitle = 'time from kernel suspend start to %s mode [%s time]' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 			(sysvals.suspendmode, ' & '.join(ssrc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		rtitle = 'time from %s mode to kernel resume complete [%s time]' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 			(sysvals.suspendmode, ' & '.join(rsrc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 		if(len(testruns) > 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 			testdesc = testdesc2 = ordinal(data.testnumber+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 			testdesc2 += ' '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 		if(len(data.tLow) == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 			thtml = html_timetotal.format(suspend_time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 				resume_time, testdesc, stitle, rtitle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 			low_time = '+'.join(data.tLow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 			thtml = html_timetotal2.format(suspend_time, low_time, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 				resume_time, testdesc, stitle, rtitle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 		devtl.html += thtml
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 		if not data.fwValid and 'dev' not in data.wifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 		# extra detail when the times come from multiple sources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 		thtml = '<table class="time2">\n<tr>'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 		thtml += html_kdesc.format(testdesc2, '%.3f'%sktime, 'Suspend', 'green')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 		if data.fwValid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 			sftime = '%.3f'%(data.fwSuspend / 1000000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 			rftime = '%.3f'%(data.fwResume / 1000000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 			thtml += html_fwdesc.format(testdesc2, sftime, 'Suspend', 'green')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 			thtml += html_fwdesc.format(testdesc2, rftime, 'Resume', 'yellow')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 		thtml += html_kdesc.format(testdesc2, '%.3f'%rktime, 'Resume', 'yellow')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 		if 'time' in data.wifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 			if data.wifi['stat'] != 'timeout':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 				wtime = '%.0f ms'%(data.end - data.tKernRes + (data.wifi['time'] * 1000.0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 				wtime = 'TIMEOUT'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 			thtml += html_wifdesc.format(testdesc2, wtime, data.wifi['dev'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 		thtml += '</tr>\n</table>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 		devtl.html += thtml
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 	if testfail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 		devtl.html += html_fail.format(testfail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 	# time scale for potentially multiple datasets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 	t0 = testruns[0].start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 	tMax = testruns[-1].end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 	tTotal = tMax - t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 	# determine the maximum number of rows we need to draw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 	fulllist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 	threadlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 	pscnt = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 	devcnt = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 		data.selectTimelineDevices('%f', tTotal, sysvals.mindevlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 		for group in data.devicegroups:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 			devlist = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 			for phase in group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 				for devname in sorted(data.tdevlist[phase]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 					d = DevItem(data.testnumber, phase, data.dmesg[phase]['list'][devname])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 					devlist.append(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 					if d.isa('kth'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 						threadlist.append(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 						if d.isa('ps'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 							pscnt += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 						else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 							devcnt += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 						fulllist.append(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 			if sysvals.mixedphaseheight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 				devtl.getPhaseRows(devlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 	if not sysvals.mixedphaseheight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 		if len(threadlist) > 0 and len(fulllist) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 			if pscnt > 0 and devcnt > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 				msg = 'user processes & device pm callbacks'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 			elif pscnt > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 				msg = 'user processes'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 				msg = 'device pm callbacks'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 			d = testruns[0].addHorizontalDivider(msg, testruns[-1].end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 			fulllist.insert(0, d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 		devtl.getPhaseRows(fulllist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 		if len(threadlist) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 			d = testruns[0].addHorizontalDivider('asynchronous kernel threads', testruns[-1].end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 			threadlist.insert(0, d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 			devtl.getPhaseRows(threadlist, devtl.rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 	devtl.calcTotalRows()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 	# draw the full timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 	devtl.createZoomBox(sysvals.suspendmode, len(testruns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 		# draw each test run and block chronologically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 		phases = {'suspend':[],'resume':[]}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 		for phase in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 			if data.dmesg[phase]['start'] >= data.tSuspended:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 				phases['resume'].append(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 				phases['suspend'].append(phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 		# now draw the actual timeline blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 		for dir in phases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 			# draw suspend and resume blocks separately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 			bname = '%s%d' % (dir[0], data.testnumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 			if dir == 'suspend':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 				m0 = data.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 				mMax = data.tSuspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 				left = '%f' % (((m0-t0)*100.0)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 				m0 = data.tSuspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 				mMax = data.end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 				# in an x2 run, remove any gap between blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 				if len(testruns) > 1 and data.testnumber == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 					mMax = testruns[1].start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 				left = '%f' % ((((m0-t0)*100.0)+sysvals.srgap/2)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 			mTotal = mMax - m0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 			# if a timeline block is 0 length, skip altogether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 			if mTotal == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 			width = '%f' % (((mTotal*100.0)-sysvals.srgap/2)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 			devtl.html += devtl.html_tblock.format(bname, left, width, devtl.scaleH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 			for b in phases[dir]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 				# draw the phase color background
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 				phase = data.dmesg[b]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 				length = phase['end']-phase['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 				left = '%f' % (((phase['start']-m0)*100.0)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 				width = '%f' % ((length*100.0)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 				devtl.html += devtl.html_phase.format(left, width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 					'%.3f'%devtl.scaleH, '%.3f'%devtl.bodyH, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 					data.dmesg[b]['color'], '')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 			for e in data.errorinfo[dir]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 				# draw red lines for any kernel errors found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 				type, t, idx1, idx2 = e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 				id = '%d_%d' % (idx1, idx2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 				right = '%f' % (((mMax-t)*100.0)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 				devtl.html += html_error.format(right, id, type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 			for b in phases[dir]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 				# draw the devices for this phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 				phaselist = data.dmesg[b]['list']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 				for d in sorted(data.tdevlist[b]):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 					dname = d if '[' not in d else d.split('[')[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 					name, dev = dname, phaselist[d]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 					drv = xtraclass = xtrainfo = xtrastyle = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 					if 'htmlclass' in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 						xtraclass = dev['htmlclass']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) 					if 'color' in dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) 						xtrastyle = 'background:%s;' % dev['color']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 					if(d in sysvals.devprops):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 						name = sysvals.devprops[d].altName(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 						xtraclass = sysvals.devprops[d].xtraClass()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 						xtrainfo = sysvals.devprops[d].xtraInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 					elif xtraclass == ' kth':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 						xtrainfo = ' kernel_thread'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 					if('drv' in dev and dev['drv']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 						drv = ' {%s}' % dev['drv']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 					rowheight = devtl.phaseRowHeight(data.testnumber, b, dev['row'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 					rowtop = devtl.phaseRowTop(data.testnumber, b, dev['row'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 					top = '%.3f' % (rowtop + devtl.scaleH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 					left = '%f' % (((dev['start']-m0)*100)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 					width = '%f' % (((dev['end']-dev['start'])*100)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 					length = ' (%0.3f ms) ' % ((dev['end']-dev['start'])*1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 					title = name+drv+xtrainfo+length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 					if sysvals.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 						title += sysvals.testcommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 					elif xtraclass == ' ps':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 						if 'suspend' in b:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 							title += 'pre_suspend_process'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) 						else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 							title += 'post_resume_process'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 						title += b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 					devtl.html += devtl.html_device.format(dev['id'], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 						title, left, top, '%.3f'%rowheight, width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 						dname+drv, xtraclass, xtrastyle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 					if('cpuexec' in dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 						for t in sorted(dev['cpuexec']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 							start, end = t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 							j = float(dev['cpuexec'][t]) / 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 							if j > 1.0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 								j = 1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 							height = '%.3f' % (rowheight/3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 							top = '%.3f' % (rowtop + devtl.scaleH + 2*rowheight/3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 							left = '%f' % (((start-m0)*100)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 							width = '%f' % ((end-start)*100/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 							color = 'rgba(255, 0, 0, %f)' % j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 							devtl.html += \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 								html_cpuexec.format(left, top, height, width, color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 					if('src' not in dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 						continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 					# draw any trace events for this device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 					for e in dev['src']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 						if e.length == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 							continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 						height = '%.3f' % devtl.rowH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 						top = '%.3f' % (rowtop + devtl.scaleH + (e.row*devtl.rowH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 						left = '%f' % (((e.time-m0)*100)/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 						width = '%f' % (e.length*100/mTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 						xtrastyle = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 						if e.color:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 							xtrastyle = 'background:%s;' % e.color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 						devtl.html += \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 							html_traceevent.format(e.title(), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 								left, top, height, width, e.text(), '', xtrastyle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 			# draw the time scale, try to make the number of labels readable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 			devtl.createTimeScale(m0, mMax, tTotal, dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 			devtl.html += '</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 	# timeline is finished
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 	devtl.html += '</div>\n</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 	# draw a legend which describes the phases by color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 	if sysvals.suspendmode != 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 		phasedef = testruns[-1].phasedef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 		devtl.html += '<div class="legend">\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 		pdelta = 100.0/len(phasedef.keys())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 		pmargin = pdelta / 4.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 		for phase in sorted(phasedef, key=lambda k:phasedef[k]['order']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 			id, p = '', phasedef[phase]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 			for word in phase.split('_'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 				id += word[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 			order = '%.2f' % ((p['order'] * pdelta) + pmargin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 			name = phase.replace('_', ' &nbsp;')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 			devtl.html += devtl.html_legend.format(order, p['color'], name, id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 		devtl.html += '</div>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 	hf = open(sysvals.htmlfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 	addCSS(hf, sysvals, len(testruns), kerror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 	# write the device timeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 	hf.write(devtl.html)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 	hf.write('<div id="devicedetailtitle"></div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 	hf.write('<div id="devicedetail" style="display:none;">\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 	# draw the colored boxes for the device detail section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 		hf.write('<div id="devicedetail%d">\n' % data.testnumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 		pscolor = 'linear-gradient(to top left, #ccc, #eee)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 		hf.write(devtl.html_phaselet.format('pre_suspend_process', \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 			'0', '0', pscolor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 		for b in data.sortedPhases():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 			phase = data.dmesg[b]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 			length = phase['end']-phase['start']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 			left = '%.3f' % (((phase['start']-t0)*100.0)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 			width = '%.3f' % ((length*100.0)/tTotal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 			hf.write(devtl.html_phaselet.format(b, left, width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 				data.dmesg[b]['color']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 		hf.write(devtl.html_phaselet.format('post_resume_process', \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 			'0', '0', pscolor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 		if sysvals.suspendmode == 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 			hf.write(devtl.html_phaselet.format('cmdexec', '0', '0', pscolor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 		hf.write('</div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 	hf.write('</div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 	# write the ftrace data (callgraph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 	if sysvals.cgtest >= 0 and len(testruns) > sysvals.cgtest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 		data = testruns[sysvals.cgtest]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 		data = testruns[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 	if sysvals.usecallgraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 		addCallgraphs(sysvals, hf, data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 	# add the test log as a hidden div
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 	if sysvals.testlog and sysvals.logmsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 		hf.write('<div id="testlog" style="display:none;">\n'+sysvals.logmsg+'</div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 	# add the dmesg log as a hidden div
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	if sysvals.dmesglog and sysvals.dmesgfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 		hf.write('<div id="dmesglog" style="display:none;">\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 		lf = sysvals.openlog(sysvals.dmesgfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 		for line in lf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 			line = line.replace('<', '&lt').replace('>', '&gt')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 			hf.write(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 		lf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) 		hf.write('</div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 	# add the ftrace log as a hidden div
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) 	if sysvals.ftracelog and sysvals.ftracefile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 		hf.write('<div id="ftracelog" style="display:none;">\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 		lf = sysvals.openlog(sysvals.ftracefile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 		for line in lf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 			hf.write(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 		lf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 		hf.write('</div>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 	# write the footer and close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 	addScriptCode(hf, testruns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 	hf.write('</body>\n</html>\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 	hf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 	return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) def addCSS(hf, sv, testcount=1, kerror=False, extra=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 	kernel = sv.stamp['kernel']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 	host = sv.hostname[0].upper()+sv.hostname[1:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 	mode = sv.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 	if sv.suspendmode in suspendmodename:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 		mode = suspendmodename[sv.suspendmode]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 	title = host+' '+mode+' '+kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 	# various format changes by flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 	cgchk = 'checked'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 	cgnchk = 'not(:checked)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 	if sv.cgexp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 		cgchk = 'not(:checked)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 		cgnchk = 'checked'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 	hoverZ = 'z-index:8;'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 	if sv.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 		hoverZ = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 	devlistpos = 'absolute'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 	if testcount > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 		devlistpos = 'relative'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 	scaleTH = 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 	if kerror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 		scaleTH = 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 	# write the html header first (html head, css code, up to body start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 	html_header = '<!DOCTYPE html>\n<html>\n<head>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 	<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 	<title>'+title+'</title>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 	<style type=\'text/css\'>\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 		body {overflow-y:scroll;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 		.stamp {width:100%;text-align:center;background:gray;line-height:30px;color:white;font:25px Arial;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 		.stamp.sysinfo {font:10px Arial;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 		.callgraph {margin-top:30px;box-shadow:5px 5px 20px black;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 		.callgraph article * {padding-left:28px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 		h1 {color:black;font:bold 30px Times;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 		t0 {color:black;font:bold 30px Times;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 		t1 {color:black;font:30px Times;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 		t2 {color:black;font:25px Times;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 		t3 {color:black;font:20px Times;white-space:nowrap;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 		t4 {color:black;font:bold 30px Times;line-height:60px;white-space:nowrap;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 		cS {font:bold 13px Times;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 		table {width:100%;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 		.gray {background:rgba(80,80,80,0.1);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 		.green {background:rgba(204,255,204,0.4);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 		.purple {background:rgba(128,0,128,0.2);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 		.yellow {background:rgba(255,255,204,0.4);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 		.blue {background:rgba(169,208,245,0.4);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 		.time1 {font:22px Arial;border:1px solid;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 		.time2 {font:15px Arial;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 		.testfail {font:bold 22px Arial;color:red;border:1px dashed;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 		td {text-align:center;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 		r {color:#500000;font:15px Tahoma;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 		n {color:#505050;font:15px Tahoma;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 		.tdhl {color:red;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 		.hide {display:none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 		.pf {display:none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 		.pf:'+cgchk+' + label {background:url(\'data:image/svg+xml;utf,<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" version="1.1"><circle cx="9" cy="9" r="8" stroke="black" stroke-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:black;stroke-width:0"/><rect x="8" y="4" width="2" height="10" style="fill:black;stroke-width:0"/></svg>\') no-repeat left center;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 		.pf:'+cgnchk+' ~ label {background:url(\'data:image/svg+xml;utf,<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" version="1.1"><circle cx="9" cy="9" r="8" stroke="black" stroke-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:black;stroke-width:0"/></svg>\') no-repeat left center;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 		.pf:'+cgchk+' ~ *:not(:nth-child(2)) {display:none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 		.zoombox {position:relative;width:100%;overflow-x:scroll;-webkit-user-select:none;-moz-user-select:none;user-select:none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 		.timeline {position:relative;font-size:14px;cursor:pointer;width:100%; overflow:hidden;background:linear-gradient(#cccccc, white);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 		.thread {position:absolute;height:0%;overflow:hidden;z-index:7;line-height:30px;font-size:14px;border:1px solid;text-align:center;white-space:nowrap;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 		.thread.ps {border-radius:3px;background:linear-gradient(to top, #ccc, #eee);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 		.thread:hover {background:white;border:1px solid red;'+hoverZ+'}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 		.thread.sec,.thread.sec:hover {background:black;border:0;color:white;line-height:15px;font-size:10px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 		.hover {background:white;border:1px solid red;'+hoverZ+'}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 		.hover.sync {background:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 		.hover.bg,.hover.kth,.hover.sync,.hover.ps {background:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 		.jiffie {position:absolute;pointer-events: none;z-index:8;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 		.traceevent {position:absolute;font-size:10px;z-index:7;overflow:hidden;color:black;text-align:center;white-space:nowrap;border-radius:5px;border:1px solid black;background:linear-gradient(to bottom right,#CCC,#969696);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 		.traceevent:hover {color:white;font-weight:bold;border:1px solid white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 		.phase {position:absolute;overflow:hidden;border:0px;text-align:center;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 		.phaselet {float:left;overflow:hidden;border:0px;text-align:center;min-height:100px;font-size:24px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 		.t {position:absolute;line-height:'+('%d'%scaleTH)+'px;pointer-events:none;top:0;height:100%;border-right:1px solid black;z-index:6;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 		.err {position:absolute;top:0%;height:100%;border-right:3px solid red;color:red;font:bold 14px Times;line-height:18px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 		.legend {position:relative; width:100%; height:40px; text-align:center;margin-bottom:20px}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 		.legend .square {position:absolute;cursor:pointer;top:10px; width:0px;height:20px;border:1px solid;padding-left:20px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 		button {height:40px;width:200px;margin-bottom:20px;margin-top:20px;font-size:24px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 		.btnfmt {position:relative;float:right;height:25px;width:auto;margin-top:3px;margin-bottom:0;font-size:10px;text-align:center;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 		.devlist {position:'+devlistpos+';width:190px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 		a:link {color:white;text-decoration:none;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 		a:visited {color:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 		a:hover {color:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 		a:active {color:white;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 		.version {position:relative;float:left;color:white;font-size:10px;line-height:30px;margin-left:10px;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 		#devicedetail {min-height:100px;box-shadow:5px 5px 20px black;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 		.tblock {position:absolute;height:100%;background:#ddd;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 		.tback {position:absolute;width:100%;background:linear-gradient(#ccc, #ddd);}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 		.bg {z-index:1;}\n\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) '+extra+'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 	</style>\n</head>\n<body>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 	hf.write(html_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) # Function: addScriptCode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) #	 Adds the javascript code to the output html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) #	 hf: the open html file pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) #	 testruns: array of Data objects from parseKernelLog or parseTraceLog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) def addScriptCode(hf, testruns):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 	t0 = testruns[0].start * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 	tMax = testruns[-1].end * 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 	# create an array in javascript memory with the device details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 	detail = '	var devtable = [];\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 		topo = data.deviceTopology()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 		detail += '	devtable[%d] = "%s";\n' % (data.testnumber, topo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 	detail += '	var bounds = [%f,%f];\n' % (t0, tMax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 	# add the code which will manipulate the data in the browser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 	script_code = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) 	'<script type="text/javascript">\n'+detail+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 	'	var resolution = -1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 	'	var dragval = [0, 0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 	'	function redrawTimescale(t0, tMax, tS) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 	'		var rline = \'<div class="t" style="left:0;border-left:1px solid black;border-right:0;">\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 	'		var tTotal = tMax - t0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 	'		var list = document.getElementsByClassName("tblock");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 	'		for (var i = 0; i < list.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 	'			var timescale = list[i].getElementsByClassName("timescale")[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 	'			var m0 = t0 + (tTotal*parseFloat(list[i].style.left)/100);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 	'			var mTotal = tTotal*parseFloat(list[i].style.width)/100;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 	'			var mMax = m0 + mTotal;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 	'			var html = "";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 	'			var divTotal = Math.floor(mTotal/tS) + 1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 	'			if(divTotal > 1000) continue;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 	'			var divEdge = (mTotal - tS*(divTotal-1))*100/mTotal;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 	'			var pos = 0.0, val = 0.0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 	'			for (var j = 0; j < divTotal; j++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 	'				var htmlline = "";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 	'				var mode = list[i].id[5];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) 	'				if(mode == "s") {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 	'					pos = 100 - (((j)*tS*100)/mTotal) - divEdge;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 	'					val = (j-divTotal+1)*tS;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 	'					if(j == divTotal - 1)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 	'						htmlline = \'<div class="t" style="right:\'+pos+\'%"><cS>S&rarr;</cS></div>\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 	'					else\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) 	'						htmlline = \'<div class="t" style="right:\'+pos+\'%">\'+val+\'ms</div>\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 	'				} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 	'					pos = 100 - (((j)*tS*100)/mTotal);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) 	'					val = (j)*tS;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 	'					htmlline = \'<div class="t" style="right:\'+pos+\'%">\'+val+\'ms</div>\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) 	'					if(j == 0)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) 	'						if(mode == "r")\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) 	'							htmlline = rline+"<cS>&larr;R</cS></div>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) 	'						else\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 	'							htmlline = rline+"<cS>0ms</div>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) 	'				}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 	'				html += htmlline;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 	'			timescale.innerHTML = html;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 	'	function zoomTimeline() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 	'		var dmesg = document.getElementById("dmesg");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 	'		var zoombox = document.getElementById("dmesgzoombox");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 	'		var left = zoombox.scrollLeft;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 	'		var val = parseFloat(dmesg.style.width);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 	'		var newval = 100;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 	'		var sh = window.outerWidth / 2;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 	'		if(this.id == "zoomin") {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 	'			newval = val * 1.2;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 	'			if(newval > 910034) newval = 910034;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 	'			dmesg.style.width = newval+"%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 	'			zoombox.scrollLeft = ((left + sh) * newval / val) - sh;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 	'		} else if (this.id == "zoomout") {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 	'			newval = val / 1.2;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 	'			if(newval < 100) newval = 100;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 	'			dmesg.style.width = newval+"%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 	'			zoombox.scrollLeft = ((left + sh) * newval / val) - sh;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 	'		} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 	'			zoombox.scrollLeft = 0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 	'			dmesg.style.width = "100%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 	'		var tS = [10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5, 2, 1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 	'		var t0 = bounds[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 	'		var tMax = bounds[1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 	'		var tTotal = tMax - t0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 	'		var wTotal = tTotal * 100.0 / newval;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	'		var idx = 7*window.innerWidth/1100;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 	'		for(var i = 0; (i < tS.length)&&((wTotal / tS[i]) < idx); i++);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 	'		if(i >= tS.length) i = tS.length - 1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 	'		if(tS[i] == resolution) return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 	'		resolution = tS[i];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 	'		redrawTimescale(t0, tMax, tS[i]);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 	'	function deviceName(title) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 	'		var name = title.slice(0, title.indexOf(" ("));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 	'		return name;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 	'	function deviceHover() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 	'		var name = deviceName(this.title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 	'		var dmesg = document.getElementById("dmesg");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 	'		var dev = dmesg.getElementsByClassName("thread");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 	'		var cpu = -1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 	'		if(name.match("CPU_ON\[[0-9]*\]"))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 	'			cpu = parseInt(name.slice(7));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 	'		else if(name.match("CPU_OFF\[[0-9]*\]"))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 	'			cpu = parseInt(name.slice(8));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 	'		for (var i = 0; i < dev.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 	'			dname = deviceName(dev[i].title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 	'			var cname = dev[i].className.slice(dev[i].className.indexOf("thread"));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 	'			if((cpu >= 0 && dname.match("CPU_O[NF]*\\\[*"+cpu+"\\\]")) ||\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) 	'				(name == dname))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 	'			{\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 	'				dev[i].className = "hover "+cname;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 	'			} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 	'				dev[i].className = cname;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 	'	function deviceUnhover() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 	'		var dmesg = document.getElementById("dmesg");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 	'		var dev = dmesg.getElementsByClassName("thread");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 	'		for (var i = 0; i < dev.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 	'			dev[i].className = dev[i].className.slice(dev[i].className.indexOf("thread"));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 	'	function deviceTitle(title, total, cpu) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 	'		var prefix = "Total";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) 	'		if(total.length > 3) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 	'			prefix = "Average";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) 	'			total[1] = (total[1]+total[3])/2;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 	'			total[2] = (total[2]+total[4])/2;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 	'		var devtitle = document.getElementById("devicedetailtitle");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 	'		var name = deviceName(title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 	'		if(cpu >= 0) name = "CPU"+cpu;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 	'		var driver = "";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 	'		var tS = "<t2>(</t2>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 	'		var tR = "<t2>)</t2>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 	'		if(total[1] > 0)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) 	'			tS = "<t2>("+prefix+" Suspend:</t2><t0> "+total[1].toFixed(3)+" ms</t0> ";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) 	'		if(total[2] > 0)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 	'			tR = " <t2>"+prefix+" Resume:</t2><t0> "+total[2].toFixed(3)+" ms<t2>)</t2></t0>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) 	'		var s = title.indexOf("{");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 	'		var e = title.indexOf("}");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) 	'		if((s >= 0) && (e >= 0))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 	'			driver = title.slice(s+1, e) + " <t1>@</t1> ";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) 	'		if(total[1] > 0 && total[2] > 0)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 	'			devtitle.innerHTML = "<t0>"+driver+name+"</t0> "+tS+tR;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 	'		else\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 	'			devtitle.innerHTML = "<t0>"+title+"</t0>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 	'		return name;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 	'	function deviceDetail() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) 	'		var devinfo = document.getElementById("devicedetail");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 	'		devinfo.style.display = "block";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) 	'		var name = deviceName(this.title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) 	'		var cpu = -1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 	'		if(name.match("CPU_ON\[[0-9]*\]"))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 	'			cpu = parseInt(name.slice(7));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 	'		else if(name.match("CPU_OFF\[[0-9]*\]"))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) 	'			cpu = parseInt(name.slice(8));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) 	'		var dmesg = document.getElementById("dmesg");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 	'		var dev = dmesg.getElementsByClassName("thread");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 	'		var idlist = [];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 	'		var pdata = [[]];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) 	'		if(document.getElementById("devicedetail1"))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 	'			pdata = [[], []];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) 	'		var pd = pdata[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) 	'		var total = [0.0, 0.0, 0.0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 	'		for (var i = 0; i < dev.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 	'			dname = deviceName(dev[i].title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 	'			if((cpu >= 0 && dname.match("CPU_O[NF]*\\\[*"+cpu+"\\\]")) ||\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) 	'				(name == dname))\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) 	'			{\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) 	'				idlist[idlist.length] = dev[i].id;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) 	'				var tidx = 1;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 	'				if(dev[i].id[0] == "a") {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 	'					pd = pdata[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 	'				} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 	'					if(pdata.length == 1) pdata[1] = [];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 	'					if(total.length == 3) total[3]=total[4]=0.0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) 	'					pd = pdata[1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 	'					tidx = 3;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 	'				}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 	'				var info = dev[i].title.split(" ");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 	'				var pname = info[info.length-1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) 	'				pd[pname] = parseFloat(info[info.length-3].slice(1));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 	'				total[0] += pd[pname];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 	'				if(pname.indexOf("suspend") >= 0)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 	'					total[tidx] += pd[pname];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 	'				else\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) 	'					total[tidx+1] += pd[pname];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 	'		var devname = deviceTitle(this.title, total, cpu);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) 	'		var left = 0.0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 	'		for (var t = 0; t < pdata.length; t++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 	'			pd = pdata[t];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 	'			devinfo = document.getElementById("devicedetail"+t);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 	'			var phases = devinfo.getElementsByClassName("phaselet");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 	'			for (var i = 0; i < phases.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 	'				if(phases[i].id in pd) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 	'					var w = 100.0*pd[phases[i].id]/total[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 	'					var fs = 32;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 	'					if(w < 8) fs = 4*w | 0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 	'					var fs2 = fs*3/4;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 	'					phases[i].style.width = w+"%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 	'					phases[i].style.left = left+"%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 	'					phases[i].title = phases[i].id+" "+pd[phases[i].id]+" ms";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 	'					left += w;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 	'					var time = "<t4 style=\\"font-size:"+fs+"px\\">"+pd[phases[i].id]+" ms<br></t4>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 	'					var pname = "<t3 style=\\"font-size:"+fs2+"px\\">"+phases[i].id.replace(new RegExp("_", "g"), " ")+"</t3>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) 	'					phases[i].innerHTML = time+pname;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 	'				} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 	'					phases[i].style.width = "0%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 	'					phases[i].style.left = left+"%";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 	'				}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 	'		if(typeof devstats !== \'undefined\')\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 	'			callDetail(this.id, this.title);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 	'		var cglist = document.getElementById("callgraphs");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 	'		if(!cglist) return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 	'		var cg = cglist.getElementsByClassName("atop");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 	'		if(cg.length < 10) return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 	'		for (var i = 0; i < cg.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 	'			cgid = cg[i].id.split("x")[0]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 	'			if(idlist.indexOf(cgid) >= 0) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 	'				cg[i].style.display = "block";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 	'			} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 	'				cg[i].style.display = "none";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 	'	function callDetail(devid, devtitle) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 	'		if(!(devid in devstats) || devstats[devid].length < 1)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 	'			return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 	'		var list = devstats[devid];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 	'		var tmp = devtitle.split(" ");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 	'		var name = tmp[0], phase = tmp[tmp.length-1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 	'		var dd = document.getElementById(phase);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 	'		var total = parseFloat(tmp[1].slice(1));\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 	'		var mlist = [];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 	'		var maxlen = 0;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 	'		var info = []\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 	'		for(var i in list) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 	'			if(list[i][0] == "@") {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 	'				info = list[i].split("|");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 	'				continue;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 	'			var tmp = list[i].split("|");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) 	'			var t = parseFloat(tmp[0]), f = tmp[1], c = parseInt(tmp[2]);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) 	'			var p = (t*100.0/total).toFixed(2);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) 	'			mlist[mlist.length] = [f, c, t.toFixed(2), p+"%"];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) 	'			if(f.length > maxlen)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) 	'				maxlen = f.length;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) 	'		var pad = 5;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 	'		if(mlist.length == 0) pad = 30;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) 	'		var html = \'<div style="padding-top:\'+pad+\'px"><t3> <b>\'+name+\':</b>\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 	'		if(info.length > 2)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) 	'			html += " start=<b>"+info[1]+"</b>, end=<b>"+info[2]+"</b>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) 	'		if(info.length > 3)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) 	'			html += ", length<i>(w/o overhead)</i>=<b>"+info[3]+" ms</b>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 	'		if(info.length > 4)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 	'			html += ", return=<b>"+info[4]+"</b>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 	'		html += "</t3></div>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 	'		if(mlist.length > 0) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 	'			html += \'<table class=fstat style="padding-top:\'+(maxlen*5)+\'px;"><tr><th>Function</th>\';\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 	'			for(var i in mlist)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 	'				html += "<td class=vt>"+mlist[i][0]+"</td>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 	'			html += "</tr><tr><th>Calls</th>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 	'			for(var i in mlist)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 	'				html += "<td>"+mlist[i][1]+"</td>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 	'			html += "</tr><tr><th>Time(ms)</th>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 	'			for(var i in mlist)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 	'				html += "<td>"+mlist[i][2]+"</td>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 	'			html += "</tr><tr><th>Percent</th>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) 	'			for(var i in mlist)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 	'				html += "<td>"+mlist[i][3]+"</td>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 	'			html += "</tr></table>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 	'		dd.innerHTML = html;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 	'		var height = (maxlen*5)+100;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 	'		dd.style.height = height+"px";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 	'		document.getElementById("devicedetail").style.height = height+"px";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 	'	function callSelect() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 	'		var cglist = document.getElementById("callgraphs");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 	'		if(!cglist) return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 	'		var cg = cglist.getElementsByClassName("atop");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 	'		for (var i = 0; i < cg.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 	'			if(this.id == cg[i].id) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 	'				cg[i].style.display = "block";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 	'			} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 	'				cg[i].style.display = "none";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 	'	function devListWindow(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 	'		var win = window.open();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 	'		var html = "<title>"+e.target.innerHTML+"</title>"+\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 	'			"<style type=\\"text/css\\">"+\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 	'			"   ul {list-style-type:circle;padding-left:10px;margin-left:10px;}"+\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 	'			"</style>"\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 	'		var dt = devtable[0];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) 	'		if(e.target.id != "devlist1")\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 	'			dt = devtable[1];\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) 	'		win.document.write(html+dt);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 	'	function errWindow() {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 	'		var range = this.id.split("_");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 	'		var idx1 = parseInt(range[0]);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 	'		var idx2 = parseInt(range[1]);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 	'		var win = window.open();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) 	'		var log = document.getElementById("dmesglog");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 	'		var title = "<title>dmesg log</title>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 	'		var text = log.innerHTML.split("\\n");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 	'		var html = "";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 	'		for(var i = 0; i < text.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 	'			if(i == idx1) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 	'				html += "<e id=target>"+text[i]+"</e>\\n";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 	'			} else if(i > idx1 && i <= idx2) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 	'				html += "<e>"+text[i]+"</e>\\n";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 	'			} else {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 	'				html += text[i]+"\\n";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) 	'			}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 	'		win.document.write("<style>e{color:red}</style>"+title+"<pre>"+html+"</pre>");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) 	'		win.location.hash = "#target";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 	'		win.document.close();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) 	'	function logWindow(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 	'		var name = e.target.id.slice(4);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) 	'		var win = window.open();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 	'		var log = document.getElementById(name+"log");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) 	'		var title = "<title>"+document.title.split(" ")[0]+" "+name+" log</title>";\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) 	'		win.document.write(title+"<pre>"+log.innerHTML+"</pre>");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 	'		win.document.close();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) 	'	function onMouseDown(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 	'		dragval[0] = e.clientX;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) 	'		dragval[1] = document.getElementById("dmesgzoombox").scrollLeft;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 	'		document.onmousemove = onMouseMove;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) 	'	function onMouseMove(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 	'		var zoombox = document.getElementById("dmesgzoombox");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 	'		zoombox.scrollLeft = dragval[1] + dragval[0] - e.clientX;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 	'	function onMouseUp(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 	'		document.onmousemove = null;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 	'	function onKeyPress(e) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 	'		var c = e.charCode;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 	'		if(c != 42 && c != 43 && c != 45) return;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 	'		var click = document.createEvent("Events");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 	'		click.initEvent("click", true, false);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 	'		if(c == 43)  \n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 	'			document.getElementById("zoomin").dispatchEvent(click);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 	'		else if(c == 45)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 	'			document.getElementById("zoomout").dispatchEvent(click);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 	'		else if(c == 42)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 	'			document.getElementById("zoomdef").dispatchEvent(click);\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 	'	}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 	'	window.addEventListener("resize", function () {zoomTimeline();});\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 	'	window.addEventListener("load", function () {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) 	'		var dmesg = document.getElementById("dmesg");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 	'		dmesg.style.width = "100%"\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 	'		dmesg.onmousedown = onMouseDown;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 	'		document.onmouseup = onMouseUp;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 	'		document.onkeypress = onKeyPress;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) 	'		document.getElementById("zoomin").onclick = zoomTimeline;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 	'		document.getElementById("zoomout").onclick = zoomTimeline;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 	'		document.getElementById("zoomdef").onclick = zoomTimeline;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 	'		var list = document.getElementsByClassName("err");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 	'		for (var i = 0; i < list.length; i++)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 	'			list[i].onclick = errWindow;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 	'		var list = document.getElementsByClassName("logbtn");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) 	'		for (var i = 0; i < list.length; i++)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 	'			list[i].onclick = logWindow;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 	'		list = document.getElementsByClassName("devlist");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 	'		for (var i = 0; i < list.length; i++)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) 	'			list[i].onclick = devListWindow;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 	'		var dev = dmesg.getElementsByClassName("thread");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) 	'		for (var i = 0; i < dev.length; i++) {\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 	'			dev[i].onclick = deviceDetail;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 	'			dev[i].onmouseover = deviceHover;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 	'			dev[i].onmouseout = deviceUnhover;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) 	'		}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 	'		var dev = dmesg.getElementsByClassName("srccall");\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) 	'		for (var i = 0; i < dev.length; i++)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 	'			dev[i].onclick = callSelect;\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 	'		zoomTimeline();\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 	'	});\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) 	'</script>\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 	hf.write(script_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) def setRuntimeSuspend(before=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 	global sysvals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) 	sv = sysvals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 	if sv.rs == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) 	if before:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 		# runtime suspend disable or enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) 		if sv.rs > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) 			sv.rstgt, sv.rsval, sv.rsdir = 'on', 'auto', 'enabled'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) 			sv.rstgt, sv.rsval, sv.rsdir = 'auto', 'on', 'disabled'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) 		pprint('CONFIGURING RUNTIME SUSPEND...')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) 		sv.rslist = deviceInfo(sv.rstgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) 		for i in sv.rslist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 			sv.setVal(sv.rsval, i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) 		pprint('runtime suspend %s on all devices (%d changed)' % (sv.rsdir, len(sv.rslist)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 		pprint('waiting 5 seconds...')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 		time.sleep(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 		# runtime suspend re-enable or re-disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 		for i in sv.rslist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 			sv.setVal(sv.rstgt, i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 		pprint('runtime suspend settings restored on %d devices' % len(sv.rslist))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) # Function: executeSuspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) #	 Execute system suspend through the sysfs interface, then copy the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) #	 dmesg and ftrace files to the test output directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) def executeSuspend(quiet=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 	pm = ProcessMonitor()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 	tp = sysvals.tpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 	if sysvals.wifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 		wifi = sysvals.checkWifi()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 	testdata = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 	# run these commands to prepare the system for suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 	if sysvals.display:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 		if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 			pprint('SET DISPLAY TO %s' % sysvals.display.upper())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 		displayControl(sysvals.display)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 		time.sleep(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 	if sysvals.sync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 		if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 			pprint('SYNCING FILESYSTEMS')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 		call('sync', shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 	# mark the start point in the kernel ring buffer just as we start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 	sysvals.initdmesg()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 	# start ftrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 	if(sysvals.usecallgraph or sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 		if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) 			pprint('START TRACING')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 		sysvals.fsetVal('1', 'tracing_on')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) 		if sysvals.useprocmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 			pm.start()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 	sysvals.cmdinfo(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 	# execute however many s/r runs requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 	for count in range(1,sysvals.execcount+1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 		# x2delay in between test runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 		if(count > 1 and sysvals.x2delay > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 			sysvals.fsetVal('WAIT %d' % sysvals.x2delay, 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 			time.sleep(sysvals.x2delay/1000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 			sysvals.fsetVal('WAIT END', 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 		# start message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 		if sysvals.testcommand != '':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) 			pprint('COMMAND START')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) 			if(sysvals.rtcwake):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 				pprint('SUSPEND START')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 				pprint('SUSPEND START (press a key to resume)')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 		# set rtcwake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 		if(sysvals.rtcwake):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 			if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) 				pprint('will issue an rtcwake in %d seconds' % sysvals.rtcwaketime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 			sysvals.rtcWakeAlarmOn()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 		# start of suspend trace marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 		if(sysvals.usecallgraph or sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 			sysvals.fsetVal(datetime.now().strftime(sysvals.tmstart), 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) 		# predelay delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 		if(count == 1 and sysvals.predelay > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 			sysvals.fsetVal('WAIT %d' % sysvals.predelay, 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 			time.sleep(sysvals.predelay/1000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 			sysvals.fsetVal('WAIT END', 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 		# initiate suspend or command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 		tdata = {'error': ''}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 		if sysvals.testcommand != '':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 			res = call(sysvals.testcommand+' 2>&1', shell=True);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 			if res != 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) 				tdata['error'] = 'cmd returned %d' % res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) 			mode = sysvals.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 			if sysvals.memmode and os.path.exists(sysvals.mempowerfile):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) 				mode = 'mem'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 				pf = open(sysvals.mempowerfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 				pf.write(sysvals.memmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 				pf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 			if sysvals.diskmode and os.path.exists(sysvals.diskpowerfile):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 				mode = 'disk'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 				pf = open(sysvals.diskpowerfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) 				pf.write(sysvals.diskmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 				pf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 			if mode == 'freeze' and sysvals.haveTurbostat():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 				# execution will pause here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 				turbo = sysvals.turbostat()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) 				if turbo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) 					tdata['turbo'] = turbo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) 				pf = open(sysvals.powerfile, 'w')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) 				pf.write(mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) 				# execution will pause here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) 				try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) 					pf.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) 				except Exception as e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) 					tdata['error'] = str(e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) 		if(sysvals.rtcwake):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) 			sysvals.rtcWakeAlarmOff()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 		# postdelay delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 		if(count == sysvals.execcount and sysvals.postdelay > 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 			sysvals.fsetVal('WAIT %d' % sysvals.postdelay, 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) 			time.sleep(sysvals.postdelay/1000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 			sysvals.fsetVal('WAIT END', 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 		# return from suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 		pprint('RESUME COMPLETE')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 		if(sysvals.usecallgraph or sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 			sysvals.fsetVal(datetime.now().strftime(sysvals.tmend), 'trace_marker')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 		if sysvals.wifi and wifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 			tdata['wifi'] = sysvals.pollWifi(wifi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 		if(sysvals.suspendmode == 'mem' or sysvals.suspendmode == 'command'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) 			tdata['fw'] = getFPDT(False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 		testdata.append(tdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 	cmdafter = sysvals.cmdinfo(False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 	# stop ftrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 	if(sysvals.usecallgraph or sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 		if sysvals.useprocmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 			pm.stop()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 		sysvals.fsetVal('0', 'tracing_on')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 	# grab a copy of the dmesg output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) 	if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) 		pprint('CAPTURING DMESG')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 	sysvals.getdmesg(testdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 	# grab a copy of the ftrace output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 	if(sysvals.usecallgraph or sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) 		if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 			pprint('CAPTURING TRACE')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) 		op = sysvals.writeDatafileHeader(sysvals.ftracefile, testdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) 		fp = open(tp+'trace', 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) 			op.write(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) 		op.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) 		sysvals.fsetVal('', 'trace')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) 		sysvals.platforminfo(cmdafter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) def readFile(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 	if os.path.islink(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 		return os.readlink(file).split('/')[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 		return sysvals.getVal(file).strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) # Function: ms2nice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) #	 Print out a very concise time string in minutes and seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) #	 The time string, e.g. "1901m16s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) def ms2nice(val):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 	val = int(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 	h = val // 3600000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 	m = (val // 60000) % 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 	s = (val // 1000) % 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 	if h > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 		return '%d:%02d:%02d' % (h, m, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 	if m > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 		return '%02d:%02d' % (m, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 	return '%ds' % s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) def yesno(val):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 	list = {'enabled':'A', 'disabled':'S', 'auto':'E', 'on':'D',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 		'active':'A', 'suspended':'S', 'suspending':'S'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) 	if val not in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 		return ' '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) 	return list[val]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) # Function: deviceInfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) #	 Detect all the USB hosts and devices currently connected and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) #	 a list of USB device names to sysvals for better timeline readability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) def deviceInfo(output=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 	if not output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 		pprint('LEGEND\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 		'---------------------------------------------------------------------------------------------\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 		'  A = async/sync PM queue (A/S)               C = runtime active children\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 		'  R = runtime suspend enabled/disabled (E/D)  rACTIVE = runtime active (min/sec)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 		'  S = runtime status active/suspended (A/S)   rSUSPEND = runtime suspend (min/sec)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 		'  U = runtime usage count\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 		'---------------------------------------------------------------------------------------------\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 		'DEVICE                     NAME                       A R S U C    rACTIVE   rSUSPEND\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 		'---------------------------------------------------------------------------------------------')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 	res = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 	tgtval = 'runtime_status'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 	lines = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 	for dirname, dirnames, filenames in os.walk('/sys/devices'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 		if(not re.match('.*/power', dirname) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 			'control' not in filenames or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 			tgtval not in filenames):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 		name = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 		dirname = dirname[:-6]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 		device = dirname.split('/')[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 		power = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 		power[tgtval] = readFile('%s/power/%s' % (dirname, tgtval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 		# only list devices which support runtime suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 		if power[tgtval] not in ['active', 'suspended', 'suspending']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 		for i in ['product', 'driver', 'subsystem']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 			file = '%s/%s' % (dirname, i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 			if os.path.exists(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 				name = readFile(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 		for i in ['async', 'control', 'runtime_status', 'runtime_usage',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 			'runtime_active_kids', 'runtime_active_time',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 			'runtime_suspended_time']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 			if i in filenames:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 				power[i] = readFile('%s/power/%s' % (dirname, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 		if output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 			if power['control'] == output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 				res.append('%s/power/control' % dirname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 		lines[dirname] = '%-26s %-26s %1s %1s %1s %1s %1s %10s %10s' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 			(device[:26], name[:26],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 			yesno(power['async']), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 			yesno(power['control']), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) 			yesno(power['runtime_status']), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 			power['runtime_usage'], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 			power['runtime_active_kids'], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 			ms2nice(power['runtime_active_time']), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 			ms2nice(power['runtime_suspended_time']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 	for i in sorted(lines):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 		print(lines[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 	return res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) # Function: getModes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) #	 Determine the supported power modes on this system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) #	 A string list of the available modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) def getModes():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 	modes = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 	if(os.path.exists(sysvals.powerfile)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 		fp = open(sysvals.powerfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 		modes = fp.read().split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 	if(os.path.exists(sysvals.mempowerfile)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 		deep = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 		fp = open(sysvals.mempowerfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 		for m in fp.read().split():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 			memmode = m.strip('[]')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 			if memmode == 'deep':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 				deep = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 				modes.append('mem-%s' % memmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) 		if 'mem' in modes and not deep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 			modes.remove('mem')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 	if('disk' in modes and os.path.exists(sysvals.diskpowerfile)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 		fp = open(sysvals.diskpowerfile, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 		for m in fp.read().split():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 			modes.append('disk-%s' % m.strip('[]'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) 	return modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) # Function: dmidecode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) #	 Read the bios tables and pull out system info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) #	 mempath: /dev/mem or custom mem path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) #	 fatal: True to exit on error, False to return empty dict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) #	 A dict object with all available key/values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) def dmidecode(mempath, fatal=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 	out = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 	# the list of values to retrieve, with hardcoded (type, idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 	info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 		'bios-vendor': (0, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 		'bios-version': (0, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 		'bios-release-date': (0, 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 		'system-manufacturer': (1, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 		'system-product-name': (1, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 		'system-version': (1, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 		'system-serial-number': (1, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 		'baseboard-manufacturer': (2, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 		'baseboard-product-name': (2, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 		'baseboard-version': (2, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 		'baseboard-serial-number': (2, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 		'chassis-manufacturer': (3, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 		'chassis-type': (3, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) 		'chassis-version': (3, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 		'chassis-serial-number': (3, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) 		'processor-manufacturer': (4, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) 		'processor-version': (4, 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) 	if(not os.path.exists(mempath)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 		if(fatal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) 			doError('file does not exist: %s' % mempath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 	if(not os.access(mempath, os.R_OK)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) 		if(fatal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) 			doError('file is not readable: %s' % mempath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) 		return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 	# by default use legacy scan, but try to use EFI first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 	memaddr = 0xf0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 	memsize = 0x10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 	for ep in ['/sys/firmware/efi/systab', '/proc/efi/systab']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 		if not os.path.exists(ep) or not os.access(ep, os.R_OK):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 		fp = open(ep, 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 		buf = fp.read()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 		i = buf.find('SMBIOS=')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 		if i >= 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 				memaddr = int(buf[i+7:], 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) 				memsize = 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 	# read in the memory for scanning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 		fp = open(mempath, 'rb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 		fp.seek(memaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 		buf = fp.read(memsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 		if(fatal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 			doError('DMI table is unreachable, sorry')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 			pprint('WARNING: /dev/mem is not readable, ignoring DMI data')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 			return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 	fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	# search for either an SM table or DMI table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 	i = base = length = num = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 	while(i < memsize):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 		if buf[i:i+4] == b'_SM_' and i < memsize - 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 			length = struct.unpack('H', buf[i+22:i+24])[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 			base, num = struct.unpack('IH', buf[i+24:i+30])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 			break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 		elif buf[i:i+5] == b'_DMI_':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 			length = struct.unpack('H', buf[i+6:i+8])[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 			base, num = struct.unpack('IH', buf[i+8:i+14])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 			break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 		i += 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 	if base == 0 and length == 0 and num == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 		if(fatal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 			doError('Neither SMBIOS nor DMI were found')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 			return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 	# read in the SM or DMI table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 		fp = open(mempath, 'rb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 		fp.seek(base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 		buf = fp.read(length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 		if(fatal):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 			doError('DMI table is unreachable, sorry')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 			pprint('WARNING: /dev/mem is not readable, ignoring DMI data')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 			return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) 	fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) 	# scan the table for the values we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) 	count = i = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) 	while(count < num and i <= len(buf) - 4):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) 		type, size, handle = struct.unpack('BBH', buf[i:i+4])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) 		n = i + size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) 		while n < len(buf) - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) 			if 0 == struct.unpack('H', buf[n:n+2])[0]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) 			n += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) 		data = buf[i+size:n+2].split(b'\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 		for name in info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 			itype, idxadr = info[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 			if itype == type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 				idx = struct.unpack('B', buf[i+idxadr:i+idxadr+1])[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 				if idx > 0 and idx < len(data) - 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 					s = data[idx-1].decode('utf-8')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) 					if s.strip() and s.strip().lower() != 'to be filled by o.e.m.':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 						out[name] = s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 		i = n + 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 		count += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 	return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) def displayControl(cmd):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 	xset, ret = 'timeout 10 xset -d :0.0 {0}', 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 	if sysvals.sudouser:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 		xset = 'sudo -u %s %s' % (sysvals.sudouser, xset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 	if cmd == 'init':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 		ret = call(xset.format('dpms 0 0 0'), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 		if not ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 			ret = call(xset.format('s off'), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 	elif cmd == 'reset':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) 		ret = call(xset.format('s reset'), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 	elif cmd in ['on', 'off', 'standby', 'suspend']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 		b4 = displayControl('stat')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 		ret = call(xset.format('dpms force %s' % cmd), shell=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 		if not ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 			curr = displayControl('stat')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 			sysvals.vprint('Display Switched: %s -> %s' % (b4, curr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 			if curr != cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 				sysvals.vprint('WARNING: Display failed to change to %s' % cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 		if ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 			sysvals.vprint('WARNING: Display failed to change to %s with xset' % cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 			return ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 	elif cmd == 'stat':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 		fp = Popen(xset.format('q').split(' '), stdout=PIPE).stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 		ret = 'unknown'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 		for line in fp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 			m = re.match('[\s]*Monitor is (?P<m>.*)', ascii(line))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 			if(m and len(m.group('m')) >= 2):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 				out = m.group('m').lower()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 				ret = out[3:] if out[0:2] == 'in' else out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 		fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 	return ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) # Function: getFPDT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) #	 Read the acpi bios tables and pull out FPDT, the firmware data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) #	 output: True to output the info to stdout, False otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) def getFPDT(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 	rectype = {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 	rectype[0] = 'Firmware Basic Boot Performance Record'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 	rectype[1] = 'S3 Performance Table Record'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 	prectype = {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 	prectype[0] = 'Basic S3 Resume Performance Record'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 	prectype[1] = 'Basic S3 Suspend Performance Record'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 	sysvals.rootCheck(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 	if(not os.path.exists(sysvals.fpdtpath)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 			doError('file does not exist: %s' % sysvals.fpdtpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 	if(not os.access(sysvals.fpdtpath, os.R_OK)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 			doError('file is not readable: %s' % sysvals.fpdtpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) 	if(not os.path.exists(sysvals.mempath)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) 			doError('file does not exist: %s' % sysvals.mempath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) 	if(not os.access(sysvals.mempath, os.R_OK)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) 			doError('file is not readable: %s' % sysvals.mempath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 	fp = open(sysvals.fpdtpath, 'rb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 	buf = fp.read()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 	fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 	if(len(buf) < 36):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) 			doError('Invalid FPDT table data, should '+\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 				'be at least 36 bytes')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 	table = struct.unpack('4sIBB6s8sI4sI', buf[0:36])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 	if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 		pprint('\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 		'Firmware Performance Data Table (%s)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 		'                  Signature : %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 		'               Table Length : %u\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 		'                   Revision : %u\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 		'                   Checksum : 0x%x\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 		'                     OEM ID : %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 		'               OEM Table ID : %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 		'               OEM Revision : %u\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 		'                 Creator ID : %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) 		'           Creator Revision : 0x%x\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 		'' % (ascii(table[0]), ascii(table[0]), table[1], table[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 			table[3], ascii(table[4]), ascii(table[5]), table[6],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 			ascii(table[7]), table[8]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 	if(table[0] != b'FPDT'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 			doError('Invalid FPDT table')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 	if(len(buf) <= 36):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 	i = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 	fwData = [0, 0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 	records = buf[36:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 		fp = open(sysvals.mempath, 'rb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) 		pprint('WARNING: /dev/mem is not readable, ignoring the FPDT data')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 	while(i < len(records)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 		header = struct.unpack('HBB', records[i:i+4])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 		if(header[0] not in rectype):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) 			i += header[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 		if(header[1] != 16):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 			i += header[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 		addr = struct.unpack('Q', records[i+8:i+16])[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) 			fp.seek(addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) 			first = fp.read(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) 			if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 				pprint('Bad address 0x%x in %s' % (addr, sysvals.mempath))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 			return [0, 0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 		rechead = struct.unpack('4sI', first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 		recdata = fp.read(rechead[1]-8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 		if(rechead[0] == b'FBPT'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 			record = struct.unpack('HBBIQQQQQ', recdata[:48])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 			if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 				pprint('%s (%s)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 				'                  Reset END : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 				'  OS Loader LoadImage Start : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 				' OS Loader StartImage Start : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 				'     ExitBootServices Entry : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) 				'      ExitBootServices Exit : %u ns'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 				'' % (rectype[header[0]], ascii(rechead[0]), record[4], record[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 					record[6], record[7], record[8]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 		elif(rechead[0] == b'S3PT'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 			if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 				pprint('%s (%s)' % (rectype[header[0]], ascii(rechead[0])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 			j = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 			while(j < len(recdata)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 				prechead = struct.unpack('HBB', recdata[j:j+4])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 				if(prechead[0] not in prectype):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 					continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 				if(prechead[0] == 0):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 					record = struct.unpack('IIQQ', recdata[j:j+prechead[1]])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 					fwData[1] = record[2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 					if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 						pprint('    %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 						'               Resume Count : %u\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 						'                 FullResume : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 						'              AverageResume : %u ns'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 						'' % (prectype[prechead[0]], record[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 								record[2], record[3]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 				elif(prechead[0] == 1):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 					record = struct.unpack('QQ', recdata[j+4:j+prechead[1]])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) 					fwData[0] = record[1] - record[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) 					if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) 						pprint('    %s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) 						'               SuspendStart : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 						'                 SuspendEnd : %u ns\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 						'                SuspendTime : %u ns'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) 						'' % (prectype[prechead[0]], record[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 								record[1], fwData[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 				j += prechead[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 		if(output):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 			pprint('')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) 		i += header[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 	fp.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) 	return fwData
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) # Function: statusCheck
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) #	 Verify that the requested command and options will work, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) #	 print the results to the terminal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) # Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) #	 True if the test will work, False if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) def statusCheck(probecheck=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) 	status = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 	pprint('Checking this system (%s)...' % platform.node())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 	# check we have root access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 	res = sysvals.colorText('NO (No features of this tool will work!)')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 	if(sysvals.rootCheck(False)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 		res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 	pprint('    have root access: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 	if(res != 'YES'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) 		pprint('    Try running this script with sudo')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) 		return 'missing root access'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) 	# check sysfs is mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) 	res = sysvals.colorText('NO (No features of this tool will work!)')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 	if(os.path.exists(sysvals.powerfile)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 		res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) 	pprint('    is sysfs mounted: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 	if(res != 'YES'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) 		return 'sysfs is missing'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 	# check target mode is a valid mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) 	if sysvals.suspendmode != 'command':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) 		res = sysvals.colorText('NO')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) 		modes = getModes()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) 		if(sysvals.suspendmode in modes):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) 			res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) 			status = '%s mode is not supported' % sysvals.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 		pprint('    is "%s" a valid power mode: %s' % (sysvals.suspendmode, res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 		if(res == 'NO'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 			pprint('      valid power modes are: %s' % modes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 			pprint('      please choose one with -m')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 	# check if ftrace is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 	res = sysvals.colorText('NO')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 	ftgood = sysvals.verifyFtrace()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 	if(ftgood):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 		res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 	elif(sysvals.usecallgraph):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 		status = 'ftrace is not properly supported'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 	pprint('    is ftrace supported: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 	# check if kprobes are available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 	if sysvals.usekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 		res = sysvals.colorText('NO')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 		sysvals.usekprobes = sysvals.verifyKprobes()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 		if(sysvals.usekprobes):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 			res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 			sysvals.usedevsrc = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 		pprint('    are kprobes supported: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 	# what data source are we using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 	res = 'DMESG'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 	if(ftgood):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 		sysvals.usetraceevents = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 		for e in sysvals.traceevents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 			if not os.path.exists(sysvals.epath+e):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 				sysvals.usetraceevents = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 		if(sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 			res = 'FTRACE (all trace events found)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 	pprint('    timeline data source: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 	# check if rtcwake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 	res = sysvals.colorText('NO')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 	if(sysvals.rtcpath != ''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 		res = 'YES'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 	elif(sysvals.rtcwake):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 		status = 'rtcwake is not properly supported'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 	pprint('    is rtcwake supported: %s' % res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 	# check info commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 	pprint('    optional commands this tool may use for info:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 	no = sysvals.colorText('MISSING')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) 	yes = sysvals.colorText('FOUND', 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 	for c in ['turbostat', 'mcelog', 'lspci', 'lsusb']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) 		if c == 'turbostat':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) 			res = yes if sysvals.haveTurbostat() else no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 			res = yes if sysvals.getExec(c) else no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 		pprint('        %s: %s' % (c, res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 	if not probecheck:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 		return status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 	# verify kprobes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 	if sysvals.usekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 		for name in sysvals.tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 			sysvals.defaultKprobe(name, sysvals.tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 		if sysvals.usedevsrc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 			for name in sysvals.dev_tracefuncs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 				sysvals.defaultKprobe(name, sysvals.dev_tracefuncs[name])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 		sysvals.addKprobes(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 	return status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) # Function: doError
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) #	 generic error function for catastrphic failures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) # Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) #	 msg: the error message to print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) #	 help: True if printHelp should be called after, False otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) def doError(msg, help=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) 	if(help == True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 		printHelp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) 	pprint('ERROR: %s\n' % msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 	sysvals.outputResult({'error':msg})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 	sys.exit(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) # Function: getArgInt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) #	 pull out an integer argument from the command line with checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) def getArgInt(name, args, min, max, main=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 	if main:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 			arg = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 			doError(name+': no argument supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 		arg = args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 		val = int(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 		doError(name+': non-integer value given', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 	if(val < min or val > max):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 		doError(name+': value should be between %d and %d' % (min, max), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 	return val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) # Function: getArgFloat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) #	 pull out a float argument from the command line with checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) def getArgFloat(name, args, min, max, main=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 	if main:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) 			arg = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 		except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) 			doError(name+': no argument supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 		arg = args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 		val = float(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) 		doError(name+': non-numerical value given', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) 	if(val < min or val > max):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) 		doError(name+': value should be between %f and %f' % (min, max), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 	return val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) def processData(live=False, quiet=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 	if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 		pprint('PROCESSING: %s' % sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 	sysvals.vprint('usetraceevents=%s, usetracemarkers=%s, usekprobes=%s' % \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 		(sysvals.usetraceevents, sysvals.usetracemarkers, sysvals.usekprobes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 	error = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 	if(sysvals.usetraceevents):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 		testruns, error = parseTraceLog(live)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 		if sysvals.dmesgfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 			for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 				data.extractErrorInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 		testruns = loadKernelLog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 		for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 			parseKernelLog(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 		if(sysvals.ftracefile and (sysvals.usecallgraph or sysvals.usetraceevents)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 			appendIncompleteTraceLog(testruns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 	if not sysvals.stamp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 		pprint('ERROR: data does not include the expected stamp')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 		return (testruns, {'error': 'timeline generation failed'})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 	shown = ['bios', 'biosdate', 'cpu', 'host', 'kernel', 'man', 'memfr',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 			'memsz', 'mode', 'numcpu', 'plat', 'time', 'wifi']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 	sysvals.vprint('System Info:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 	for key in sorted(sysvals.stamp):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 		if key in shown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 			sysvals.vprint('    %-8s : %s' % (key.upper(), sysvals.stamp[key]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 	sysvals.vprint('Command:\n    %s' % sysvals.cmdline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 		if data.turbostat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 			idx, s = 0, 'Turbostat:\n    '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 			for val in data.turbostat.split('|'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 				idx += len(val) + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 				if idx >= 80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 					idx = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 					s += '\n    '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 				s += val + ' '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 			sysvals.vprint(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 		data.printDetails()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 	if len(sysvals.platinfo) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 		sysvals.vprint('\nPlatform Info:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 		for info in sysvals.platinfo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 			sysvals.vprint('[%s - %s]' % (info[0], info[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 			sysvals.vprint(info[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 		sysvals.vprint('')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 	if sysvals.cgdump:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 		for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 			data.debugPrint()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 		sys.exit(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 	if len(testruns) < 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 		pprint('ERROR: Not enough test data to build a timeline')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 		return (testruns, {'error': 'timeline generation failed'})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 	sysvals.vprint('Creating the html timeline (%s)...' % sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 	createHTML(testruns, error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 	if not quiet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 		pprint('DONE:       %s' % sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 	data = testruns[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 	stamp = data.stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 	stamp['suspend'], stamp['resume'] = data.getTimeValues()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 	if data.fwValid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 		stamp['fwsuspend'], stamp['fwresume'] = data.fwSuspend, data.fwResume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 	if error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 		stamp['error'] = error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 	return (testruns, stamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) # Function: rerunTest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) #	 generate an output from an existing set of ftrace/dmesg logs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) def rerunTest(htmlfile=''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 	if sysvals.ftracefile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 		doesTraceLogHaveTraceEvents()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 	if not sysvals.dmesgfile and not sysvals.usetraceevents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 		doError('recreating this html output requires a dmesg file')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 	if htmlfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 		sysvals.htmlfile = htmlfile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 		sysvals.setOutputFile()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 	if os.path.exists(sysvals.htmlfile):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 		if not os.path.isfile(sysvals.htmlfile):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 			doError('a directory already exists with this name: %s' % sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 		elif not os.access(sysvals.htmlfile, os.W_OK):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 			doError('missing permission to write to %s' % sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 	testruns, stamp = processData()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 	sysvals.resetlog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 	return stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) # Function: runTest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) #	 execute a suspend/resume, gather the logs, and generate the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) def runTest(n=0, quiet=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 	# prepare for the test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 	sysvals.initFtrace(quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 	sysvals.initTestOutput('suspend')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 	# execute the test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 	executeSuspend(quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 	sysvals.cleanupFtrace()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 	if sysvals.skiphtml:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) 		sysvals.outputResult({}, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 		sysvals.sudoUserchown(sysvals.testdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 	testruns, stamp = processData(True, quiet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 	for data in testruns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 		del data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 	sysvals.sudoUserchown(sysvals.testdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 	sysvals.outputResult(stamp, n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) 	if 'error' in stamp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) 		return 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) def find_in_html(html, start, end, firstonly=True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 	cnt, out, list = len(html), [], []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 	if firstonly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 		m = re.search(start, html)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) 		if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) 			list.append(m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) 		list = re.finditer(start, html)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 	for match in list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) 		s = match.end()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 		e = cnt if (len(out) < 1 or s + 10000 > cnt) else s + 10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 		m = re.search(end, html[s:e])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 		if not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 			break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 		e = s + m.start()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 		str = html[s:e]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 		if end == 'ms':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 			num = re.search(r'[-+]?\d*\.\d+|\d+', str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 			str = num.group() if num else 'NaN'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 		if firstonly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 			return str
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 		out.append(str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 	if firstonly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 		return ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 	return out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) def data_from_html(file, outpath, issues, fulldetail=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) 	html = open(file, 'r').read()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 	sysvals.htmlfile = os.path.relpath(file, outpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 	# extract general info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 	suspend = find_in_html(html, 'Kernel Suspend', 'ms')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) 	resume = find_in_html(html, 'Kernel Resume', 'ms')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) 	sysinfo = find_in_html(html, '<div class="stamp sysinfo">', '</div>')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 	line = find_in_html(html, '<div class="stamp">', '</div>')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 	stmp = line.split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 	if not suspend or not resume or len(stmp) != 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 		dt = datetime.strptime(' '.join(stmp[3:]), '%B %d %Y, %I:%M:%S %p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 		return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 	sysvals.hostname = stmp[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 	tstr = dt.strftime('%Y/%m/%d %H:%M:%S')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 	error = find_in_html(html, '<table class="testfail"><tr><td>', '</td>')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 	if error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 		m = re.match('[a-z0-9]* failed in (?P<p>\S*).*', error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 		if m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) 			result = 'fail in %s' % m.group('p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 			result = 'fail'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 		result = 'pass'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 	# extract error info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 	tp, ilist = False, []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 	extra = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 	log = find_in_html(html, '<div id="dmesglog" style="display:none;">',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 		'</div>').strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) 	if log:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 		d = Data(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 		d.end = 999999999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) 		d.dmesgtext = log.split('\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 		tp = d.extractErrorInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) 		for msg in tp.msglist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) 			sysvals.errorSummary(issues, msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 		if stmp[2] == 'freeze':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) 			extra = d.turbostatInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 		elist = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 		for dir in d.errorinfo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 			for err in d.errorinfo[dir]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) 				if err[0] not in elist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 					elist[err[0]] = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 				elist[err[0]] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 		for i in elist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 			ilist.append('%sx%d' % (i, elist[i]) if elist[i] > 1 else i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 	wifi = find_in_html(html, 'Wifi Resume: ', '</td>')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 	if wifi:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 		extra['wifi'] = wifi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) 	low = find_in_html(html, 'freeze time: <b>', ' ms</b>')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 	if low and 'waking' in low:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 		issue = 'FREEZEWAKE'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 		match = [i for i in issues if i['match'] == issue]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 		if len(match) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 			match[0]['count'] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 			if sysvals.hostname not in match[0]['urls']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 				match[0]['urls'][sysvals.hostname] = [sysvals.htmlfile]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 			elif sysvals.htmlfile not in match[0]['urls'][sysvals.hostname]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 				match[0]['urls'][sysvals.hostname].append(sysvals.htmlfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 			issues.append({
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 				'match': issue, 'count': 1, 'line': issue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 				'urls': {sysvals.hostname: [sysvals.htmlfile]},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 			})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 		ilist.append(issue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 	# extract device info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 	devices = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 	for line in html.split('\n'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 		m = re.match(' *<div id=\"[a,0-9]*\" *title=\"(?P<title>.*)\" class=\"thread.*', line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 		if not m or 'thread kth' in line or 'thread sec' in line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 		m = re.match('(?P<n>.*) \((?P<t>[0-9,\.]*) ms\) (?P<p>.*)', m.group('title'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 		if not m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 		name, time, phase = m.group('n'), m.group('t'), m.group('p')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 		if ' async' in name or ' sync' in name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 			name = ' '.join(name.split(' ')[:-1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 		if phase.startswith('suspend'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) 			d = 'suspend'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 		elif phase.startswith('resume'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 			d = 'resume'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 			continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 		if d not in devices:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 			devices[d] = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) 		if name not in devices[d]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 			devices[d][name] = 0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 		devices[d][name] += float(time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 	# create worst device info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 	worst = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 	for d in ['suspend', 'resume']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) 		worst[d] = {'name':'', 'time': 0.0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 		dev = devices[d] if d in devices else 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 		if dev and len(dev.keys()) > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 			n = sorted(dev, key=lambda k:(dev[k], k), reverse=True)[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 			worst[d]['name'], worst[d]['time'] = n, dev[n]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) 	data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 		'mode': stmp[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) 		'host': stmp[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 		'kernel': stmp[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) 		'sysinfo': sysinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 		'time': tstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) 		'result': result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) 		'issues': ' '.join(ilist),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) 		'suspend': suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 		'resume': resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) 		'devlist': devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 		'sus_worst': worst['suspend']['name'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 		'sus_worsttime': worst['suspend']['time'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 		'res_worst': worst['resume']['name'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) 		'res_worsttime': worst['resume']['time'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) 		'url': sysvals.htmlfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) 	for key in extra:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) 		data[key] = extra[key]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) 	if fulldetail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) 		data['funclist'] = find_in_html(html, '<div title="', '" class="traceevent"', False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 	if tp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) 		for arg in ['-multi ', '-info ']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 			if arg in tp.cmdline:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) 				data['target'] = tp.cmdline[tp.cmdline.find(arg):].split()[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) 	return data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) def genHtml(subdir, force=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 	for dirname, dirnames, filenames in os.walk(subdir):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 		sysvals.dmesgfile = sysvals.ftracefile = sysvals.htmlfile = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 		for filename in filenames:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 			file = os.path.join(dirname, filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 			if sysvals.usable(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 				if(re.match('.*_dmesg.txt', filename)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 					sysvals.dmesgfile = file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 				elif(re.match('.*_ftrace.txt', filename)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) 					sysvals.ftracefile = file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 		sysvals.setOutputFile()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 		if (sysvals.dmesgfile or sysvals.ftracefile) and sysvals.htmlfile and \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) 			(force or not sysvals.usable(sysvals.htmlfile)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) 			pprint('FTRACE: %s' % sysvals.ftracefile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 			if sysvals.dmesgfile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) 				pprint('DMESG : %s' % sysvals.dmesgfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) 			rerunTest()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) # Function: runSummary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) #	 create a summary of tests in a sub-directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) def runSummary(subdir, local=True, genhtml=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 	inpath = os.path.abspath(subdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	outpath = os.path.abspath('.') if local else inpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 	pprint('Generating a summary of folder:\n   %s' % inpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	if genhtml:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 		genHtml(subdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 	target, issues, testruns = '', [], []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) 	desc = {'host':[],'mode':[],'kernel':[]}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 	for dirname, dirnames, filenames in os.walk(subdir):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) 		for filename in filenames:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) 			if(not re.match('.*.html', filename)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 			data = data_from_html(os.path.join(dirname, filename), outpath, issues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 			if(not data):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 			if 'target' in data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 				target = data['target']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 			testruns.append(data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 			for key in desc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 				if data[key] not in desc[key]:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) 					desc[key].append(data[key])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 	pprint('Summary files:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) 	if len(desc['host']) == len(desc['mode']) == len(desc['kernel']) == 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 		title = '%s %s %s' % (desc['host'][0], desc['kernel'][0], desc['mode'][0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 		if target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 			title += ' %s' % target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 		title = inpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) 	createHTMLSummarySimple(testruns, os.path.join(outpath, 'summary.html'), title)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 	pprint('   summary.html         - tabular list of test data found')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 	createHTMLDeviceSummary(testruns, os.path.join(outpath, 'summary-devices.html'), title)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 	pprint('   summary-devices.html - kernel device list sorted by total execution time')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 	createHTMLIssuesSummary(testruns, issues, os.path.join(outpath, 'summary-issues.html'), title)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 	pprint('   summary-issues.html  - kernel issues found sorted by frequency')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) # Function: checkArgBool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) #	 check if a boolean string value is true or false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) def checkArgBool(name, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 	if value in switchvalues:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 		if value in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 			return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 		return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 	doError('invalid boolean --> (%s: %s), use "true/false" or "1/0"' % (name, value), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 	return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) # Function: configFromFile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) #	 Configure the script via the info in a config file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) def configFromFile(file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 	Config = configparser.ConfigParser()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 	Config.read(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 	sections = Config.sections()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 	overridekprobes = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 	overridedevkprobes = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 	if 'Settings' in sections:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 		for opt in Config.options('Settings'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 			value = Config.get('Settings', opt).lower()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 			option = opt.lower()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 			if(option == 'verbose'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) 				sysvals.verbose = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 			elif(option == 'addlogs'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) 				sysvals.dmesglog = sysvals.ftracelog = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) 			elif(option == 'dev'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 				sysvals.usedevsrc = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 			elif(option == 'proc'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) 				sysvals.useprocmon = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 			elif(option == 'x2'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 				if checkArgBool(option, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 					sysvals.execcount = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 			elif(option == 'callgraph'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 				sysvals.usecallgraph = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 			elif(option == 'override-timeline-functions'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 				overridekprobes = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 			elif(option == 'override-dev-timeline-functions'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) 				overridedevkprobes = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 			elif(option == 'skiphtml'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 				sysvals.skiphtml = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) 			elif(option == 'sync'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 				sysvals.sync = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) 			elif(option == 'rs' or option == 'runtimesuspend'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 				if value in switchvalues:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) 					if value in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) 						sysvals.rs = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 					else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 						sysvals.rs = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 					doError('invalid value --> (%s: %s), use "enable/disable"' % (option, value), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 			elif(option == 'display'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 				disopt = ['on', 'off', 'standby', 'suspend']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 				if value not in disopt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 					doError('invalid value --> (%s: %s), use %s' % (option, value, disopt), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 				sysvals.display = value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 			elif(option == 'gzip'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 				sysvals.gzip = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 			elif(option == 'cgfilter'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 				sysvals.setCallgraphFilter(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 			elif(option == 'cgskip'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 				if value in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 					sysvals.cgskip = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 					sysvals.cgskip = sysvals.configFile(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 					if(not sysvals.cgskip):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 						doError('%s does not exist' % sysvals.cgskip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 			elif(option == 'cgtest'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 				sysvals.cgtest = getArgInt('cgtest', value, 0, 1, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 			elif(option == 'cgphase'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 				d = Data(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 				if value not in d.phasedef:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 					doError('invalid phase --> (%s: %s), valid phases are %s'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 						% (option, value, d.phasedef.keys()), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 				sysvals.cgphase = value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 			elif(option == 'fadd'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 				file = sysvals.configFile(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 				if(not file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 					doError('%s does not exist' % value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 				sysvals.addFtraceFilterFunctions(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 			elif(option == 'result'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 				sysvals.result = value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 			elif(option == 'multi'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 				nums = value.split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) 				if len(nums) != 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 					doError('multi requires 2 integers (exec_count and delay)', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) 				sysvals.multiinit(nums[0], nums[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 			elif(option == 'devicefilter'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 				sysvals.setDeviceFilter(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 			elif(option == 'expandcg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 				sysvals.cgexp = checkArgBool(option, value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 			elif(option == 'srgap'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 				if checkArgBool(option, value):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 					sysvals.srgap = 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 			elif(option == 'mode'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 				sysvals.suspendmode = value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 			elif(option == 'command' or option == 'cmd'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 				sysvals.testcommand = value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 			elif(option == 'x2delay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 				sysvals.x2delay = getArgInt('x2delay', value, 0, 60000, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 			elif(option == 'predelay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 				sysvals.predelay = getArgInt('predelay', value, 0, 60000, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 			elif(option == 'postdelay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 				sysvals.postdelay = getArgInt('postdelay', value, 0, 60000, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 			elif(option == 'maxdepth'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 				sysvals.max_graph_depth = getArgInt('maxdepth', value, 0, 1000, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 			elif(option == 'rtcwake'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 				if value in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 					sysvals.rtcwake = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 					sysvals.rtcwake = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 					sysvals.rtcwaketime = getArgInt('rtcwake', value, 0, 3600, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 			elif(option == 'timeprec'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 				sysvals.setPrecision(getArgInt('timeprec', value, 0, 6, False))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) 			elif(option == 'mindev'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 				sysvals.mindevlen = getArgFloat('mindev', value, 0.0, 10000.0, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 			elif(option == 'callloop-maxgap'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 				sysvals.callloopmaxgap = getArgFloat('callloop-maxgap', value, 0.0, 1.0, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 			elif(option == 'callloop-maxlen'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 				sysvals.callloopmaxgap = getArgFloat('callloop-maxlen', value, 0.0, 1.0, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 			elif(option == 'mincg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 				sysvals.mincglen = getArgFloat('mincg', value, 0.0, 10000.0, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 			elif(option == 'bufsize'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) 				sysvals.bufsize = getArgInt('bufsize', value, 1, 1024*1024*8, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 			elif(option == 'output-dir'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) 				sysvals.outdir = sysvals.setOutputFolder(value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 	if sysvals.suspendmode == 'command' and not sysvals.testcommand:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) 		doError('No command supplied for mode "command"')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) 	# compatibility errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 	if sysvals.usedevsrc and sysvals.usecallgraph:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 		doError('-dev is not compatible with -f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 	if sysvals.usecallgraph and sysvals.useprocmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 		doError('-proc is not compatible with -f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 	if overridekprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 		sysvals.tracefuncs = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) 	if overridedevkprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) 		sysvals.dev_tracefuncs = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) 	kprobes = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) 	kprobesec = 'dev_timeline_functions_'+platform.machine()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 	if kprobesec in sections:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) 		for name in Config.options(kprobesec):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 			text = Config.get(kprobesec, name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 			kprobes[name] = (text, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 	kprobesec = 'timeline_functions_'+platform.machine()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 	if kprobesec in sections:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 		for name in Config.options(kprobesec):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 			if name in kprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 				doError('Duplicate timeline function found "%s"' % (name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 			text = Config.get(kprobesec, name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 			kprobes[name] = (text, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 	for name in kprobes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 		function = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 		format = name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 		color = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 		args = dict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 		text, dev = kprobes[name]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 		data = text.split()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 		i = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 		for val in data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 			# bracketted strings are special formatting, read them separately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 			if val[0] == '[' and val[-1] == ']':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 				for prop in val[1:-1].split(','):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 					p = prop.split('=')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 					if p[0] == 'color':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 						try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 							color = int(p[1], 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 							color = '#'+p[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 						except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 							color = p[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 				continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 			# first real arg should be the format string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) 			if i == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 				format = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 			# all other args are actual function args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 				d = val.split('=')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 				args[d[0]] = d[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) 			i += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 		if not function or not format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) 			doError('Invalid kprobe: %s' % name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 		for arg in re.findall('{(?P<n>[a-z,A-Z,0-9]*)}', format):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 			if arg not in args:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 				doError('Kprobe "%s" is missing argument "%s"' % (name, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 		if (dev and name in sysvals.dev_tracefuncs) or (not dev and name in sysvals.tracefuncs):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 			doError('Duplicate timeline function found "%s"' % (name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 		kp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 			'name': name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 			'func': function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 			'format': format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 			sysvals.archargs: args
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 		if color:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 			kp['color'] = color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 		if dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 			sysvals.dev_tracefuncs[name] = kp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 			sysvals.tracefuncs[name] = kp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) # Function: printHelp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) # Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) #	 print out the help text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) def printHelp():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) 	pprint('\n%s v%s\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) 	'Usage: sudo sleepgraph <options> <commands>\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 	'\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 	'Description:\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) 	'  This tool is designed to assist kernel and OS developers in optimizing\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 	'  their linux stack\'s suspend/resume time. Using a kernel image built\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 	'  with a few extra options enabled, the tool will execute a suspend and\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 	'  capture dmesg and ftrace data until resume is complete. This data is\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 	'  transformed into a device timeline and an optional callgraph to give\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 	'  a detailed view of which devices/subsystems are taking the most\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 	'  time in suspend/resume.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 	'\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 	'  If no specific command is given, the default behavior is to initiate\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 	'  a suspend/resume and capture the dmesg/ftrace output as an html timeline.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	'\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 	'  Generates output files in subdirectory: suspend-yymmdd-HHMMSS\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 	'   HTML output:                    <hostname>_<mode>.html\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 	'   raw dmesg output:               <hostname>_<mode>_dmesg.txt\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) 	'   raw ftrace output:              <hostname>_<mode>_ftrace.txt\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 	'\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) 	'Options:\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) 	'   -h           Print this help text\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) 	'   -v           Print the current tool version\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) 	'   -config fn   Pull arguments and config options from file fn\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) 	'   -verbose     Print extra information during execution and analysis\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) 	'   -m mode      Mode to initiate for suspend (default: %s)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) 	'   -o name      Overrides the output subdirectory name when running a new test\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) 	'                default: suspend-{date}-{time}\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) 	'   -rtcwake t   Wakeup t seconds after suspend, set t to "off" to disable (default: 15)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) 	'   -addlogs     Add the dmesg and ftrace logs to the html output\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 	'   -noturbostat Dont use turbostat in freeze mode (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 	'   -srgap       Add a visible gap in the timeline between sus/res (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 	'   -skiphtml    Run the test and capture the trace logs, but skip the timeline (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 	'   -result fn   Export a results table to a text file for parsing.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 	'   -wifi        If a wifi connection is available, check that it reconnects after resume.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 	'  [testprep]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 	'   -sync        Sync the filesystems before starting the test\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 	'   -rs on/off   Enable/disable runtime suspend for all devices, restore all after test\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 	'   -display m   Change the display mode to m for the test (on/off/standby/suspend)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 	'  [advanced]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 	'   -gzip        Gzip the trace and dmesg logs to save space\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 	'   -cmd {s}     Run the timeline over a custom command, e.g. "sync -d"\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 	'   -proc        Add usermode process info into the timeline (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 	'   -dev         Add kernel function calls and threads to the timeline (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 	'   -x2          Run two suspend/resumes back to back (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 	'   -x2delay t   Include t ms delay between multiple test runs (default: 0 ms)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 	'   -predelay t  Include t ms delay before 1st suspend (default: 0 ms)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 	'   -postdelay t Include t ms delay after last resume (default: 0 ms)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 	'   -mindev ms   Discard all device blocks shorter than ms milliseconds (e.g. 0.001 for us)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 	'   -multi n d   Execute <n> consecutive tests at <d> seconds intervals. If <n> is followed\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 	'                by a "d", "h", or "m" execute for <n> days, hours, or mins instead.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 	'                The outputs will be created in a new subdirectory with a summary page.\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 	'   -maxfail n   Abort a -multi run after n consecutive fails (default is 0 = never abort)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 	'  [debug]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 	'   -f           Use ftrace to create device callgraphs (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) 	'   -ftop        Use ftrace on the top level call: "%s" (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 	'   -maxdepth N  limit the callgraph data to N call levels (default: 0=all)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 	'   -expandcg    pre-expand the callgraph data in the html output (default: disabled)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 	'   -fadd file   Add functions to be graphed in the timeline from a list in a text file\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 	'   -filter "d1,d2,..." Filter out all but this comma-delimited list of device names\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 	'   -mincg  ms   Discard all callgraphs shorter than ms milliseconds (e.g. 0.001 for us)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 	'   -cgphase P   Only show callgraph data for phase P (e.g. suspend_late)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 	'   -cgtest N    Only show callgraph data for test N (e.g. 0 or 1 in an x2 run)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 	'   -timeprec N  Number of significant digits in timestamps (0:S, [3:ms], 6:us)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 	'   -cgfilter S  Filter the callgraph output in the timeline\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 	'   -cgskip file Callgraph functions to skip, off to disable (default: cgskip.txt)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 	'   -bufsize N   Set trace buffer size to N kilo-bytes (default: all of free memory)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 	'   -devdump     Print out all the raw device data for each phase\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 	'   -cgdump      Print out all the raw callgraph data\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) 	'\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 	'Other commands:\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 	'   -modes       List available suspend modes\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 	'   -status      Test to see if the system is enabled to run this tool\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 	'   -fpdt        Print out the contents of the ACPI Firmware Performance Data Table\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 	'   -wificheck   Print out wifi connection info\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 	'   -x<mode>     Test xset by toggling the given mode (on/off/standby/suspend)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 	'   -sysinfo     Print out system info extracted from BIOS\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 	'   -devinfo     Print out the pm settings of all devices which support runtime suspend\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 	'   -cmdinfo     Print out all the platform info collected before and after suspend/resume\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 	'   -flist       Print the list of functions currently being captured in ftrace\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 	'   -flistall    Print all functions capable of being captured in ftrace\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 	'   -summary dir Create a summary of tests in this dir [-genhtml builds missing html]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 	'  [redo]\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 	'   -ftrace ftracefile  Create HTML output using ftrace input (used with -dmesg)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 	'   -dmesg dmesgfile    Create HTML output using dmesg (used with -ftrace)\n'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 	'' % (sysvals.title, sysvals.version, sysvals.suspendmode, sysvals.ftopfunc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 	return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) # ----------------- MAIN --------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) # exec start (skipped if script is loaded as library)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) if __name__ == '__main__':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 	genhtml = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 	cmd = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 	simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 		'-devinfo', '-status', '-xon', '-xoff', '-xstandby', '-xsuspend',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 		'-xinit', '-xreset', '-xstat', '-wificheck', '-cmdinfo']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 	if '-f' in sys.argv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 		sysvals.cgskip = sysvals.configFile('cgskip.txt')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 	# loop through the command line arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) 	args = iter(sys.argv[1:])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 	for arg in args:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 		if(arg == '-m'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 				doError('No mode supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 			if val == 'command' and not sysvals.testcommand:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 				doError('No command supplied for mode "command"', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 			sysvals.suspendmode = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 		elif(arg in simplecmds):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 			cmd = arg[1:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 		elif(arg == '-h'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 			printHelp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 			sys.exit(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) 		elif(arg == '-v'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 			pprint("Version %s" % sysvals.version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) 			sys.exit(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 		elif(arg == '-x2'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 			sysvals.execcount = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 		elif(arg == '-x2delay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 			sysvals.x2delay = getArgInt('-x2delay', args, 0, 60000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 		elif(arg == '-predelay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 			sysvals.predelay = getArgInt('-predelay', args, 0, 60000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) 		elif(arg == '-postdelay'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 			sysvals.postdelay = getArgInt('-postdelay', args, 0, 60000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 		elif(arg == '-f'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 			sysvals.usecallgraph = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 		elif(arg == '-ftop'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 			sysvals.usecallgraph = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 			sysvals.ftop = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 			sysvals.usekprobes = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 		elif(arg == '-skiphtml'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 			sysvals.skiphtml = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) 		elif(arg == '-cgdump'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) 			sysvals.cgdump = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) 		elif(arg == '-devdump'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 			sysvals.devdump = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 		elif(arg == '-genhtml'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 			genhtml = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 		elif(arg == '-addlogs'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 			sysvals.dmesglog = sysvals.ftracelog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 		elif(arg == '-nologs'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 			sysvals.dmesglog = sysvals.ftracelog = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) 		elif(arg == '-addlogdmesg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) 			sysvals.dmesglog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) 		elif(arg == '-addlogftrace'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) 			sysvals.ftracelog = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 		elif(arg == '-noturbostat'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) 			sysvals.tstat = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 		elif(arg == '-verbose'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) 			sysvals.verbose = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 		elif(arg == '-proc'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) 			sysvals.useprocmon = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) 		elif(arg == '-dev'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) 			sysvals.usedevsrc = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) 		elif(arg == '-sync'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) 			sysvals.sync = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) 		elif(arg == '-wifi'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) 			sysvals.wifi = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) 		elif(arg == '-gzip'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 			sysvals.gzip = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) 		elif(arg == '-info'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 				doError('-info requires one string argument', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) 		elif(arg == '-rs'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) 				doError('-rs requires "enable" or "disable"', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 			if val.lower() in switchvalues:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 				if val.lower() in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 					sysvals.rs = -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 				else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) 					sysvals.rs = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) 				doError('invalid option: %s, use "enable/disable" or "on/off"' % val, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) 		elif(arg == '-display'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) 				doError('-display requires an mode value', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) 			disopt = ['on', 'off', 'standby', 'suspend']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 			if val.lower() not in disopt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 				doError('valid display mode values are %s' % disopt, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) 			sysvals.display = val.lower()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 		elif(arg == '-maxdepth'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) 			sysvals.max_graph_depth = getArgInt('-maxdepth', args, 0, 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 		elif(arg == '-rtcwake'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) 				doError('No rtcwake time supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 			if val.lower() in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) 				sysvals.rtcwake = False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 				sysvals.rtcwake = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) 				sysvals.rtcwaketime = getArgInt('-rtcwake', val, 0, 3600, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) 		elif(arg == '-timeprec'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) 			sysvals.setPrecision(getArgInt('-timeprec', args, 0, 6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) 		elif(arg == '-mindev'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) 			sysvals.mindevlen = getArgFloat('-mindev', args, 0.0, 10000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) 		elif(arg == '-mincg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) 			sysvals.mincglen = getArgFloat('-mincg', args, 0.0, 10000.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) 		elif(arg == '-bufsize'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) 			sysvals.bufsize = getArgInt('-bufsize', args, 1, 1024*1024*8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) 		elif(arg == '-cgtest'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) 			sysvals.cgtest = getArgInt('-cgtest', args, 0, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 		elif(arg == '-cgphase'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 				doError('No phase name supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) 			d = Data(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) 			if val not in d.phasedef:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 				doError('invalid phase --> (%s: %s), valid phases are %s'\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) 					% (arg, val, d.phasedef.keys()), True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) 			sysvals.cgphase = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 		elif(arg == '-cgfilter'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 				doError('No callgraph functions supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 			sysvals.setCallgraphFilter(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 		elif(arg == '-skipkprobe'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) 				doError('No kprobe functions supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 			sysvals.skipKprobes(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) 		elif(arg == '-cgskip'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) 				doError('No file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) 			if val.lower() in switchoff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) 				sysvals.cgskip = ''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) 				sysvals.cgskip = sysvals.configFile(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) 				if(not sysvals.cgskip):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 					doError('%s does not exist' % sysvals.cgskip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 		elif(arg == '-callloop-maxgap'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 			sysvals.callloopmaxgap = getArgFloat('-callloop-maxgap', args, 0.0, 1.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) 		elif(arg == '-callloop-maxlen'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 			sysvals.callloopmaxlen = getArgFloat('-callloop-maxlen', args, 0.0, 1.0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 		elif(arg == '-cmd'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) 				doError('No command string supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 			sysvals.testcommand = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) 			sysvals.suspendmode = 'command'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 		elif(arg == '-expandcg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) 			sysvals.cgexp = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 		elif(arg == '-srgap'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 			sysvals.srgap = 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) 		elif(arg == '-maxfail'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 			sysvals.maxfail = getArgInt('-maxfail', args, 0, 1000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) 		elif(arg == '-multi'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) 				c, d = next(args), next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 				doError('-multi requires two values', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 			sysvals.multiinit(c, d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 		elif(arg == '-o'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 				doError('No subdirectory name supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 			sysvals.outdir = sysvals.setOutputFolder(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) 		elif(arg == '-config'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 				doError('No text file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) 			file = sysvals.configFile(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) 			if(not file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) 				doError('%s does not exist' % val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) 			configFromFile(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) 		elif(arg == '-fadd'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) 				doError('No text file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) 			file = sysvals.configFile(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) 			if(not file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) 				doError('%s does not exist' % val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) 			sysvals.addFtraceFilterFunctions(file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) 		elif(arg == '-dmesg'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) 				doError('No dmesg file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) 			sysvals.notestrun = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) 			sysvals.dmesgfile = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 			if(os.path.exists(sysvals.dmesgfile) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 				doError('%s does not exist' % sysvals.dmesgfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) 		elif(arg == '-ftrace'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) 				doError('No ftrace file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) 			sysvals.notestrun = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) 			sysvals.ftracefile = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) 			if(os.path.exists(sysvals.ftracefile) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) 				doError('%s does not exist' % sysvals.ftracefile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) 		elif(arg == '-summary'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 				doError('No directory supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 			cmd = 'summary'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 			sysvals.outdir = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 			sysvals.notestrun = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) 			if(os.path.isdir(val) == False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 				doError('%s is not accesible' % val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) 		elif(arg == '-filter'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) 				doError('No devnames supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) 			sysvals.setDeviceFilter(val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) 		elif(arg == '-result'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) 			try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) 				val = next(args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) 			except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) 				doError('No result file supplied', True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) 			sysvals.result = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) 			sysvals.signalHandlerInit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) 			doError('Invalid argument: '+arg, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) 	# compatibility errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) 	if(sysvals.usecallgraph and sysvals.usedevsrc):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) 		doError('-dev is not compatible with -f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) 	if(sysvals.usecallgraph and sysvals.useprocmon):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) 		doError('-proc is not compatible with -f')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) 	if sysvals.usecallgraph and sysvals.cgskip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) 		sysvals.vprint('Using cgskip file: %s' % sysvals.cgskip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) 		sysvals.setCallgraphBlacklist(sysvals.cgskip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) 	# callgraph size cannot exceed device size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) 	if sysvals.mincglen < sysvals.mindevlen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) 		sysvals.mincglen = sysvals.mindevlen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) 	# remove existing buffers before calculating memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) 	if(sysvals.usecallgraph or sysvals.usedevsrc):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) 		sysvals.fsetVal('16', 'buffer_size_kb')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) 	sysvals.cpuInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) 	# just run a utility command and exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) 	if(cmd != ''):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) 		ret = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) 		if(cmd == 'status'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) 			if not statusCheck(True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) 				ret = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) 		elif(cmd == 'fpdt'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801) 			if not getFPDT(True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) 				ret = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) 		elif(cmd == 'sysinfo'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804) 			sysvals.printSystemInfo(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) 		elif(cmd == 'devinfo'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) 			deviceInfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) 		elif(cmd == 'modes'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) 			pprint(getModes())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) 		elif(cmd == 'flist'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) 			sysvals.getFtraceFilterFunctions(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) 		elif(cmd == 'flistall'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) 			sysvals.getFtraceFilterFunctions(False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) 		elif(cmd == 'summary'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) 			runSummary(sysvals.outdir, True, genhtml)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) 		elif(cmd in ['xon', 'xoff', 'xstandby', 'xsuspend', 'xinit', 'xreset']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) 			sysvals.verbose = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) 			ret = displayControl(cmd[1:])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) 		elif(cmd == 'xstat'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) 			pprint('Display Status: %s' % displayControl('stat').upper())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) 		elif(cmd == 'wificheck'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) 			dev = sysvals.checkWifi()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) 			if dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) 				print('%s is connected' % sysvals.wifiDetails(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) 				print('No wifi connection found')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) 		elif(cmd == 'cmdinfo'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) 			for out in sysvals.cmdinfo(False, True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) 				print('[%s - %s]\n%s\n' % out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) 		sys.exit(ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) 	# if instructed, re-analyze existing data files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) 	if(sysvals.notestrun):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) 		stamp = rerunTest(sysvals.outdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) 		sysvals.outputResult(stamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) 		sys.exit(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) 	# verify that we can run a test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) 	error = statusCheck()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) 	if(error):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) 		doError(error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) 	# extract mem/disk extra modes and convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) 	mode = sysvals.suspendmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) 	if mode.startswith('mem'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) 		memmode = mode.split('-', 1)[-1] if '-' in mode else 'deep'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846) 		if memmode == 'shallow':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) 			mode = 'standby'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) 		elif memmode ==  's2idle':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) 			mode = 'freeze'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) 		else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851) 			mode = 'mem'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) 		sysvals.memmode = memmode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) 		sysvals.suspendmode = mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) 	if mode.startswith('disk-'):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) 		sysvals.diskmode = mode.split('-', 1)[-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) 		sysvals.suspendmode = 'disk'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) 	sysvals.systemInfo(dmidecode(sysvals.mempath))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) 	setRuntimeSuspend(True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) 	if sysvals.display:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) 		displayControl('init')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) 	failcnt, ret = 0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) 	if sysvals.multitest['run']:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) 		# run multiple tests in a separate subdirectory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) 		if not sysvals.outdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) 			if 'time' in sysvals.multitest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) 				s = '-%dm' % sysvals.multitest['time']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) 			else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) 				s = '-x%d' % sysvals.multitest['count']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) 			sysvals.outdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S'+s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) 		if not os.path.isdir(sysvals.outdir):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) 			os.makedirs(sysvals.outdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) 		sysvals.sudoUserchown(sysvals.outdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) 		finish = datetime.now()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) 		if 'time' in sysvals.multitest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) 			finish += timedelta(minutes=sysvals.multitest['time'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) 		for i in range(sysvals.multitest['count']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) 			sysvals.multistat(True, i, finish)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) 			if i != 0 and sysvals.multitest['delay'] > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) 				pprint('Waiting %d seconds...' % (sysvals.multitest['delay']))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) 				time.sleep(sysvals.multitest['delay'])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) 			fmt = 'suspend-%y%m%d-%H%M%S'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) 			sysvals.testdir = os.path.join(sysvals.outdir, datetime.now().strftime(fmt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) 			ret = runTest(i+1, True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) 			failcnt = 0 if not ret else failcnt + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) 			if sysvals.maxfail > 0 and failcnt >= sysvals.maxfail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) 				pprint('Maximum fail count of %d reached, aborting multitest' % (sysvals.maxfail))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) 			time.sleep(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) 			sysvals.resetlog()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) 			sysvals.multistat(False, i, finish)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) 			if 'time' in sysvals.multitest and datetime.now() >= finish:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) 				break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) 		if not sysvals.skiphtml:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) 			runSummary(sysvals.outdir, False, False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) 		sysvals.sudoUserchown(sysvals.outdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) 		if sysvals.outdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) 			sysvals.testdir = sysvals.outdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) 		# run the test in the current directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) 		ret = runTest()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) 	if sysvals.display:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) 		displayControl('reset')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) 	setRuntimeSuspend(False)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) 	sys.exit(ret)