#!/usr/bin/python
#
# Tool for analyzing suspend/resume timing
# Copyright (c) 2013, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors:
# Todd Brandt <todd.e.brandt@linux.intel.com>
#
# Description:
# This tool is designed to assist kernel and OS developers in optimizing
# their linux stack's suspend/resume time. Using a kernel image built
# with a few extra options enabled, the tool will execute a suspend and
# will capture dmesg and ftrace data until resume is complete. This data
# is transformed into a device timeline and a callgraph to give a quick
# and detailed view of which devices and callbacks are taking the most
# time in suspend/resume. The output is a single html file which can be
# viewed in firefox or chrome.
#
# The following kernel build options are required:
# CONFIG_PM_DEBUG=y
# CONFIG_PM_SLEEP_DEBUG=y
# CONFIG_FTRACE=y
# CONFIG_FUNCTION_TRACER=y
# CONFIG_FUNCTION_GRAPH_TRACER=y
#
# The following additional kernel parameters are required:
# (e.g. in file /etc/default/grub)
# GRUB_CMDLINE_LINUX_DEFAULT="... initcall_debug log_buf_len=16M ..."
#
import sys
import time
import os
import string
import re
import array
import platform
import datetime
import struct
# -- classes --
class SystemValues:
testdir = "."
tpath = "/sys/kernel/debug/tracing/"
mempath = "/dev/mem"
powerfile = "/sys/power/state"
suspendmode = "mem"
prefix = "test"
teststamp = ""
dmesgfile = ""
ftracefile = ""
htmlfile = ""
rtcwake = False
def setOutputFile(self):
if((self.htmlfile == "") and (self.dmesgfile != "")):
m = re.match(r"(?P<name>.*)_dmesg\.txt$", self.dmesgfile)
if(m):
self.htmlfile = m.group("name")+".html"
if((self.htmlfile == "") and (self.ftracefile != "")):
m = re.match(r"(?P<name>.*)_ftrace\.txt$", self.ftracefile