branch: elpa/flamegraph
commit e4e8ec246595bee57190d7ebc8887b82edae6d08
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>

    Dim below-threshold callees in the Calls tree
    
    A callee under flamegraph-call-site-threshold is omitted from the snippet
    but still listed in Calls, which read as inconsistent.  Shadow its name
    there so the row explains its own absence above; counts and percentages
    stay at full weight, and the row stays clickable.
---
 flamegraph.el            | 23 +++++++++++++++--------
 test/flamegraph-tests.el | 20 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/flamegraph.el b/flamegraph.el
index fd66a40c1c..6aa1f5434b 100644
--- a/flamegraph.el
+++ b/flamegraph.el
@@ -751,7 +751,12 @@ that frame.  DEPTH controls the indentation."
       (insert (format "%7s  " (profiler-format-number
                                (profiler-calltree-count k))))
       (insert (make-string (* 2 depth) ?\s))
-      (flamegraph--describe-button k total directory)
+      ;; Dim callees below the threshold: they are absent from the snippet
+      ;; (see `flamegraph-call-site-threshold'), so mark why here.
+      (flamegraph--describe-button
+       k total directory
+       (< (/ (float (profiler-calltree-count k)) ref)
+          flamegraph-call-site-threshold))
       (insert (format "  (%s)\n"
                       (flamegraph--percent
                        (profiler-calltree-count k) ref)))
@@ -759,13 +764,15 @@ that frame.  DEPTH controls the indentation."
         (flamegraph--insert-call-tree k total ref (1+ depth) directory
                                       reached)))))
 
-(defun flamegraph--describe-button (node total directory)
-  "Insert a button that describes NODE, passing TOTAL and DIRECTORY along."
-  (insert-text-button (flamegraph--frame-display-name
-                       (profiler-calltree-entry node))
-                      'type 'help-xref
-                      'help-function #'flamegraph--describe-frame
-                      'help-args (list node total directory)))
+(defun flamegraph--describe-button (node total directory &optional dim)
+  "Insert a button that describes NODE, passing TOTAL and DIRECTORY along.
+With DIM non-nil, shadow the name (but keep it clickable)."
+  (apply #'insert-text-button (flamegraph--frame-display-name
+                               (profiler-calltree-entry node))
+         'type 'help-xref
+         'help-function #'flamegraph--describe-frame
+         'help-args (list node total directory)
+         (when dim '(face (shadow button)))))
 
 (defun flamegraph--describe-frame (node total directory)
   "Show a report for calltree NODE in the *Help* buffer.
diff --git a/test/flamegraph-tests.el b/test/flamegraph-tests.el
index 81f19456de..816b06ece7 100644
--- a/test/flamegraph-tests.el
+++ b/test/flamegraph-tests.el
@@ -363,6 +363,26 @@ unreached sibling does not, and stays at the top depth."
       (should (flamegraph-test--line-with "kid" lines))
       (should-not (flamegraph-test--line-with "grand" lines)))))
 
+(defun flamegraph-test--name-dimmed-p (str name)
+  "Non-nil if NAME's button in STR carries the `shadow' face."
+  (let ((pos (string-match (concat "\\_<" (regexp-quote name) "\\_>") str)))
+    (and pos
+         (let ((face (get-text-property pos 'face str)))
+           (and (listp face) (memq 'shadow face))))))
+
+(ert-deftest flamegraph-test-call-tree-dims-below-threshold ()
+  "Callees below `flamegraph-call-site-threshold' get a dimmed name;
+those at or above it do not."
+  (let* ((cold (profiler-make-calltree :entry 'cold :count 1))
+         (hot  (profiler-make-calltree :entry 'hot :count 99))
+         (root (profiler-make-calltree :entry 'root :count 100
+                                       :children (list hot cold)))
+         (flamegraph-call-site-threshold 0.02)
+         (out (flamegraph-test--render-call-tree root 100)))
+    ;; cold is 1% -> dimmed; hot is 99% -> normal.
+    (should (flamegraph-test--name-dimmed-p out "cold"))
+    (should-not (flamegraph-test--name-dimmed-p out "hot"))))
+
 (ert-deftest flamegraph-test-call-tree-percent-scaled-to-ref ()
   "Sub-children's percentage uses REF (the described frame's count),
 not their immediate parent — so all percents add up under that frame."

Reply via email to