1
0
Fork 0

powertop2tuned now generates tuned profile without any command in shell script. Everything is done using the tuned plugins

This commit is contained in:
Jan Kaluza 2012-05-11 10:36:57 +02:00
parent 18f32d6080
commit cfed1abaa8

View file

@ -44,11 +44,11 @@ stop() {
process $@
"""
TUNED_CONF_PROLOG = "# Automatically generated by powertop2tuned tool"
TUNED_CONF_PROLOG = "# Automatically generated by powertop2tuned tool\n"
TUNED_CONF_INCLUDE = """[main]
%s
%s\n
"""
TUNED_CONF_EPILOG="""[powertop_script]
TUNED_CONF_EPILOG="""\n[powertop_script]
type=script
script=script.sh
"""
@ -64,19 +64,58 @@ class PowertopHTMLParser(HTMLParser):
self.tdCounter = 0
self.lastDesc = ""
self.data = ""
self.currentScript = ""
if enable_tunings:
self.prefix = ""
else:
self.prefix = "#"
self.plugins = {}
def getParsedData(self):
return self.data
def getPlugins(self):
return self.plugins
def handle_starttag(self, tag, attrs):
self.lastStartTag = tag
if self.inProperTable and tag == "td":
self.tdCounter += 1
def parse_command(self, command):
prefix = ""
command = command.strip()
if command[0] == '#':
prefix = "#"
command = command[1:]
if command.startswith("echo") and command.find("/proc/sys") != -1:
splitted = command.split("'")
value = splitted[1]
path = splitted[3]
path = path.replace("/proc/sys/", "").replace("/", ".")
self.plugins.setdefault("sysfs", "[sysfs]\ndynamic_tuning=0\n")
self.plugins["sysfs"] += "#%s\n%s%s=%s\n\n" % (self.lastDesc, prefix, path, value)
# TODO: plugins/plugin_sysfs.py doesn't support this so far, it has to be implemented to
# let it work properly.
elif command.startswith("echo") and (command.find("'/sys/") != -1 or command.find("\"/sys/") != -1):
splitted = command.split("'")
value = splitted[1]
path = splitted[3]
if path == "/sys/module/snd_hda_intel/parameters/power_save":
self.plugins.setdefault("audio", "[audio]\ndynamic_tuning=0\n")
self.plugins["audio"] += "#%s\n%shda_intel_powersave=1\n" % (self.lastDesc, prefix)
else:
self.plugins.setdefault("sysfs", "[sysfs]\ndynamic_tuning=0\n")
self.plugins["sysfs"] += "#%s\n%s%s=%s\n\n" % (self.lastDesc, prefix, path, value)
elif command.startswith("ethtool -s ") and command.endswith("wol d;"):
self.plugins.setdefault("net", "[net]\ndynamic_tuning=0\n")
self.plugins["net"] += "#%s\n%swake_on_lan=0\n" % (self.lastDesc, prefix)
else:
return False
return True
def handle_endtag(self, tag):
if self.inProperTable and tag == "table":
self.inProperTable = False
@ -84,11 +123,13 @@ class PowertopHTMLParser(HTMLParser):
self.tdCounter = 0
if self.inScript:
self.inScript = False
self.data += "\n\n"
# Command is not handled, so just store it in the script
if not self.parse_command(self.currentScript.split("\n")[-1]):
self.data += self.currentScript + "\n\n"
def handle_entityref(self, name):
if self.inScript:
self.data += unichr(name2codepoint[name])
self.currentScript += unichr(name2codepoint[name])
def handle_data(self, data):
prefix = self.prefix
@ -102,11 +143,11 @@ class PowertopHTMLParser(HTMLParser):
if (self.inProperTable and self.tdCounter == 2) or self.inScript:
self.tdCounter = 0
if not self.inScript:
self.data += "\t# " + self.lastDesc + "\n"
self.data += "\t" + prefix + data
self.currentScript += "\t# " + self.lastDesc + "\n"
self.currentScript += "\t" + prefix + data
self.inScript = True
else:
self.data += data
self.currentScript += data
class PowertopProfile:
BAD_PRIVS = 100
@ -149,7 +190,7 @@ class PowertopProfile:
parser.feed(f.read())
f.close()
return parser.getParsedData()
return parser.getParsedData(), parser.getPlugins()
def generateShellScript(self, profile, data):
print "Generating shell script", os.path.join(self.output, "script.sh")
@ -159,12 +200,16 @@ class PowertopProfile:
f.close()
return True
def generateTunedConf(self, profile, new_profile):
def generateTunedConf(self, profile, new_profile, plugins):
print "Generating Tuned config file", os.path.join(self.output, "tuned.conf")
f = open(os.path.join(self.output, "tuned.conf"), "w")
f.write(TUNED_CONF_PROLOG)
if (new_profile):
if (new_profile):
f.write(TUNED_CONF_INCLUDE % ("include=" + profile))
for plugin in plugins.values():
f.write(plugin + "\n")
f.write(TUNED_CONF_EPILOG)
f.close()
@ -180,12 +225,12 @@ class PowertopProfile:
return name
self.name = name
data = self.parseHTML(enable_tunings)
data, plugins = self.parseHTML(enable_tunings)
if generated_html:
os.unlink(self.name)
if len(data) == 0:
if len(data) == 0 and len(plugins) == 0:
print >> sys.stderr, 'Your Powertop version is incompatible (maybe too old) or the generated HTML output is malformed'
return self.PARSING_ERROR
@ -197,7 +242,7 @@ class PowertopProfile:
if not self.generateShellScript(profile, data):
return self.BAD_SCRIPTSH
self.generateTunedConf(profile, new_profile)
self.generateTunedConf(profile, new_profile, plugins)
return 0