[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cpupower 5efe8c1f7d 11/35: clean up pass
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cpupower 5efe8c1f7d 11/35: clean up pass |
Date: |
Thu, 5 May 2022 15:57:45 -0400 (EDT) |
branch: externals/cpupower
commit 5efe8c1f7d3b0a4a1d6fb486a3cb43298aa008ed
Author: smeister <smeister@awstruepower.com>
Commit: smeister <smeister@awstruepower.com>
clean up pass
---
cpupower.el | 80 +++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 51 insertions(+), 29 deletions(-)
diff --git a/cpupower.el b/cpupower.el
index 352e790b8d..9eef3d41a9 100644
--- a/cpupower.el
+++ b/cpupower.el
@@ -16,11 +16,29 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+;;; Commentary
+
+;; If you have cpupower installed, this provides a very simple wrapper
+;; to that program.
+;;
+;; The commands you'll probably want to use:
+;; * cpupower-info
+;; - displays (briefly) the current cpupower information
+;; * cpupower-set-governor
+;; - sets cpu governor for all cores.
+;; * cpupower-helm-set-governor
+;; - sets cpu governor for all cores (uses helm)
+;;
+;; Less useful commands:
+;; * cpupower-get-current-frequencies
+;; - returns a list of all cpu frequencies in KHz by core.
+;; * cpupower-get-current-governors
+;; - returns a list of all cpu governors by core.
+
;; pretty sure I don't need this, but?
(setq lexical-binding t)
-
(defconst cpupower-cmd
"sudo cpupower"
"cpupower command, might need a 'sudo' infront of it")
@@ -54,7 +72,7 @@ writing macros. So here we are."
(when (string-equal (car tokens) "cpupower")
(cadr tokens)))))
-(defun cpupower--num-cpus ()
+(defun cpupower--get-num-cpus ()
"Return the number of CPUs on this system.
Done by cat-ing /proc/cpuinfo and counting lines with
@@ -73,7 +91,7 @@ TODO: do this in a less bad way?"
"Get a list of all valid governors for this system."
(cpupower--with-cache-slot :governors
(let ((governors-per-cpu))
- (cl-loop for cpu-num in (number-sequence 0 (cpupower--num-cpus))
+ (cl-loop for cpu-num in (number-sequence 0 (cpupower--get-num-cpus))
for cpu-governors-file = (format
"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors" cpu-num)
while (file-exists-p cpu-governors-file)
do (push (split-string
@@ -95,25 +113,6 @@ TODO: do this in a less bad way?"
(shell-command command (current-buffer))
(buffer-string))))
-(defun cpupower-info ()
- "Place current cpupower information into the message buffer."
- (interactive)
- (let ((governors (seq-uniq (cpupower-get-governors) 'string-equal))
- (frequencies (mapcar 'cpupower--format-KHz
(cpupower-get-frequencies))))
- (message "Governor: %s [ %s ] (version: %s)"
- (mapconcat 'identity governors ", ")
- (mapconcat 'identity frequencies ", ")
- (cpupower--get-version))))
-
-(defun cpupower-set-governor (governor)
- "Set the governor on all CPUs to a given governor by name"
- (interactive "sGovernor: ")
- (let ((valid-governors (cpupower--get-available-governors)))
- (unless (member governor valid-governors)
- (error "Invalid governor: %s, must be one of %s" governor
valid-governors))
- (cpupower--run (format "--cpu all frequency-set -g %s" governor))
- (cpupower-info)))
-
(defun cpupower--format-KHz (KHz)
"Format KHz for human eyes (probably translating to MHz or GHz)."
(cond ((> KHz 1000000)
@@ -149,7 +148,26 @@ function returns: (\"and\" \"too\")
(setq next-token-is-target t))
finally return output-tokens))
-(defun cpupower-get-frequencies (&optional print-message)
+(defun cpupower-info ()
+ "Place current cpupower information into the message buffer."
+ (interactive)
+ (let ((governors (seq-uniq (cpupower-get-current-governors) 'string-equal))
+ (frequencies (mapcar 'cpupower--format-KHz
(cpupower-get-current-frequencies))))
+ (message "Governor: %s [ %s ] (version: %s)"
+ (mapconcat 'identity governors ", ")
+ (mapconcat 'identity frequencies ", ")
+ (cpupower--get-version))))
+
+(defun cpupower-set-governor (governor)
+ "Set the governor on all CPUs to a given governor by name (string)."
+ (interactive "sGovernor: ")
+ (let ((valid-governors (cpupower--get-available-governors)))
+ (unless (member governor valid-governors)
+ (error "Invalid governor: %s, must be one of %s" governor
valid-governors))
+ (cpupower--run (format "--cpu all frequency-set -g %s" governor))
+ (cpupower-info)))
+
+(defun cpupower-get-current-frequencies (&optional print-message)
"Return a list of CPU frequencies in KHz"
(interactive "p")
(let* ((output (cpupower--run "--cpu all frequency-info -f"))
@@ -160,7 +178,7 @@ function returns: (\"and\" \"too\")
(mapconcat 'cpupower--format-KHz frequencies ", "))))
frequencies))
-(defun cpupower-get-governors (&optional print-message)
+(defun cpupower-get-current-governors (&optional print-message)
"Return a list of CPU governors"
(interactive "p")
(let* ((output (cpupower--run "--cpu all frequency-info -p"))
@@ -174,12 +192,16 @@ function returns: (\"and\" \"too\")
", "))))
governors))
-;; TODO - only define if helm exists?
(defun cpupower-helm-set-governor ()
+ "Set cpu governor using helm
+
+@TODO - this should only exist when helm is installed?"
(interactive)
- (cpupower-set-governor
- (helm :sources (helm-build-sync-source "cpu-governors"
- :candidates (cpupower--get-available-governors))
- :buffer "*helm set cpu governor*")))
+ (if (package-installed-p 'helm)
+ (cpupower-set-governor
+ (helm :sources (helm-build-sync-source "cpu-governors"
+ :candidates (cpupower--get-available-governors))
+ :buffer "*helm set cpu governor*"))
+ (call-interactively 'cpupower-set-governor)))
(provide 'cpupower)
- [elpa] externals/cpupower f661743bcf 19/35: :shrug:, (continued)
- [elpa] externals/cpupower f661743bcf 19/35: :shrug:, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 24bd212efe 28/35: ok, got those backwards, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 3b29497bc3 01/35: here's the first piece, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 7b0e057ca6 05/35: ok, I think it works now., ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 4e85b4dc02 04/35: Initial commit, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower d38011bbb9 06/35: Merge branch 'starting' into 'main', ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower db7bf2406c 12/35: a bit more, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 3501256e73 14/35: okay., ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower b661a409c6 16/35: :shrug:, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower fa9888163d 03/35: more?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 5efe8c1f7d 11/35: clean up pass,
ELPA Syncer <=
- [elpa] externals/cpupower 9f283594a9 20/35: :shrug:, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 40952ede70 32/35: using keyword recommended by the manual, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower a18d913837 29/35: logging control, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower e9127b20a4 21/35: now working with quelpa without warnings, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 41cd60e2e5 26/35: keywords?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower a8da800f6a 18/35: testing?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 26d745d610 35/35: Merge branch 'review-feedback-changes' into 'main', ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower a1c0d4e1d1 34/35: Update cpupower.el, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 0b3d8f2d89 23/35: you need that semi-colon to get package info, TIL, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 56406a83b1 22/35: Merge branch 'testing', ELPA Syncer, 2022/05/05