commit 21eed7d2c9eb264410f784eb3e49a1efdc3da6f3
parent 4fa172ed19e4f804dc2fcf3bb2d2efd0a2ee1bc2
Author: Brendan Gregg <brendan.d.gregg@gmail.com>
Date: Thu, 24 Oct 2019 12:16:27 -0700
Merge pull request #211 from knittl/feature/search-improvements
Interactive search improvements
Diffstat:
1 file changed, 36 insertions(+), 6 deletions(-)
diff --git a/flamegraph.pl b/flamegraph.pl
@@ -734,8 +734,8 @@ my $inc = <<INC;
</defs>
<style type="text/css">
text { font-family:$fonttype; font-size:${fontsize}px; fill:$black; }
- #search { opacity:0.1; cursor:pointer; }
- #search:hover, #search.show { opacity:1; }
+ #search, #ignorecase { opacity:0.1; cursor:pointer; }
+ #search:hover, #search.show, #ignorecase:hover, #ignorecase.show { opacity:1; }
#subtitle { text-anchor:middle; font-color:$vdgrey; }
#title { text-anchor:middle; font-size:${titlesize}px}
#unzoom { cursor:pointer; }
@@ -746,14 +746,16 @@ my $inc = <<INC;
<script type="text/ecmascript">
<![CDATA[
"use strict";
- var details, searchbtn, unzoombtn, matchedtxt, svg, searching;
+ var details, searchbtn, unzoombtn, matchedtxt, svg, searching, currentSearchTerm, ignorecase, ignorecaseBtn;
function init(evt) {
details = document.getElementById("details").firstChild;
searchbtn = document.getElementById("search");
+ ignorecaseBtn = document.getElementById("ignorecase");
unzoombtn = document.getElementById("unzoom");
matchedtxt = document.getElementById("matched");
svg = document.getElementsByTagName("svg")[0];
searching = 0;
+ currentSearchTerm = null;
}
window.addEventListener("click", function(e) {
@@ -768,6 +770,7 @@ my $inc = <<INC;
}
else if (e.target.id == "unzoom") unzoom();
else if (e.target.id == "search") search_prompt();
+ else if (e.target.id == "ignorecase") toggle_ignorecase();
}, false)
// mouse-over for info
@@ -791,6 +794,14 @@ my $inc = <<INC;
}
}, false)
+ // ctrl-I to toggle case-sensitive search
+ window.addEventListener("keydown",function (e) {
+ if (e.ctrlKey && e.keyCode === 73) {
+ e.preventDefault();
+ toggle_ignorecase();
+ }
+ }, false)
+
// functions
function find_child(node, selector) {
var children = node.querySelectorAll(selector);
@@ -946,6 +957,7 @@ my $inc = <<INC;
}
}
}
+ search();
}
function unzoom() {
unzoombtn.classList.add("hide");
@@ -956,9 +968,20 @@ my $inc = <<INC;
zoom_reset(el[i]);
update_text(el[i]);
}
+ search();
}
// search
+ function toggle_ignorecase() {
+ ignorecase = !ignorecase;
+ if (ignorecase) {
+ ignorecaseBtn.classList.add("show");
+ } else {
+ ignorecaseBtn.classList.remove("show");
+ }
+ reset_search();
+ search();
+ }
function reset_search() {
var el = document.querySelectorAll("#frames rect");
for (var i = 0; i < el.length; i++) {
@@ -968,13 +991,16 @@ my $inc = <<INC;
function search_prompt() {
if (!searching) {
var term = prompt("Enter a search term (regexp " +
- "allowed, eg: ^ext4_)", "");
+ "allowed, eg: ^ext4_)"
+ + (ignorecase ? ", ignoring case" : ""), "");
if (term != null) {
- search(term)
+ currentSearchTerm = term;
+ search();
}
} else {
reset_search();
searching = 0;
+ currentSearchTerm = null;
searchbtn.classList.remove("show");
searchbtn.firstChild.nodeValue = "Search"
matchedtxt.classList.add("hide");
@@ -982,7 +1008,10 @@ my $inc = <<INC;
}
}
function search(term) {
- var re = new RegExp(term);
+ if (currentSearchTerm === null) return;
+ var term = currentSearchTerm;
+
+ var re = new RegExp(term, ignorecase ? 'i' : '');
var el = document.getElementById("frames").children;
var matches = new Object();
var maxwidth = 0;
@@ -1065,6 +1094,7 @@ $im->stringTTF("subtitle", int($imagewidth / 2), $fontsize * 4, $subtitletext) i
$im->stringTTF("details", $xpad, $imageheight - ($ypad2 / 2), " ");
$im->stringTTF("unzoom", $xpad, $fontsize * 2, "Reset Zoom", 'class="hide"');
$im->stringTTF("search", $imagewidth - $xpad - 100, $fontsize * 2, "Search");
+$im->stringTTF("ignorecase", $imagewidth - $xpad - 16, $fontsize * 2, "ic");
$im->stringTTF("matched", $imagewidth - $xpad - 100, $imageheight - ($ypad2 / 2), " ");
if ($palette) {