History

Merge branches 'pm-cpuidle' and 'pm-tools'

* pm-cpuidle: cpuidle: poll_state: Avoid invoking local_clock() too often PM: cpuidle/suspend: Add s2idle usage and time state attributes cpuidle: Enable coupled cpuidle support on Exynos3250 platform cpuidle: poll_state: Add time limit to poll_idle() ARM: cpuidle: Drop memory allocation error message from arm_idle_init_cpu() * pm-tools: pm-graph: AnalyzeSuspend v5.0 pm-graph: AnalyzeBoot v2.2 pm-graph: config files and installer

Rafael J. Wysocki committed 8 years ago

Commit 103cf0e3 parents a9f36db 4dc2375 700abc925 files · +2685 −706Browse files

Unified · Split

25 files
  1. Documentation/ABI/testing/sysfs-devices-system-cpu +25 −0
  2. drivers/cpuidle/cpuidle-arm.c +0 −1
  3. drivers/cpuidle/cpuidle-exynos.c +2 −1
  4. drivers/cpuidle/cpuidle.c +9 −0
  5. drivers/cpuidle/poll_state.c +16 −1
  6. drivers/cpuidle/sysfs.c +54 −0
  7. include/linux/cpuidle.h +4 −0
  8. tools/power/pm-graph/Makefile +22 −7
  9. tools/power/pm-graph/bootgraph.8 +14 −4
  10. tools/power/pm-graph/bootgraph.py +146 −73
  11. tools/power/pm-graph/config/cgskip.txt +65 −0
  12. tools/power/pm-graph/config/custom-timeline-functions.cfg +205 −0
  13. tools/power/pm-graph/config/example.cfg +133 −0
  14. tools/power/pm-graph/config/freeze-callgraph.cfg +94 −0
  15. tools/power/pm-graph/config/freeze-dev.cfg +93 −0
  16. tools/power/pm-graph/config/freeze.cfg +93 −0
  17. tools/power/pm-graph/config/standby-callgraph.cfg +94 −0
  18. tools/power/pm-graph/config/standby-dev.cfg +93 −0
  19. tools/power/pm-graph/config/standby.cfg +93 −0
  20. tools/power/pm-graph/config/suspend-callgraph.cfg +98 −0
  21. tools/power/pm-graph/config/suspend-dev.cfg +93 −0
  22. tools/power/pm-graph/config/suspend-x2-proc.cfg +93 −0
  23. tools/power/pm-graph/config/suspend.cfg +93 −0
  24. tools/power/pm-graph/sleepgraph.8 +41 −6
  25. tools/power/pm-graph/sleepgraph.py +1012 −613
