emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/emacs-gc-stats 1a8cd5dd08 11/24: Add idle time counter


From: ELPA Syncer
Subject: [elpa] externals/emacs-gc-stats 1a8cd5dd08 11/24: Add idle time counter
Date: Sat, 10 Jun 2023 12:58:45 -0400 (EDT)

branch: externals/emacs-gc-stats
commit 1a8cd5dd08cd5a84f63f83127a6715b40c3d0481
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    Add idle time counter
    
    * emacs-gc-stats.el (emacs-gc-stats-idle-delay): New variable.  Number
    of seconds to consider the time idle.
    (emacs-gc-stats--idle-tic): New variable holding how many
    `emacs-gc-stats-idle-delay' intervals Emacs was idle.
    (emacs-gc-stats--idle-timer): New variable holding the timer.
    (emacs-gc-stats-idle-tic): New function.  Idle counter tic counter.
    (emacs-gc-stats-mode): Run idle timer.
    (emacs-gc-stats--command-vars):
    (emacs-gc-stats--summary-vars): Record idle tic counter.
---
 emacs-gc-stats.el | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/emacs-gc-stats.el b/emacs-gc-stats.el
index f41943ef55..39a46a9433 100644
--- a/emacs-gc-stats.el
+++ b/emacs-gc-stats.el
@@ -69,7 +69,8 @@
     this-command
     memory-limit
     (memory-info)
-    (memory-use-counts))
+    (memory-use-counts)
+    emacs-gc-stats--idle-tic)
   "List of variable/function symbols to collect for each GC or command.")
 
 (defvar emacs-gc-stats--summary-vars
@@ -80,7 +81,9 @@
     memory-limit
     (memory-info)
     emacs-uptime
-    (memory-use-counts))
+    (memory-use-counts)
+    emacs-gc-stats-idle-delay
+    emacs-gc-stats--idle-tic)
   "List of variables to collect at session end.")
 
 (defun emacs-gc-stats--collect (&rest symbols)
@@ -169,6 +172,19 @@ Otherwise, collect symbol."
     (emacs-gc-stats-mode -1)
     (emacs-gc-stats-mode +1)))
 
+(defvar emacs-gc-stats-idle-delay 300
+  "Delay in seconds to count idle time.")
+
+(defvar emacs-gc-stats--idle-tic 0
+  "Idle counter.")
+(defvar emacs-gc-stats--idle-timer nil
+  "Time counting idle time.")
+(defun emacs-gc-stats-idle-tic ()
+  "Increase idle counter."
+  (when (and (current-idle-time)
+             (> (time-to-seconds (current-idle-time)) 
emacs-gc-stats-idle-delay))
+    (cl-incf emacs-gc-stats--idle-tic)))
+
 (define-minor-mode emacs-gc-stats-mode
   "Toggle collecting Emacs GC statistics."
   :global t
@@ -176,9 +192,17 @@ Otherwise, collect symbol."
       (progn
         (unless emacs-gc-stats--data
           (emacs-gc-stats--collect-init))
+        ;; 5 minutes counter.
+        (setq emacs-gc-stats--idle-time
+              (run-with-timer
+               emacs-gc-stats-idle-delay
+               emacs-gc-stats-idle-delay
+               #'emacs-gc-stats-idle-tic))
         (add-hook 'post-gc-hook #'emacs-gc-stats--collect-gc)
         (add-hook 'after-init-hook #'emacs-gc-stats--collect-init-end)
         (add-hook 'kill-emacs-hook #'emacs-gc-stats-save-session))
+    (when (timerp emacs-gc-stats--idle-time)
+      (cancel-timer emacs-gc-stats--idle-time))
     (remove-hook 'post-gc-hook #'emacs-gc-stats--collect-gc)
     (remove-hook 'after-init-hook #'emacs-gc-stats--collect-init-end)
     (remove-hook 'kill-emacs-hook #'emacs-gc-stats-save-session)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]