[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cpupower 54da9938b4 07/35: well, it's slightly more con
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cpupower 54da9938b4 07/35: well, it's slightly more concise. |
Date: |
Thu, 5 May 2022 15:57:44 -0400 (EDT) |
branch: externals/cpupower
commit 54da9938b4c663174dba5f75b5e0b341807924bc
Author: smeister <smeister@awstruepower.com>
Commit: smeister <smeister@awstruepower.com>
well, it's slightly more concise.
---
cpupower.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 64 insertions(+), 16 deletions(-)
diff --git a/cpupower.el b/cpupower.el
index f6aaca218e..250f0c9655 100644
--- a/cpupower.el
+++ b/cpupower.el
@@ -13,7 +13,7 @@
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
-;; You should have received a copy of the GN U General Public License
+;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -98,7 +98,11 @@ TODO: do this in a less bad way?"
(defun cpupower-info ()
"Place current cpupower information into the message buffer."
(interactive)
- (message (cpupower--run "--cpu all frequency-info")))
+ (let ((governors (seq-uniq (cpupower-get-governors) 'string-equal))
+ (frequencies (mapcar 'cpupower--format-KHz
(cpupower-get-frequencies))))
+ (message "Governor: %s [ %s ]"
+ (mapconcat 'identity governors ", ")
+ (mapconcat 'identity frequencies ", "))))
(defun cpupower-set-governor (governor)
"Set the governor on all CPUs to a given governor by name"
@@ -109,21 +113,65 @@ TODO: do this in a less bad way?"
(cpupower--run (format "--cpu all frequency-set -g %s" governor))
(cpupower-info)))
-(defun cpupower-get-frequencies ()
- (interactive)
+(defun cpupower--format-KHz (KHz)
+ "Format KHz for human eyes (probably translating to MHz or GHz)."
+ (cond ((> KHz 1000000)
+ (format "%.2fGHz" (/ KHz 1000000.0)))
+ ((> KHz 1000)
+ (format "%.1fMHz" (/ KHz 1000.0)))
+ (t
+ (format "%dKHz" KHz))))
+
+(defun cpupower--parse-output (output-string pre-token)
+ "Warning: bad idea - parse console output for tokens
+
+Split OUTPUT-STRING on whitespace characters then scan through
+all the strings for the PRE-TOKEN. When PRE-TOKEN is found the
+next string is accumulated for output.
+
+Example:
+output-string => \"this here and this one here too\"
+pre-token => \"here\"
+
+function returns: (\"and\" \"too\")
+
+:("
+ (cl-loop with output-tokens = nil
+ with next-token-is-target = nil
+ for token in (split-string output-string)
+ if next-token-is-target
+ do (progn
+ (push token output-tokens)
+ (setq next-token-is-target nil))
+ else
+ do (when (string-equal token pre-token)
+ (setq next-token-is-target t))
+ finally return output-tokens))
+
+(defun cpupower-get-frequencies (&optional print-message)
+ "Return a list of CPU frequencies in KHz"
+ (interactive "p")
(let* ((output (cpupower--run "--cpu all frequency-info -f"))
- (tokens (split-string output))
- (frequencies))
- (cl-loop with next-token-is-frequency = nil
- for token in tokens
- if next-token-is-frequency
- do (progn
- (push (string-to-number token) frequencies)
- (setq next-token-is-frequency nil))
- else
- do (when (string-equal token "frequency:")
- (setq next-token-is-frequency t))
- finally return frequencies)))
+ (frequencies (mapcar 'string-to-number
+ (cpupower--parse-output output "frequency:"))))
+ (when print-message
+ (message (format "CPU Frequencies: %s"
+ (mapconcat 'cpupower--format-KHz frequencies ", "))))
+ frequencies))
+
+(defun cpupower-get-governors (&optional print-message)
+ "Return a list of CPU governors"
+ (interactive "p")
+ (let* ((output (cpupower--run "--cpu all frequency-info -p"))
+ (governors (mapcar (lambda (quoted)
+ (string-replace "\"" "" quoted))
+ (cpupower--parse-output output "governor"))))
+ (when print-message
+ (message (format "CPU Governors: %s"
+ (mapconcat 'identity
+ (seq-uniq governors 'string-equal)
+ ", "))))
+ governors))
;; TODO - only define if helm exists?
(defun cpupower-helm-set-governor ()
- [elpa] branch externals/cpupower created (now 26d745d610), ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 54da9938b4 07/35: well, it's slightly more concise.,
ELPA Syncer <=
- [elpa] externals/cpupower 24b05daf79 02/35: GPL-v3, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 4204048eea 08/35: Merge branch 'cpu-info-change', ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 757ef4a6fb 09/35: now with a version string, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 6ab7e0caec 10/35: whitespace, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower b3742b03bf 15/35: Merge branch 'formalize', ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower bdc0013d83 33/35: version 1.0.1?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower b6c476e8f1 27/35: do these need to be out here?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 0325122de5 31/35: Merge remote-tracking branch 'origin/version-check', ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower 3824c2aae4 25/35: remove that warning?, ELPA Syncer, 2022/05/05
- [elpa] externals/cpupower c62689f72e 24/35: now without cat-ing random files, ELPA Syncer, 2022/05/05