Documentation/ABI/testing/sysfs-devices-system-cpu+25−0
@@ -198,6 +198,31 @@ Description: · 197 unmodified lines
198198 time (in microseconds) this cpu should spend in this idle state
199199 to make the transition worth the effort.
200200
201+What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/s2idle/
202+Date: March 2018
203+KernelVersion: v4.17
204+Contact: Linux power management list <linux-pm@vger.kernel.org>
205+Description:
206+ Idle state usage statistics related to suspend-to-idle.
207+
208+ This attribute group is only present for states that can be
209+ used in suspend-to-idle with suspended timekeeping.
210+
211+What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/s2idle/time
212+Date: March 2018
213+KernelVersion: v4.17
214+Contact: Linux power management list <linux-pm@vger.kernel.org>
215+Description:
216+ Total time spent by the CPU in suspend-to-idle (with scheduler
217+ tick suspended) after requesting this state.
218+
219+What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/s2idle/usage
220+Date: March 2018
221+KernelVersion: v4.17
222+Contact: Linux power management list <linux-pm@vger.kernel.org>
223+Description:
224+ Total number of times this state has been requested by the CPU
225+ while entering suspend-to-idle.
201226
202227 What: /sys/devices/system/cpu/cpu#/cpufreq/*
203228 Date: pre-git history
drivers/cpuidle/cpuidle-arm.c+0−1
@@ -129,7 +129,6 @@ static int __init arm_idle_init_cpu(int cpu) · 128 unmodified lines
129129
130130 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
131131 if (!dev) {
132− pr_err("Failed to allocate cpuidle device\n");
133132 ret = -ENOMEM;
134133 goto out_unregister_drv;
135134 }
drivers/cpuidle/cpuidle-exynos.c+2−1
@@ -117,7 +117,8 @@ static int exynos_cpuidle_probe(struct platform_device *pdev) · 116 unmodified lines
117117 int ret;
118118
119119 if (IS_ENABLED(CONFIG_SMP) &&
120− of_machine_is_compatible("samsung,exynos4210")) {
120+ (of_machine_is_compatible("samsung,exynos4210") ||
121+ of_machine_is_compatible("samsung,exynos3250"))) {
121122 exynos_cpuidle_pdata = pdev->dev.platform_data;
122123
123124 ret = cpuidle_register(&exynos_coupled_idle_driver,
drivers/cpuidle/cpuidle.c+9−0
@@ -131,6 +131,10 @@ int cpuidle_find_deepest_state(struct cpuidle_driver *drv, · 130 unmodified lines
131131 static void enter_s2idle_proper(struct cpuidle_driver *drv,
132132 struct cpuidle_device *dev, int index)
133133 {
134+ ktime_t time_start, time_end;
135+
136+ time_start = ns_to_ktime(local_clock());
137+
134138 /*
135139 * trace_suspend_resume() called by tick_freeze() for the last CPU
136140 * executing it contains RCU usage regarded as invalid in the idle
@@ -152,6 +156,11 @@ static void enter_s2idle_proper(struct cpuidle_driver *drv, · 15 unmodified lines
152156 */
153157 RCU_NONIDLE(tick_unfreeze());
154158 start_critical_timings();
159+
160+ time_end = ns_to_ktime(local_clock());
161+
162+ dev->states_usage[index].s2idle_time += ktime_us_delta(time_end, time_start);
163+ dev->states_usage[index].s2idle_usage++;
155164 }
156165
157166 /**
drivers/cpuidle/poll_state.c+16−1
@@ -6,15 +6,30 @@ · 5 unmodified lines
66
77 #include <linux/cpuidle.h>
88 #include <linux/sched.h>
9+#include <linux/sched/clock.h>
910 #include <linux/sched/idle.h>
1011
12+#define POLL_IDLE_TIME_LIMIT (TICK_NSEC / 16)
13+#define POLL_IDLE_RELAX_COUNT 200
14+
1115 static int __cpuidle poll_idle(struct cpuidle_device *dev,
1216 struct cpuidle_driver *drv, int index)
1317 {
18+ u64 time_start = local_clock();
19+
1420 local_irq_enable();
1521 if (!current_set_polling_and_test()) {
16− while (!need_resched())
22+ unsigned int loop_count = 0;
23+
24+ while (!need_resched()) {
1725 cpu_relax();
26+ if (loop_count++ < POLL_IDLE_RELAX_COUNT)
27+ continue;
28+
29+ loop_count = 0;
30+ if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT)
31+ break;
32+ }
1833 }
1934 current_clr_polling();
2035
drivers/cpuidle/sysfs.c+54−0
@@ -330,6 +330,58 @@ struct cpuidle_state_kobj { · 329 unmodified lines
330330 struct kobject kobj;
331331 };
332332
333+#ifdef CONFIG_SUSPEND
334+#define define_show_state_s2idle_ull_function(_name) \
335+static ssize_t show_state_s2idle_##_name(struct cpuidle_state *state, \
336+ struct cpuidle_state_usage *state_usage, \
337+ char *buf) \
338+{ \
339+ return sprintf(buf, "%llu\n", state_usage->s2idle_##_name);\
340+}
341+
342+define_show_state_s2idle_ull_function(usage);
343+define_show_state_s2idle_ull_function(time);
344+
345+#define define_one_state_s2idle_ro(_name, show) \
346+static struct cpuidle_state_attr attr_s2idle_##_name = \
347+ __ATTR(_name, 0444, show, NULL)
348+
349+define_one_state_s2idle_ro(usage, show_state_s2idle_usage);
350+define_one_state_s2idle_ro(time, show_state_s2idle_time);
351+
352+static struct attribute *cpuidle_state_s2idle_attrs[] = {
353+ &attr_s2idle_usage.attr,
354+ &attr_s2idle_time.attr,
355+ NULL
356+};
357+
358+static const struct attribute_group cpuidle_state_s2idle_group = {
359+ .name = "s2idle",
360+ .attrs = cpuidle_state_s2idle_attrs,
361+};
362+
363+static void cpuidle_add_s2idle_attr_group(struct cpuidle_state_kobj *kobj)
364+{
365+ int ret;
366+
367+ if (!kobj->state->enter_s2idle)
368+ return;
369+
370+ ret = sysfs_create_group(&kobj->kobj, &cpuidle_state_s2idle_group);
371+ if (ret)
372+ pr_debug("%s: sysfs attribute group not created\n", __func__);
373+}
374+
375+static void cpuidle_remove_s2idle_attr_group(struct cpuidle_state_kobj *kobj)
376+{
377+ if (kobj->state->enter_s2idle)
378+ sysfs_remove_group(&kobj->kobj, &cpuidle_state_s2idle_group);
379+}
380+#else
381+static inline void cpuidle_add_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { }
382+static inline void cpuidle_remove_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { }
383+#endif /* CONFIG_SUSPEND */
384+
333385 #define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
334386 #define kobj_to_state(k) (kobj_to_state_obj(k)->state)
335387 #define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
@@ -383,6 +435,7 @@ static struct kobj_type ktype_state_cpuidle = { · 47 unmodified lines
383435
384436 static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
385437 {
438+ cpuidle_remove_s2idle_attr_group(device->kobjs[i]);
386439 kobject_put(&device->kobjs[i]->kobj);
387440 wait_for_completion(&device->kobjs[i]->kobj_unregister);
388441 kfree(device->kobjs[i]);
@@ -417,6 +470,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device) · 28 unmodified lines
417470 kfree(kobj);
418471 goto error_state;
419472 }
473+ cpuidle_add_s2idle_attr_group(kobj);
420474 kobject_uevent(&kobj->kobj, KOBJ_ADD);
421475 device->kobjs[i] = kobj;
422476 }
include/linux/cpuidle.h+4−0
@@ -33,6 +33,10 @@ struct cpuidle_state_usage { · 32 unmodified lines
3333 unsigned long long disable;
3434 unsigned long long usage;
3535 unsigned long long time; /* in US */
36+#ifdef CONFIG_SUSPEND
37+ unsigned long long s2idle_usage;
38+ unsigned long long s2idle_time; /* in US */
39+#endif
3640 };
3741
3842 struct cpuidle_state {
tools/power/pm-graph/Makefile+22−7
@@ -7,11 +7,24 @@ all: · 6 unmodified lines
77
88 install : uninstall
99 install -d $(DESTDIR)$(PREFIX)/lib/pm-graph
10− install analyze_suspend.py $(DESTDIR)$(PREFIX)/lib/pm-graph
11− install analyze_boot.py $(DESTDIR)$(PREFIX)/lib/pm-graph
10+ install sleepgraph.py $(DESTDIR)$(PREFIX)/lib/pm-graph
11+ install bootgraph.py $(DESTDIR)$(PREFIX)/lib/pm-graph
12+ install -d $(DESTDIR)$(PREFIX)/lib/pm-graph/config
13+ install -m 644 config/cgskip.txt $(DESTDIR)$(PREFIX)/lib/pm-graph/config
14+ install -m 644 config/freeze-callgraph.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
15+ install -m 644 config/freeze.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
16+ install -m 644 config/freeze-dev.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
17+ install -m 644 config/standby-callgraph.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
18+ install -m 644 config/standby.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
19+ install -m 644 config/standby-dev.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
20+ install -m 644 config/suspend-callgraph.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
21+ install -m 644 config/suspend.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
22+ install -m 644 config/suspend-dev.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
23+ install -m 644 config/suspend-x2-proc.cfg $(DESTDIR)$(PREFIX)/lib/pm-graph/config
1224
13− ln -s $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_boot.py $(DESTDIR)$(PREFIX)/bin/bootgraph
14− ln -s $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_suspend.py $(DESTDIR)$(PREFIX)/bin/sleepgraph
25+ install -d $(DESTDIR)$(PREFIX)/bin
26+ ln -s $(DESTDIR)$(PREFIX)/lib/pm-graph/bootgraph.py $(DESTDIR)$(PREFIX)/bin/bootgraph
27+ ln -s $(DESTDIR)$(PREFIX)/lib/pm-graph/sleepgraph.py $(DESTDIR)$(PREFIX)/bin/sleepgraph
1528
1629 install -d $(DESTDIR)$(PREFIX)/share/man/man8
1730 install bootgraph.8 $(DESTDIR)$(PREFIX)/share/man/man8
@@ -24,9 +37,11 @@ uninstall : · 6 unmodified lines
2437 rm -f $(DESTDIR)$(PREFIX)/bin/bootgraph
2538 rm -f $(DESTDIR)$(PREFIX)/bin/sleepgraph
2639
27− rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_boot.py
28− rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_suspend.py
29− rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/*.pyc
40+ rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/config/*
41+ if [ -d $(DESTDIR)$(PREFIX)/lib/pm-graph/config ] ; then \
42+ rmdir $(DESTDIR)$(PREFIX)/lib/pm-graph/config; \
43+ fi;
44+ rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/*
3045 if [ -d $(DESTDIR)$(PREFIX)/lib/pm-graph ] ; then \
3146 rmdir $(DESTDIR)$(PREFIX)/lib/pm-graph; \
3247 fi;
tools/power/pm-graph/bootgraph.8+14−4
@@ -37,6 +37,9 @@ Print the current tool version · 36 unmodified lines
3737 Add the dmesg log to the html output. It will be viewable by
3838 clicking a button in the timeline.
3939 .TP
40+\fB-result \fIfile\fR
41+Export a results table to a text file for parsing.
42+.TP
4043 \fB-o \fIname\fR
4144 Overrides the output subdirectory name when running a new test.
4245 Use {date}, {time}, {hostname} for current values.
@@ -44,14 +47,14 @@ Use {date}, {time}, {hostname} for current values. · 1 unmodified line
4447 e.g. boot-{hostname}-{date}-{time}
4548 .SS "advanced"
4649 .TP
47−\fB-f\fR
48−Use ftrace to add function detail (default: disabled)
49−.TP
50−\fB-callgraph\fR
50+\fB-f or -callgraph\fR
5151 Use ftrace to create initcall callgraphs (default: disabled). If -func
5252 is not used there will be one callgraph per initcall. This can produce
5353 very large outputs, i.e. 10MB - 100MB.
5454 .TP
55+\fB-fstat\fR
56+Use ftrace to add function detail (default: disabled)
57+.TP
5558 \fB-maxdepth \fIlevel\fR
5659 limit the callgraph trace depth to \fIlevel\fR (default: 2). This is
5760 the best way to limit the output size when using -callgraph.
@@ -67,6 +70,13 @@ Reduce callgraph output in the timeline by limiting it to a list of calls. The · 9 unmodified lines
6770 argument can be a single function name or a comma delimited list.
6871 (default: none)
6972 .TP
73+\fB-cgskip \fIfile\fR
74+Reduce callgraph output in the timeline by skipping over uninteresting
75+functions in the trace, e.g. printk or console_unlock. The functions listed
76+in this file will show up as empty leaves in the callgraph with only the start/end
77+times displayed.
78+(default: none)
79+.TP
7080 \fB-timeprec \fIn\fR
7181 Number of significant digits in timestamps (0:S, 3:ms, [6:us])
7282 .TP
tools/power/pm-graph/bootgraph.pyrenamed from tools/power/pm-graph/analyze_boot.py+146−73
@@ -32,7 +32,7 @@ import platform · 31 unmodified lines
3232 import shutil
3333 from datetime import datetime, timedelta
3434 from subprocess import call, Popen, PIPE
35−import analyze_suspend as aslib
35+import sleepgraph as aslib
3636
3737 # ----------------- CLASSES --------------------
3838
@@ -42,23 +42,18 @@ import analyze_suspend as aslib · 3 unmodified lines
4242 # store system values and test parameters
4343 class SystemValues(aslib.SystemValues):
4444 title = 'BootGraph'
45− version = '2.1'
45+ version = '2.2'
4646 hostname = 'localhost'
4747 testtime = ''
4848 kernel = ''
4949 dmesgfile = ''
5050 ftracefile = ''
5151 htmlfile = 'bootgraph.html'
52− outfile = ''
5352 testdir = ''
54− testdirprefix = 'boot'
55− embedded = False
56− testlog = False
57− dmesglog = False
58− ftracelog = False
53+ kparams = ''
54+ result = ''
5955 useftrace = False
6056 usecallgraph = False
61− usedevsrc = True
6257 suspendmode = 'boot'
6358 max_graph_depth = 2
6459 graph_filter = 'do_one_initcall'
@@ -69,11 +64,6 @@ class SystemValues(aslib.SystemValues): · 4 unmodified lines
6964 bootloader = 'grub'
7065 blexec = []
7166 def __init__(self):
72− if('LOG_FILE' in os.environ and 'TEST_RESULTS_IDENTIFIER' in os.environ):
73− self.embedded = True
74− self.dmesglog = True
75− self.outfile = os.environ['LOG_FILE']
76− self.htmlfile = os.environ['LOG_FILE']
7767 self.hostname = platform.node()
7868 self.testtime = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
7969 if os.path.exists('/proc/version'):
@@ -148,11 +138,18 @@ class SystemValues(aslib.SystemValues): · 68 unmodified lines
148138 cmdline = '%s -cronjob' % os.path.abspath(sys.argv[0])
149139 args = iter(sys.argv[1:])
150140 for arg in args:
151− if arg in ['-h', '-v', '-cronjob', '-reboot']:
141+ if arg in ['-h', '-v', '-cronjob', '-reboot', '-verbose']:
152142 continue
153143 elif arg in ['-o', '-dmesg', '-ftrace', '-func']:
154144 args.next()
155145 continue
146+ elif arg == '-result':
147+ cmdline += ' %s "%s"' % (arg, os.path.abspath(args.next()))
148+ continue
149+ elif arg == '-cgskip':
150+ file = self.configFile(args.next())
151+ cmdline += ' %s "%s"' % (arg, os.path.abspath(file))
152+ continue
156153 cmdline += ' '+arg
157154 if self.graph_filter != 'do_one_initcall':
158155 cmdline += ' -func "%s"' % self.graph_filter
@@ -166,14 +163,6 @@ class SystemValues(aslib.SystemValues): · 7 unmodified lines
166163 print '3. After reboot, re-run this tool with the same arguments but no command (w/o -reboot or -manual).\n'
167164 print 'CMDLINE="%s"' % cmdline
168165 sys.exit()
169− def getExec(self, cmd):
170− dirlist = ['/sbin', '/bin', '/usr/sbin', '/usr/bin',
171− '/usr/local/sbin', '/usr/local/bin']
172− for path in dirlist:
173− cmdfull = os.path.join(path, cmd)
174− if os.path.exists(cmdfull):
175− return cmdfull
176− return ''
177166 def blGrub(self):
178167 blcmd = ''
179168 for cmd in ['update-grub', 'grub-mkconfig', 'grub2-mkconfig']:
@@ -199,6 +188,14 @@ class SystemValues(aslib.SystemValues): · 19 unmodified lines
199188 self.blGrub()
200189 else:
201190 doError('unknown boot loader: %s' % self.bootloader)
191+ def writeDatafileHeader(self, filename):
192+ self.kparams = open('/proc/cmdline', 'r').read().strip()
193+ fp = open(filename, 'w')
194+ fp.write(self.teststamp+'\n')
195+ fp.write(self.sysstamp+'\n')
196+ fp.write('# command | %s\n' % self.cmdline)
197+ fp.write('# kparams | %s\n' % self.kparams)
198+ fp.close()
202199
203200 sysvals = SystemValues()
204201
@@ -249,7 +246,7 @@ class Data(aslib.Data): · 44 unmodified lines
249246 return name
250247 def deviceMatch(self, pid, cg):
251248 if cg.end - cg.start == 0:
252− return True
249+ return ''
253250 for p in data.phases:
254251 list = self.dmesg[p]['list']
255252 for devname in list:
@@ -260,14 +257,25 @@ class Data(aslib.Data): · 4 unmodified lines
260257 if(cg.start <= dev['start'] and cg.end >= dev['end'] and dev['length'] > 0):
261258 dev['ftrace'] = cg
262259 self.do_one_initcall = True
263− return True
260+ return devname
264261 else:
265262 if(cg.start > dev['start'] and cg.end < dev['end']):
266263 if 'ftraces' not in dev:
267264 dev['ftraces'] = []
268265 dev['ftraces'].append(cg)
269− return True
270− return False
266+ return devname
267+ return ''
268+ def printDetails(self):
269+ sysvals.vprint('Timeline Details:')
270+ sysvals.vprint(' Host: %s' % sysvals.hostname)
271+ sysvals.vprint(' Kernel: %s' % sysvals.kernel)
272+ sysvals.vprint(' Test time: %s' % sysvals.testtime)
273+ sysvals.vprint(' Boot time: %s' % self.boottime)
274+ for phase in self.phases:
275+ dc = len(self.dmesg[phase]['list'])
276+ sysvals.vprint('%9s mode: %.3f - %.3f (%d initcalls)' % (phase,
277+ self.dmesg[phase]['start']*1000,
278+ self.dmesg[phase]['end']*1000, dc))
271279
272280 # ----------------- FUNCTIONS --------------------
273281
@@ -275,6 +283,8 @@ class Data(aslib.Data): · 1 unmodified line
275283 # Description:
276284 # parse a kernel log for boot data
277285 def parseKernelLog():
286+ sysvals.vprint('Analyzing the dmesg data (%s)...' % \
287+ os.path.basename(sysvals.dmesgfile))
278288 phase = 'kernel'
279289 data = Data(0)
280290 data.dmesg['kernel']['start'] = data.start = ktime = 0.0
@@ -298,6 +308,12 @@ def parseKernelLog(): · 17 unmodified lines
298308 elif re.match(tp.sysinfofmt, line):
299309 tp.sysinfo = line
300310 continue
311+ elif re.match(tp.cmdlinefmt, line):
312+ tp.cmdline = line
313+ continue
314+ elif re.match(tp.kparamsfmt, line):
315+ tp.kparams = line
316+ continue
301317 idx = line.find('[')
302318 if idx > 1:
303319 line = line[idx:]
@@ -353,6 +369,17 @@ def parseKernelLog(): · 49 unmodified lines
353369 # Description:
354370 # Check if trace is available and copy to a temp file
355371 def parseTraceLog(data):
372+ sysvals.vprint('Analyzing the ftrace data (%s)...' % \
373+ os.path.basename(sysvals.ftracefile))
374+ # if available, calculate cgfilter allowable ranges
375+ cgfilter = []
376+ if len(sysvals.cgfilter) > 0:
377+ for p in data.phases:
378+ list = data.dmesg[p]['list']
379+ for i in sysvals.cgfilter:
380+ if i in list:
381+ cgfilter.append([list[i]['start']-0.0001,
382+ list[i]['end']+0.0001])
356383 # parse the trace log
357384 ftemp = dict()
358385 tp = aslib.TestProps()
@@ -366,7 +393,16 @@ def parseTraceLog(data): · 7 unmodified lines
366393 continue
367394 m_time, m_proc, m_pid, m_msg, m_dur = \
368395 m.group('time', 'proc', 'pid', 'msg', 'dur')
369− if float(m_time) > data.end:
396+ t = float(m_time)
397+ if len(cgfilter) > 0:
398+ allow = False
399+ for r in cgfilter:
400+ if t >= r[0] and t < r[1]:
401+ allow = True
402+ break
403+ if not allow:
404+ continue
405+ if t > data.end:
370406 break
371407 if(m_time and m_pid and m_msg):
372408 t = aslib.FTraceLine(m_time, m_msg, m_dur)
@@ -378,24 +414,36 @@ def parseTraceLog(data): · 5 unmodified lines
378414 key = (m_proc, pid)
379415 if(key not in ftemp):
380416 ftemp[key] = []
381− ftemp[key].append(aslib.FTraceCallGraph(pid))
417+ ftemp[key].append(aslib.FTraceCallGraph(pid, sysvals))
382418 cg = ftemp[key][-1]
383− if(cg.addLine(t)):
384− ftemp[key].append(aslib.FTraceCallGraph(pid))
419+ res = cg.addLine(t)
420+ if(res != 0):
421+ ftemp[key].append(aslib.FTraceCallGraph(pid, sysvals))
422+ if(res == -1):
423+ ftemp[key][-1].addLine(t)
424+
385425 tf.close()
386426
387427 # add the callgraph data to the device hierarchy
388428 for key in ftemp:
389429 proc, pid = key
390430 for cg in ftemp[key]:
391− if len(cg.list) < 1 or cg.invalid:
431+ if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
392432 continue
393433 if(not cg.postProcess()):
394434 print('Sanity check failed for %s-%d' % (proc, pid))
395435 continue
396436 # match cg data to devices
397− if not data.deviceMatch(pid, cg):
398− print ' BAD: %s %s-%d [%f - %f]' % (cg.name, proc, pid, cg.start, cg.end)
437+ devname = data.deviceMatch(pid, cg)
438+ if not devname:
439+ kind = 'Orphan'
440+ if cg.partial:
441+ kind = 'Partial'
442+ sysvals.vprint('%s callgraph found for %s %s-%d [%f - %f]' %\
443+ (kind, cg.name, proc, pid, cg.start, cg.end))
444+ elif len(cg.list) > 1000000:
445+ print 'WARNING: the callgraph found for %s is massive! (%d lines)' %\
446+ (devname, len(cg.list))
399447
400448 # Function: retrieveLogs
401449 # Description:
@@ -473,7 +521,7 @@ def createBootGraph(data): · 71 unmodified lines
473521 devtl = aslib.Timeline(100, 20)
474522
475523 # write the test title and general info header
476− devtl.createHeader(sysvals)
524+ devtl.createHeader(sysvals, sysvals.stamp)
477525
478526 # Generate the header for this timeline
479527 t0 = data.start
@@ -574,12 +622,9 @@ def createBootGraph(data): · 94 unmodified lines
574622 data.dmesg[phase]['color'], phase+'_mode', phase[0])
575623 devtl.html += '</div>\n'
576624
577− if(sysvals.outfile == sysvals.htmlfile):
578− hf = open(sysvals.htmlfile, 'a')
579− else:
580− hf = open(sysvals.htmlfile, 'w')
625+ hf = open(sysvals.htmlfile, 'w')
581626
582− # add the css if this is not an embedded run
627+ # add the css
583628 extra = '\
584629 .c1 {background:rgba(209,0,0,0.4);}\n\
585630 .c2 {background:rgba(255,102,34,0.4);}\n\
@@ -597,8 +642,7 @@ def createBootGraph(data): · 11 unmodified lines
597642 .fstat td {text-align:left;width:35px;}\n\
598643 .srccall {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\
599644 .srccall:hover {color:white;font-weight:bold;border:1px solid white;}\n'
600− if(not sysvals.embedded):
601− aslib.addCSS(hf, sysvals, 1, False, extra)
645+ aslib.addCSS(hf, sysvals, 1, False, extra)
602646
603647 # write the device timeline
604648 hf.write(devtl.html)
@@ -631,6 +675,9 @@ def createBootGraph(data): · 26 unmodified lines
631675 if(sysvals.usecallgraph):
632676 aslib.addCallgraphs(sysvals, hf, data)
633677
678+ # add the test log as a hidden div
679+ if sysvals.testlog and sysvals.logmsg:
680+ hf.write('<div id="testlog" style="display:none;">\n'+sysvals.logmsg+'</div>\n')
634681 # add the dmesg log as a hidden div
635682 if sysvals.dmesglog:
636683 hf.write('<div id="dmesglog" style="display:none;">\n')
@@ -639,14 +686,9 @@ def createBootGraph(data): · 2 unmodified lines
639686 hf.write(line)
640687 hf.write('</div>\n')
641688
642− if(not sysvals.embedded):
643− # write the footer and close
644− aslib.addScriptCode(hf, [data])
645− hf.write('</body>\n</html>\n')
646− else:
647− # embedded out will be loaded in a page, skip the js
648− hf.write('<div id=bounds style=display:none>%f,%f</div>' % \
649− (data.start*1000, data.end*1000))
689+ # write the footer and close
690+ aslib.addScriptCode(hf, [data])
691+ hf.write('</body>\n</html>\n')
650692 hf.close()
651693 return True
652694
@@ -780,6 +822,7 @@ def doError(msg, help=False): · 127 unmodified lines
780822 if help == True:
781823 printHelp()
782824 print 'ERROR: %s\n' % msg
825+ sysvals.outputResult({'error':msg})
783826 sys.exit()
784827
785828 # Function: printHelp
@@ -806,18 +849,21 @@ def printHelp(): · 20 unmodified lines
806849 print('Options:')
807850 print(' -h Print this help text')
808851 print(' -v Print the current tool version')
852+ print(' -verbose Print extra information during execution and analysis')
809853 print(' -addlogs Add the dmesg log to the html output')
854+ print(' -result fn Export a results table to a text file for parsing.')
810855 print(' -o name Overrides the output subdirectory name when running a new test')
811856 print(' default: boot-{date}-{time}')
812857 print(' [advanced]')
813− print(' -f Use ftrace to add function detail (default: disabled)')
814− print(' -callgraph Add callgraph detail, can be very large (default: disabled)')
858+ print(' -fstat Use ftrace to add function detail and statistics (default: disabled)')
859+ print(' -f/-callgraph Add callgraph detail, can be very large (default: disabled)')
815860 print(' -maxdepth N limit the callgraph data to N call levels (default: 2)')
816861 print(' -mincg ms Discard all callgraphs shorter than ms milliseconds (e.g. 0.001 for us)')
817862 print(' -timeprec N Number of significant digits in timestamps (0:S, 3:ms, [6:us])')
818863 print(' -expandcg pre-expand the callgraph data in the html output (default: disabled)')
819864 print(' -func list Limit ftrace to comma-delimited list of functions (default: do_one_initcall)')
820865 print(' -cgfilter S Filter the callgraph output in the timeline')
866+ print(' -cgskip file Callgraph functions to skip, off to disable (default: cgskip.txt)')
821867 print(' -bl name Use the following boot loader for kernel params (default: grub)')
822868 print(' -reboot Reboot the machine automatically and generate a new timeline')
823869 print(' -manual Show the steps to generate a new timeline manually (used with -reboot)')
@@ -837,8 +883,13 @@ if __name__ == '__main__': · 13 unmodified lines
837883 # loop through the command line arguments
838884 cmd = ''
839885 testrun = True
886+ switchoff = ['disable', 'off', 'false', '0']
840887 simplecmds = ['-sysinfo', '-kpupdate', '-flistall', '-checkbl']
888+ cgskip = ''
889+ if '-f' in sys.argv:
890+ cgskip = sysvals.configFile('cgskip.txt')
841891 args = iter(sys.argv[1:])
892+ mdset = False
842893 for arg in args:
843894 if(arg == '-h'):
844895 printHelp()
@@ -846,13 +897,17 @@ if __name__ == '__main__': · 1 unmodified line
846897 elif(arg == '-v'):
847898 print("Version %s" % sysvals.version)
848899 sys.exit()
900+ elif(arg == '-verbose'):
901+ sysvals.verbose = True
849902 elif(arg in simplecmds):
850903 cmd = arg[1:]
851− elif(arg == '-f'):
904+ elif(arg == '-fstat'):
852905 sysvals.useftrace = True
853− elif(arg == '-callgraph'):
906+ elif(arg == '-callgraph' or arg == '-f'):
854907 sysvals.useftrace = True
855908 sysvals.usecallgraph = True
909+ elif(arg == '-cgdump'):
910+ sysvals.cgdump = True
856911 elif(arg == '-mincg'):
857912 sysvals.mincglen = aslib.getArgFloat('-mincg', args, 0.0, 10000.0)
858913 elif(arg == '-cgfilter'):
@@ -860,7 +915,18 @@ if __name__ == '__main__': · 1 unmodified line
860915 val = args.next()
861916 except:
862917 doError('No callgraph functions supplied', True)
863− sysvals.setDeviceFilter(val)
918+ sysvals.setCallgraphFilter(val)
919+ elif(arg == '-cgskip'):
920+ try:
921+ val = args.next()
922+ except:
923+ doError('No file supplied', True)
924+ if val.lower() in switchoff:
925+ cgskip = ''
926+ else:
927+ cgskip = sysvals.configFile(val)
928+ if(not cgskip):
929+ doError('%s does not exist' % cgskip)
864930 elif(arg == '-bl'):
865931 try:
866932 val = args.next()
@@ -872,6 +938,7 @@ if __name__ == '__main__': · 5 unmodified lines
872938 elif(arg == '-timeprec'):
873939 sysvals.setPrecision(aslib.getArgInt('-timeprec', args, 0, 6))
874940 elif(arg == '-maxdepth'):
941+ mdset = True
875942 sysvals.max_graph_depth = aslib.getArgInt('-maxdepth', args, 0, 1000)
876943 elif(arg == '-func'):
877944 try:
@@ -902,8 +969,6 @@ if __name__ == '__main__': · 24 unmodified lines
902969 doError('No dmesg file supplied', True)
903970 if(os.path.exists(val) == False):
904971 doError('%s does not exist' % val)
905− if(sysvals.htmlfile == val or sysvals.outfile == val):
906− doError('Output filename collision')
907972 testrun = False
908973 sysvals.dmesgfile = val
909974 elif(arg == '-o'):
@@ -912,6 +977,12 @@ if __name__ == '__main__': · 2 unmodified lines
912977 except:
913978 doError('No subdirectory name supplied', True)
914979 sysvals.testdir = sysvals.setOutputFolder(val)
980+ elif(arg == '-result'):
981+ try:
982+ val = args.next()
983+ except:
984+ doError('No result file supplied', True)
985+ sysvals.result = val
915986 elif(arg == '-reboot'):
916987 sysvals.reboot = True
917988 elif(arg == '-manual'):
@@ -947,7 +1018,7 @@ if __name__ == '__main__': · 29 unmodified lines
9471018 sysvals.getBootLoader()
9481019 print 'Boot Loader: %s\n%s' % (sysvals.bootloader, sysvals.blexec)
9491020 elif(cmd == 'sysinfo'):
950− sysvals.printSystemInfo()
1021+ sysvals.printSystemInfo(True)
9511022 sys.exit()
9521023
9531024 # reboot: update grub, setup a cronjob, and reboot
@@ -963,6 +1034,10 @@ if __name__ == '__main__': · 9 unmodified lines
9631034 sysvals.manualRebootRequired()
9641035 sys.exit()
9651036
1037+ if sysvals.usecallgraph and cgskip:
1038+ sysvals.vprint('Using cgskip file: %s' % cgskip)
1039+ sysvals.setCallgraphBlacklist(cgskip)
1040+
9661041 # cronjob: remove the cronjob, grub changes, and disable ftrace
9671042 if sysvals.iscronjob:
9681043 updateCron(True)
@@ -980,29 +1055,23 @@ if __name__ == '__main__': · 11 unmodified lines
9801055
9811056 # process the log data
9821057 if sysvals.dmesgfile:
1058+ if not mdset:
1059+ sysvals.max_graph_depth = 0
9831060 data = parseKernelLog()
9841061 if(not data.valid):
9851062 doError('No initcall data found in %s' % sysvals.dmesgfile)
9861063 if sysvals.useftrace and sysvals.ftracefile:
9871064 parseTraceLog(data)
1065+ if sysvals.cgdump:
1066+ data.debugPrint()
1067+ sys.exit()
9881068 else:
9891069 doError('dmesg file required')
9901070
991− print(' Host: %s' % sysvals.hostname)
992− print(' Test time: %s' % sysvals.testtime)
993− print(' Boot time: %s' % data.boottime)
994− print('Kernel Version: %s' % sysvals.kernel)
995− print(' Kernel start: %.3f' % (data.start * 1000))
996− print('Usermode start: %.3f' % (data.tUserMode * 1000))
997− print('Last Init Call: %.3f' % (data.end * 1000))
998−
999− # handle embedded output logs
1000− if(sysvals.outfile and sysvals.embedded):
1001− fp = open(sysvals.outfile, 'w')
1002− fp.write('pass %s initstart %.3f end %.3f boot %s\n' %
1003− (data.valid, data.tUserMode*1000, data.end*1000, data.boottime))
1004− fp.close()
1005−
1071+ sysvals.vprint('Creating the html timeline (%s)...' % sysvals.htmlfile)
1072+ sysvals.vprint('Command:\n %s' % sysvals.cmdline)
1073+ sysvals.vprint('Kernel parameters:\n %s' % sysvals.kparams)
1074+ data.printDetails()
10061075 createBootGraph(data)
10071076
10081077 # if running as root, change output dir owner to sudo_user
@@ -1010,3 +1079,7 @@ if __name__ == '__main__': · 1 unmodified line
10101079 os.getuid() == 0 and 'SUDO_USER' in os.environ:
10111080 cmd = 'chown -R {0}:{0} {1} > /dev/null 2>&1'
10121081 call(cmd.format(os.environ['SUDO_USER'], sysvals.testdir), shell=True)
1082+
1083+ sysvals.stamp['boot'] = (data.tUserMode - data.start) * 1000
1084+ sysvals.stamp['lastinit'] = data.end * 1000
1085+ sysvals.outputResult(sysvals.stamp)
tools/power/pm-graph/config/cgskip.txt+65−0
@@ -0,0 +1,65 @@
1+# -----------------------------------------------
2+# CallGraph function skip list
3+#
4+# This file contains a list of functions which are
5+# meant to be skipped in the callgraph trace. It reduces
6+# the callgraph html file size by treating these functions
7+# as leaves with no child calls. It can be editted by
8+# adding or removing function symbol names.
9+#
10+# The sleepgraph tool automatically pulls this file in when
11+# it is found in the config folder. It can be ignored if
12+# the tool is called with "-cgskip off".
13+# -----------------------------------------------
14+
15+# low level scheduling and timing
16+up
17+down_timeout
18+mutex_lock
19+down_read
20+complete_all
21+schedule_timeout
22+wake_up_process
23+msleep
24+__udelay
25+ktime_get
26+
27+# console calls
28+printk
29+dev_printk
30+console_unlock
31+
32+# memory handling
33+__kmalloc
34+__kmalloc_track_caller
35+kmem_cache_alloc
36+kmem_cache_alloc_trace
37+kmem_cache_free
38+kstrdup
39+kstrdup_const
40+kmalloc_slab
41+new_slab
42+__slab_alloc
43+__slab_free
44+raw_pci_read
45+pci_read
46+alloc_pages_current
47+
48+# debugfs and sysfs setup
49+debugfs_remove_recursive
50+debugfs_create_dir
51+debugfs_create_files
52+debugfs_create_dir
53+debugfs_get_inode
54+sysfs_add_file_mode_ns
55+sysfs_add_file
56+sysfs_create_dir_ns
57+sysfs_create_link
58+sysfs_create_group
59+sysfs_create_groups
60+sysfs_create_bin_file
61+dpm_sysfs_add
62+sysfs_create_file_ns
63+sysfs_merge_group
64+sysfs_add_link_to_group
65+sysfs_create_link_sd
tools/power/pm-graph/config/custom-timeline-functions.cfg+205−0
@@ -0,0 +1,205 @@
1+#
2+# This is the configuration file for sleepgraph. It contains
3+# all the tool arguments so that they don't have to be given on the
4+# command line. It also includes advanced settings for functions
5+# and kprobes. It is run like this
6+#
7+# sudo ./sleepgraph.py -config thisfile.txt
8+#
9+
10+[Settings]
11+
12+# Verbosity
13+# print verbose messages (default: false)
14+verbose: false
15+
16+# Suspend Mode
17+# e.g. standby, mem, freeze, disk (default: mem)
18+mode: mem
19+
20+# Automatic Wakeup
21+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
22+rtcwake: 15
23+
24+# Add Logs
25+# add the dmesg and ftrace log to the html output (default: false)
26+addlogs: false
27+
28+# Display function calls
29+# graph source functions in the timeline (default: false)
30+dev: true
31+
32+# Callgraph
33+# gather detailed ftrace callgraph data on all timeline events (default: false)
34+callgraph: false
35+
36+# Back to Back Suspend/Resume
37+# Run two suspend/resumes back to back (default: false)
38+x2: false
39+
40+# Back to Back Suspend Delay
41+# Time delay between the two test runs in ms (default: 0 ms)
42+x2delay: 0
43+
44+# Minimum Device Length
45+# graph only devices longer than min in the timeline (default: 0.001 ms)
46+mindev: 1
47+
48+# Minimum Callgraph Length
49+# provide callgraph data for blocks longer than min (default: 0.001 ms)
50+mincg: 1
51+
52+# Suspend/Resume Gap
53+# insert a small visible gap between suspend and resume on the timeline (default: false)
54+srgap: false
55+
56+# Output Directory Format
57+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
58+output-dir: suspend-{hostname}-{date}-{time}-custom
59+
60+# Override default timeline entries
61+# Do not use the internal default functions for timeline entries (default: false)
62+# Set this to true if you intend to only use the ones defined in this config
63+override-timeline-functions: true
64+
65+# Override default dev timeline entries
66+# Do not use the internal default functions for dev timeline entries (default: false)
67+# Set this to true if you intend to only use the ones defined in this config
68+override-dev-timeline-functions: true
69+
70+[timeline_functions_x86_64]
71+#
72+# Function calls to display in the timeline alongside device callbacks.
73+# The tool has an internal set of these functions which should cover the
74+# whole of kernel execution, but you can append or override here.
75+#
76+# This is a list of kprobes which use both symbol data and function arg data.
77+# The function calls are displayed on the timeline alongside the device blocks.
78+# The args are pulled directly from the stack using this architecture's registers
79+# and stack formatting. Three pieces of info are required. The function name,
80+# a format string, and an argument list
81+#
82+# Entry format:
83+#
84+# function: format{fn_arg1}_{fn_arg2} fn_arg1 fn_arg2 ... [color=purple]
85+#
86+# Required Arguments:
87+#
88+# function: The symbol name for the function you want probed, this is the
89+# minimum required for an entry, it will show up as the function
90+# name with no arguments.
91+#
92+# example: _cpu_up:
93+#
94+# Optional Arguments:
95+#
96+# format: The format to display the data on the timeline in. Use braces to
97+# enclose the arg names.
98+#
99+# example: CPU_ON[{cpu}]
100+#
101+# color: The color of the entry block in the timeline. The default color is
102+# transparent, so the entry shares the phase color. The color is an
103+# html color string, either a word, or an RGB.
104+#
105+# example: [color=#CC00CC]
106+#
107+# arglist: A list of arguments from registers/stack addresses. See URL:
108+# https://www.kernel.org/doc/Documentation/trace/kprobetrace.txt
109+#
110+# example: cpu=%di:s32
111+#
112+# Example: Display cpu resume in the timeline
113+#
114+# _cpu_up: CPU_ON[{cpu}] cpu=%di:s32 [color=orange]
115+#
116+_cpu_down: CPU_OFF[{cpu}] cpu=%di:s32
117+_cpu_up: CPU_ON[{cpu}] cpu=%di:s32
118+sys_sync:
119+pm_prepare_console:
120+pm_notifier_call_chain:
121+freeze_processes:
122+freeze_kernel_threads:
123+pm_restrict_gfp_mask:
124+acpi_suspend_begin:
125+suspend_console:
126+acpi_pm_prepare:
127+syscore_suspend:
128+arch_enable_nonboot_cpus_end:
129+syscore_resume:
130+acpi_pm_finish:
131+resume_console:
132+acpi_pm_end:
133+pm_restore_gfp_mask:
134+thaw_processes:
135+pm_restore_console:
136+
137+[dev_timeline_functions_x86_64]
138+#
139+# Dev mode function calls to display inside timeline entries
140+#
141+# This is a list of kprobes which use both symbol data and function arg data.
142+# The function calls are displayed on the timeline alongside the device blocks.
143+# The args are pulled directly from the stack using this architecture's registers
144+# and stack formatting. Three pieces of info are required. The function name,
145+# a format string, and an argument list
146+#
147+# Entry format:
148+#
149+# function: format{fn_arg1}_{fn_arg2} fn_arg1 fn_arg2 ... [color=purple]
150+#
151+# Required Arguments:
152+#
153+# function: The symbol name for the function you want probed, this is the
154+# minimum required for an entry, it will show up as the function
155+# name with no arguments.
156+#
157+# example: ata_eh_recover:
158+#
159+# Optional Arguments:
160+#
161+# format: The format to display the data on the timeline in. Use braces to
162+# enclose the arg names.
163+#
164+# example: ata{port}_port_reset
165+#
166+# color: The color of the entry block in the timeline. The default color is
167+# transparent, so the entry shares the phase color. The color is an
168+# html color string, either a word, or an RGB.
169+#
170+# example: [color=#CC00CC]
171+#
172+# arglist: A list of arguments from registers/stack addresses. See URL:
173+# https://www.kernel.org/doc/Documentation/trace/kprobetrace.txt
174+#
175+# example: port=+36(%di):s32
176+#
177+# Example: Display ATA port reset as ataN_port_reset in the timeline
178+#
179+# ata_eh_recover: ata{port}_port_reset port=+36(%di):s32
180+#
181+msleep: msleep time=%di:s32
182+schedule_timeout_uninterruptible: schedule_timeout_uninterruptible timeout=%di:s32
183+schedule_timeout: schedule_timeout timeout=%di:s32
184+usleep_range: usleep_range min=%di:s32 max=%si:s32
185+__const_udelay: udelay loops=%di:s32
186+__mutex_lock_slowpath: mutex_lock_slowpath
187+ata_eh_recover: ata_eh_recover port=+36(%di):s32
188+acpi_os_stall:
189+acpi_resume_power_resources:
190+acpi_ps_parse_aml:
191+ext4_sync_fs:
192+i915_gem_resume:
193+i915_restore_state:
194+intel_opregion_setup:
195+g4x_pre_enable_dp:
196+vlv_pre_enable_dp:
197+chv_pre_enable_dp:
198+g4x_enable_dp:
199+vlv_enable_dp:
200+intel_hpd_init:
201+intel_opregion_register:
202+intel_dp_detect:
203+intel_hdmi_detect:
204+intel_opregion_init:
205+intel_fbdev_set_suspend:
tools/power/pm-graph/config/example.cfg+133−0
@@ -0,0 +1,133 @@
1+#
2+# Generic S3 (Suspend to Mem) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/example.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: mem
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: suspend-{hostname}-{date}-{time}
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: true
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# Skip HTML generation
41+# Only capture the logs, don't generate the html timeline (default: false)
42+skiphtml: false
43+
44+# Sync filesystem before suspend
45+# run sync before the test, minimizes sys_sync call time (default: false)
46+sync: true
47+
48+# Runtime suspend enable/disable
49+# Enable/disable runtime suspend for all devices, restore all after test (default: no-action)
50+# rs: disable
51+
52+# Turn display on/off for test
53+# Switch the display on/off for the test using xset (default: no-action)
54+# display: on
55+
56+# Print results to text file
57+# Print the status of the test run in the given file (default: no-action)
58+result: result.txt
59+
60+# Gzip the log files to save space
61+# Gzip the generated log files, and read gzipped log files (default: false)
62+gzip: true
63+
64+# ---- Advanced Options ----
65+
66+# Command to execute in lieu of suspend (default: "")
67+# command: echo mem > /sys/power/state
68+
69+# Display user processes
70+# graph user processes and cpu usage in the timeline (default: false)
71+proc: false
72+
73+# Display function calls
74+# graph source functions in the timeline (default: false)
75+dev: false
76+
77+# Multiple test runs
78+# Run N tests D seconds apart, generates separate outputs with a summary (default: false)
79+# multi: 3 5
80+
81+# Back to Back Suspend/Resume
82+# Run two suspend/resumes back to back and display in the same timeline (default: false)
83+x2: false
84+
85+# Back to Back Suspend Delay
86+# Time delay between the two test runs in ms (default: 0 ms)
87+x2delay: 0
88+
89+# Pre Suspend Delay
90+# Include an N ms delay before (1st) suspend (default: 0 ms)
91+predelay: 0
92+
93+# Post Resume Delay
94+# Include an N ms delay after (last) resume (default: 0 ms)
95+postdelay: 0
96+
97+# Minimum Device Length
98+# graph only devices longer than min in the timeline (default: 0.001 ms)
99+mindev: 0.001
100+
101+# ---- Debug Options ----
102+
103+# Callgraph
104+# gather detailed ftrace callgraph data on all timeline events (default: false)
105+callgraph: false
106+
107+# Callgraph phase filter
108+# Only enable callgraphs for one phase, i.e. resume_noirq (default: all)
109+cgphase: suspend
110+
111+# Callgraph x2 test filter
112+# Only enable callgraphs test 0 or 1 when using -x2 (default: 1)
113+cgtest: 0
114+
115+# Expand Callgraph
116+# pre-expand the callgraph data in the html output (default: disabled)
117+expandcg: false
118+
119+# Minimum Callgraph Length
120+# provide callgraph data for blocks longer than min (default: 0.001 ms)
121+mincg: 1
122+
123+# Timestamp Precision
124+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
125+timeprec: 6
126+
127+# Device Filter
128+# show only devices whose name/driver includes one of these strings
129+# devicefilter: _cpu_up,_cpu_down,i915,usb
130+
131+# Add kprobe functions to the timeline
132+# Add functions to the timeline from a text file (default: no-action)
133+# fadd: file.txt
tools/power/pm-graph/config/freeze-callgraph.cfg+94−0
@@ -0,0 +1,94 @@
1+#
2+# Full Callgraph for S2 (Freeze) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/freeze-callgraph.cfg
10+#
11+# NOTE: the output of this test is very large (> 30MB)
12+
13+[Settings]
14+
15+# ---- General Options ----
16+
17+# Verbosity
18+# print verbose messages (default: false)
19+verbose: false
20+
21+# Suspend Mode
22+# e.g. standby, mem, freeze, disk (default: mem)
23+mode: freeze
24+
25+# Output Directory Format
26+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
27+output-dir: freeze-{hostname}-{date}-{time}-cg
28+
29+# Automatic Wakeup
30+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
31+rtcwake: 15
32+
33+# Add Logs
34+# add the dmesg and ftrace log to the html output (default: false)
35+addlogs: false
36+
37+# Suspend/Resume Gap
38+# insert a small visible gap between suspend and resume on the timeline (default: false)
39+srgap: false
40+
41+# ---- Advanced Options ----
42+
43+# Command to execute in lieu of freeze (default: "")
44+# command: echo freeze > /sys/power/state
45+
46+# Display user processes
47+# graph user processes and cpu usage in the timeline (default: false)
48+proc: false
49+
50+# Display function calls
51+# graph source functions in the timeline (default: false)
52+dev: false
53+
54+# Back to Back Suspend/Resume
55+# Run two suspend/resumes back to back (default: false)
56+x2: false
57+
58+# Back to Back Suspend Delay
59+# Time delay between the two test runs in ms (default: 0 ms)
60+x2delay: 0
61+
62+# Pre Suspend Delay
63+# Include an N ms delay before (1st) suspend (default: 0 ms)
64+predelay: 0
65+
66+# Post Resume Delay
67+# Include an N ms delay after (last) resume (default: 0 ms)
68+postdelay: 0
69+
70+# Minimum Device Length
71+# graph only devices longer than min in the timeline (default: 0.001 ms)
72+mindev: 1
73+
74+# ---- Debug Options ----
75+
76+# Callgraph
77+# gather detailed ftrace callgraph data on all timeline events (default: false)
78+callgraph: true
79+
80+# Expand Callgraph
81+# pre-expand the callgraph data in the html output (default: disabled)
82+expandcg: false
83+
84+# Minimum Callgraph Length
85+# provide callgraph data for blocks longer than min (default: 0.001 ms)
86+mincg: 1
87+
88+# Timestamp Precision
89+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
90+timeprec: 6
91+
92+# Device Filter
93+# show only devs whose name/driver includes one of these strings
94+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/freeze-dev.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Dev S2 (Freeze) test - includes src calls / kernel threads
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/freeze-dev.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: freeze
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: freeze-{hostname}-{date}-{time}-dev
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of freeze (default: "")
43+# command: echo freeze > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: true
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 1
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/freeze.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Generic S2 (Freeze) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/freeze.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: freeze
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: freeze-{hostname}-{date}-{time}
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of freeze (default: "")
43+# command: echo freeze > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: false
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 0.001
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/standby-callgraph.cfg+94−0
@@ -0,0 +1,94 @@
1+#
2+# Full Callgraph for S1 (Standby) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/standby-callgraph.cfg
10+#
11+# NOTE: the output of this test is very large (> 30MB)
12+
13+[Settings]
14+
15+# ---- General Options ----
16+
17+# Verbosity
18+# print verbose messages (default: false)
19+verbose: false
20+
21+# Suspend Mode
22+# e.g. standby, mem, freeze, disk (default: mem)
23+mode: standby
24+
25+# Output Directory Format
26+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
27+output-dir: standby-{hostname}-{date}-{time}-cg
28+
29+# Automatic Wakeup
30+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
31+rtcwake: 15
32+
33+# Add Logs
34+# add the dmesg and ftrace log to the html output (default: false)
35+addlogs: false
36+
37+# Suspend/Resume Gap
38+# insert a small visible gap between suspend and resume on the timeline (default: false)
39+srgap: false
40+
41+# ---- Advanced Options ----
42+
43+# Command to execute in lieu of standby (default: "")
44+# command: echo standby > /sys/power/state
45+
46+# Display user processes
47+# graph user processes and cpu usage in the timeline (default: false)
48+proc: false
49+
50+# Display function calls
51+# graph source functions in the timeline (default: false)
52+dev: false
53+
54+# Back to Back Suspend/Resume
55+# Run two suspend/resumes back to back (default: false)
56+x2: false
57+
58+# Back to Back Suspend Delay
59+# Time delay between the two test runs in ms (default: 0 ms)
60+x2delay: 0
61+
62+# Pre Suspend Delay
63+# Include an N ms delay before (1st) suspend (default: 0 ms)
64+predelay: 0
65+
66+# Post Resume Delay
67+# Include an N ms delay after (last) resume (default: 0 ms)
68+postdelay: 0
69+
70+# Minimum Device Length
71+# graph only devices longer than min in the timeline (default: 0.001 ms)
72+mindev: 1
73+
74+# ---- Debug Options ----
75+
76+# Callgraph
77+# gather detailed ftrace callgraph data on all timeline events (default: false)
78+callgraph: true
79+
80+# Expand Callgraph
81+# pre-expand the callgraph data in the html output (default: disabled)
82+expandcg: false
83+
84+# Minimum Callgraph Length
85+# provide callgraph data for blocks longer than min (default: 0.001 ms)
86+mincg: 1
87+
88+# Timestamp Precision
89+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
90+timeprec: 6
91+
92+# Device Filter
93+# show only devs whose name/driver includes one of these strings
94+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/standby-dev.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Dev S1 (Standby) test - includes src calls / kernel threads
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/standby-dev.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: standby
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: standby-{hostname}-{date}-{time}-dev
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of standby (default: "")
43+# command: echo standby > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: true
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 1
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/standby.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Generic S1 (Standby) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/standby.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: standby
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: standby-{hostname}-{date}-{time}
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of standby (default: "")
43+# command: echo standby > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: false
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 0.001
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/suspend-callgraph.cfg+98−0
@@ -0,0 +1,98 @@
1+#
2+# Full Callgraph for S3 (Suspend to Mem) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/suspend.cfg
10+#
11+# NOTE: the output of this test is very large (> 30MB)
12+
13+[Settings]
14+
15+# ---- General Options ----
16+
17+# Verbosity
18+# print verbose messages (default: false)
19+verbose: false
20+
21+# Suspend Mode
22+# e.g. standby, mem, freeze, disk (default: mem)
23+mode: mem
24+
25+# Output Directory Format
26+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
27+output-dir: suspend-{hostname}-{date}-{time}-cg
28+
29+# Automatic Wakeup
30+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
31+rtcwake: 15
32+
33+# Add Logs
34+# add the dmesg and ftrace log to the html output (default: false)
35+addlogs: false
36+
37+# Suspend/Resume Gap
38+# insert a small visible gap between suspend and resume on the timeline (default: false)
39+srgap: false
40+
41+# ---- Advanced Options ----
42+
43+# Command to execute in lieu of suspend (default: "")
44+# command: echo mem > /sys/power/state
45+
46+# Display user processes
47+# graph user processes and cpu usage in the timeline (default: false)
48+proc: false
49+
50+# Display function calls
51+# graph source functions in the timeline (default: false)
52+dev: false
53+
54+# Back to Back Suspend/Resume
55+# Run two suspend/resumes back to back (default: false)
56+x2: false
57+
58+# Back to Back Suspend Delay
59+# Time delay between the two test runs in ms (default: 0 ms)
60+x2delay: 0
61+
62+# Pre Suspend Delay
63+# Include an N ms delay before (1st) suspend (default: 0 ms)
64+predelay: 0
65+
66+# Post Resume Delay
67+# Include an N ms delay after (last) resume (default: 0 ms)
68+postdelay: 0
69+
70+# Minimum Device Length
71+# graph only devices longer than min in the timeline (default: 0.001 ms)
72+mindev: 0.001
73+
74+# ---- Debug Options ----
75+
76+# Callgraph
77+# gather detailed ftrace callgraph data on all timeline events (default: false)
78+callgraph: true
79+
80+# Max graph depth
81+# limit the callgraph trace to this depth (default: 0 = all)
82+maxdepth: 5
83+
84+# Expand Callgraph
85+# pre-expand the callgraph data in the html output (default: disabled)
86+expandcg: false
87+
88+# Minimum Callgraph Length
89+# provide callgraph data for blocks longer than min (default: 0.001 ms)
90+mincg: 1
91+
92+# Timestamp Precision
93+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
94+timeprec: 6
95+
96+# Device Filter
97+# show only devs whose name/driver includes one of these strings
98+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/suspend-dev.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Dev S3 (Suspend to Mem) test - includes src calls / kernel threads
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/suspend-dev.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: mem
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: suspend-{hostname}-{date}-{time}-dev
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of suspend (default: "")
43+# command: echo mem > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: true
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 1
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/suspend-x2-proc.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Proc S3 (Suspend to Mem) x2 test - includes user processes
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/suspend-proc.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: mem
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: suspend-{hostname}-{date}-{time}-x2-proc
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of suspend (default: "")
43+# command: echo mem > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: true
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: false
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: true
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 1000
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 1000
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 1000
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 1
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/config/suspend.cfg+93−0
@@ -0,0 +1,93 @@
1+#
2+# Generic S3 (Suspend to Mem) test
3+#
4+# This is the configuration file for sleepgraph. It contains
5+# all the tool arguments so that they don't have to be given on the
6+# command line. It also includes advanced settings for functions
7+# and kprobes. It is run like this
8+#
9+# sudo ./sleepgraph.py -config config/suspend.cfg
10+#
11+
12+[Settings]
13+
14+# ---- General Options ----
15+
16+# Verbosity
17+# print verbose messages (default: false)
18+verbose: false
19+
20+# Suspend Mode
21+# e.g. standby, mem, freeze, disk (default: mem)
22+mode: mem
23+
24+# Output Directory Format
25+# output folder for html, ftrace, and dmesg. Use {date} and {time} for current values
26+output-dir: suspend-{hostname}-{date}-{time}
27+
28+# Automatic Wakeup
29+# Use rtcwake to autoresume after X seconds, or off to disable (default: 15)
30+rtcwake: 15
31+
32+# Add Logs
33+# add the dmesg and ftrace log to the html output (default: false)
34+addlogs: false
35+
36+# Suspend/Resume Gap
37+# insert a small visible gap between suspend and resume on the timeline (default: false)
38+srgap: false
39+
40+# ---- Advanced Options ----
41+
42+# Command to execute in lieu of suspend (default: "")
43+# command: echo mem > /sys/power/state
44+
45+# Display user processes
46+# graph user processes and cpu usage in the timeline (default: false)
47+proc: false
48+
49+# Display function calls
50+# graph source functions in the timeline (default: false)
51+dev: false
52+
53+# Back to Back Suspend/Resume
54+# Run two suspend/resumes back to back (default: false)
55+x2: false
56+
57+# Back to Back Suspend Delay
58+# Time delay between the two test runs in ms (default: 0 ms)
59+x2delay: 0
60+
61+# Pre Suspend Delay
62+# Include an N ms delay before (1st) suspend (default: 0 ms)
63+predelay: 0
64+
65+# Post Resume Delay
66+# Include an N ms delay after (last) resume (default: 0 ms)
67+postdelay: 0
68+
69+# Minimum Device Length
70+# graph only devices longer than min in the timeline (default: 0.001 ms)
71+mindev: 0.001
72+
73+# ---- Debug Options ----
74+
75+# Callgraph
76+# gather detailed ftrace callgraph data on all timeline events (default: false)
77+callgraph: false
78+
79+# Expand Callgraph
80+# pre-expand the callgraph data in the html output (default: disabled)
81+expandcg: false
82+
83+# Minimum Callgraph Length
84+# provide callgraph data for blocks longer than min (default: 0.001 ms)
85+mincg: 1
86+
87+# Timestamp Precision
88+# Number of significant digits in timestamps (0:S, [3:ms], 6:us)
89+timeprec: 3
90+
91+# Device Filter
92+# show only devs whose name/driver includes one of these strings
93+# devicefilter: _cpu_up,_cpu_down,i915,usb
tools/power/pm-graph/sleepgraph.8+41−6
@@ -52,9 +52,32 @@ disable rtcwake and require a user keypress to resume. · 51 unmodified lines
5252 \fB-addlogs\fR
5353 Add the dmesg and ftrace logs to the html output. They will be viewable by
5454 clicking buttons in the timeline.
55+.TP
56+\fB-result \fIfile\fR
57+Export a results table to a text file for parsing.
58+.TP
59+\fB-sync\fR
60+Sync the filesystems before starting the test. This reduces the size of
61+the sys_sync call which happens in the suspend_prepare phase.
62+.TP
63+\fB-rs \fIenable/disable\fR
64+During test, enable/disable runtime suspend for all devices. The test is delayed
65+by 5 seconds to allow runtime suspend changes to occur. The settings are restored
66+after the test is complete.
67+.TP
68+\fB-display \fIon/off\fR
69+Turn the display on or off for the test using the xset command. This helps
70+maintain the consistecy of test data for better comparison.
71+.TP
72+\fB-skiphtml\fR
73+Run the test and capture the trace logs, but skip the timeline generation.
5574
5675 .SS "advanced"
5776 .TP
77+\fB-gzip\fR
78+Gzip the trace and dmesg logs to save space. The tool can also read in gzipped
79+logs for processing.
80+.TP
5881 \fB-cmd \fIstr\fR
5982 Run the timeline over a custom suspend command, e.g. pm-suspend. By default
6083 the tool forces suspend via /sys/power/state so this allows testing over
@@ -114,6 +137,18 @@ This reduces the html file size as there can be many tiny callgraphs · 53 unmodified lines
114137 which are barely visible in the timeline.
115138 The value is a float: e.g. 0.001 represents 1 us.
116139 .TP
140+\fB-cgfilter \fI"func1,func2,..."\fR
141+Reduce callgraph output in the timeline by limiting it to a list of calls. The
142+argument can be a single function name or a comma delimited list.
143+(default: none)
144+.TP
145+\fB-cgskip \fIfile\fR
146+Reduce callgraph timeline size by skipping over uninteresting functions
147+in the trace, e.g. printk or console_unlock. The functions listed
148+in this file will show up as empty leaves in the callgraph with only the start/end
149+times displayed. cgskip.txt is used automatically if found in the path, so
150+use "off" to disable completely (default: cgskip.txt)
151+.TP
117152 \fB-cgphase \fIp\fR
118153 Only show callgraph data for phase \fIp\fR (e.g. suspend_late).
119154 .TP
@@ -122,6 +157,9 @@ In an x2 run, only show callgraph data for test \fIn\fR (e.g. 0 or 1). · 2 unmodified lines
122157 .TP
123158 \fB-timeprec \fIn\fR
124159 Number of significant digits in timestamps (0:S, [3:ms], 6:us).
160+.TP
161+\fB-bufsize \fIN\fR
162+Set trace buffer size to N kilo-bytes (default: all of free memory up to 3GB)
125163
126164 .SH COMMANDS
127165 .TP
@@ -144,11 +182,8 @@ Print out the contents of the ACPI Firmware Performance Data Table. · 16 unmodified lines
144182 \fB-sysinfo\fR
145183 Print out system info extracted from BIOS. Reads /dev/mem directly instead of going through dmidecode.
146184 .TP
147−\fB-usbtopo\fR
148−Print out the current USB topology with power info.
149−.TP
150−\fB-usbauto\fR
151−Enable autosuspend for all connected USB devices.
185+\fB-devinfo\fR
186+Print out the pm settings of all devices which support runtime suspend.
152187 .TP
153188 \fB-flist\fR
154189 Print the list of ftrace functions currently being captured. Functions
@@ -198,7 +233,7 @@ Execute a mem suspend with a 15 second wakeup. Include the logs in the html. · 43 unmodified lines
198233 .PP
199234 Execute a standby with a 15 second wakeup. Change the output folder name.
200235 .IP
201−\f(CW$ sudo sleepgraph -m standby -rtcwake 15 -o "standby-{hostname}-{date}-{time}"\fR
236+\f(CW$ sudo sleepgraph -m standby -rtcwake 15 -o "standby-{host}-{date}-{time}"\fR
202237 .PP
203238 Execute a freeze with no wakeup (require keypress). Change output folder name.
204239 .IP
tools/power/pm-graph/sleepgraph.pyrenamed from tools/power/pm-graph/analyze_suspend.py+1012−613
@@ -19,7 +19,7 @@ · 18 unmodified lines
1919 # Home Page
2020 # https://01.org/suspendresume
2121 # Source repo
22−# https://github.com/01org/pm-graph
22+# git@github.com:01org/pm-graph
2323 #
2424 # Description:
2525 # This tool is designed to assist kernel and OS developers in optimizing
@@ -57,6 +57,7 @@ import platform · 31 unmodified lines
5757 from datetime import datetime
5858 import struct
5959 import ConfigParser
60+import gzip
6061 from threading import Thread
6162 from subprocess import call, Popen, PIPE
6263
@@ -68,8 +69,12 @@ from subprocess import call, Popen, PIPE · 5 unmodified lines
6869 # store system values and test parameters
6970 class SystemValues:
7071 title = 'SleepGraph'
71− version = '4.7'
72+ version = '5.0'
7273 ansi = False
74+ rs = 0
75+ display = 0
76+ gzip = False
77+ sync = False
7378 verbose = False
7479 testlog = True
7580 dmesglog = False
@@ -78,14 +83,19 @@ class SystemValues: · 2 unmodified lines
7883 mincglen = 0.0
7984 cgphase = ''
8085 cgtest = -1
86+ cgskip = ''
87+ multitest = {'run': False, 'count': 0, 'delay': 0}
8188 max_graph_depth = 0
8289 callloopmaxgap = 0.0001
8390 callloopmaxlen = 0.005
91+ bufsize = 0
8492 cpucount = 0
8593 memtotal = 204800
94+ memfree = 204800
8695 srgap = 0
8796 cgexp = False
8897 testdir = ''
98+ outdir = ''
8999 tpath = '/sys/kernel/debug/tracing/'
90100 fpdtpath = '/sys/firmware/acpi/tables/FPDT'
91101 epath = '/sys/kernel/debug/tracing/events/power/'
@@ -109,22 +119,24 @@ class SystemValues: · 17 unmodified lines
109119 dmesgfile = ''
110120 ftracefile = ''
111121 htmlfile = 'output.html'
112− embedded = False
122+ result = ''
113123 rtcwake = True
114124 rtcwaketime = 15
115125 rtcpath = ''
116126 devicefilter = []
127+ cgfilter = []
117128 stamp = 0
118129 execcount = 1
119130 x2delay = 0
131+ skiphtml = False
120132 usecallgraph = False
121133 usetraceevents = False
122− usetraceeventsonly = False
123134 usetracemarkers = True
124135 usekprobes = True
125136 usedevsrc = False
126137 useprocmon = False
127138 notestrun = False
139+ cgdump = False
128140 mixedphaseheight = True
129141 devprops = dict()
130142 predelay = 0
@@ -134,24 +146,33 @@ class SystemValues: · 3 unmodified lines
134146 tracertypefmt = '# tracer: (?P<t>.*)'
135147 firmwarefmt = '# fwsuspend (?P<s>[0-9]*) fwresume (?P<r>[0-9]*)$'
136148 tracefuncs = {
137− 'sys_sync': dict(),
138− 'pm_prepare_console': dict(),
139− 'pm_notifier_call_chain': dict(),
140− 'freeze_processes': dict(),
141− 'freeze_kernel_threads': dict(),
142− 'pm_restrict_gfp_mask': dict(),
143− 'acpi_suspend_begin': dict(),
144− 'suspend_console': dict(),
145− 'acpi_pm_prepare': dict(),
146− 'syscore_suspend': dict(),
147− 'arch_enable_nonboot_cpus_end': dict(),
148− 'syscore_resume': dict(),
149− 'acpi_pm_finish': dict(),
150− 'resume_console': dict(),
151− 'acpi_pm_end': dict(),
152− 'pm_restore_gfp_mask': dict(),
153− 'thaw_processes': dict(),
154− 'pm_restore_console': dict(),
149+ 'sys_sync': {},
150+ '__pm_notifier_call_chain': {},
151+ 'pm_prepare_console': {},
152+ 'pm_notifier_call_chain': {},
153+ 'freeze_processes': {},
154+ 'freeze_kernel_threads': {},
155+ 'pm_restrict_gfp_mask': {},
156+ 'acpi_suspend_begin': {},
157+ 'acpi_hibernation_begin': {},
158+ 'acpi_hibernation_enter': {},
159+ 'acpi_hibernation_leave': {},
160+ 'acpi_pm_freeze': {},
161+ 'acpi_pm_thaw': {},
162+ 'hibernate_preallocate_memory': {},
163+ 'create_basic_memory_bitmaps': {},
164+ 'swsusp_write': {},
165+ 'suspend_console': {},
166+ 'acpi_pm_prepare': {},
167+ 'syscore_suspend': {},
168+ 'arch_enable_nonboot_cpus_end': {},
169+ 'syscore_resume': {},
170+ 'acpi_pm_finish': {},
171+ 'resume_console': {},
172+ 'acpi_pm_end': {},
173+ 'pm_restore_gfp_mask': {},
174+ 'thaw_processes': {},
175+ 'pm_restore_console': {},
155176 'CPU_OFF': {
156177 'func':'_cpu_down',
157178 'args_x86_64': {'cpu':'%di:s32'},
@@ -173,56 +194,54 @@ class SystemValues: · 15 unmodified lines
173194 'mutex_lock_slowpath': { 'func':'__mutex_lock_slowpath', 'ub': 1 },
174195 'acpi_os_stall': {'ub': 1},
175196 # ACPI
176− 'acpi_resume_power_resources': dict(),
177− 'acpi_ps_parse_aml': dict(),
197+ 'acpi_resume_power_resources': {},
198+ 'acpi_ps_parse_aml': {},
178199 # filesystem
179− 'ext4_sync_fs': dict(),
200+ 'ext4_sync_fs': {},
180201 # 80211
181− 'iwlagn_mac_start': dict(),
182− 'iwlagn_alloc_bcast_station': dict(),
183− 'iwl_trans_pcie_start_hw': dict(),
184− 'iwl_trans_pcie_start_fw': dict(),
185− 'iwl_run_init_ucode': dict(),
186− 'iwl_load_ucode_wait_alive': dict(),
187− 'iwl_alive_start': dict(),
188− 'iwlagn_mac_stop': dict(),
189− 'iwlagn_mac_suspend': dict(),
190− 'iwlagn_mac_resume': dict(),
191− 'iwlagn_mac_add_interface': dict(),
192− 'iwlagn_mac_remove_interface': dict(),
193− 'iwlagn_mac_change_interface': dict(),
194− 'iwlagn_mac_config': dict(),
195− 'iwlagn_configure_filter': dict(),
196− 'iwlagn_mac_hw_scan': dict(),
197− 'iwlagn_bss_info_changed': dict(),
198− 'iwlagn_mac_channel_switch': dict(),
199− 'iwlagn_mac_flush': dict(),
202+ 'iwlagn_mac_start': {},
203+ 'iwlagn_alloc_bcast_station': {},
204+ 'iwl_trans_pcie_start_hw': {},
205+ 'iwl_trans_pcie_start_fw': {},
206+ 'iwl_run_init_ucode': {},
207+ 'iwl_load_ucode_wait_alive': {},
208+ 'iwl_alive_start': {},
209+ 'iwlagn_mac_stop': {},
210+ 'iwlagn_mac_suspend': {},
211+ 'iwlagn_mac_resume': {},
212+ 'iwlagn_mac_add_interface': {},
213+ 'iwlagn_mac_remove_interface': {},
214+ 'iwlagn_mac_change_interface': {},
215+ 'iwlagn_mac_config': {},
216+ 'iwlagn_configure_filter': {},
217+ 'iwlagn_mac_hw_scan': {},
218+ 'iwlagn_bss_info_changed': {},
219+ 'iwlagn_mac_channel_switch': {},
220+ 'iwlagn_mac_flush': {},
200221 # ATA
201222 'ata_eh_recover': { 'args_x86_64': {'port':'+36(%di):s32'} },
202223 # i915
203− 'i915_gem_resume': dict(),
204− 'i915_restore_state': dict(),
205− 'intel_opregion_setup': dict(),
206− 'g4x_pre_enable_dp': dict(),
207− 'vlv_pre_enable_dp': dict(),
208− 'chv_pre_enable_dp': dict(),
209− 'g4x_enable_dp': dict(),
210− 'vlv_enable_dp': dict(),
211− 'intel_hpd_init': dict(),
212− 'intel_opregion_register': dict(),
213− 'intel_dp_detect': dict(),
214− 'intel_hdmi_detect': dict(),
215− 'intel_opregion_init': dict(),
216− 'intel_fbdev_set_suspend': dict(),
224+ 'i915_gem_resume': {},
225+ 'i915_restore_state': {},
226+ 'intel_opregion_setup': {},
227+ 'g4x_pre_enable_dp': {},
228+ 'vlv_pre_enable_dp': {},
229+ 'chv_pre_enable_dp': {},
230+ 'g4x_enable_dp': {},
231+ 'vlv_enable_dp': {},
232+ 'intel_hpd_init': {},
233+ 'intel_opregion_register': {},
234+ 'intel_dp_detect': {},
235+ 'intel_hdmi_detect': {},
236+ 'intel_opregion_init': {},
237+ 'intel_fbdev_set_suspend': {},
217238 }
239+ cgblacklist = []
218240 kprobes = dict()
219241 timeformat = '%.3f'
242+ cmdline = '%s %s' % \
243+ (os.path.basename(sys.argv[0]), string.join(sys.argv[1:], ' '))
220244 def __init__(self):
221− # if this is a phoronix test run, set some default options
222− if('LOG_FILE' in os.environ and 'TEST_RESULTS_IDENTIFIER' in os.environ):
223− self.embedded = True
224− self.dmesglog = self.ftracelog = True
225− self.htmlfile = os.environ['LOG_FILE']
226245 self.archargs = 'args_'+platform.machine()
227246 self.hostname = platform.node()
228247 if(self.hostname == ''):
@@ -237,18 +256,36 @@ class SystemValues: · 8 unmodified lines
237256 if (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()):
238257 self.ansi = True
239258 self.testdir = datetime.now().strftime('suspend-%y%m%d-%H%M%S')
259+ def vprint(self, msg):
260+ self.logmsg += msg+'\n'
261+ if(self.verbose):
262+ print(msg)
240263 def rootCheck(self, fatal=True):
241264 if(os.access(self.powerfile, os.W_OK)):
242265 return True
243266 if fatal:
244− doError('This command requires sysfs mount and root access')
267+ msg = 'This command requires sysfs mount and root access'
268+ print('ERROR: %s\n') % msg
269+ self.outputResult({'error':msg})
270+ sys.exit()
245271 return False
246272 def rootUser(self, fatal=False):
247273 if 'USER' in os.environ and os.environ['USER'] == 'root':
248274 return True
249275 if fatal:
250− doError('This command must be run as root')
276+ msg = 'This command must be run as root'
277+ print('ERROR: %s\n') % msg
278+ self.outputResult({'error':msg})
279+ sys.exit()
251280 return False
281+ def getExec(self, cmd):
282+ dirlist = ['/sbin', '/bin', '/usr/sbin', '/usr/bin',
283+ '/usr/local/sbin', '/usr/local/bin']
284+ for path in dirlist:
285+ cmdfull = os.path.join(path, cmd)
286+ if os.path.exists(cmdfull):
287+ return cmdfull
288+ return ''
252289 def setPrecision(self, num):
253290 if num < 0 or num > 6:
254291 return
@@ -258,15 +295,15 @@ class SystemValues: · 3 unmodified lines
258295 n = datetime.now()
259296 args['date'] = n.strftime('%y%m%d')
260297 args['time'] = n.strftime('%H%M%S')
261− args['hostname'] = self.hostname
298+ args['hostname'] = args['host'] = self.hostname
262299 return value.format(**args)
263300 def setOutputFile(self):
264301 if self.dmesgfile != '':
265− m = re.match('(?P<name>.*)_dmesg\.txt$', self.dmesgfile)
302+ m = re.match('(?P<name>.*)_dmesg\.txt.*', self.dmesgfile)
266303 if(m):
267304 self.htmlfile = m.group('name')+'.html'
268305 if self.ftracefile != '':
269− m = re.match('(?P<name>.*)_ftrace\.txt$', self.ftracefile)
306+ m = re.match('(?P<name>.*)_ftrace\.txt.*', self.ftracefile)
270307 if(m):
271308 self.htmlfile = m.group('name')+'.html'
272309 def systemInfo(self, info):
@@ -283,16 +320,19 @@ class SystemValues: · 10 unmodified lines
283320 c = info['processor-version']
284321 if 'bios-version' in info:
285322 b = info['bios-version']
286− self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | numcpu:%d | memsz:%d' % \
287− (m, p, c, b, self.cpucount, self.memtotal)
288− def printSystemInfo(self):
323+ self.sysstamp = '# sysinfo | man:%s | plat:%s | cpu:%s | bios:%s | numcpu:%d | memsz:%d | memfr:%d' % \
324+ (m, p, c, b, self.cpucount, self.memtotal, self.memfree)
325+ def printSystemInfo(self, fatal=False):
289326 self.rootCheck(True)
290− out = dmidecode(self.mempath, True)
327+ out = dmidecode(self.mempath, fatal)
328+ if len(out) < 1:
329+ return
291330 fmt = '%-24s: %s'
292331 for name in sorted(out):
293332 print fmt % (name, out[name])
294333 print fmt % ('cpucount', ('%d' % self.cpucount))
295334 print fmt % ('memtotal', ('%d kB' % self.memtotal))
335+ print fmt % ('memfree', ('%d kB' % self.memfree))
296336 def cpuInfo(self):
297337 self.cpucount = 0
298338 fp = open('/proc/cpuinfo', 'r')
@@ -305,7 +345,9 @@ class SystemValues: · 6 unmodified lines
305345 m = re.match('^MemTotal:[ \t]*(?P<sz>[0-9]*) *kB', line)
306346 if m:
307347 self.memtotal = int(m.group('sz'))
308− break
348+ m = re.match('^MemFree:[ \t]*(?P<sz>[0-9]*) *kB', line)
349+ if m:
350+ self.memfree = int(m.group('sz'))
309351 fp.close()
310352 def initTestOutput(self, name):
311353 self.prefix = self.hostname
@@ -315,39 +357,34 @@ class SystemValues: · 3 unmodified lines
315357 testtime = datetime.now().strftime(fmt)
316358 self.teststamp = \
317359 '# '+testtime+' '+self.prefix+' '+self.suspendmode+' '+kver
318− if(self.embedded):
319− self.dmesgfile = \
320− '/tmp/'+testtime+'_'+self.suspendmode+'_dmesg.txt'
321− self.ftracefile = \
322− '/tmp/'+testtime+'_'+self.suspendmode+'_ftrace.txt'
323− return
360+ ext = ''
361+ if self.gzip:
362+ ext = '.gz'
324363 self.dmesgfile = \
325− self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'
364+ self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'+ext
326365 self.ftracefile = \
327− self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'
366+ self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'+ext
328367 self.htmlfile = \
329368 self.testdir+'/'+self.prefix+'_'+self.suspendmode+'.html'
330369 if not os.path.isdir(self.testdir):
331370 os.mkdir(self.testdir)
371+ def getValueList(self, value):
372+ out = []
373+ for i in value.split(','):
374+ if i.strip():
375+ out.append(i.strip())
376+ return out
332377 def setDeviceFilter(self, value):
333− self.devicefilter = []
334− if value:
335− value = value.split(',')
336− for i in value:
337− self.devicefilter.append(i.strip())
378+ self.devicefilter = self.getValueList(value)
379+ def setCallgraphFilter(self, value):
380+ self.cgfilter = self.getValueList(value)
381+ def setCallgraphBlacklist(self, file):
382+ self.cgblacklist = self.listFromFile(file)
338383 def rtcWakeAlarmOn(self):
339384 call('echo 0 > '+self.rtcpath+'/wakealarm', shell=True)
340− outD = open(self.rtcpath+'/date', 'r').read().strip()
341− outT = open(self.rtcpath+'/time', 'r').read().strip()
342− mD = re.match('^(?P<y>[0-9]*)-(?P<m>[0-9]*)-(?P<d>[0-9]*)', outD)
343− mT = re.match('^(?P<h>[0-9]*):(?P<m>[0-9]*):(?P<s>[0-9]*)', outT)
344− if(mD and mT):
345− # get the current time from hardware
346− utcoffset = int((datetime.now() - datetime.utcnow()).total_seconds())
347− dt = datetime(\
348− int(mD.group('y')), int(mD.group('m')), int(mD.group('d')),
349− int(mT.group('h')), int(mT.group('m')), int(mT.group('s')))
350− nowtime = int(dt.strftime('%s')) + utcoffset
385+ nowtime = open(self.rtcpath+'/since_epoch', 'r').read().strip()
386+ if nowtime:
387+ nowtime = int(nowtime)
351388 else:
352389 # if hardware time fails, use the software time
353390 nowtime = int(datetime.now().strftime('%s'))
@@ -369,10 +406,10 @@ class SystemValues: · 15 unmodified lines
369406 ktime = m.group('ktime')
370407 fp.close()
371408 self.dmesgstart = float(ktime)
372− def getdmesg(self):
409+ def getdmesg(self, fwdata=[]):
410+ op = self.writeDatafileHeader(sysvals.dmesgfile, fwdata)
373411 # store all new dmesg lines since initdmesg was called
374412 fp = Popen('dmesg', stdout=PIPE).stdout
375− op = open(self.dmesgfile, 'a')
376413 for line in fp:
377414 line = line.replace('\r\n', '')
378415 idx = line.find('[')
@@ -386,11 +423,17 @@ class SystemValues: · 7 unmodified lines
386423 op.write(line)
387424 fp.close()
388425 op.close()
389− def addFtraceFilterFunctions(self, file):
426+ def listFromFile(self, file):
427+ list = []
390428 fp = open(file)
391− list = fp.read().split('\n')
429+ for i in fp.read().split('\n'):
430+ i = i.strip()
431+ if i and i[0] != '#':
432+ list.append(i)
392433 fp.close()
393− for i in list:
434+ return list
435+ def addFtraceFilterFunctions(self, file):
436+ for i in self.listFromFile(file):
394437 if len(i) < 2:
395438 continue
396439 self.tracefuncs[i] = dict()
@@ -399,9 +442,7 @@ class SystemValues: · 2 unmodified lines
399442 if not current:
400443 call('cat '+self.tpath+'available_filter_functions', shell=True)
401444 return
402− fp = open(self.tpath+'available_filter_functions')
403− master = fp.read().split('\n')
404− fp.close()
445+ master = self.listFromFile(self.tpath+'available_filter_functions')
405446 for i in self.tracefuncs:
406447 if 'func' in self.tracefuncs[i]:
407448 i = self.tracefuncs[i]['func']
@@ -410,9 +451,7 @@ class SystemValues: · 2 unmodified lines
410451 else:
411452 print self.colorText(i)
412453 def setFtraceFilterFunctions(self, list):
413− fp = open(self.tpath+'available_filter_functions')
414− master = fp.read().split('\n')
415− fp.close()
454+ master = self.listFromFile(self.tpath+'available_filter_functions')
416455 flist = ''
417456 for i in list:
418457 if i not in master:
@@ -501,6 +540,7 @@ class SystemValues: · 82 unmodified lines
501540 rejects = []
502541 # sort kprobes: trace, ub-dev, custom, dev
503542 kpl = [[], [], [], []]
543+ linesout = len(self.kprobes)
504544 for name in sorted(self.kprobes):
505545 res = self.colorText('YES', 32)
506546 if not self.testKprobe(name, self.kprobes[name]):
@@ -528,17 +568,10 @@ class SystemValues: · 21 unmodified lines
528568 for kp in kplist:
529569 kprobeevents += self.kprobeText(kp, self.kprobes[kp])
530570 self.fsetVal(kprobeevents, 'kprobe_events')
531− # verify that the kprobes were set as ordered
532− check = self.fgetVal('kprobe_events')
533− linesout = len(kprobeevents.split('\n')) - 1
534− linesack = len(check.split('\n')) - 1
535571 if output:
536− res = '%d/%d' % (linesack, linesout)
537− if linesack < linesout:
538− res = self.colorText(res, 31)
539− else:
540− res = self.colorText(res, 32)
541− print(' working kprobe functions enabled: %s' % res)
572+ check = self.fgetVal('kprobe_events')
573+ linesack = (len(check.split('\n')) - 1) / 2
574+ print(' kprobe functions enabled: %d/%d' % (linesack, linesout))
542575 self.fsetVal('1', 'events/kprobes/enable')
543576 def testKprobe(self, kname, kprobe):
544577 self.fsetVal('0', 'events/kprobes/enable')
@@ -555,8 +588,7 @@ class SystemValues: · 10 unmodified lines
555588 if linesack < linesout:
556589 return False
557590 return True
558− def fsetVal(self, val, path, mode='w'):
559− file = self.tpath+path
591+ def setVal(self, val, file, mode='w'):
560592 if not os.path.exists(file):
561593 return False
562594 try:
@@ -567,8 +599,9 @@ class SystemValues: · 4 unmodified lines
567599 except:
568600 return False
569601 return True
570− def fgetVal(self, path):
571− file = self.tpath+path
602+ def fsetVal(self, val, path, mode='w'):
603+ return self.setVal(val, self.tpath+path, mode)
604+ def getVal(self, file):
572605 res = ''
573606 if not os.path.exists(file):
574607 return res
@@ -579,10 +612,13 @@ class SystemValues: · 4 unmodified lines
579612 except:
580613 pass
581614 return res
615+ def fgetVal(self, path):
616+ return self.getVal(self.tpath+path)
582617 def cleanupFtrace(self):
583− if(self.usecallgraph or self.usetraceevents):
618+ if(self.usecallgraph or self.usetraceevents or self.usedevsrc):
584619 self.fsetVal('0', 'events/kprobes/enable')
585620 self.fsetVal('', 'kprobe_events')
621+ self.fsetVal('1024', 'buffer_size_kb')
586622 def setupAllKprobes(self):
587623 for name in self.tracefuncs:
588624 self.defaultKprobe(name, self.tracefuncs[name])
@@ -599,7 +635,8 @@ class SystemValues: · 10 unmodified lines
599635 if name == f:
600636 return True
601637 return False
602− def initFtrace(self, testing=False):
638+ def initFtrace(self):
639+ self.printSystemInfo(False)
603640 print('INITIALIZING FTRACE...')
604641 # turn trace off
605642 self.fsetVal('0', 'tracing_on')
@@ -607,17 +644,21 @@ class SystemValues: · 1 unmodified line
607644 # set the trace clock to global
608645 self.fsetVal('global', 'trace_clock')
609646 self.fsetVal('nop', 'current_tracer')
610− # set trace buffer to a huge value
611− if self.usecallgraph or self.usedevsrc:
612− tgtsize = min(self.memtotal / 2, 2*1024*1024)
613− maxbuf = '%d' % (tgtsize / max(1, self.cpucount))
614− if self.cpucount < 1 or not self.fsetVal(maxbuf, 'buffer_size_kb'):
615− self.fsetVal('131072', 'buffer_size_kb')
647+ # set trace buffer to an appropriate value
648+ cpus = max(1, self.cpucount)
649+ if self.bufsize > 0:
650+ tgtsize = self.bufsize
651+ elif self.usecallgraph or self.usedevsrc:
652+ tgtsize = min(self.memfree, 3*1024*1024)
616653 else:
617− self.fsetVal('16384', 'buffer_size_kb')
618− # go no further if this is just a status check
619− if testing:
620− return
654+ tgtsize = 65536
655+ while not self.fsetVal('%d' % (tgtsize / cpus), 'buffer_size_kb'):
656+ # if the size failed to set, lower it and keep trying
657+ tgtsize -= 65536
658+ if tgtsize < 65536:
659+ tgtsize = int(self.fgetVal('buffer_size_kb')) * cpus
660+ break
661+ print 'Setting trace buffers to %d kB (%d kB per cpu)' % (tgtsize, tgtsize/cpus)
621662 # initialize the callgraph trace
622663 if(self.usecallgraph):
623664 # set trace type
@@ -635,7 +676,7 @@ class SystemValues: · 11 unmodified lines
635676 self.fsetVal('graph-time', 'trace_options')
636677 self.fsetVal('%d' % self.max_graph_depth, 'max_graph_depth')
637678 cf = ['dpm_run_callback']
638− if(self.usetraceeventsonly):
679+ if(self.usetraceevents):
639680 cf += ['dpm_prepare', 'dpm_complete']
640681 for fn in self.tracefuncs:
641682 if 'func' in self.tracefuncs[fn]:
@@ -688,16 +729,65 @@ class SystemValues: · 46 unmodified lines
688729 return str
689730 return '\x1B[%d;40m%s\x1B[m' % (color, str)
690731 def writeDatafileHeader(self, filename, fwdata=[]):
691− fp = open(filename, 'w')
692− fp.write(self.teststamp+'\n')
693− fp.write(self.sysstamp+'\n')
732+ fp = self.openlog(filename, 'w')
733+ fp.write('%s\n%s\n# command | %s\n' % (self.teststamp, self.sysstamp, self.cmdline))
694734 if(self.suspendmode == 'mem' or self.suspendmode == 'command'):
695735 for fw in fwdata:
696736 if(fw):
697737 fp.write('# fwsuspend %u fwresume %u\n' % (fw[0], fw[1]))
738+ return fp
739+ def sudouser(self, dir):
740+ if os.path.exists(dir) and os.getuid() == 0 and \
741+ 'SUDO_USER' in os.environ:
742+ cmd = 'chown -R {0}:{0} {1} > /dev/null 2>&1'
743+ call(cmd.format(os.environ['SUDO_USER'], dir), shell=True)
744+ def outputResult(self, testdata, num=0):
745+ if not self.result:
746+ return
747+ n = ''
748+ if num > 0:
749+ n = '%d' % num
750+ fp = open(self.result, 'a')
751+ if 'error' in testdata:
752+ fp.write('result%s: fail\n' % n)
753+ fp.write('error%s: %s\n' % (n, testdata['error']))
754+ else:
755+ fp.write('result%s: pass\n' % n)
756+ for v in ['suspend', 'resume', 'boot', 'lastinit']:
757+ if v in testdata:
758+ fp.write('%s%s: %.3f\n' % (v, n, testdata[v]))
759+ for v in ['fwsuspend', 'fwresume']:
760+ if v in testdata:
761+ fp.write('%s%s: %.3f\n' % (v, n, testdata[v] / 1000000.0))
762+ if 'bugurl' in testdata:
763+ fp.write('url%s: %s\n' % (n, testdata['bugurl']))
698764 fp.close()
765+ self.sudouser(self.result)
766+ def configFile(self, file):
767+ dir = os.path.dirname(os.path.realpath(__file__))
768+ if os.path.exists(file):
769+ return file
770+ elif os.path.exists(dir+'/'+file):
771+ return dir+'/'+file
772+ elif os.path.exists(dir+'/config/'+file):
773+ return dir+'/config/'+file
774+ return ''
775+ def openlog(self, filename, mode):
776+ isgz = self.gzip
777+ if mode == 'r':
778+ try:
779+ with gzip.open(filename, mode+'b') as fp:
780+ test = fp.read(64)
781+ isgz = True
782+ except:
783+ isgz = False
784+ if isgz:
785+ return gzip.open(filename, mode+'b')
786+ return open(filename, mode)
699787
700788 sysvals = SystemValues()
789+switchvalues = ['enable', 'disable', 'on', 'off', 'true', 'false', '1', '0']
790+switchoff = ['disable', 'off', 'false', '0']
701791 suspendmodename = {
702792 'freeze': 'Freeze (S0)',
703793 'standby': 'Standby (S1)',
@@ -826,34 +916,65 @@ class Data: · 122 unmodified lines
826916 for phase in self.phases:
827917 self.devicegroups.append([phase])
828918 self.errorinfo = {'suspend':[],'resume':[]}
829− def extractErrorInfo(self, dmesg):
830− error = ''
831− tm = 0.0
832− for i in range(len(dmesg)):
833− if 'Call Trace:' in dmesg[i]:
834− m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) .*', dmesg[i])
835− if not m:
836− continue
837− tm = float(m.group('ktime'))
838− if tm < self.start or tm > self.end:
839− continue
840− for j in range(i-10, i+1):
841− error += dmesg[j]
919+ def extractErrorInfo(self):
920+ lf = sysvals.openlog(sysvals.dmesgfile, 'r')
921+ i = 0
922+ list = []
923+ # sl = start line, et = error time, el = error line
924+ type = 'ERROR'
925+ sl = et = el = -1
926+ for line in lf:
927+ i += 1
928+ m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
929+ if not m:
842930 continue
843− if error:
844− m = re.match('[ \t]*\[ *[0-9\.]*\] \[\<[0-9a-fA-F]*\>\] .*', dmesg[i])
845− if m:
846− error += dmesg[i]
847− else:
848− if tm < self.tSuspended:
849− dir = 'suspend'
850− else:
851− dir = 'resume'
852− error = error.replace('<', '&lt').replace('>', '&gt')
853− vprint('kernel error found in %s at %f' % (dir, tm))
854− self.errorinfo[dir].append((tm, error))
931+ t = float(m.group('ktime'))
932+ if t < self.start or t > self.end:
933+ continue
934+ if t < self.tSuspended:
935+ dir = 'suspend'
936+ else:
937+ dir = 'resume'
938+ msg = m.group('msg')
939+ if re.match('-*\[ *cut here *\]-*', msg):
940+ type = 'WARNING'
941+ sl = i
942+ elif re.match('genirq: .*', msg):
943+ type = 'IRQ'
944+ sl = i
945+ elif re.match('BUG: .*', msg) or re.match('kernel BUG .*', msg):
946+ type = 'BUG'
947+ sl = i
948+ elif re.match('-*\[ *end trace .*\]-*', msg) or \
949+ re.match('R13: .*', msg):
950+ if et >= 0 and sl >= 0:
951+ list.append((type, dir, et, sl, i))
855952 self.kerror = True
856− error = ''
953+ sl = et = el = -1
954+ type = 'ERROR'
955+ elif 'Call Trace:' in msg:
956+ if el >= 0 and et >= 0:
957+ list.append((type, dir, et, el, el))
958+ self.kerror = True
959+ et, el = t, i
960+ if sl < 0 or type == 'BUG':
961+ slval = i
962+ if sl >= 0:
963+ slval = sl
964+ list.append((type, dir, et, slval, i))
965+ self.kerror = True
966+ sl = et = el = -1
967+ type = 'ERROR'
968+ if el >= 0 and et >= 0:
969+ list.append((type, dir, et, el, el))
970+ self.kerror = True
971+ for e in list:
972+ type, dir, t, idx1, idx2 = e
973+ sysvals.vprint('kernel %s found in %s at %f' % (type, dir, t))
974+ self.errorinfo[dir].append((type, t, idx1, idx2))
975+ if self.kerror:
976+ sysvals.dmesglog = True
977+ lf.close()
857978 def setStart(self, time):
858979 self.start = time
859980 def setEnd(self, time):
@@ -867,6 +988,14 @@ class Data: · 7 unmodified lines
867988 time < d['end']):
868989 return False
869990 return True
991+ def phaseCollision(self, phase, isbegin, line):
992+ key = 'end'
993+ if isbegin:
994+ key = 'start'
995+ if self.dmesg[phase][key] >= 0:
996+ sysvals.vprint('IGNORE: %s' % line.strip())
997+ return True
998+ return False
870999 def sourcePhase(self, start):
8711000 for phase in self.phases:
8721001 pend = self.dmesg[phase]['end']
@@ -918,7 +1047,7 @@ class Data: · 45 unmodified lines
9181047 return self.addDeviceFunctionCall(displayname, kprobename, proc, pid, start, end, cdata, rdata)
9191048 # this should not happen
9201049 if not tgtdev:
921− vprint('[%f - %f] %s-%d %s %s %s' % \
1050+ sysvals.vprint('[%f - %f] %s-%d %s %s %s' % \
9221051 (start, end, proc, pid, kprobename, cdata, rdata))
9231052 return False
9241053 # place the call data inside the src element of the tgtdev
@@ -1054,6 +1183,13 @@ class Data: · 129 unmodified lines
10541183 if('src' in d):
10551184 for e in d['src']:
10561185 e.time = self.trimTimeVal(e.time, t0, dT, left)
1186+ for dir in ['suspend', 'resume']:
1187+ list = []
1188+ for e in self.errorinfo[dir]:
1189+ type, tm, idx1, idx2 = e
1190+ tm = self.trimTimeVal(tm, t0, dT, left)
1191+ list.append((type, tm, idx1, idx2))
1192+ self.errorinfo[dir] = list
10571193 def normalizeTime(self, tZero):
10581194 # trim out any standby or freeze clock time
10591195 if(self.tSuspended != self.tResumed):
@@ -1100,7 +1236,7 @@ class Data: · 40 unmodified lines
11001236 if self.dmesg[p]['end'] > dev['start']:
11011237 dev['end'] = self.dmesg[p]['end']
11021238 break
1103− vprint('%s (%s): callback didnt return' % (devname, phase))
1239+ sysvals.vprint('%s (%s): callback didnt return' % (devname, phase))
11041240 def deviceFilter(self, devicefilter):
11051241 for phase in self.phases:
11061242 list = self.dmesg[phase]['list']
@@ -1200,15 +1336,15 @@ class Data: · 93 unmodified lines
12001336 devlist.append(child)
12011337 return devlist
12021338 def printDetails(self):
1203− vprint('Timeline Details:')
1204− vprint(' test start: %f' % self.start)
1205− vprint('kernel suspend start: %f' % self.tKernSus)
1339+ sysvals.vprint('Timeline Details:')
1340+ sysvals.vprint(' test start: %f' % self.start)
1341+ sysvals.vprint('kernel suspend start: %f' % self.tKernSus)
12061342 for phase in self.phases:
12071343 dc = len(self.dmesg[phase]['list'])
1208− vprint(' %16s: %f - %f (%d devices)' % (phase, \
1344+ sysvals.vprint(' %16s: %f - %f (%d devices)' % (phase, \
12091345 self.dmesg[phase]['start'], self.dmesg[phase]['end'], dc))
1210− vprint(' kernel resume end: %f' % self.tKernRes)
1211− vprint(' test end: %f' % self.end)
1346+ sysvals.vprint(' kernel resume end: %f' % self.tKernRes)
1347+ sysvals.vprint(' test end: %f' % self.end)
12121348 def deviceChildrenAllPhases(self, devname):
12131349 devlist = []
12141350 for phase in self.phases:
@@ -1358,14 +1494,21 @@ class Data: · 143 unmodified lines
13581494 tres.append(t)
13591495 # process the events for suspend and resume
13601496 if len(proclist) > 0:
1361− vprint('Process Execution:')
1497+ sysvals.vprint('Process Execution:')
13621498 for ps in proclist:
13631499 c = self.addProcessUsageEvent(ps, tsus)
13641500 if c > 0:
1365− vprint('%25s (sus): %d' % (ps, c))
1501+ sysvals.vprint('%25s (sus): %d' % (ps, c))
13661502 c = self.addProcessUsageEvent(ps, tres)
13671503 if c > 0:
1368− vprint('%25s (res): %d' % (ps, c))
1504+ sysvals.vprint('%25s (res): %d' % (ps, c))
1505+ def debugPrint(self):
1506+ for p in self.phases:
1507+ list = self.dmesg[p]['list']
1508+ for devname in list:
1509+ dev = list[devname]
1510+ if 'ftrace' in dev:
1511+ dev['ftrace'].debugPrint(' [%s]' % devname)
13691512
13701513 # Class: DevFunction
13711514 # Description:
@@ -1504,18 +1647,24 @@ class FTraceLine: · 132 unmodified lines
15041647 # something else (possibly a trace marker)
15051648 else:
15061649 self.name = m
1650+ def isCall(self):
1651+ return self.fcall and not self.freturn
1652+ def isReturn(self):
1653+ return self.freturn and not self.fcall
1654+ def isLeaf(self):
1655+ return self.fcall and self.freturn
15071656 def getDepth(self, str):
15081657 return len(str)/2
1509− def debugPrint(self, dev=''):
1510− if(self.freturn and self.fcall):
1511− print('%s -- %f (%02d): %s(); (%.3f us)' % (dev, self.time, \
1512− self.depth, self.name, self.length*1000000))
1513− elif(self.freturn):
1514− print('%s -- %f (%02d): %s} (%.3f us)' % (dev, self.time, \
1515− self.depth, self.name, self.length*1000000))
1658+ def debugPrint(self, info=''):
1659+ if self.isLeaf():
1660+ print(' -- %12.6f (depth=%02d): %s(); (%.3f us) %s' % (self.time, \
1661+ self.depth, self.name, self.length*1000000, info))
1662+ elif self.freturn:
1663+ print(' -- %12.6f (depth=%02d): %s} (%.3f us) %s' % (self.time, \
1664+ self.depth, self.name, self.length*1000000, info))
15161665 else:
1517− print('%s -- %f (%02d): %s() { (%.3f us)' % (dev, self.time, \
1518− self.depth, self.name, self.length*1000000))
1666+ print(' -- %12.6f (depth=%02d): %s() { (%.3f us) %s' % (self.time, \
1667+ self.depth, self.name, self.length*1000000, info))
15191668 def startMarker(self):
15201669 # Is this the starting line of a suspend?
15211670 if not self.fevent:
@@ -1558,107 +1707,160 @@ class FTraceCallGraph: · 36 unmodified lines
15581707 depth = 0
15591708 pid = 0
15601709 name = ''
1561− def __init__(self, pid):
1710+ partial = False
1711+ vfname = 'missing_function_name'
1712+ ignore = False
1713+ sv = 0
1714+ def __init__(self, pid, sv):
15621715 self.start = -1.0
15631716 self.end = -1.0
15641717 self.list = []
15651718 self.depth = 0
15661719 self.pid = pid
1567− def addLine(self, line, debug=False):
1720+ self.sv = sv
1721+ def addLine(self, line):
15681722 # if this is already invalid, just leave
15691723 if(self.invalid):
1570− return False
1571− # invalidate on too much data or bad depth
1572− if(len(self.list) >= 1000000 or self.depth < 0):
1724+ if(line.depth == 0 and line.freturn):
1725+ return 1
1726+ return 0
1727+ # invalidate on bad depth
1728+ if(self.depth < 0):
15731729 self.invalidate(line)
1574− return False
1730+ return 0
1731+ # ignore data til we return to the current depth
1732+ if self.ignore:
1733+ if line.depth > self.depth:
1734+ return 0
1735+ else:
1736+ self.list[-1].freturn = True
1737+ self.list[-1].length = line.time - self.list[-1].time
1738+ self.ignore = False
1739+ # if this is a return at self.depth, no more work is needed
1740+ if line.depth == self.depth and line.isReturn():
1741+ if line.depth == 0:
1742+ self.end = line.time
1743+ return 1
1744+ return 0
15751745 # compare current depth with this lines pre-call depth
15761746 prelinedep = line.depth
1577− if(line.freturn and not line.fcall):
1747+ if line.isReturn():
15781748 prelinedep += 1
15791749 last = 0
15801750 lasttime = line.time
1581− virtualfname = 'missing_function_name'
15821751 if len(self.list) > 0:
15831752 last = self.list[-1]
15841753 lasttime = last.time
1754+ if last.isLeaf():
1755+ lasttime += last.length
15851756 # handle low misalignments by inserting returns
1586− if prelinedep < self.depth:
1587− if debug and last:
1588− print '-------- task %d --------' % self.pid
1589− last.debugPrint()
1757+ mismatch = prelinedep - self.depth
1758+ warning = self.sv.verbose and abs(mismatch) > 1
1759+ info = []
1760+ if mismatch < 0:
15901761 idx = 0
15911762 # add return calls to get the depth down
15921763 while prelinedep < self.depth:
1593− if debug:
1594− print 'MISALIGN LOW (add returns): C%d - eC%d' % (self.depth, prelinedep)
15951764 self.depth -= 1
1596− if idx == 0 and last and last.fcall and not last.freturn:
1765+ if idx == 0 and last and last.isCall():
15971766 # special case, turn last call into a leaf
15981767 last.depth = self.depth
15991768 last.freturn = True
16001769 last.length = line.time - last.time
1601− if debug:
1602− last.debugPrint()
1770+ if warning:
1771+ info.append(('[make leaf]', last))
16031772 else:
16041773 vline = FTraceLine(lasttime)
16051774 vline.depth = self.depth
1606− vline.name = virtualfname
1775+ vline.name = self.vfname
16071776 vline.freturn = True
16081777 self.list.append(vline)
1609− if debug:
1610− vline.debugPrint()
1778+ if warning:
1779+ if idx == 0:
1780+ info.append(('', last))
1781+ info.append(('[add return]', vline))
16111782 idx += 1
1612− if debug:
1613− line.debugPrint()
1614− print ''
1783+ if warning:
1784+ info.append(('', line))
16151785 # handle high misalignments by inserting calls
1616− elif prelinedep > self.depth:
1617− if debug and last:
1618− print '-------- task %d --------' % self.pid
1619− last.debugPrint()
1786+ elif mismatch > 0:
16201787 idx = 0
1788+ if warning:
1789+ info.append(('', last))
16211790 # add calls to get the depth up
16221791 while prelinedep > self.depth:
1623− if debug:
1624− print 'MISALIGN HIGH (add calls): C%d - eC%d' % (self.depth, prelinedep)
1625− if idx == 0 and line.freturn and not line.fcall:
1792+ if idx == 0 and line.isReturn():
16261793 # special case, turn this return into a leaf
16271794 line.fcall = True
16281795 prelinedep -= 1
1796+ if warning:
1797+ info.append(('[make leaf]', line))
16291798 else:
16301799 vline = FTraceLine(lasttime)
16311800 vline.depth = self.depth
1632− vline.name = virtualfname
1801+ vline.name = self.vfname
16331802 vline.fcall = True
1634− if debug:
1635− vline.debugPrint()
16361803 self.list.append(vline)
16371804 self.depth += 1
16381805 if not last:
16391806 self.start = vline.time
1807+ if warning:
1808+ info.append(('[add call]', vline))
16401809 idx += 1
1641− if debug:
1642− line.debugPrint()
1643− print ''
1810+ if warning and ('[make leaf]', line) not in info:
1811+ info.append(('', line))
1812+ if warning:
1813+ print 'WARNING: ftrace data missing, corrections made:'
1814+ for i in info:
1815+ t, obj = i
1816+ if obj:
1817+ obj.debugPrint(t)
16441818 # process the call and set the new depth
1645− if(line.fcall and not line.freturn):
1646− self.depth += 1
1647− elif(line.freturn and not line.fcall):
1819+ skipadd = False
1820+ md = self.sv.max_graph_depth
1821+ if line.isCall():
1822+ # ignore blacklisted/overdepth funcs
1823+ if (md and self.depth >= md - 1) or (line.name in self.sv.cgblacklist):
1824+ self.ignore = True
1825+ else:
1826+ self.depth += 1
1827+ elif line.isReturn():
16481828 self.depth -= 1
1829+ # remove blacklisted/overdepth/empty funcs that slipped through
1830+ if (last and last.isCall() and last.depth == line.depth) or \
1831+ (md and last and last.depth >= md) or \
1832+ (line.name in self.sv.cgblacklist):
1833+ while len(self.list) > 0 and self.list[-1].depth > line.depth:
1834+ self.list.pop(-1)
1835+ if len(self.list) == 0:
1836+ self.invalid = True
1837+ return 1
1838+ self.list[-1].freturn = True
1839+ self.list[-1].length = line.time - self.list[-1].time
1840+ self.list[-1].name = line.name
1841+ skipadd = True
16491842 if len(self.list) < 1:
16501843 self.start = line.time
1651− self.list.append(line)
1844+ # check for a mismatch that returned all the way to callgraph end
1845+ res = 1
1846+ if mismatch < 0 and self.list[-1].depth == 0 and self.list[-1].freturn:
1847+ line = self.list[-1]
1848+ skipadd = True
1849+ res = -1
1850+ if not skipadd:
1851+ self.list.append(line)
16521852 if(line.depth == 0 and line.freturn):
16531853 if(self.start < 0):
16541854 self.start = line.time
16551855 self.end = line.time
16561856 if line.fcall:
16571857 self.end += line.length
1658− if self.list[0].name == virtualfname:
1858+ if self.list[0].name == self.vfname:
16591859 self.invalid = True
1660− return True
1661− return False
1860+ if res == -1:
1861+ self.partial = True
1862+ return res
1863+ return 0
16621864 def invalidate(self, line):
16631865 if(len(self.list) > 0):
16641866 first = self.list[0]
@@ -1668,29 +1870,30 @@ class FTraceCallGraph: · 3 unmodified lines
16681870 id = 'task %s' % (self.pid)
16691871 window = '(%f - %f)' % (self.start, line.time)
16701872 if(self.depth < 0):
1671− vprint('Too much data for '+id+\
1873+ print('Data misalignment for '+id+\
16721874 ' (buffer overflow), ignoring this callback')
16731875 else:
1674− vprint('Too much data for '+id+\
1876+ print('Too much data for '+id+\
16751877 ' '+window+', ignoring this callback')
1676− def slice(self, t0, tN):
1677− minicg = FTraceCallGraph(0)
1678− count = -1
1679− firstdepth = 0
1878+ def slice(self, dev):
1879+ minicg = FTraceCallGraph(dev['pid'], self.sv)
1880+ minicg.name = self.name
1881+ mydepth = -1
1882+ good = False
16801883 for l in self.list:
1681− if(l.time < t0 or l.time > tN):
1884+ if(l.time < dev['start'] or l.time > dev['end']):
16821885 continue
1683− if(count < 0):
1684− if(not l.fcall or l.name == 'dev_driver_string'):
1685− continue
1686− firstdepth = l.depth
1687− count = 0
1688− l.depth -= firstdepth
1689− minicg.addLine(l)
1690− if((count == 0 and l.freturn and l.fcall) or
1691− (count > 0 and l.depth <= 0)):
1886+ if mydepth < 0:
1887+ if l.name == 'mutex_lock' and l.freturn:
1888+ mydepth = l.depth
1889+ continue
1890+ elif l.depth == mydepth and l.name == 'mutex_unlock' and l.fcall:
1891+ good = True
16921892 break
1693− count += 1
1893+ l.depth -= mydepth
1894+ minicg.addLine(l)
1895+ if not good or len(minicg.list) < 1:
1896+ return 0
16941897 return minicg
16951898 def repair(self, enddepth):
16961899 # bring the depth back to 0 with additional returns
@@ -1701,11 +1904,11 @@ class FTraceCallGraph: · 4 unmodified lines
17011904 t.depth = i
17021905 t.freturn = True
17031906 fixed = self.addLine(t)
1704− if fixed:
1907+ if fixed != 0:
17051908 self.end = last.time
17061909 return True
17071910 return False
1708− def postProcess(self, debug=False):
1911+ def postProcess(self):
17091912 if len(self.list) > 0:
17101913 self.name = self.list[0].name
17111914 stack = dict()
@@ -1714,20 +1917,23 @@ class FTraceCallGraph: · 2 unmodified lines
17141917 for l in self.list:
17151918 # ftrace bug: reported duration is not reliable
17161919 # check each leaf and clip it at max possible length
1717− if(last and last.freturn and last.fcall):
1920+ if last and last.isLeaf():
17181921 if last.length > l.time - last.time:
17191922 last.length = l.time - last.time
1720− if(l.fcall and not l.freturn):
1923+ if l.isCall():
17211924 stack[l.depth] = l
17221925 cnt += 1
1723− elif(l.freturn and not l.fcall):
1926+ elif l.isReturn():
17241927 if(l.depth not in stack):
1725− if debug:
1928+ if self.sv.verbose:
17261929 print 'Post Process Error: Depth missing'
17271930 l.debugPrint()
17281931 return False
17291932 # calculate call length from call/return lines
1730− stack[l.depth].length = l.time - stack[l.depth].time
1933+ cl = stack[l.depth]
1934+ cl.length = l.time - cl.time
1935+ if cl.name == self.vfname:
1936+ cl.name = l.name
17311937 stack.pop(l.depth)
17321938 l.length = 0
17331939 cnt -= 1
@@ -1736,13 +1942,13 @@ class FTraceCallGraph: · 2 unmodified lines
17361942 # trace caught the whole call tree
17371943 return True
17381944 elif(cnt < 0):
1739− if debug:
1945+ if self.sv.verbose:
17401946 print 'Post Process Error: Depth is less than 0'
17411947 return False
17421948 # trace ended before call tree finished
17431949 return self.repair(cnt)
17441950 def deviceMatch(self, pid, data):
1745− found = False
1951+ found = ''
17461952 # add the callgraph data to the device hierarchy
17471953 borderphase = {
17481954 'dpm_prepare': 'suspend_prepare',
@@ -1756,8 +1962,10 @@ class FTraceCallGraph: · 7 unmodified lines
17561962 if(pid == dev['pid'] and
17571963 self.start <= dev['start'] and
17581964 self.end >= dev['end']):
1759− dev['ftrace'] = self.slice(dev['start'], dev['end'])
1760− found = True
1965+ cg = self.slice(dev)
1966+ if cg:
1967+ dev['ftrace'] = cg
1968+ found = devname
17611969 return found
17621970 for p in data.phases:
17631971 if(data.dmesg[p]['start'] <= self.start and
@@ -1769,7 +1977,7 @@ class FTraceCallGraph: · 5 unmodified lines
17691977 self.start <= dev['start'] and
17701978 self.end >= dev['end']):
17711979 dev['ftrace'] = self
1772− found = True
1980+ found = devname
17731981 break
17741982 break
17751983 return found
@@ -1793,18 +2001,20 @@ class FTraceCallGraph: · 17 unmodified lines
17932001 if out:
17942002 phase, myname = out
17952003 data.dmesg[phase]['list'][myname]['ftrace'] = self
1796− def debugPrint(self):
1797− print('[%f - %f] %s (%d)') % (self.start, self.end, self.name, self.pid)
2004+ def debugPrint(self, info=''):
2005+ print('%s pid=%d [%f - %f] %.3f us') % \
2006+ (self.name, self.pid, self.start, self.end,
2007+ (self.end - self.start)*1000000)
17982008 for l in self.list:
1799− if(l.freturn and l.fcall):
1800− print('%f (%02d): %s(); (%.3f us)' % (l.time, \
1801− l.depth, l.name, l.length*1000000))
1802− elif(l.freturn):
1803− print('%f (%02d): %s} (%.3f us)' % (l.time, \
1804− l.depth, l.name, l.length*1000000))
2009+ if l.isLeaf():
2010+ print('%f (%02d): %s(); (%.3f us)%s' % (l.time, \
2011+ l.depth, l.name, l.length*1000000, info))
2012+ elif l.freturn:
2013+ print('%f (%02d): %s} (%.3f us)%s' % (l.time, \
2014+ l.depth, l.name, l.length*1000000, info))
18052015 else:
1806− print('%f (%02d): %s() { (%.3f us)' % (l.time, \
1807− l.depth, l.name, l.length*1000000))
2016+ print('%f (%02d): %s() { (%.3f us)%s' % (l.time, \
2017+ l.depth, l.name, l.length*1000000, info))
18082018 print(' ')
18092019
18102020 class DevItem:
@@ -1839,8 +2049,8 @@ class Timeline: · 28 unmodified lines
18392049 self.rowH = rowheight
18402050 self.scaleH = scaleheight
18412051 self.html = ''
1842− def createHeader(self, sv):
1843− if(not sv.stamp['time']):
2052+ def createHeader(self, sv, stamp):
2053+ if(not stamp['time']):
18442054 return
18452055 self.html += '<div class="version"><a href="https://01.org/suspendresume">%s v%s</a></div>' \
18462056 % (sv.title, sv.version)
@@ -1851,12 +2061,12 @@ class Timeline: · 4 unmodified lines
18512061 if sv.ftracelog:
18522062 self.html += '<button id="showftrace" class="logbtn btnfmt">ftrace</button>'
18532063 headline_stamp = '<div class="stamp">{0} {1} {2} {3}</div>\n'
1854− self.html += headline_stamp.format(sv.stamp['host'], sv.stamp['kernel'],
1855− sv.stamp['mode'], sv.stamp['time'])
1856− if 'man' in sv.stamp and 'plat' in sv.stamp and 'cpu' in sv.stamp:
2064+ self.html += headline_stamp.format(stamp['host'], stamp['kernel'],
2065+ stamp['mode'], stamp['time'])
2066+ if 'man' in stamp and 'plat' in stamp and 'cpu' in stamp and \
2067+ stamp['man'] and stamp['plat'] and stamp['cpu']:
18572068 headline_sysinfo = '<div class="stamp sysinfo">{0} {1} <i>with</i> {2}</div>\n'
1858− self.html += headline_sysinfo.format(sv.stamp['man'],
1859− sv.stamp['plat'], sv.stamp['cpu'])
2069+ self.html += headline_sysinfo.format(stamp['man'], stamp['plat'], stamp['cpu'])
18602070
18612071 # Function: getDeviceRows
18622072 # Description:
@@ -2067,12 +2277,16 @@ class Timeline: · 204 unmodified lines
20672277 class TestProps:
20682278 stamp = ''
20692279 sysinfo = ''
2280+ cmdline = ''
2281+ kparams = ''
20702282 S0i3 = False
20712283 fwdata = []
20722284 stampfmt = '# [a-z]*-(?P<m>[0-9]{2})(?P<d>[0-9]{2})(?P<y>[0-9]{2})-'+\
20732285 '(?P<H>[0-9]{2})(?P<M>[0-9]{2})(?P<S>[0-9]{2})'+\
20742286 ' (?P<host>.*) (?P<mode>.*) (?P<kernel>.*)$'
20752287 sysinfofmt = '^# sysinfo .*'
2288+ cmdlinefmt = '^# command \| (?P<cmd>.*)'
2289+ kparamsfmt = '^# kparams \| (?P<kp>.*)'
20762290 ftrace_line_fmt_fg = \
20772291 '^ *(?P<time>[0-9\.]*) *\| *(?P<cpu>[0-9]*)\)'+\
20782292 ' *(?P<proc>.*)-(?P<pid>[0-9]*) *\|'+\
@@ -2116,13 +2330,20 @@ class TestProps: · 37 unmodified lines
21162330 sv.hostname = data.stamp['host']
21172331 sv.suspendmode = data.stamp['mode']
21182332 if sv.suspendmode == 'command' and sv.ftracefile != '':
2119− modes = ['on', 'freeze', 'standby', 'mem']
2120− out = Popen(['grep', 'suspend_enter', sv.ftracefile],
2333+ modes = ['on', 'freeze', 'standby', 'mem', 'disk']
2334+ out = Popen(['grep', 'machine_suspend', sv.ftracefile],
21212335 stderr=PIPE, stdout=PIPE).stdout.read()
2122− m = re.match('.* suspend_enter\[(?P<mode>.*)\]', out)
2123− if m and m.group('mode') in ['1', '2', '3']:
2336+ m = re.match('.* machine_suspend\[(?P<mode>.*)\]', out)
2337+ if m and m.group('mode') in ['1', '2', '3', '4']:
21242338 sv.suspendmode = modes[int(m.group('mode'))]
21252339 data.stamp['mode'] = sv.suspendmode
2340+ m = re.match(self.cmdlinefmt, self.cmdline)
2341+ if m:
2342+ sv.cmdline = m.group('cmd')
2343+ if self.kparams:
2344+ m = re.match(self.kparamsfmt, self.kparams)
2345+ if m:
2346+ sv.kparams = m.group('kp')
21262347 if not sv.stamp:
21272348 sv.stamp = data.stamp
21282349
@@ -2186,47 +2407,43 @@ class ProcessMonitor: · 57 unmodified lines
21862407
21872408 # ----------------- FUNCTIONS --------------------
21882409
2189−# Function: vprint
2190−# Description:
2191−# verbose print (prints only with -verbose option)
2192−# Arguments:
2193−# msg: the debug/log message to print
2194−def vprint(msg):
2195− sysvals.logmsg += msg+'\n'
2196− if(sysvals.verbose):
2197− print(msg)
2198−
21992410 # Function: doesTraceLogHaveTraceEvents
22002411 # Description:
2201−# Quickly determine if the ftrace log has some or all of the trace events
2202−# required for primary parsing. Set the usetraceevents and/or
2203−# usetraceeventsonly flags in the global sysvals object
2412+# Quickly determine if the ftrace log has all of the trace events,
2413+# markers, and/or kprobes required for primary parsing.
22042414 def doesTraceLogHaveTraceEvents():
2205− # check for kprobes
2415+ kpcheck = ['_cal: (', '_cpu_down()']
2416+ techeck = sysvals.traceevents[:]
2417+ tmcheck = ['SUSPEND START', 'RESUME COMPLETE']
22062418 sysvals.usekprobes = False
2207− out = call('grep -q "_cal: (" '+sysvals.ftracefile, shell=True)
2208− if(out == 0):
2209− sysvals.usekprobes = True
2210− # check for callgraph data on trace event blocks
2211− out = call('grep -q "_cpu_down()" '+sysvals.ftracefile, shell=True)
2212− if(out == 0):
2213− sysvals.usekprobes = True
2214− out = Popen(['head', '-1', sysvals.ftracefile],
2215− stderr=PIPE, stdout=PIPE).stdout.read().replace('\n', '')
2216− # figure out what level of trace events are supported
2217− sysvals.usetraceeventsonly = True
2218− sysvals.usetraceevents = False
2219− for e in sysvals.traceevents:
2220− out = call('grep -q "'+e+': " '+sysvals.ftracefile, shell=True)
2221− if(out != 0):
2222− sysvals.usetraceeventsonly = False
2223− if(e == 'suspend_resume' and out == 0):
2224− sysvals.usetraceevents = True
2225− # determine is this log is properly formatted
2226− for e in ['SUSPEND START', 'RESUME COMPLETE']:
2227− out = call('grep -q "'+e+'" '+sysvals.ftracefile, shell=True)
2228− if(out != 0):
2229− sysvals.usetracemarkers = False
2419+ fp = sysvals.openlog(sysvals.ftracefile, 'r')
2420+ for line in fp:
2421+ # check for kprobes
2422+ if not sysvals.usekprobes:
2423+ for i in kpcheck:
2424+ if i in line:
2425+ sysvals.usekprobes = True
2426+ # check for all necessary trace events
2427+ check = techeck[:]
2428+ for i in techeck:
2429+ if i in line:
2430+ check.remove(i)
2431+ techeck = check
2432+ # check for all necessary trace markers
2433+ check = tmcheck[:]
2434+ for i in tmcheck:
2435+ if i in line:
2436+ check.remove(i)
2437+ tmcheck = check
2438+ fp.close()
2439+ if len(techeck) == 0:
2440+ sysvals.usetraceevents = True
2441+ else:
2442+ sysvals.usetraceevents = False
2443+ if len(tmcheck) == 0:
2444+ sysvals.usetracemarkers = True
2445+ else:
2446+ sysvals.usetracemarkers = False
22302447
22312448 # Function: appendIncompleteTraceLog
22322449 # Description:
@@ -2247,9 +2464,10 @@ def appendIncompleteTraceLog(testruns): · 14 unmodified lines
22472464 testrun.append(TestRun(data))
22482465
22492466 # extract the callgraph and traceevent data
2250− vprint('Analyzing the ftrace data...')
2467+ sysvals.vprint('Analyzing the ftrace data (%s)...' % \
2468+ os.path.basename(sysvals.ftracefile))
22512469 tp = TestProps()
2252− tf = open(sysvals.ftracefile, 'r')
2470+ tf = sysvals.openlog(sysvals.ftracefile, 'r')
22532471 data = 0
22542472 for line in tf:
22552473 # remove any latent carriage returns
@@ -2261,6 +2479,9 @@ def appendIncompleteTraceLog(testruns): · 5 unmodified lines
22612479 elif re.match(tp.sysinfofmt, line):
22622480 tp.sysinfo = line
22632481 continue
2482+ elif re.match(tp.cmdlinefmt, line):
2483+ tp.cmdline = line
2484+ continue
22642485 # determine the trace data type (required for further parsing)
22652486 m = re.match(sysvals.tracertypefmt, line)
22662487 if(m):
@@ -2393,11 +2614,14 @@ def appendIncompleteTraceLog(testruns): · 126 unmodified lines
23932614 # create a callgraph object for the data
23942615 if(pid not in testrun[testidx].ftemp):
23952616 testrun[testidx].ftemp[pid] = []
2396− testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid))
2617+ testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid, sysvals))
23972618 # when the call is finished, see which device matches it
23982619 cg = testrun[testidx].ftemp[pid][-1]
2399− if(cg.addLine(t)):
2400− testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid))
2620+ res = cg.addLine(t)
2621+ if(res != 0):
2622+ testrun[testidx].ftemp[pid].append(FTraceCallGraph(pid, sysvals))
2623+ if(res == -1):
2624+ testrun[testidx].ftemp[pid][-1].addLine(t)
24012625 tf.close()
24022626
24032627 for test in testrun:
@@ -2410,11 +2634,11 @@ def appendIncompleteTraceLog(testruns): · 6 unmodified lines
24102634 # add the callgraph data to the device hierarchy
24112635 for pid in test.ftemp:
24122636 for cg in test.ftemp[pid]:
2413− if len(cg.list) < 1 or cg.invalid:
2637+ if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
24142638 continue
24152639 if(not cg.postProcess()):
24162640 id = 'task %s cpu %s' % (pid, m.group('cpu'))
2417− vprint('Sanity check failed for '+\
2641+ sysvals.vprint('Sanity check failed for '+\
24182642 id+', ignoring this callback')
24192643 continue
24202644 callstart = cg.start
@@ -2431,8 +2655,6 @@ def appendIncompleteTraceLog(testruns): · 10 unmodified lines
24312655 dev['ftrace'] = cg
24322656 break
24332657
2434− test.data.printDetails()
2435−
24362658 # Function: parseTraceLog
24372659 # Description:
24382660 # Analyze an ftrace log output file generated from this app during
@@ -2441,12 +2663,13 @@ def appendIncompleteTraceLog(testruns): · 2 unmodified lines
24412663 # The ftrace filename is taken from sysvals
24422664 # Output:
24432665 # An array of Data objects
2444−def parseTraceLog():
2445− vprint('Analyzing the ftrace data...')
2666+def parseTraceLog(live=False):
2667+ sysvals.vprint('Analyzing the ftrace data (%s)...' % \
2668+ os.path.basename(sysvals.ftracefile))
24462669 if(os.path.exists(sysvals.ftracefile) == False):
24472670 doError('%s does not exist' % sysvals.ftracefile)
2448−
2449− sysvals.setupAllKprobes()
2671+ if not live:
2672+ sysvals.setupAllKprobes()
24502673 tracewatch = []
24512674 if sysvals.usekprobes:
24522675 tracewatch += ['sync_filesystems', 'freeze_processes', 'syscore_suspend',
@@ -2458,7 +2681,7 @@ def parseTraceLog(): · 5 unmodified lines
24582681 testdata = []
24592682 testrun = 0
24602683 data = 0
2461− tf = open(sysvals.ftracefile, 'r')
2684+ tf = sysvals.openlog(sysvals.ftracefile, 'r')
24622685 phase = 'suspend_prepare'
24632686 for line in tf:
24642687 # remove any latent carriage returns
@@ -2470,6 +2693,9 @@ def parseTraceLog(): · 5 unmodified lines
24702693 elif re.match(tp.sysinfofmt, line):
24712694 tp.sysinfo = line
24722695 continue
2696+ elif re.match(tp.cmdlinefmt, line):
2697+ tp.cmdline = line
2698+ continue
24732699 # firmware line: pull out any firmware data
24742700 m = re.match(sysvals.firmwarefmt, line)
24752701 if(m):
@@ -2591,6 +2817,8 @@ def parseTraceLog(): · 115 unmodified lines
25912817 phase = 'suspend_prepare'
25922818 if(not isbegin):
25932819 data.dmesg[phase]['end'] = t.time
2820+ if data.dmesg[phase]['start'] < 0:
2821+ data.dmesg[phase]['start'] = data.start
25942822 continue
25952823 # suspend start
25962824 elif(re.match('dpm_suspend\[.*', t.name)):
@@ -2604,6 +2832,8 @@ def parseTraceLog(): · 7 unmodified lines
26042832 continue
26052833 # suspend_noirq start
26062834 elif(re.match('dpm_suspend_noirq\[.*', t.name)):
2835+ if data.phaseCollision('suspend_noirq', isbegin, line):
2836+ continue
26072837 phase = 'suspend_noirq'
26082838 data.setPhase(phase, t.time, isbegin)
26092839 if(not isbegin):
@@ -2636,6 +2866,8 @@ def parseTraceLog(): · 26 unmodified lines
26362866 continue
26372867 # resume_noirq start
26382868 elif(re.match('dpm_resume_noirq\[.*', t.name)):
2869+ if data.phaseCollision('resume_noirq', isbegin, line):
2870+ continue
26392871 phase = 'resume_noirq'
26402872 data.setPhase(phase, t.time, isbegin)
26412873 if(isbegin):
@@ -2742,11 +2974,14 @@ def parseTraceLog(): · 100 unmodified lines
27422974 key = (m_proc, pid)
27432975 if(key not in testrun.ftemp):
27442976 testrun.ftemp[key] = []
2745− testrun.ftemp[key].append(FTraceCallGraph(pid))
2977+ testrun.ftemp[key].append(FTraceCallGraph(pid, sysvals))
27462978 # when the call is finished, see which device matches it
27472979 cg = testrun.ftemp[key][-1]
2748− if(cg.addLine(t)):
2749− testrun.ftemp[key].append(FTraceCallGraph(pid))
2980+ res = cg.addLine(t)
2981+ if(res != 0):
2982+ testrun.ftemp[key].append(FTraceCallGraph(pid, sysvals))
2983+ if(res == -1):
2984+ testrun.ftemp[key][-1].addLine(t)
27502985 tf.close()
27512986
27522987 if sysvals.suspendmode == 'command':
@@ -2812,28 +3047,31 @@ def parseTraceLog(): · 59 unmodified lines
28123047 for key in test.ftemp:
28133048 proc, pid = key
28143049 for cg in test.ftemp[key]:
2815− if len(cg.list) < 1 or cg.invalid:
3050+ if len(cg.list) < 1 or cg.invalid or (cg.end - cg.start == 0):
28163051 continue
28173052 if(not cg.postProcess()):
28183053 id = 'task %s' % (pid)
2819− vprint('Sanity check failed for '+\
3054+ sysvals.vprint('Sanity check failed for '+\
28203055 id+', ignoring this callback')
28213056 continue
28223057 # match cg data to devices
2823− if sysvals.suspendmode == 'command' or not cg.deviceMatch(pid, data):
3058+ devname = ''
3059+ if sysvals.suspendmode != 'command':
3060+ devname = cg.deviceMatch(pid, data)
3061+ if not devname:
28243062 sortkey = '%f%f%d' % (cg.start, cg.end, pid)
28253063 sortlist[sortkey] = cg
3064+ elif len(cg.list) > 1000000:
3065+ print 'WARNING: the callgraph for %s is massive (%d lines)' %\
3066+ (devname, len(cg.list))
28263067 # create blocks for orphan cg data
28273068 for sortkey in sorted(sortlist):
28283069 cg = sortlist[sortkey]
28293070 name = cg.name
28303071 if sysvals.isCallgraphFunc(name):
2831− vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name))
3072+ sysvals.vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name))
28323073 cg.newActionFromFunction(data)
2833−
28343074 if sysvals.suspendmode == 'command':
2835− for data in testdata:
2836− data.printDetails()
28373075 return testdata
28383076
28393077 # fill in any missing phases
@@ -2841,7 +3079,7 @@ def parseTraceLog(): · 1 unmodified line
28413079 lp = data.phases[0]
28423080 for p in data.phases:
28433081 if(data.dmesg[p]['start'] < 0 and data.dmesg[p]['end'] < 0):
2844− vprint('WARNING: phase "%s" is missing!' % p)
3082+ sysvals.vprint('WARNING: phase "%s" is missing!' % p)
28453083 if(data.dmesg[p]['start'] < 0):
28463084 data.dmesg[p]['start'] = data.dmesg[lp]['end']
28473085 if(p == 'resume_machine'):
@@ -2859,7 +3097,6 @@ def parseTraceLog(): · 11 unmodified lines
28593097 data.fixupInitcallsThatDidntReturn()
28603098 if sysvals.usedevsrc:
28613099 data.optimizeDevSrc()
2862− data.printDetails()
28633100
28643101 # x2: merge any overlapping devices between test runs
28653102 if sysvals.usedevsrc and len(testdata) > 1:
@@ -2878,19 +3115,18 @@ def parseTraceLog(): · 12 unmodified lines
28783115 # The dmesg filename is taken from sysvals
28793116 # Output:
28803117 # An array of empty Data objects with only their dmesgtext attributes set
2881−def loadKernelLog(justtext=False):
2882− vprint('Analyzing the dmesg data...')
3118+def loadKernelLog():
3119+ sysvals.vprint('Analyzing the dmesg data (%s)...' % \
3120+ os.path.basename(sysvals.dmesgfile))
28833121 if(os.path.exists(sysvals.dmesgfile) == False):
28843122 doError('%s does not exist' % sysvals.dmesgfile)
28853123
2886− if justtext:
2887− dmesgtext = []
28883124 # there can be multiple test runs in a single file
28893125 tp = TestProps()
28903126 tp.stamp = datetime.now().strftime('# suspend-%m%d%y-%H%M%S localhost mem unknown')
28913127 testruns = []
28923128 data = 0
2893− lf = open(sysvals.dmesgfile, 'r')
3129+ lf = sysvals.openlog(sysvals.dmesgfile, 'r')
28943130 for line in lf:
28953131 line = line.replace('\r\n', '')
28963132 idx = line.find('[')
@@ -2903,6 +3139,9 @@ def loadKernelLog(justtext=False): · 6 unmodified lines
29033139 elif re.match(tp.sysinfofmt, line):
29043140 tp.sysinfo = line
29053141 continue
3142+ elif re.match(tp.cmdlinefmt, line):
3143+ tp.cmdline = line
3144+ continue
29063145 m = re.match(sysvals.firmwarefmt, line)
29073146 if(m):
29083147 tp.fwdata.append((int(m.group('s')), int(m.group('r'))))
@@ -2911,9 +3150,6 @@ def loadKernelLog(justtext=False): · 2 unmodified lines
29113150 if(not m):
29123151 continue
29133152 msg = m.group("msg")
2914− if justtext:
2915− dmesgtext.append(line)
2916− continue
29173153 if(re.match('PM: Syncing filesystems.*', msg)):
29183154 if(data):
29193155 testruns.append(data)
@@ -2934,8 +3170,6 @@ def loadKernelLog(justtext=False): · 14 unmodified lines
29343170 data.dmesgtext.append(line)
29353171 lf.close()
29363172
2937− if justtext:
2938− return dmesgtext
29393173 if data:
29403174 testruns.append(data)
29413175 if len(testruns) < 1:
@@ -2975,7 +3209,7 @@ def parseKernelLog(data): · 33 unmodified lines
29753209 phase = 'suspend_runtime'
29763210
29773211 if(data.fwValid):
2978− vprint('Firmware Suspend = %u ns, Firmware Resume = %u ns' % \
3212+ sysvals.vprint('Firmware Suspend = %u ns, Firmware Resume = %u ns' % \
29793213 (data.fwSuspend, data.fwResume))
29803214
29813215 # dmesg phase match table
@@ -3201,7 +3435,6 @@ def parseKernelLog(data): · 219 unmodified lines
32013435 for event in actions[name]:
32023436 data.newActionGlobal(name, event['begin'], event['end'])
32033437
3204− data.printDetails()
32053438 if(len(sysvals.devicefilter) > 0):
32063439 data.deviceFilter(sysvals.devicefilter)
32073440 data.fixupInitcallsThatDidntReturn()
@@ -3230,9 +3463,9 @@ def callgraphHTML(sv, hf, num, cg, title, color, devid): · 22 unmodified lines
32303463 else:
32313464 fmt = '<n>(%.3f ms @ '+sv.timeformat+')</n>'
32323465 flen = fmt % (line.length*1000, line.time)
3233− if(line.freturn and line.fcall):
3466+ if line.isLeaf():
32343467 hf.write(html_func_leaf.format(line.name, flen))
3235− elif(line.freturn):
3468+ elif line.freturn:
32363469 hf.write(html_func_end)
32373470 else:
32383471 hf.write(html_func_start.format(num, line.name, flen))
@@ -3249,7 +3482,7 @@ def addCallgraphs(sv, hf, data): · 10 unmodified lines
32493482 continue
32503483 list = data.dmesg[p]['list']
32513484 for devname in data.sortedDevices(p):
3252− if len(sv.devicefilter) > 0 and devname not in sv.devicefilter:
3485+ if len(sv.cgfilter) > 0 and devname not in sv.cgfilter:
32533486 continue
32543487 dev = list[devname]
32553488 color = 'white'
@@ -3270,7 +3503,6 @@ def addCallgraphs(sv, hf, data): · 14 unmodified lines
32703503 for cg in dev['ftraces']:
32713504 num = callgraphHTML(sv, hf, num, cg,
32723505 name+' &rarr; '+cg.name, color, dev['id'])
3273−
32743506 hf.write('\n\n </section>\n')
32753507
32763508 # Function: createHTMLSummarySimple
@@ -3311,7 +3543,7 @@ def createHTMLSummarySimple(testruns, htmlfile, folder): · 34 unmodified lines
33113543 sTimeAvg = rTimeAvg = 0.0
33123544 mode = ''
33133545 num = 0
3314− for data in sorted(testruns, key=lambda v:(v['mode'], v['host'], v['kernel'])):
3546+ for data in sorted(testruns, key=lambda v:(v['mode'], v['host'], v['kernel'], v['time'])):
33153547 if mode != data['mode']:
33163548 # test average line
33173549 if(num > 0):
@@ -3387,7 +3619,7 @@ def createHTML(testruns): · 69 unmodified lines
33873619 data.normalizeTime(testruns[-1].tSuspended)
33883620
33893621 # html function templates
3390− html_error = '<div id="{1}" title="kernel error/warning" class="err" style="right:{0}%">ERROR&rarr;</div>\n'
3622+ html_error = '<div id="{1}" title="kernel error/warning" class="err" style="right:{0}%">{2}&rarr;</div>\n'
33913623 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'
33923624 html_cpuexec = '<div class="jiffie" style="left:{0}%;top:{1}px;height:{2}px;width:{3}%;background:{4};"></div>\n'
33933625 html_timetotal = '<table class="time1">\n<tr>'\
@@ -3416,20 +3648,17 @@ def createHTML(testruns): · 22 unmodified lines
34163648 scaleH = 40
34173649
34183650 # device timeline
3419− vprint('Creating Device Timeline...')
3420−
34213651 devtl = Timeline(30, scaleH)
34223652
34233653 # write the test title and general info header
3424− devtl.createHeader(sysvals)
3654+ devtl.createHeader(sysvals, testruns[0].stamp)
34253655
34263656 # Generate the header for this timeline
34273657 for data in testruns:
34283658 tTotal = data.end - data.start
34293659 sktime, rktime = data.getTimeValues()
34303660 if(tTotal == 0):
3431− print('ERROR: No timeline data')
3432− sys.exit()
3661+ doError('No timeline data')
34333662 if(data.tLow > 0):
34343663 low_time = '%.0f'%(data.tLow*1000)
34353664 if sysvals.suspendmode == 'command':
@@ -3567,9 +3796,10 @@ def createHTML(testruns): · 131 unmodified lines
35673796 data.dmesg[b]['color'], '')
35683797 for e in data.errorinfo[dir]:
35693798 # draw red lines for any kernel errors found
3570− t, err = e
3799+ type, t, idx1, idx2 = e
3800+ id = '%d_%d' % (idx1, idx2)
35713801 right = '%f' % (((mMax-t)*100.0)/mTotal)
3572− devtl.html += html_error.format(right, err)
3802+ devtl.html += html_error.format(right, id, type)
35733803 for b in sorted(phases[dir]):
35743804 # draw the devices for this phase
35753805 phaselist = data.dmesg[b]['list']
@@ -3663,14 +3893,7 @@ def createHTML(testruns): · 87 unmodified lines
36633893 devtl.html += '</div>\n'
36643894
36653895 hf = open(sysvals.htmlfile, 'w')
3666−
3667− # no header or css if its embedded
3668− if(sysvals.embedded):
3669− hf.write('pass True tSus %.3f tRes %.3f tLow %.3f fwvalid %s tSus %.3f tRes %.3f\n' %
3670− (data.tSuspended-data.start, data.end-data.tSuspended, data.tLow, data.fwValid, \
3671− data.fwSuspend/1000000, data.fwResume/1000000))
3672− else:
3673− addCSS(hf, sysvals, len(testruns), kerror)
3896+ addCSS(hf, sysvals, len(testruns), kerror)
36743897
36753898 # write the device timeline
36763899 hf.write(devtl.html)
@@ -3701,7 +3924,7 @@ def createHTML(testruns): · 24 unmodified lines
37013924 data = testruns[sysvals.cgtest]
37023925 else:
37033926 data = testruns[-1]
3704− if(sysvals.usecallgraph and not sysvals.embedded):
3927+ if sysvals.usecallgraph:
37053928 addCallgraphs(sysvals, hf, data)
37063929
37073930 # add the test log as a hidden div
@@ -3710,7 +3933,7 @@ def createHTML(testruns): · 2 unmodified lines
37103933 # add the dmesg log as a hidden div
37113934 if sysvals.dmesglog and sysvals.dmesgfile:
37123935 hf.write('<div id="dmesglog" style="display:none;">\n')
3713− lf = open(sysvals.dmesgfile, 'r')
3936+ lf = sysvals.openlog(sysvals.dmesgfile, 'r')
37143937 for line in lf:
37153938 line = line.replace('<', '&lt').replace('>', '&gt')
37163939 hf.write(line)
@@ -3719,28 +3942,15 @@ def createHTML(testruns): · 2 unmodified lines
37193942 # add the ftrace log as a hidden div
37203943 if sysvals.ftracelog and sysvals.ftracefile:
37213944 hf.write('<div id="ftracelog" style="display:none;">\n')
3722− lf = open(sysvals.ftracefile, 'r')
3945+ lf = sysvals.openlog(sysvals.ftracefile, 'r')
37233946 for line in lf:
37243947 hf.write(line)
37253948 lf.close()
37263949 hf.write('</div>\n')
37273950
3728− if(not sysvals.embedded):
3729− # write the footer and close
3730− addScriptCode(hf, testruns)
3731− hf.write('</body>\n</html>\n')
3732− else:
3733− # embedded out will be loaded in a page, skip the js
3734− t0 = (testruns[0].start - testruns[-1].tSuspended) * 1000
3735− tMax = (testruns[-1].end - testruns[-1].tSuspended) * 1000
3736− # add js code in a div entry for later evaluation
3737− detail = 'var bounds = [%f,%f];\n' % (t0, tMax)
3738− detail += 'var devtable = [\n'
3739− for data in testruns:
3740− topo = data.deviceTopology()
3741− detail += '\t"%s",\n' % (topo)
3742− detail += '];\n'
3743− hf.write('<div id=customcode style=display:none>\n'+detail+'</div>\n')
3951+ # write the footer and close
3952+ addScriptCode(hf, testruns)
3953+ hf.write('</body>\n</html>\n')
37443954 hf.close()
37453955 return True
37463956
@@ -4149,9 +4359,25 @@ def addScriptCode(hf, testruns): · 402 unmodified lines
41494359 ' win.document.write(html+dt);\n'\
41504360 ' }\n'\
41514361 ' function errWindow() {\n'\
4152− ' var text = this.id;\n'\
4362+ ' var range = this.id.split("_");\n'\
4363+ ' var idx1 = parseInt(range[0]);\n'\
4364+ ' var idx2 = parseInt(range[1]);\n'\
41534365 ' var win = window.open();\n'\
4154− ' win.document.write("<pre>"+text+"</pre>");\n'\
4366+ ' var log = document.getElementById("dmesglog");\n'\
4367+ ' var title = "<title>dmesg log</title>";\n'\
4368+ ' var text = log.innerHTML.split("\\n");\n'\
4369+ ' var html = "";\n'\
4370+ ' for(var i = 0; i < text.length; i++) {\n'\
4371+ ' if(i == idx1) {\n'\
4372+ ' html += "<e id=target>"+text[i]+"</e>\\n";\n'\
4373+ ' } else if(i > idx1 && i <= idx2) {\n'\
4374+ ' html += "<e>"+text[i]+"</e>\\n";\n'\
4375+ ' } else {\n'\
4376+ ' html += text[i]+"\\n";\n'\
4377+ ' }\n'\
4378+ ' }\n'\
4379+ ' win.document.write("<style>e{color:red}</style>"+title+"<pre>"+html+"</pre>");\n'\
4380+ ' win.location.hash = "#target";\n'\
41554381 ' win.document.close();\n'\
41564382 ' }\n'\
41574383 ' function logWindow(e) {\n'\
@@ -4219,6 +4445,30 @@ def addScriptCode(hf, testruns): · 61 unmodified lines
42194445 '</script>\n'
42204446 hf.write(script_code);
42214447
4448+def setRuntimeSuspend(before=True):
4449+ global sysvals
4450+ sv = sysvals
4451+ if sv.rs == 0:
4452+ return
4453+ if before:
4454+ # runtime suspend disable or enable
4455+ if sv.rs > 0:
4456+ sv.rstgt, sv.rsval, sv.rsdir = 'on', 'auto', 'enabled'
4457+ else:
4458+ sv.rstgt, sv.rsval, sv.rsdir = 'auto', 'on', 'disabled'
4459+ print('CONFIGURING RUNTIME SUSPEND...')
4460+ sv.rslist = deviceInfo(sv.rstgt)
4461+ for i in sv.rslist:
4462+ sv.setVal(sv.rsval, i)
4463+ print('runtime suspend %s on all devices (%d changed)' % (sv.rsdir, len(sv.rslist)))
4464+ print('waiting 5 seconds...')
4465+ time.sleep(5)
4466+ else:
4467+ # runtime suspend re-enable or re-disable
4468+ for i in sv.rslist:
4469+ sv.setVal(sv.rstgt, i)
4470+ print('runtime suspend settings restored on %d devices' % len(sv.rslist))
4471+
42224472 # Function: executeSuspend
42234473 # Description:
42244474 # Execute system suspend through the sysfs interface, then copy the output
@@ -4227,6 +4477,19 @@ def executeSuspend(): · 2 unmodified lines
42274477 pm = ProcessMonitor()
42284478 tp = sysvals.tpath
42294479 fwdata = []
4480+ # run these commands to prepare the system for suspend
4481+ if sysvals.display:
4482+ if sysvals.display > 0:
4483+ print('TURN DISPLAY ON')
4484+ call('xset -d :0.0 dpms force suspend', shell=True)
4485+ call('xset -d :0.0 dpms force on', shell=True)
4486+ else:
4487+ print('TURN DISPLAY OFF')
4488+ call('xset -d :0.0 dpms force suspend', shell=True)
4489+ time.sleep(1)
4490+ if sysvals.sync:
4491+ print('SYNCING FILESYSTEMS')
4492+ call('sync', shell=True)
42304493 # mark the start point in the kernel ring buffer just as we start
42314494 sysvals.initdmesg()
42324495 # start ftrace
@@ -4298,47 +4561,22 @@ def executeSuspend(): · 65 unmodified lines
42984561 pm.stop()
42994562 sysvals.fsetVal('0', 'tracing_on')
43004563 print('CAPTURING TRACE')
4301− sysvals.writeDatafileHeader(sysvals.ftracefile, fwdata)
4302− call('cat '+tp+'trace >> '+sysvals.ftracefile, shell=True)
4564+ op = sysvals.writeDatafileHeader(sysvals.ftracefile, fwdata)
4565+ fp = open(tp+'trace', 'r')
4566+ for line in fp:
4567+ op.write(line)
4568+ op.close()
43034569 sysvals.fsetVal('', 'trace')
43044570 devProps()
43054571 # grab a copy of the dmesg output
43064572 print('CAPTURING DMESG')
4307− sysvals.writeDatafileHeader(sysvals.dmesgfile, fwdata)
4308− sysvals.getdmesg()
4573+ sysvals.getdmesg(fwdata)
43094574
4310−# Function: setUSBDevicesAuto
4311−# Description:
4312−# Set the autosuspend control parameter of all USB devices to auto
4313−# This can be dangerous, so use at your own risk, most devices are set
4314−# to always-on since the kernel cant determine if the device can
4315−# properly autosuspend
4316−def setUSBDevicesAuto():
4317− sysvals.rootCheck(True)
4318− for dirname, dirnames, filenames in os.walk('/sys/devices'):
4319− if(re.match('.*/usb[0-9]*.*', dirname) and
4320− 'idVendor' in filenames and 'idProduct' in filenames):
4321− call('echo auto > %s/power/control' % dirname, shell=True)
4322− name = dirname.split('/')[-1]
4323− desc = Popen(['cat', '%s/product' % dirname],
4324− stderr=PIPE, stdout=PIPE).stdout.read().replace('\n', '')
4325− ctrl = Popen(['cat', '%s/power/control' % dirname],
4326− stderr=PIPE, stdout=PIPE).stdout.read().replace('\n', '')
4327− print('control is %s for %6s: %s' % (ctrl, name, desc))
4328−
4329−# Function: yesno
4330−# Description:
4331−# Print out an equivalent Y or N for a set of known parameter values
4332−# Output:
4333−# 'Y', 'N', or ' ' if the value is unknown
4334−def yesno(val):
4335− yesvals = ['auto', 'enabled', 'active', '1']
4336− novals = ['on', 'disabled', 'suspended', 'forbidden', 'unsupported']
4337− if val in yesvals:
4338− return 'Y'
4339− elif val in novals:
4340− return 'N'
4341− return ' '
4575+def readFile(file):
4576+ if os.path.islink(file):
4577+ return os.readlink(file).split('/')[-1]
4578+ else:
4579+ return sysvals.getVal(file).strip()
43424580
43434581 # Function: ms2nice
43444582 # Description:
@@ -4346,69 +4584,81 @@ def yesno(val): · 1 unmodified line
43464584 # Output:
43474585 # The time string, e.g. "1901m16s"
43484586 def ms2nice(val):
4349− ms = 0
4350− try:
4351− ms = int(val)
4352− except:
4353− return 0.0
4354− m = ms / 60000
4355− s = (ms / 1000) - (m * 60)
4356− return '%3dm%2ds' % (m, s)
4587+ val = int(val)
4588+ h = val / 3600000
4589+ m = (val / 60000) % 60
4590+ s = (val / 1000) % 60
4591+ if h > 0:
4592+ return '%d:%02d:%02d' % (h, m, s)
4593+ if m > 0:
4594+ return '%02d:%02d' % (m, s)
4595+ return '%ds' % s
43574596
4358−# Function: detectUSB
4597+def yesno(val):
4598+ list = {'enabled':'A', 'disabled':'S', 'auto':'E', 'on':'D',
4599+ 'active':'A', 'suspended':'S', 'suspending':'S'}
4600+ if val not in list:
4601+ return ' '
4602+ return list[val]
4603+
4604+# Function: deviceInfo
43594605 # Description:
43604606 # Detect all the USB hosts and devices currently connected and add
43614607 # a list of USB device names to sysvals for better timeline readability
4362−def detectUSB():
4363− field = {'idVendor':'', 'idProduct':'', 'product':'', 'speed':''}
4364− power = {'async':'', 'autosuspend':'', 'autosuspend_delay_ms':'',
4365− 'control':'', 'persist':'', 'runtime_enabled':'',
4366− 'runtime_status':'', 'runtime_usage':'',
4367− 'runtime_active_time':'',
4368− 'runtime_suspended_time':'',
4369− 'active_duration':'',
4370− 'connected_duration':''}
4371−
4372− print('LEGEND')
4373− print('---------------------------------------------------------------------------------------------')
4374− print(' A = async/sync PM queue Y/N D = autosuspend delay (seconds)')
4375− print(' S = autosuspend Y/N rACTIVE = runtime active (min/sec)')
4376− print(' P = persist across suspend Y/N rSUSPEN = runtime suspend (min/sec)')
4377− print(' E = runtime suspend enabled/forbidden Y/N ACTIVE = active duration (min/sec)')
4378− print(' R = runtime status active/suspended Y/N CONNECT = connected duration (min/sec)')
4379− print(' U = runtime usage count')
4380− print('---------------------------------------------------------------------------------------------')
4381− print(' NAME ID DESCRIPTION SPEED A S P E R U D rACTIVE rSUSPEN ACTIVE CONNECT')
4382− print('---------------------------------------------------------------------------------------------')
4383−
4608+def deviceInfo(output=''):
4609+ if not output:
4610+ print('LEGEND')
4611+ print('---------------------------------------------------------------------------------------------')
4612+ print(' A = async/sync PM queue (A/S) C = runtime active children')
4613+ print(' R = runtime suspend enabled/disabled (E/D) rACTIVE = runtime active (min/sec)')
4614+ print(' S = runtime status active/suspended (A/S) rSUSPEND = runtime suspend (min/sec)')
4615+ print(' U = runtime usage count')
4616+ print('---------------------------------------------------------------------------------------------')
4617+ print('DEVICE NAME A R S U C rACTIVE rSUSPEND')
4618+ print('---------------------------------------------------------------------------------------------')
4619+
4620+ res = []
4621+ tgtval = 'runtime_status'
4622+ lines = dict()
43844623 for dirname, dirnames, filenames in os.walk('/sys/devices'):
4385− if(re.match('.*/usb[0-9]*.*', dirname) and
4386− 'idVendor' in filenames and 'idProduct' in filenames):
4387− for i in field:
4388− field[i] = Popen(['cat', '%s/%s' % (dirname, i)],
4389− stderr=PIPE, stdout=PIPE).stdout.read().replace('\n', '')
4390− name = dirname.split('/')[-1]
4391− for i in power:
4392− power[i] = Popen(['cat', '%s/power/%s' % (dirname, i)],
4393− stderr=PIPE, stdout=PIPE).stdout.read().replace('\n', '')
4394− if(re.match('usb[0-9]*', name)):
4395− first = '%-8s' % name
4396− else:
4397− first = '%8s' % name
4398− print('%s [%s:%s] %-20s %-4s %1s %1s %1s %1s %1s %1s %1s %s %s %s %s' % \
4399− (first, field['idVendor'], field['idProduct'], \
4400− field['product'][0:20], field['speed'], \
4401− yesno(power['async']), \
4402− yesno(power['control']), \
4403− yesno(power['persist']), \
4404− yesno(power['runtime_enabled']), \
4405− yesno(power['runtime_status']), \
4406− power['runtime_usage'], \
4407− power['autosuspend'], \
4408− ms2nice(power['runtime_active_time']), \
4409− ms2nice(power['runtime_suspended_time']), \
4410− ms2nice(power['active_duration']), \
4411− ms2nice(power['connected_duration'])))
4624+ if(not re.match('.*/power', dirname) or
4625+ 'control' not in filenames or
4626+ tgtval not in filenames):
4627+ continue
4628+ name = ''
4629+ dirname = dirname[:-6]
4630+ device = dirname.split('/')[-1]
4631+ power = dict()
4632+ power[tgtval] = readFile('%s/power/%s' % (dirname, tgtval))
4633+ # only list devices which support runtime suspend
4634+ if power[tgtval] not in ['active', 'suspended', 'suspending']:
4635+ continue
4636+ for i in ['product', 'driver', 'subsystem']:
4637+ file = '%s/%s' % (dirname, i)
4638+ if os.path.exists(file):
4639+ name = readFile(file)
4640+ break
4641+ for i in ['async', 'control', 'runtime_status', 'runtime_usage',
4642+ 'runtime_active_kids', 'runtime_active_time',
4643+ 'runtime_suspended_time']:
4644+ if i in filenames:
4645+ power[i] = readFile('%s/power/%s' % (dirname, i))
4646+ if output:
4647+ if power['control'] == output:
4648+ res.append('%s/power/control' % dirname)
4649+ continue
4650+ lines[dirname] = '%-26s %-26s %1s %1s %1s %1s %1s %10s %10s' % \
4651+ (device[:26], name[:26],
4652+ yesno(power['async']), \
4653+ yesno(power['control']), \
4654+ yesno(power['runtime_status']), \
4655+ power['runtime_usage'], \
4656+ power['runtime_active_kids'], \
4657+ ms2nice(power['runtime_active_time']), \
4658+ ms2nice(power['runtime_suspended_time']))
4659+ for i in sorted(lines):
4660+ print lines[i]
4661+ return res
44124662
44134663 # Function: devProps
44144664 # Description:
@@ -4444,7 +4694,7 @@ def devProps(data=0): · 29 unmodified lines
44444694 msghead = 'Additional data added by AnalyzeSuspend'
44454695 alreadystamped = False
44464696 tp = TestProps()
4447− tf = open(sysvals.ftracefile, 'r')
4697+ tf = sysvals.openlog(sysvals.ftracefile, 'r')
44484698 for line in tf:
44494699 if msghead in line:
44504700 alreadystamped = True
@@ -4469,7 +4719,7 @@ def devProps(data=0): · 18 unmodified lines
44694719 if not alreadystamped and sysvals.suspendmode == 'command':
44704720 out = '#\n# '+msghead+'\n# Device Properties: '
44714721 out += 'testcommandstring,%s,0;' % (sysvals.testcommand)
4472− with open(sysvals.ftracefile, 'a') as fp:
4722+ with sysvals.openlog(sysvals.ftracefile, 'a') as fp:
44734723 fp.write(out+'\n')
44744724 sysvals.devprops = props
44754725 return
@@ -4526,7 +4776,7 @@ def devProps(data=0): · 50 unmodified lines
45264776 out = '#\n# '+msghead+'\n# Device Properties: '
45274777 for dev in sorted(props):
45284778 out += props[dev].out(dev)
4529− with open(sysvals.ftracefile, 'a') as fp:
4779+ with sysvals.openlog(sysvals.ftracefile, 'a') as fp:
45304780 fp.write(out+'\n')
45314781
45324782 sysvals.devprops = props
@@ -4869,20 +5119,12 @@ def statusCheck(probecheck=False): · 336 unmodified lines
48695119 # what data source are we using
48705120 res = 'DMESG'
48715121 if(ftgood):
4872− sysvals.usetraceeventsonly = True
4873− sysvals.usetraceevents = False
5122+ sysvals.usetraceevents = True
48745123 for e in sysvals.traceevents:
4875− check = False
4876− if(os.path.exists(sysvals.epath+e)):
4877− check = True
4878− if(not check):
4879− sysvals.usetraceeventsonly = False
4880− if(e == 'suspend_resume' and check):
4881− sysvals.usetraceevents = True
4882− if(sysvals.usetraceevents and sysvals.usetraceeventsonly):
5124+ if not os.path.exists(sysvals.epath+e):
5125+ sysvals.usetraceevents = False
5126+ if(sysvals.usetraceevents):
48835127 res = 'FTRACE (all trace events found)'
4884− elif(sysvals.usetraceevents):
4885− res = 'DMESG and FTRACE (suspend_resume trace event found)'
48865128 print(' timeline data source: %s' % res)
48875129
48885130 # check if rtcwake
@@ -4917,6 +5159,7 @@ def doError(msg, help=False): · 28 unmodified lines
49175159 if(help == True):
49185160 printHelp()
49195161 print('ERROR: %s\n') % msg
5162+ sysvals.outputResult({'error':msg})
49205163 sys.exit()
49215164
49225165 # Function: getArgInt
@@ -4957,22 +5200,36 @@ def getArgFloat(name, args, min, max, main=True): · 34 unmodified lines
49575200 doError(name+': value should be between %f and %f' % (min, max), True)
49585201 return val
49595202
4960−def processData():
5203+def processData(live=False):
49615204 print('PROCESSING DATA')
4962− if(sysvals.usetraceeventsonly):
4963− testruns = parseTraceLog()
5205+ if(sysvals.usetraceevents):
5206+ testruns = parseTraceLog(live)
49645207 if sysvals.dmesgfile:
4965− dmesgtext = loadKernelLog(True)
49665208 for data in testruns:
4967− data.extractErrorInfo(dmesgtext)
5209+ data.extractErrorInfo()
49685210 else:
49695211 testruns = loadKernelLog()
49705212 for data in testruns:
49715213 parseKernelLog(data)
49725214 if(sysvals.ftracefile and (sysvals.usecallgraph or sysvals.usetraceevents)):
49735215 appendIncompleteTraceLog(testruns)
5216+ sysvals.vprint('Command:\n %s' % sysvals.cmdline)
5217+ for data in testruns:
5218+ data.printDetails()
5219+ if sysvals.cgdump:
5220+ for data in testruns:
5221+ data.debugPrint()
5222+ sys.exit()
5223+
5224+ sysvals.vprint('Creating the html timeline (%s)...' % sysvals.htmlfile)
49745225 createHTML(testruns)
4975− return testruns
5226+ print('DONE')
5227+ data = testruns[0]
5228+ stamp = data.stamp
5229+ stamp['suspend'], stamp['resume'] = data.getTimeValues()
5230+ if data.fwValid:
5231+ stamp['fwsuspend'], stamp['fwresume'] = data.fwSuspend, data.fwResume
5232+ return (testruns, stamp)
49765233
49775234 # Function: rerunTest
49785235 # Description:
@@ -4980,37 +5237,36 @@ def processData(): · 1 unmodified line
49805237 def rerunTest():
49815238 if sysvals.ftracefile:
49825239 doesTraceLogHaveTraceEvents()
4983− if not sysvals.dmesgfile and not sysvals.usetraceeventsonly:
5240+ if not sysvals.dmesgfile and not sysvals.usetraceevents:
49845241 doError('recreating this html output requires a dmesg file')
49855242 sysvals.setOutputFile()
4986− vprint('Output file: %s' % sysvals.htmlfile)
49875243 if os.path.exists(sysvals.htmlfile):
49885244 if not os.path.isfile(sysvals.htmlfile):
49895245 doError('a directory already exists with this name: %s' % sysvals.htmlfile)
49905246 elif not os.access(sysvals.htmlfile, os.W_OK):
49915247 doError('missing permission to write to %s' % sysvals.htmlfile)
4992− return processData()
5248+ testruns, stamp = processData(False)
5249+ return stamp
49935250
49945251 # Function: runTest
49955252 # Description:
49965253 # execute a suspend/resume, gather the logs, and generate the output
4997−def runTest():
5254+def runTest(n=0):
49985255 # prepare for the test
49995256 sysvals.initFtrace()
50005257 sysvals.initTestOutput('suspend')
5001− vprint('Output files:\n\t%s\n\t%s\n\t%s' % \
5002− (sysvals.dmesgfile, sysvals.ftracefile, sysvals.htmlfile))
50035258
50045259 # execute the test
50055260 executeSuspend()
50065261 sysvals.cleanupFtrace()
5007− processData()
5008−
5009− # if running as root, change output dir owner to sudo_user
5010− if os.path.isdir(sysvals.testdir) and os.getuid() == 0 and \
5011− 'SUDO_USER' in os.environ:
5012− cmd = 'chown -R {0}:{0} {1} > /dev/null 2>&1'
5013− call(cmd.format(os.environ['SUDO_USER'], sysvals.testdir), shell=True)
5262+ if sysvals.skiphtml:
5263+ sysvals.sudouser(sysvals.testdir)
5264+ return
5265+ testruns, stamp = processData(True)
5266+ for data in testruns:
5267+ del data
5268+ sysvals.sudouser(sysvals.testdir)
5269+ sysvals.outputResult(stamp, n)
50145270
50155271 def find_in_html(html, strs, div=False):
50165272 for str in strs:
@@ -5072,10 +5328,12 @@ def runSummary(subdir, local=True): · 55 unmodified lines
50725328 # Function: checkArgBool
50735329 # Description:
50745330 # check if a boolean string value is true or false
5075−def checkArgBool(value):
5076− yes = ['1', 'true', 'yes', 'on']
5077− if value.lower() in yes:
5331+def checkArgBool(name, value):
5332+ if value in switchvalues:
5333+ if value in switchoff:
5334+ return False
50785335 return True
5336+ doError('invalid boolean --> (%s: %s), use "true/false" or "1/0"' % (name, value), True)
50795337 return False
50805338
50815339 # Function: configFromFile
@@ -5091,60 +5349,116 @@ def configFromFile(file): · 9 unmodified lines
50915349 if 'Settings' in sections:
50925350 for opt in Config.options('Settings'):
50935351 value = Config.get('Settings', opt).lower()
5094− if(opt.lower() == 'verbose'):
5095− sysvals.verbose = checkArgBool(value)
5096− elif(opt.lower() == 'addlogs'):
5097− sysvals.dmesglog = sysvals.ftracelog = checkArgBool(value)
5098− elif(opt.lower() == 'dev'):
5099− sysvals.usedevsrc = checkArgBool(value)
5100− elif(opt.lower() == 'proc'):
5101− sysvals.useprocmon = checkArgBool(value)
5102− elif(opt.lower() == 'x2'):
5103− if checkArgBool(value):
5352+ option = opt.lower()
5353+ if(option == 'verbose'):
5354+ sysvals.verbose = checkArgBool(option, value)
5355+ elif(option == 'addlogs'):
5356+ sysvals.dmesglog = sysvals.ftracelog = checkArgBool(option, value)
5357+ elif(option == 'dev'):
5358+ sysvals.usedevsrc = checkArgBool(option, value)
5359+ elif(option == 'proc'):
5360+ sysvals.useprocmon = checkArgBool(option, value)
5361+ elif(option == 'x2'):
5362+ if checkArgBool(option, value):
51045363 sysvals.execcount = 2
5105− elif(opt.lower() == 'callgraph'):
5106− sysvals.usecallgraph = checkArgBool(value)
5107− elif(opt.lower() == 'override-timeline-functions'):
5108− overridekprobes = checkArgBool(value)
5109− elif(opt.lower() == 'override-dev-timeline-functions'):
5110− overridedevkprobes = checkArgBool(value)
5111− elif(opt.lower() == 'devicefilter'):
5364+ elif(option == 'callgraph'):
5365+ sysvals.usecallgraph = checkArgBool(option, value)
5366+ elif(option == 'override-timeline-functions'):
5367+ overridekprobes = checkArgBool(option, value)
5368+ elif(option == 'override-dev-timeline-functions'):
5369+ overridedevkprobes = checkArgBool(option, value)
5370+ elif(option == 'skiphtml'):
5371+ sysvals.skiphtml = checkArgBool(option, value)
5372+ elif(option == 'sync'):
5373+ sysvals.sync = checkArgBool(option, value)
5374+ elif(option == 'rs' or option == 'runtimesuspend'):
5375+ if value in switchvalues:
5376+ if value in switchoff:
5377+ sysvals.rs = -1
5378+ else:
5379+ sysvals.rs = 1
5380+ else:
5381+ doError('invalid value --> (%s: %s), use "enable/disable"' % (option, value), True)
5382+ elif(option == 'display'):
5383+ if value in switchvalues:
5384+ if value in switchoff:
5385+ sysvals.display = -1
5386+ else:
5387+ sysvals.display = 1
5388+ else:
5389+ doError('invalid value --> (%s: %s), use "on/off"' % (option, value), True)
5390+ elif(option == 'gzip'):
5391+ sysvals.gzip = checkArgBool(option, value)
5392+ elif(option == 'cgfilter'):
5393+ sysvals.setCallgraphFilter(value)
5394+ elif(option == 'cgskip'):
5395+ if value in switchoff:
5396+ sysvals.cgskip = ''
5397+ else:
5398+ sysvals.cgskip = sysvals.configFile(val)
5399+ if(not sysvals.cgskip):
5400+ doError('%s does not exist' % sysvals.cgskip)
5401+ elif(option == 'cgtest'):
5402+ sysvals.cgtest = getArgInt('cgtest', value, 0, 1, False)
5403+ elif(option == 'cgphase'):
5404+ d = Data(0)
5405+ if value not in d.phases:
5406+ doError('invalid phase --> (%s: %s), valid phases are %s'\
5407+ % (option, value, d.phases), True)
5408+ sysvals.cgphase = value
5409+ elif(option == 'fadd'):
5410+ file = sysvals.configFile(value)
5411+ if(not file):
5412+ doError('%s does not exist' % value)
5413+ sysvals.addFtraceFilterFunctions(file)
5414+ elif(option == 'result'):
5415+ sysvals.result = value
5416+ elif(option == 'multi'):
5417+ nums = value.split()
5418+ if len(nums) != 2:
5419+ doError('multi requires 2 integers (exec_count and delay)', True)
5420+ sysvals.multitest['run'] = True
5421+ sysvals.multitest['count'] = getArgInt('multi: n d (exec count)', nums[0], 2, 1000000, False)
5422+ sysvals.multitest['delay'] = getArgInt('multi: n d (delay between tests)', nums[1], 0, 3600, False)
5423+ elif(option == 'devicefilter'):
51125424 sysvals.setDeviceFilter(value)
5113− elif(opt.lower() == 'expandcg'):
5114− sysvals.cgexp = checkArgBool(value)
5115− elif(opt.lower() == 'srgap'):
5116− if checkArgBool(value):
5425+ elif(option == 'expandcg'):
5426+ sysvals.cgexp = checkArgBool(option, value)
5427+ elif(option == 'srgap'):
5428+ if checkArgBool(option, value):
51175429 sysvals.srgap = 5
5118− elif(opt.lower() == 'mode'):
5430+ elif(option == 'mode'):
51195431 sysvals.suspendmode = value
5120− elif(opt.lower() == 'command'):
5432+ elif(option == 'command' or option == 'cmd'):
51215433 sysvals.testcommand = value
5122− elif(opt.lower() == 'x2delay'):
5123− sysvals.x2delay = getArgInt('-x2delay', value, 0, 60000, False)
5124− elif(opt.lower() == 'predelay'):
5125− sysvals.predelay = getArgInt('-predelay', value, 0, 60000, False)
5126− elif(opt.lower() == 'postdelay'):
5127− sysvals.postdelay = getArgInt('-postdelay', value, 0, 60000, False)
5128− elif(opt.lower() == 'maxdepth'):
5129− sysvals.max_graph_depth = getArgInt('-maxdepth', value, 0, 1000, False)
5130− elif(opt.lower() == 'rtcwake'):
5131− if value.lower() == 'off':
5434+ elif(option == 'x2delay'):
5435+ sysvals.x2delay = getArgInt('x2delay', value, 0, 60000, False)
5436+ elif(option == 'predelay'):
5437+ sysvals.predelay = getArgInt('predelay', value, 0, 60000, False)
5438+ elif(option == 'postdelay'):
5439+ sysvals.postdelay = getArgInt('postdelay', value, 0, 60000, False)
5440+ elif(option == 'maxdepth'):
5441+ sysvals.max_graph_depth = getArgInt('maxdepth', value, 0, 1000, False)
5442+ elif(option == 'rtcwake'):
5443+ if value in switchoff:
51325444 sysvals.rtcwake = False
51335445 else:
51345446 sysvals.rtcwake = True
5135− sysvals.rtcwaketime = getArgInt('-rtcwake', value, 0, 3600, False)
5136− elif(opt.lower() == 'timeprec'):
5137− sysvals.setPrecision(getArgInt('-timeprec', value, 0, 6, False))
5138− elif(opt.lower() == 'mindev'):
5139− sysvals.mindevlen = getArgFloat('-mindev', value, 0.0, 10000.0, False)
5140− elif(opt.lower() == 'callloop-maxgap'):
5141− sysvals.callloopmaxgap = getArgFloat('-callloop-maxgap', value, 0.0, 1.0, False)
5142− elif(opt.lower() == 'callloop-maxlen'):
5143− sysvals.callloopmaxgap = getArgFloat('-callloop-maxlen', value, 0.0, 1.0, False)
5144− elif(opt.lower() == 'mincg'):
5145− sysvals.mincglen = getArgFloat('-mincg', value, 0.0, 10000.0, False)
5146− elif(opt.lower() == 'output-dir'):
5147− sysvals.testdir = sysvals.setOutputFolder(value)
5447+ sysvals.rtcwaketime = getArgInt('rtcwake', value, 0, 3600, False)
5448+ elif(option == 'timeprec'):
5449+ sysvals.setPrecision(getArgInt('timeprec', value, 0, 6, False))
5450+ elif(option == 'mindev'):
5451+ sysvals.mindevlen = getArgFloat('mindev', value, 0.0, 10000.0, False)
5452+ elif(option == 'callloop-maxgap'):
5453+ sysvals.callloopmaxgap = getArgFloat('callloop-maxgap', value, 0.0, 1.0, False)
5454+ elif(option == 'callloop-maxlen'):
5455+ sysvals.callloopmaxgap = getArgFloat('callloop-maxlen', value, 0.0, 1.0, False)
5456+ elif(option == 'mincg'):
5457+ sysvals.mincglen = getArgFloat('mincg', value, 0.0, 10000.0, False)
5458+ elif(option == 'bufsize'):
5459+ sysvals.bufsize = getArgInt('bufsize', value, 1, 1024*1024*8, False)
5460+ elif(option == 'output-dir'):
5461+ sysvals.outdir = sysvals.setOutputFolder(value)
51485462
51495463 if sysvals.suspendmode == 'command' and not sysvals.testcommand:
51505464 doError('No command supplied for mode "command"')
@@ -5259,7 +5573,14 @@ def printHelp(): · 108 unmodified lines
52595573 print(' -rtcwake t Wakeup t seconds after suspend, set t to "off" to disable (default: 15)')
52605574 print(' -addlogs Add the dmesg and ftrace logs to the html output')
52615575 print(' -srgap Add a visible gap in the timeline between sus/res (default: disabled)')
5576+ print(' -skiphtml Run the test and capture the trace logs, but skip the timeline (default: disabled)')
5577+ print(' -result fn Export a results table to a text file for parsing.')
5578+ print(' [testprep]')
5579+ print(' -sync Sync the filesystems before starting the test')
5580+ print(' -rs on/off Enable/disable runtime suspend for all devices, restore all after test')
5581+ print(' -display on/off Turn the display on or off for the test')
52625582 print(' [advanced]')
5583+ print(' -gzip Gzip the trace and dmesg logs to save space')
52635584 print(' -cmd {s} Run the timeline over a custom command, e.g. "sync -d"')
52645585 print(' -proc Add usermode process info into the timeline (default: disabled)')
52655586 print(' -dev Add kernel function calls and threads to the timeline (default: disabled)')
@@ -5280,14 +5601,16 @@ def printHelp(): · 14 unmodified lines
52805601 print(' -cgphase P Only show callgraph data for phase P (e.g. suspend_late)')
52815602 print(' -cgtest N Only show callgraph data for test N (e.g. 0 or 1 in an x2 run)')
52825603 print(' -timeprec N Number of significant digits in timestamps (0:S, [3:ms], 6:us)')
5604+ print(' -cgfilter S Filter the callgraph output in the timeline')
5605+ print(' -cgskip file Callgraph functions to skip, off to disable (default: cgskip.txt)')
5606+ print(' -bufsize N Set trace buffer size to N kilo-bytes (default: all of free memory)')
52835607 print('')
52845608 print('Other commands:')
52855609 print(' -modes List available suspend modes')
52865610 print(' -status Test to see if the system is enabled to run this tool')
52875611 print(' -fpdt Print out the contents of the ACPI Firmware Performance Data Table')
52885612 print(' -sysinfo Print out system info extracted from BIOS')
5289− print(' -usbtopo Print out the current USB topology with power info')
5290− print(' -usbauto Enable autosuspend for all connected USB devices')
5613+ print(' -devinfo Print out the pm settings of all devices which support runtime suspend')
52915614 print(' -flist Print the list of functions currently being captured in ftrace')
52925615 print(' -flistall Print all functions capable of being captured in ftrace')
52935616 print(' -summary directory Create a summary of all test in this dir')
@@ -5301,9 +5624,9 @@ def printHelp(): · 7 unmodified lines
53015624 # exec start (skipped if script is loaded as library)
53025625 if __name__ == '__main__':
53035626 cmd = ''
5304− outdir = ''
5305− multitest = {'run': False, 'count': 0, 'delay': 0}
5306− simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall', '-usbtopo', '-usbauto', '-status']
5627+ simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall', '-devinfo', '-status']
5628+ if '-f' in sys.argv:
5629+ sysvals.cgskip = sysvals.configFile('cgskip.txt')
53075630 # loop through the command line arguments
53085631 args = iter(sys.argv[1:])
53095632 for arg in args:
@@ -5333,6 +5656,10 @@ if __name__ == '__main__': · 23 unmodified lines
53335656 sysvals.postdelay = getArgInt('-postdelay', args, 0, 60000)
53345657 elif(arg == '-f'):
53355658 sysvals.usecallgraph = True
5659+ elif(arg == '-skiphtml'):
5660+ sysvals.skiphtml = True
5661+ elif(arg == '-cgdump'):
5662+ sysvals.cgdump = True
53365663 elif(arg == '-addlogs'):
53375664 sysvals.dmesglog = sysvals.ftracelog = True
53385665 elif(arg == '-verbose'):
@@ -5341,6 +5668,34 @@ if __name__ == '__main__': · 2 unmodified lines
53415668 sysvals.useprocmon = True
53425669 elif(arg == '-dev'):
53435670 sysvals.usedevsrc = True
5671+ elif(arg == '-sync'):
5672+ sysvals.sync = True
5673+ elif(arg == '-gzip'):
5674+ sysvals.gzip = True
5675+ elif(arg == '-rs'):
5676+ try:
5677+ val = args.next()
5678+ except:
5679+ doError('-rs requires "enable" or "disable"', True)
5680+ if val.lower() in switchvalues:
5681+ if val.lower() in switchoff:
5682+ sysvals.rs = -1
5683+ else:
5684+ sysvals.rs = 1
5685+ else:
5686+ doError('invalid option: %s, use "enable/disable" or "on/off"' % val, True)
5687+ elif(arg == '-display'):
5688+ try:
5689+ val = args.next()
5690+ except:
5691+ doError('-display requires "on" or "off"', True)
5692+ if val.lower() in switchvalues:
5693+ if val.lower() in switchoff:
5694+ sysvals.display = -1
5695+ else:
5696+ sysvals.display = 1
5697+ else:
5698+ doError('invalid option: %s, use "on/off"' % val, True)
53445699 elif(arg == '-maxdepth'):
53455700 sysvals.max_graph_depth = getArgInt('-maxdepth', args, 0, 1000)
53465701 elif(arg == '-rtcwake'):
@@ -5348,7 +5703,7 @@ if __name__ == '__main__': · 1 unmodified line
53485703 val = args.next()
53495704 except:
53505705 doError('No rtcwake time supplied', True)
5351− if val.lower() == 'off':
5706+ if val.lower() in switchoff:
53525707 sysvals.rtcwake = False
53535708 else:
53545709 sysvals.rtcwake = True
@@ -5359,6 +5714,8 @@ if __name__ == '__main__': · 4 unmodified lines
53595714 sysvals.mindevlen = getArgFloat('-mindev', args, 0.0, 10000.0)
53605715 elif(arg == '-mincg'):
53615716 sysvals.mincglen = getArgFloat('-mincg', args, 0.0, 10000.0)
5717+ elif(arg == '-bufsize'):
5718+ sysvals.bufsize = getArgInt('-bufsize', args, 1, 1024*1024*8)
53625719 elif(arg == '-cgtest'):
53635720 sysvals.cgtest = getArgInt('-cgtest', args, 0, 1)
53645721 elif(arg == '-cgphase'):
@@ -5368,8 +5725,26 @@ if __name__ == '__main__': · 3 unmodified lines
53685725 doError('No phase name supplied', True)
53695726 d = Data(0)
53705727 if val not in d.phases:
5371− doError('Invalid phase, valid phaess are %s' % d.phases, True)
5728+ doError('invalid phase --> (%s: %s), valid phases are %s'\
5729+ % (arg, val, d.phases), True)
53725730 sysvals.cgphase = val
5731+ elif(arg == '-cgfilter'):
5732+ try:
5733+ val = args.next()
5734+ except:
5735+ doError('No callgraph functions supplied', True)
5736+ sysvals.setCallgraphFilter(val)
5737+ elif(arg == '-cgskip'):
5738+ try:
5739+ val = args.next()
5740+ except:
5741+ doError('No file supplied', True)
5742+ if val.lower() in switchoff:
5743+ sysvals.cgskip = ''
5744+ else:
5745+ sysvals.cgskip = sysvals.configFile(val)
5746+ if(not sysvals.cgskip):
5747+ doError('%s does not exist' % sysvals.cgskip)
53735748 elif(arg == '-callloop-maxgap'):
53745749 sysvals.callloopmaxgap = getArgFloat('-callloop-maxgap', args, 0.0, 1.0)
53755750 elif(arg == '-callloop-maxlen'):
@@ -5386,31 +5761,33 @@ if __name__ == '__main__': · 10 unmodified lines
53865761 elif(arg == '-srgap'):
53875762 sysvals.srgap = 5
53885763 elif(arg == '-multi'):
5389− multitest['run'] = True
5390− multitest['count'] = getArgInt('-multi n (exec count)', args, 2, 1000000)
5391− multitest['delay'] = getArgInt('-multi d (delay between tests)', args, 0, 3600)
5764+ sysvals.multitest['run'] = True
5765+ sysvals.multitest['count'] = getArgInt('-multi n d (exec count)', args, 2, 1000000)
5766+ sysvals.multitest['delay'] = getArgInt('-multi n d (delay between tests)', args, 0, 3600)
53925767 elif(arg == '-o'):
53935768 try:
53945769 val = args.next()
53955770 except:
53965771 doError('No subdirectory name supplied', True)
5397− outdir = sysvals.setOutputFolder(val)
5772+ sysvals.outdir = sysvals.setOutputFolder(val)
53985773 elif(arg == '-config'):
53995774 try:
54005775 val = args.next()
54015776 except:
54025777 doError('No text file supplied', True)
5403− if(os.path.exists(val) == False):
5778+ file = sysvals.configFile(val)
5779+ if(not file):
54045780 doError('%s does not exist' % val)
5405− configFromFile(val)
5781+ configFromFile(file)
54065782 elif(arg == '-fadd'):
54075783 try:
54085784 val = args.next()
54095785 except:
54105786 doError('No text file supplied', True)
5411− if(os.path.exists(val) == False):
5787+ file = sysvals.configFile(val)
5788+ if(not file):
54125789 doError('%s does not exist' % val)
5413− sysvals.addFtraceFilterFunctions(val)
5790+ sysvals.addFtraceFilterFunctions(file)
54145791 elif(arg == '-dmesg'):
54155792 try:
54165793 val = args.next()
@@ -5435,7 +5812,7 @@ if __name__ == '__main__': · 18 unmodified lines
54355812 except:
54365813 doError('No directory supplied', True)
54375814 cmd = 'summary'
5438− outdir = val
5815+ sysvals.outdir = val
54395816 sysvals.notestrun = True
54405817 if(os.path.isdir(val) == False):
54415818 doError('%s is not accesible' % val)
@@ -5445,6 +5822,12 @@ if __name__ == '__main__': · 3 unmodified lines
54455822 except:
54465823 doError('No devnames supplied', True)
54475824 sysvals.setDeviceFilter(val)
5825+ elif(arg == '-result'):
5826+ try:
5827+ val = args.next()
5828+ except:
5829+ doError('No result file supplied', True)
5830+ sysvals.result = val
54485831 else:
54495832 doError('Invalid argument: '+arg, True)
54505833
@@ -5454,42 +5837,48 @@ if __name__ == '__main__': · 3 unmodified lines
54545837 if(sysvals.usecallgraph and sysvals.useprocmon):
54555838 doError('-proc is not compatible with -f')
54565839
5840+ if sysvals.usecallgraph and sysvals.cgskip:
5841+ sysvals.vprint('Using cgskip file: %s' % sysvals.cgskip)
5842+ sysvals.setCallgraphBlacklist(sysvals.cgskip)
5843+
54575844 # callgraph size cannot exceed device size
54585845 if sysvals.mincglen < sysvals.mindevlen:
54595846 sysvals.mincglen = sysvals.mindevlen
54605847
5461− # just run a utility command and exit
5848+ # remove existing buffers before calculating memory
5849+ if(sysvals.usecallgraph or sysvals.usedevsrc):
5850+ sysvals.fsetVal('16', 'buffer_size_kb')
54625851 sysvals.cpuInfo()
5852+
5853+ # just run a utility command and exit
54635854 if(cmd != ''):
54645855 if(cmd == 'status'):
54655856 statusCheck(True)
54665857 elif(cmd == 'fpdt'):
54675858 getFPDT(True)
54685859 elif(cmd == 'sysinfo'):
5469− sysvals.printSystemInfo()
5470− elif(cmd == 'usbtopo'):
5471− detectUSB()
5860+ sysvals.printSystemInfo(True)
5861+ elif(cmd == 'devinfo'):
5862+ deviceInfo()
54725863 elif(cmd == 'modes'):
54735864 print getModes()
54745865 elif(cmd == 'flist'):
54755866 sysvals.getFtraceFilterFunctions(True)
54765867 elif(cmd == 'flistall'):
54775868 sysvals.getFtraceFilterFunctions(False)
5478− elif(cmd == 'usbauto'):
5479− setUSBDevicesAuto()
54805869 elif(cmd == 'summary'):
5481− runSummary(outdir, True)
5870+ runSummary(sysvals.outdir, True)
54825871 sys.exit()
54835872
54845873 # if instructed, re-analyze existing data files
54855874 if(sysvals.notestrun):
5486− rerunTest()
5875+ stamp = rerunTest()
5876+ sysvals.outputResult(stamp)
54875877 sys.exit()
54885878
54895879 # verify that we can run a test
54905880 if(not statusCheck()):
5491− print('Check FAILED, aborting the test run!')
5492− sys.exit()
5881+ doError('Check FAILED, aborting the test run!')
54935882
54945883 # extract mem modes and convert
54955884 mode = sysvals.suspendmode
@@ -5509,25 +5898,35 @@ if __name__ == '__main__': · 13 unmodified lines
55095898
55105899 sysvals.systemInfo(dmidecode(sysvals.mempath))
55115900
5512− if multitest['run']:
5901+ setRuntimeSuspend(True)
5902+ if sysvals.display:
5903+ call('xset -d :0.0 dpms 0 0 0', shell=True)
5904+ call('xset -d :0.0 s off', shell=True)
5905+ if sysvals.multitest['run']:
55135906 # run multiple tests in a separate subdirectory
5514− if not outdir:
5515− s = 'suspend-x%d' % multitest['count']
5516− outdir = datetime.now().strftime(s+'-%y%m%d-%H%M%S')
5517− if not os.path.isdir(outdir):
5518− os.mkdir(outdir)
5519− for i in range(multitest['count']):
5907+ if not sysvals.outdir:
5908+ s = 'suspend-x%d' % sysvals.multitest['count']
5909+ sysvals.outdir = datetime.now().strftime(s+'-%y%m%d-%H%M%S')
5910+ if not os.path.isdir(sysvals.outdir):
5911+ os.mkdir(sysvals.outdir)
5912+ for i in range(sysvals.multitest['count']):
55205913 if(i != 0):
5521− print('Waiting %d seconds...' % (multitest['delay']))
5522− time.sleep(multitest['delay'])
5523− print('TEST (%d/%d) START' % (i+1, multitest['count']))
5914+ print('Waiting %d seconds...' % (sysvals.multitest['delay']))
5915+ time.sleep(sysvals.multitest['delay'])
5916+ print('TEST (%d/%d) START' % (i+1, sysvals.multitest['count']))
55245917 fmt = 'suspend-%y%m%d-%H%M%S'
5525− sysvals.testdir = os.path.join(outdir, datetime.now().strftime(fmt))
5526− runTest()
5527− print('TEST (%d/%d) COMPLETE' % (i+1, multitest['count']))
5528− runSummary(outdir, False)
5918+ sysvals.testdir = os.path.join(sysvals.outdir, datetime.now().strftime(fmt))
5919+ runTest(i+1)
5920+ print('TEST (%d/%d) COMPLETE' % (i+1, sysvals.multitest['count']))
5921+ sysvals.logmsg = ''
5922+ if not sysvals.skiphtml:
5923+ runSummary(sysvals.outdir, False)
5924+ sysvals.sudouser(sysvals.outdir)
55295925 else:
5530− if outdir:
5531− sysvals.testdir = outdir
5926+ if sysvals.outdir:
5927+ sysvals.testdir = sysvals.outdir
55325928 # run the test in the current directory
55335929 runTest()
5930+ if sysvals.display:
5931+ call('xset -d :0.0 s reset', shell=True)
5932+ setRuntimeSuspend(False)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t