martes, 18 de septiembre de 2012

emacs checking your temperature

Yesterday I was on my laptop, with the usual tools opened (that means emacs, urxvt+screen and chromium-browser).Nothing strange. I went out for a rollerskating session with a couple of friends and when I came back, the laptop was awfully warm. I mean, keyboard really hot, and when I took the laptop on my hands, it was freaking hot. Luckily it didn't melt :).  A quick glance at top(1) showed that chromium was taking all the cpu, and a big amount of memory. probably some js, who knows.

Just killing the offensive process made my little old thinkpad come back to normal temperature.

Then, to make sure it doesn't happen again, I wrote a little elisp script to warn me in case my lappy is warming beyond acceptable limits. Or even kill chromium-browser in case the temperature is >95C.

So here's the  code. Checking the temperature of the cpu, and acting if needed.

;;; raimonster@gmail.com
; The array returned by battery-statys-function => '((99 . "25330") (76 . "on-line") (100 . "54") (114 . "0 mW") (66 . "charged") (98 . "") (104 . "0") (109 . "0") (116 . "0:00") (112 . "97"))

(defun rgc-check-for-hotness ()
  (interactive)
  (let ((temp (string-to-number
                (cdr (assq (string-to-char "d")
                           (and battery-status-function (funcall battery-status-function)))))))

    (cond ((> temp 95) (async-shell-command "killall -9 chromium-browser"))
          ((> temp 75) (message "FUCK! I'M HOT"))
          (t (message "ok, no problemo")))))

(defvar rgc-hot-timer nil "timer")

(defun rgc-hot-hot-hot ()
  (interactive)
  (setq rgc-hot-timer
        (run-at-time nil (* 60 5) 'rgc-check-for-hotness)))

(defun rgc-stop-hot-checker ()
  (interactive)
  (cancel-timer rgc-hot-timer))
As always in this blog, no rocket science, but (hopefully) useful bits of elisp.

2 comentarios:

elias dijo...

em donen ganes de tornar a instal·lar l'emax xD

Raimon Grau dijo...

Hahah! ja ho saps! aqui tens un colega de lisps!

Salut!