aboutsummaryrefslogtreecommitdiff
path: root/perfmgr
diff options
context:
space:
mode:
Diffstat (limited to 'perfmgr')
-rwxr-xr-xperfmgr71
1 files changed, 71 insertions, 0 deletions
diff --git a/perfmgr b/perfmgr
new file mode 100755
index 0000000..143a23c
--- /dev/null
+++ b/perfmgr
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+import sys
+import subprocess
+
+def system(cmd):
+ print(f"$ {cmd}")
+ subprocess.run(cmd, shell=True)
+
+def usage():
+ print(f"usage: {sys.argv[0]} [on|off / turbo[on|off] / info]")
+
+def main(argv) -> int:
+ argc = len(argv)
+
+ if argc < 2:
+ usage()
+ return 1
+
+ opt1 = argv[1]
+
+ if argc == 2:
+ if opt1 == "on":
+ system("sudo -E cpupower frequency-set -g powersave")
+ return 0
+ elif opt1 == "off":
+ system("sudo -E cpupower frequency-set -g performance")
+ return 0
+ elif opt1 == "info":
+ system("cpupower frequency-info")
+ return 0
+ elif opt1 == "-h" or opt1 == "--help":
+ usage()
+ return 0
+ else:
+ print(f"unknown option \'{opt1}\'")
+ return 1
+
+ elif argc >= 3:
+ opt2 = argv[2]
+
+ if opt1 == "turbo":
+ if opt2 == "on":
+ system("echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo")
+ return 0
+ elif opt2 == "off":
+ system("echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo")
+ return 0
+ else:
+ print(f"unknown option \'{opt2}\' for 'turbo'")
+ return 1
+ else:
+ if opt1 == "on":
+ system("sudo -E cpupower frequency-set -g powersave")
+ return 0
+ elif opt1 == "off":
+ system("sudo -E cpupower frequency-set -g performance")
+ return 0
+ elif opt1 == "info":
+ system("cpupower frequency-info")
+ return 0
+ elif opt1 == "-h" or opt1 == "--help":
+ usage()
+ return 0
+ else:
+ print(f"unknown option \'{opt1}\'")
+ return 1
+
+ return 0
+
+main(sys.argv)
+