Nav apraksta

webhtml.go 36KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. // Copyright 2017 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package driver
  15. import (
  16. "html/template"
  17. "github.com/google/pprof/third_party/d3"
  18. "github.com/google/pprof/third_party/d3flamegraph"
  19. )
  20. // addTemplates adds a set of template definitions to templates.
  21. func addTemplates(templates *template.Template) {
  22. template.Must(templates.Parse(`{{define "d3script"}}` + d3.JSSource + `{{end}}`))
  23. template.Must(templates.Parse(`{{define "d3flamegraphscript"}}` + d3flamegraph.JSSource + `{{end}}`))
  24. template.Must(templates.Parse(`{{define "d3flamegraphcss"}}` + d3flamegraph.CSSSource + `{{end}}`))
  25. template.Must(templates.Parse(`
  26. {{define "css"}}
  27. <style type="text/css">
  28. * {
  29. margin: 0;
  30. padding: 0;
  31. box-sizing: border-box;
  32. }
  33. html, body {
  34. height: 100%;
  35. }
  36. body {
  37. font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  38. font-size: 13px;
  39. line-height: 1.4;
  40. display: flex;
  41. flex-direction: column;
  42. }
  43. a {
  44. color: #2a66d9;
  45. }
  46. .header {
  47. display: flex;
  48. align-items: center;
  49. height: 44px;
  50. min-height: 44px;
  51. background-color: #eee;
  52. color: #212121;
  53. padding: 0 1rem;
  54. }
  55. .header > div {
  56. margin: 0 0.125em;
  57. }
  58. .header .title h1 {
  59. font-size: 1.75em;
  60. margin-right: 1rem;
  61. }
  62. .header .title a {
  63. color: #212121;
  64. text-decoration: none;
  65. }
  66. .header .title a:hover {
  67. text-decoration: underline;
  68. }
  69. .header .description {
  70. width: 100%;
  71. text-align: right;
  72. white-space: nowrap;
  73. }
  74. @media screen and (max-width: 799px) {
  75. .header input {
  76. display: none;
  77. }
  78. }
  79. #detailsbox {
  80. display: none;
  81. z-index: 1;
  82. position: fixed;
  83. top: 40px;
  84. right: 20px;
  85. background-color: #ffffff;
  86. box-shadow: 0 1px 5px rgba(0,0,0,.3);
  87. line-height: 24px;
  88. padding: 1em;
  89. text-align: left;
  90. }
  91. .header input {
  92. background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' style='pointer-events:none;display:block;width:100%25;height:100%25;fill:%23757575'%3E%3Cpath d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61.0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E") no-repeat 4px center/20px 20px;
  93. border: 1px solid #d1d2d3;
  94. border-radius: 2px 0 0 2px;
  95. padding: 0.25em;
  96. padding-left: 28px;
  97. margin-left: 1em;
  98. font-family: 'Roboto', 'Noto', sans-serif;
  99. font-size: 1em;
  100. line-height: 24px;
  101. color: #212121;
  102. }
  103. .downArrow {
  104. border-top: .36em solid #ccc;
  105. border-left: .36em solid transparent;
  106. border-right: .36em solid transparent;
  107. margin-bottom: .05em;
  108. margin-left: .5em;
  109. transition: border-top-color 200ms;
  110. }
  111. .menu-item {
  112. height: 100%;
  113. text-transform: uppercase;
  114. font-family: 'Roboto Medium', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  115. position: relative;
  116. }
  117. .menu-item .menu-name:hover {
  118. opacity: 0.75;
  119. }
  120. .menu-item .menu-name:hover .downArrow {
  121. border-top-color: #666;
  122. }
  123. .menu-name {
  124. height: 100%;
  125. padding: 0 0.5em;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. }
  130. .submenu {
  131. display: none;
  132. z-index: 1;
  133. margin-top: -4px;
  134. min-width: 10em;
  135. position: absolute;
  136. left: 0px;
  137. background-color: white;
  138. box-shadow: 0 1px 5px rgba(0,0,0,.3);
  139. font-size: 100%;
  140. text-transform: none;
  141. }
  142. .menu-item, .submenu {
  143. user-select: none;
  144. -moz-user-select: none;
  145. -ms-user-select: none;
  146. -webkit-user-select: none;
  147. }
  148. .submenu hr {
  149. border: 0;
  150. border-top: 2px solid #eee;
  151. }
  152. .submenu a {
  153. display: block;
  154. padding: .5em 1em;
  155. text-decoration: none;
  156. }
  157. .submenu a:hover, .submenu a.active {
  158. color: white;
  159. background-color: #6b82d6;
  160. }
  161. .submenu a.disabled {
  162. color: gray;
  163. pointer-events: none;
  164. }
  165. .menu-check-mark {
  166. position: absolute;
  167. left: 2px;
  168. }
  169. .menu-delete-btn {
  170. position: absolute;
  171. right: 2px;
  172. }
  173. {{/* Used to disable events when a modal dialog is displayed */}}
  174. #dialog-overlay {
  175. display: none;
  176. position: fixed;
  177. left: 0px;
  178. top: 0px;
  179. width: 100%;
  180. height: 100%;
  181. background-color: rgba(1,1,1,0.1);
  182. }
  183. .dialog {
  184. {{/* Displayed centered horizontally near the top */}}
  185. display: none;
  186. position: fixed;
  187. margin: 0px;
  188. top: 60px;
  189. left: 50%;
  190. transform: translateX(-50%);
  191. z-index: 3;
  192. font-size: 125%;
  193. background-color: #ffffff;
  194. box-shadow: 0 1px 5px rgba(0,0,0,.3);
  195. }
  196. .dialog-header {
  197. font-size: 120%;
  198. border-bottom: 1px solid #CCCCCC;
  199. width: 100%;
  200. text-align: center;
  201. background: #EEEEEE;
  202. user-select: none;
  203. }
  204. .dialog-footer {
  205. border-top: 1px solid #CCCCCC;
  206. width: 100%;
  207. text-align: right;
  208. padding: 10px;
  209. }
  210. .dialog-error {
  211. margin: 10px;
  212. color: red;
  213. }
  214. .dialog input {
  215. margin: 10px;
  216. font-size: inherit;
  217. }
  218. .dialog button {
  219. margin-left: 10px;
  220. font-size: inherit;
  221. }
  222. #save-dialog, #delete-dialog {
  223. width: 50%;
  224. max-width: 20em;
  225. }
  226. #delete-prompt {
  227. padding: 10px;
  228. }
  229. #content {
  230. overflow-y: scroll;
  231. padding: 1em;
  232. }
  233. #top {
  234. overflow-y: scroll;
  235. }
  236. #graph {
  237. overflow: hidden;
  238. }
  239. #graph svg {
  240. width: 100%;
  241. height: auto;
  242. padding: 10px;
  243. }
  244. #content.source .filename {
  245. margin-top: 0;
  246. margin-bottom: 1em;
  247. font-size: 120%;
  248. }
  249. #content.source pre {
  250. margin-bottom: 3em;
  251. }
  252. table {
  253. border-spacing: 0px;
  254. width: 100%;
  255. padding-bottom: 1em;
  256. white-space: nowrap;
  257. }
  258. table thead {
  259. font-family: 'Roboto Medium', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  260. }
  261. table tr th {
  262. position: sticky;
  263. top: 0;
  264. background-color: #ddd;
  265. text-align: right;
  266. padding: .3em .5em;
  267. }
  268. table tr td {
  269. padding: .3em .5em;
  270. text-align: right;
  271. }
  272. #top table tr th:nth-child(6),
  273. #top table tr th:nth-child(7),
  274. #top table tr td:nth-child(6),
  275. #top table tr td:nth-child(7) {
  276. text-align: left;
  277. }
  278. #top table tr td:nth-child(6) {
  279. width: 100%;
  280. text-overflow: ellipsis;
  281. overflow: hidden;
  282. white-space: nowrap;
  283. }
  284. #flathdr1, #flathdr2, #cumhdr1, #cumhdr2, #namehdr {
  285. cursor: ns-resize;
  286. }
  287. .hilite {
  288. background-color: #ebf5fb;
  289. font-weight: bold;
  290. }
  291. </style>
  292. {{end}}
  293. {{define "header"}}
  294. <div class="header">
  295. <div class="title">
  296. <h1><a href="./">pprof</a></h1>
  297. </div>
  298. <div id="view" class="menu-item">
  299. <div class="menu-name">
  300. View
  301. <i class="downArrow"></i>
  302. </div>
  303. <div class="submenu">
  304. <a title="{{.Help.top}}" href="./top" id="topbtn">Top</a>
  305. <a title="{{.Help.graph}}" href="./dot" id="graphbtn">Graph</a>
  306. <a title="{{.Help.flamegraph}}" href="./flamegraph" id="flamegraph">Flame Graph</a>
  307. <a title="{{.Help.peek}}" href="./peek" id="peek">Peek</a>
  308. <a title="{{.Help.list}}" href="./source" id="list">Source</a>
  309. <a title="{{.Help.disasm}}" href="./disasm" id="disasm">Disassemble</a>
  310. </div>
  311. </div>
  312. {{$sampleLen := len .SampleTypes}}
  313. {{if gt $sampleLen 1}}
  314. <div id="sample" class="menu-item">
  315. <div class="menu-name">
  316. Sample
  317. <i class="downArrow"></i>
  318. </div>
  319. <div class="submenu">
  320. {{range .SampleTypes}}
  321. <a href="?si={{.}}" id="{{.}}">{{.}}</a>
  322. {{end}}
  323. </div>
  324. </div>
  325. {{end}}
  326. <div id="refine" class="menu-item">
  327. <div class="menu-name">
  328. Refine
  329. <i class="downArrow"></i>
  330. </div>
  331. <div class="submenu">
  332. <a title="{{.Help.focus}}" href="?" id="focus">Focus</a>
  333. <a title="{{.Help.ignore}}" href="?" id="ignore">Ignore</a>
  334. <a title="{{.Help.hide}}" href="?" id="hide">Hide</a>
  335. <a title="{{.Help.show}}" href="?" id="show">Show</a>
  336. <a title="{{.Help.show_from}}" href="?" id="show-from">Show from</a>
  337. <hr>
  338. <a title="{{.Help.reset}}" href="?">Reset</a>
  339. </div>
  340. </div>
  341. <div id="config" class="menu-item">
  342. <div class="menu-name">
  343. Config
  344. <i class="downArrow"></i>
  345. </div>
  346. <div class="submenu">
  347. <a title="{{.Help.save_config}}" id="save-config">Save as ...</a>
  348. <hr>
  349. {{range .Configs}}
  350. <a href="{{.URL}}">
  351. {{if .Current}}<span class="menu-check-mark">✓</span>{{end}}
  352. {{.Name}}
  353. {{if .UserConfig}}<span class="menu-delete-btn" data-config={{.Name}}>🗙</span>{{end}}
  354. </a>
  355. {{end}}
  356. </div>
  357. </div>
  358. <div>
  359. <input id="search" type="text" placeholder="Search regexp" autocomplete="off" autocapitalize="none" size=40>
  360. </div>
  361. <div class="description">
  362. <a title="{{.Help.details}}" href="#" id="details">{{.Title}}</a>
  363. <div id="detailsbox">
  364. {{range .Legend}}<div>{{.}}</div>{{end}}
  365. </div>
  366. </div>
  367. </div>
  368. <div id="dialog-overlay"></div>
  369. <div class="dialog" id="save-dialog">
  370. <div class="dialog-header">Save options as</div>
  371. <datalist id="config-list">
  372. {{range .Configs}}{{if .UserConfig}}<option value="{{.Name}}" />{{end}}{{end}}
  373. </datalist>
  374. <input id="save-name" type="text" list="config-list" placeholder="New config" />
  375. <div class="dialog-footer">
  376. <span class="dialog-error" id="save-error"></span>
  377. <button id="save-cancel">Cancel</button>
  378. <button id="save-confirm">Save</button>
  379. </div>
  380. </div>
  381. <div class="dialog" id="delete-dialog">
  382. <div class="dialog-header" id="delete-dialog-title">Delete config</div>
  383. <div id="delete-prompt"></div>
  384. <div class="dialog-footer">
  385. <span class="dialog-error" id="delete-error"></span>
  386. <button id="delete-cancel">Cancel</button>
  387. <button id="delete-confirm">Delete</button>
  388. </div>
  389. </div>
  390. <div id="errors">{{range .Errors}}<div>{{.}}</div>{{end}}</div>
  391. {{end}}
  392. {{define "graph" -}}
  393. <!DOCTYPE html>
  394. <html>
  395. <head>
  396. <meta charset="utf-8">
  397. <title>{{.Title}}</title>
  398. {{template "css" .}}
  399. </head>
  400. <body>
  401. {{template "header" .}}
  402. <div id="graph">
  403. {{.HTMLBody}}
  404. </div>
  405. {{template "script" .}}
  406. <script>viewer(new URL(window.location.href), {{.Nodes}});</script>
  407. </body>
  408. </html>
  409. {{end}}
  410. {{define "script"}}
  411. <script>
  412. // Make svg pannable and zoomable.
  413. // Call clickHandler(t) if a click event is caught by the pan event handlers.
  414. function initPanAndZoom(svg, clickHandler) {
  415. 'use strict';
  416. // Current mouse/touch handling mode
  417. const IDLE = 0;
  418. const MOUSEPAN = 1;
  419. const TOUCHPAN = 2;
  420. const TOUCHZOOM = 3;
  421. let mode = IDLE;
  422. // State needed to implement zooming.
  423. let currentScale = 1.0;
  424. const initWidth = svg.viewBox.baseVal.width;
  425. const initHeight = svg.viewBox.baseVal.height;
  426. // State needed to implement panning.
  427. let panLastX = 0; // Last event X coordinate
  428. let panLastY = 0; // Last event Y coordinate
  429. let moved = false; // Have we seen significant movement
  430. let touchid = null; // Current touch identifier
  431. // State needed for pinch zooming
  432. let touchid2 = null; // Second id for pinch zooming
  433. let initGap = 1.0; // Starting gap between two touches
  434. let initScale = 1.0; // currentScale when pinch zoom started
  435. let centerPoint = null; // Center point for scaling
  436. // Convert event coordinates to svg coordinates.
  437. function toSvg(x, y) {
  438. const p = svg.createSVGPoint();
  439. p.x = x;
  440. p.y = y;
  441. let m = svg.getCTM();
  442. if (m == null) m = svg.getScreenCTM(); // Firefox workaround.
  443. return p.matrixTransform(m.inverse());
  444. }
  445. // Change the scaling for the svg to s, keeping the point denoted
  446. // by u (in svg coordinates]) fixed at the same screen location.
  447. function rescale(s, u) {
  448. // Limit to a good range.
  449. if (s < 0.2) s = 0.2;
  450. if (s > 10.0) s = 10.0;
  451. currentScale = s;
  452. // svg.viewBox defines the visible portion of the user coordinate
  453. // system. So to magnify by s, divide the visible portion by s,
  454. // which will then be stretched to fit the viewport.
  455. const vb = svg.viewBox;
  456. const w1 = vb.baseVal.width;
  457. const w2 = initWidth / s;
  458. const h1 = vb.baseVal.height;
  459. const h2 = initHeight / s;
  460. vb.baseVal.width = w2;
  461. vb.baseVal.height = h2;
  462. // We also want to adjust vb.baseVal.x so that u.x remains at same
  463. // screen X coordinate. In other words, want to change it from x1 to x2
  464. // so that:
  465. // (u.x - x1) / w1 = (u.x - x2) / w2
  466. // Simplifying that, we get
  467. // (u.x - x1) * (w2 / w1) = u.x - x2
  468. // x2 = u.x - (u.x - x1) * (w2 / w1)
  469. vb.baseVal.x = u.x - (u.x - vb.baseVal.x) * (w2 / w1);
  470. vb.baseVal.y = u.y - (u.y - vb.baseVal.y) * (h2 / h1);
  471. }
  472. function handleWheel(e) {
  473. if (e.deltaY == 0) return;
  474. // Change scale factor by 1.1 or 1/1.1
  475. rescale(currentScale * (e.deltaY < 0 ? 1.1 : (1/1.1)),
  476. toSvg(e.offsetX, e.offsetY));
  477. }
  478. function setMode(m) {
  479. mode = m;
  480. touchid = null;
  481. touchid2 = null;
  482. }
  483. function panStart(x, y) {
  484. moved = false;
  485. panLastX = x;
  486. panLastY = y;
  487. }
  488. function panMove(x, y) {
  489. let dx = x - panLastX;
  490. let dy = y - panLastY;
  491. if (Math.abs(dx) <= 2 && Math.abs(dy) <= 2) return; // Ignore tiny moves
  492. moved = true;
  493. panLastX = x;
  494. panLastY = y;
  495. // Firefox workaround: get dimensions from parentNode.
  496. const swidth = svg.clientWidth || svg.parentNode.clientWidth;
  497. const sheight = svg.clientHeight || svg.parentNode.clientHeight;
  498. // Convert deltas from screen space to svg space.
  499. dx *= (svg.viewBox.baseVal.width / swidth);
  500. dy *= (svg.viewBox.baseVal.height / sheight);
  501. svg.viewBox.baseVal.x -= dx;
  502. svg.viewBox.baseVal.y -= dy;
  503. }
  504. function handleScanStart(e) {
  505. if (e.button != 0) return; // Do not catch right-clicks etc.
  506. setMode(MOUSEPAN);
  507. panStart(e.clientX, e.clientY);
  508. e.preventDefault();
  509. svg.addEventListener('mousemove', handleScanMove);
  510. }
  511. function handleScanMove(e) {
  512. if (e.buttons == 0) {
  513. // Missed an end event, perhaps because mouse moved outside window.
  514. setMode(IDLE);
  515. svg.removeEventListener('mousemove', handleScanMove);
  516. return;
  517. }
  518. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY);
  519. }
  520. function handleScanEnd(e) {
  521. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY);
  522. setMode(IDLE);
  523. svg.removeEventListener('mousemove', handleScanMove);
  524. if (!moved) clickHandler(e.target);
  525. }
  526. // Find touch object with specified identifier.
  527. function findTouch(tlist, id) {
  528. for (const t of tlist) {
  529. if (t.identifier == id) return t;
  530. }
  531. return null;
  532. }
  533. // Return distance between two touch points
  534. function touchGap(t1, t2) {
  535. const dx = t1.clientX - t2.clientX;
  536. const dy = t1.clientY - t2.clientY;
  537. return Math.hypot(dx, dy);
  538. }
  539. function handleTouchStart(e) {
  540. if (mode == IDLE && e.changedTouches.length == 1) {
  541. // Start touch based panning
  542. const t = e.changedTouches[0];
  543. setMode(TOUCHPAN);
  544. touchid = t.identifier;
  545. panStart(t.clientX, t.clientY);
  546. e.preventDefault();
  547. } else if (mode == TOUCHPAN && e.touches.length == 2) {
  548. // Start pinch zooming
  549. setMode(TOUCHZOOM);
  550. const t1 = e.touches[0];
  551. const t2 = e.touches[1];
  552. touchid = t1.identifier;
  553. touchid2 = t2.identifier;
  554. initScale = currentScale;
  555. initGap = touchGap(t1, t2);
  556. centerPoint = toSvg((t1.clientX + t2.clientX) / 2,
  557. (t1.clientY + t2.clientY) / 2);
  558. e.preventDefault();
  559. }
  560. }
  561. function handleTouchMove(e) {
  562. if (mode == TOUCHPAN) {
  563. const t = findTouch(e.changedTouches, touchid);
  564. if (t == null) return;
  565. if (e.touches.length != 1) {
  566. setMode(IDLE);
  567. return;
  568. }
  569. panMove(t.clientX, t.clientY);
  570. e.preventDefault();
  571. } else if (mode == TOUCHZOOM) {
  572. // Get two touches; new gap; rescale to ratio.
  573. const t1 = findTouch(e.touches, touchid);
  574. const t2 = findTouch(e.touches, touchid2);
  575. if (t1 == null || t2 == null) return;
  576. const gap = touchGap(t1, t2);
  577. rescale(initScale * gap / initGap, centerPoint);
  578. e.preventDefault();
  579. }
  580. }
  581. function handleTouchEnd(e) {
  582. if (mode == TOUCHPAN) {
  583. const t = findTouch(e.changedTouches, touchid);
  584. if (t == null) return;
  585. panMove(t.clientX, t.clientY);
  586. setMode(IDLE);
  587. e.preventDefault();
  588. if (!moved) clickHandler(t.target);
  589. } else if (mode == TOUCHZOOM) {
  590. setMode(IDLE);
  591. e.preventDefault();
  592. }
  593. }
  594. svg.addEventListener('mousedown', handleScanStart);
  595. svg.addEventListener('mouseup', handleScanEnd);
  596. svg.addEventListener('touchstart', handleTouchStart);
  597. svg.addEventListener('touchmove', handleTouchMove);
  598. svg.addEventListener('touchend', handleTouchEnd);
  599. svg.addEventListener('wheel', handleWheel, true);
  600. }
  601. function initMenus() {
  602. 'use strict';
  603. let activeMenu = null;
  604. let activeMenuHdr = null;
  605. function cancelActiveMenu() {
  606. if (activeMenu == null) return;
  607. activeMenu.style.display = 'none';
  608. activeMenu = null;
  609. activeMenuHdr = null;
  610. }
  611. // Set click handlers on every menu header.
  612. for (const menu of document.getElementsByClassName('submenu')) {
  613. const hdr = menu.parentElement;
  614. if (hdr == null) return;
  615. if (hdr.classList.contains('disabled')) return;
  616. function showMenu(e) {
  617. // menu is a child of hdr, so this event can fire for clicks
  618. // inside menu. Ignore such clicks.
  619. if (e.target.parentElement != hdr) return;
  620. activeMenu = menu;
  621. activeMenuHdr = hdr;
  622. menu.style.display = 'block';
  623. }
  624. hdr.addEventListener('mousedown', showMenu);
  625. hdr.addEventListener('touchstart', showMenu);
  626. }
  627. // If there is an active menu and a down event outside, retract the menu.
  628. for (const t of ['mousedown', 'touchstart']) {
  629. document.addEventListener(t, (e) => {
  630. // Note: to avoid unnecessary flicker, if the down event is inside
  631. // the active menu header, do not retract the menu.
  632. if (activeMenuHdr != e.target.closest('.menu-item')) {
  633. cancelActiveMenu();
  634. }
  635. }, { passive: true, capture: true });
  636. }
  637. // If there is an active menu and an up event inside, retract the menu.
  638. document.addEventListener('mouseup', (e) => {
  639. if (activeMenu == e.target.closest('.submenu')) {
  640. cancelActiveMenu();
  641. }
  642. }, { passive: true, capture: true });
  643. }
  644. function sendURL(method, url, done) {
  645. fetch(url.toString(), {method: method})
  646. .then((response) => { done(response.ok); })
  647. .catch((error) => { done(false); });
  648. }
  649. // Initialize handlers for saving/loading configurations.
  650. function initConfigManager() {
  651. 'use strict';
  652. // Initialize various elements.
  653. function elem(id) {
  654. const result = document.getElementById(id);
  655. if (!result) console.warn('element ' + id + ' not found');
  656. return result;
  657. }
  658. const overlay = elem('dialog-overlay');
  659. const saveDialog = elem('save-dialog');
  660. const saveInput = elem('save-name');
  661. const saveError = elem('save-error');
  662. const delDialog = elem('delete-dialog');
  663. const delPrompt = elem('delete-prompt');
  664. const delError = elem('delete-error');
  665. let currentDialog = null;
  666. let currentDeleteTarget = null;
  667. function showDialog(dialog) {
  668. if (currentDialog != null) {
  669. overlay.style.display = 'none';
  670. currentDialog.style.display = 'none';
  671. }
  672. currentDialog = dialog;
  673. if (dialog != null) {
  674. overlay.style.display = 'block';
  675. dialog.style.display = 'block';
  676. }
  677. }
  678. function cancelDialog(e) {
  679. showDialog(null);
  680. }
  681. // Show dialog for saving the current config.
  682. function showSaveDialog(e) {
  683. saveError.innerText = '';
  684. showDialog(saveDialog);
  685. saveInput.focus();
  686. }
  687. // Commit save config.
  688. function commitSave(e) {
  689. const name = saveInput.value;
  690. const url = new URL(document.URL);
  691. // Set path relative to existing path.
  692. url.pathname = new URL('./saveconfig', document.URL).pathname;
  693. url.searchParams.set('config', name);
  694. saveError.innerText = '';
  695. sendURL('POST', url, (ok) => {
  696. if (!ok) {
  697. saveError.innerText = 'Save failed';
  698. } else {
  699. showDialog(null);
  700. location.reload(); // Reload to show updated config menu
  701. }
  702. });
  703. }
  704. function handleSaveInputKey(e) {
  705. if (e.key === 'Enter') commitSave(e);
  706. }
  707. function deleteConfig(e, elem) {
  708. e.preventDefault();
  709. const config = elem.dataset.config;
  710. delPrompt.innerText = 'Delete ' + config + '?';
  711. currentDeleteTarget = elem;
  712. showDialog(delDialog);
  713. }
  714. function commitDelete(e, elem) {
  715. if (!currentDeleteTarget) return;
  716. const config = currentDeleteTarget.dataset.config;
  717. const url = new URL('./deleteconfig', document.URL);
  718. url.searchParams.set('config', config);
  719. delError.innerText = '';
  720. sendURL('DELETE', url, (ok) => {
  721. if (!ok) {
  722. delError.innerText = 'Delete failed';
  723. return;
  724. }
  725. showDialog(null);
  726. // Remove menu entry for this config.
  727. if (currentDeleteTarget && currentDeleteTarget.parentElement) {
  728. currentDeleteTarget.parentElement.remove();
  729. }
  730. });
  731. }
  732. // Bind event on elem to fn.
  733. function bind(event, elem, fn) {
  734. if (elem == null) return;
  735. elem.addEventListener(event, fn);
  736. if (event == 'click') {
  737. // Also enable via touch.
  738. elem.addEventListener('touchstart', fn);
  739. }
  740. }
  741. bind('click', elem('save-config'), showSaveDialog);
  742. bind('click', elem('save-cancel'), cancelDialog);
  743. bind('click', elem('save-confirm'), commitSave);
  744. bind('keydown', saveInput, handleSaveInputKey);
  745. bind('click', elem('delete-cancel'), cancelDialog);
  746. bind('click', elem('delete-confirm'), commitDelete);
  747. // Activate deletion button for all config entries in menu.
  748. for (const del of Array.from(document.getElementsByClassName('menu-delete-btn'))) {
  749. bind('click', del, (e) => {
  750. deleteConfig(e, del);
  751. });
  752. }
  753. }
  754. function viewer(baseUrl, nodes) {
  755. 'use strict';
  756. // Elements
  757. const search = document.getElementById('search');
  758. const graph0 = document.getElementById('graph0');
  759. const svg = (graph0 == null ? null : graph0.parentElement);
  760. const toptable = document.getElementById('toptable');
  761. let regexpActive = false;
  762. let selected = new Map();
  763. let origFill = new Map();
  764. let searchAlarm = null;
  765. let buttonsEnabled = true;
  766. function handleDetails(e) {
  767. e.preventDefault();
  768. const detailsText = document.getElementById('detailsbox');
  769. if (detailsText != null) {
  770. if (detailsText.style.display === 'block') {
  771. detailsText.style.display = 'none';
  772. } else {
  773. detailsText.style.display = 'block';
  774. }
  775. }
  776. }
  777. function handleKey(e) {
  778. if (e.keyCode != 13) return;
  779. setHrefParams(window.location, function (params) {
  780. params.set('f', search.value);
  781. });
  782. e.preventDefault();
  783. }
  784. function handleSearch() {
  785. // Delay expensive processing so a flurry of key strokes is handled once.
  786. if (searchAlarm != null) {
  787. clearTimeout(searchAlarm);
  788. }
  789. searchAlarm = setTimeout(selectMatching, 300);
  790. regexpActive = true;
  791. updateButtons();
  792. }
  793. function selectMatching() {
  794. searchAlarm = null;
  795. let re = null;
  796. if (search.value != '') {
  797. try {
  798. re = new RegExp(search.value);
  799. } catch (e) {
  800. // TODO: Display error state in search box
  801. return;
  802. }
  803. }
  804. function match(text) {
  805. return re != null && re.test(text);
  806. }
  807. // drop currently selected items that do not match re.
  808. selected.forEach(function(v, n) {
  809. if (!match(nodes[n])) {
  810. unselect(n, document.getElementById('node' + n));
  811. }
  812. })
  813. // add matching items that are not currently selected.
  814. if (nodes) {
  815. for (let n = 0; n < nodes.length; n++) {
  816. if (!selected.has(n) && match(nodes[n])) {
  817. select(n, document.getElementById('node' + n));
  818. }
  819. }
  820. }
  821. updateButtons();
  822. }
  823. function toggleSvgSelect(elem) {
  824. // Walk up to immediate child of graph0
  825. while (elem != null && elem.parentElement != graph0) {
  826. elem = elem.parentElement;
  827. }
  828. if (!elem) return;
  829. // Disable regexp mode.
  830. regexpActive = false;
  831. const n = nodeId(elem);
  832. if (n < 0) return;
  833. if (selected.has(n)) {
  834. unselect(n, elem);
  835. } else {
  836. select(n, elem);
  837. }
  838. updateButtons();
  839. }
  840. function unselect(n, elem) {
  841. if (elem == null) return;
  842. selected.delete(n);
  843. setBackground(elem, false);
  844. }
  845. function select(n, elem) {
  846. if (elem == null) return;
  847. selected.set(n, true);
  848. setBackground(elem, true);
  849. }
  850. function nodeId(elem) {
  851. const id = elem.id;
  852. if (!id) return -1;
  853. if (!id.startsWith('node')) return -1;
  854. const n = parseInt(id.slice(4), 10);
  855. if (isNaN(n)) return -1;
  856. if (n < 0 || n >= nodes.length) return -1;
  857. return n;
  858. }
  859. function setBackground(elem, set) {
  860. // Handle table row highlighting.
  861. if (elem.nodeName == 'TR') {
  862. elem.classList.toggle('hilite', set);
  863. return;
  864. }
  865. // Handle svg element highlighting.
  866. const p = findPolygon(elem);
  867. if (p != null) {
  868. if (set) {
  869. origFill.set(p, p.style.fill);
  870. p.style.fill = '#ccccff';
  871. } else if (origFill.has(p)) {
  872. p.style.fill = origFill.get(p);
  873. }
  874. }
  875. }
  876. function findPolygon(elem) {
  877. if (elem.localName == 'polygon') return elem;
  878. for (const c of elem.children) {
  879. const p = findPolygon(c);
  880. if (p != null) return p;
  881. }
  882. return null;
  883. }
  884. // convert a string to a regexp that matches that string.
  885. function quotemeta(str) {
  886. return str.replace(/([\\\.?+*\[\](){}|^$])/g, '\\$1');
  887. }
  888. function setSampleIndexLink(id) {
  889. const elem = document.getElementById(id);
  890. if (elem != null) {
  891. setHrefParams(elem, function (params) {
  892. params.set("si", id);
  893. });
  894. }
  895. }
  896. // Update id's href to reflect current selection whenever it is
  897. // liable to be followed.
  898. function makeSearchLinkDynamic(id) {
  899. const elem = document.getElementById(id);
  900. if (elem == null) return;
  901. // Most links copy current selection into the 'f' parameter,
  902. // but Refine menu links are different.
  903. let param = 'f';
  904. if (id == 'ignore') param = 'i';
  905. if (id == 'hide') param = 'h';
  906. if (id == 'show') param = 's';
  907. if (id == 'show-from') param = 'sf';
  908. // We update on mouseenter so middle-click/right-click work properly.
  909. elem.addEventListener('mouseenter', updater);
  910. elem.addEventListener('touchstart', updater);
  911. function updater() {
  912. // The selection can be in one of two modes: regexp-based or
  913. // list-based. Construct regular expression depending on mode.
  914. let re = regexpActive
  915. ? search.value
  916. : Array.from(selected.keys()).map(key => quotemeta(nodes[key])).join('|');
  917. setHrefParams(elem, function (params) {
  918. if (re != '') {
  919. // For focus/show/show-from, forget old parameter. For others, add to re.
  920. if (param != 'f' && param != 's' && param != 'sf' && params.has(param)) {
  921. const old = params.get(param);
  922. if (old != '') {
  923. re += '|' + old;
  924. }
  925. }
  926. params.set(param, re);
  927. } else {
  928. params.delete(param);
  929. }
  930. });
  931. }
  932. }
  933. function setHrefParams(elem, paramSetter) {
  934. let url = new URL(elem.href);
  935. url.hash = '';
  936. // Copy params from this page's URL.
  937. const params = url.searchParams;
  938. for (const p of new URLSearchParams(window.location.search)) {
  939. params.set(p[0], p[1]);
  940. }
  941. // Give the params to the setter to modify.
  942. paramSetter(params);
  943. elem.href = url.toString();
  944. }
  945. function handleTopClick(e) {
  946. // Walk back until we find TR and then get the Name column (index 5)
  947. let elem = e.target;
  948. while (elem != null && elem.nodeName != 'TR') {
  949. elem = elem.parentElement;
  950. }
  951. if (elem == null || elem.children.length < 6) return;
  952. e.preventDefault();
  953. const tr = elem;
  954. const td = elem.children[5];
  955. if (td.nodeName != 'TD') return;
  956. const name = td.innerText;
  957. const index = nodes.indexOf(name);
  958. if (index < 0) return;
  959. // Disable regexp mode.
  960. regexpActive = false;
  961. if (selected.has(index)) {
  962. unselect(index, elem);
  963. } else {
  964. select(index, elem);
  965. }
  966. updateButtons();
  967. }
  968. function updateButtons() {
  969. const enable = (search.value != '' || selected.size != 0);
  970. if (buttonsEnabled == enable) return;
  971. buttonsEnabled = enable;
  972. for (const id of ['focus', 'ignore', 'hide', 'show', 'show-from']) {
  973. const link = document.getElementById(id);
  974. if (link != null) {
  975. link.classList.toggle('disabled', !enable);
  976. }
  977. }
  978. }
  979. // Initialize button states
  980. updateButtons();
  981. // Setup event handlers
  982. initMenus();
  983. if (svg != null) {
  984. initPanAndZoom(svg, toggleSvgSelect);
  985. }
  986. if (toptable != null) {
  987. toptable.addEventListener('mousedown', handleTopClick);
  988. toptable.addEventListener('touchstart', handleTopClick);
  989. }
  990. const ids = ['topbtn', 'graphbtn', 'flamegraph', 'peek', 'list', 'disasm',
  991. 'focus', 'ignore', 'hide', 'show', 'show-from'];
  992. ids.forEach(makeSearchLinkDynamic);
  993. const sampleIDs = [{{range .SampleTypes}}'{{.}}', {{end}}];
  994. sampleIDs.forEach(setSampleIndexLink);
  995. // Bind action to button with specified id.
  996. function addAction(id, action) {
  997. const btn = document.getElementById(id);
  998. if (btn != null) {
  999. btn.addEventListener('click', action);
  1000. btn.addEventListener('touchstart', action);
  1001. }
  1002. }
  1003. addAction('details', handleDetails);
  1004. initConfigManager();
  1005. search.addEventListener('input', handleSearch);
  1006. search.addEventListener('keydown', handleKey);
  1007. // Give initial focus to main container so it can be scrolled using keys.
  1008. const main = document.getElementById('bodycontainer');
  1009. if (main) {
  1010. main.focus();
  1011. }
  1012. }
  1013. </script>
  1014. {{end}}
  1015. {{define "top" -}}
  1016. <!DOCTYPE html>
  1017. <html>
  1018. <head>
  1019. <meta charset="utf-8">
  1020. <title>{{.Title}}</title>
  1021. {{template "css" .}}
  1022. <style type="text/css">
  1023. </style>
  1024. </head>
  1025. <body>
  1026. {{template "header" .}}
  1027. <div id="top">
  1028. <table id="toptable">
  1029. <thead>
  1030. <tr>
  1031. <th id="flathdr1">Flat</th>
  1032. <th id="flathdr2">Flat%</th>
  1033. <th>Sum%</th>
  1034. <th id="cumhdr1">Cum</th>
  1035. <th id="cumhdr2">Cum%</th>
  1036. <th id="namehdr">Name</th>
  1037. <th>Inlined?</th>
  1038. </tr>
  1039. </thead>
  1040. <tbody id="rows"></tbody>
  1041. </table>
  1042. </div>
  1043. {{template "script" .}}
  1044. <script>
  1045. function makeTopTable(total, entries) {
  1046. const rows = document.getElementById('rows');
  1047. if (rows == null) return;
  1048. // Store initial index in each entry so we have stable node ids for selection.
  1049. for (let i = 0; i < entries.length; i++) {
  1050. entries[i].Id = 'node' + i;
  1051. }
  1052. // Which column are we currently sorted by and in what order?
  1053. let currentColumn = '';
  1054. let descending = false;
  1055. sortBy('Flat');
  1056. function sortBy(column) {
  1057. // Update sort criteria
  1058. if (column == currentColumn) {
  1059. descending = !descending; // Reverse order
  1060. } else {
  1061. currentColumn = column;
  1062. descending = (column != 'Name');
  1063. }
  1064. // Sort according to current criteria.
  1065. function cmp(a, b) {
  1066. const av = a[currentColumn];
  1067. const bv = b[currentColumn];
  1068. if (av < bv) return -1;
  1069. if (av > bv) return +1;
  1070. return 0;
  1071. }
  1072. entries.sort(cmp);
  1073. if (descending) entries.reverse();
  1074. function addCell(tr, val) {
  1075. const td = document.createElement('td');
  1076. td.textContent = val;
  1077. tr.appendChild(td);
  1078. }
  1079. function percent(v) {
  1080. return (v * 100.0 / total).toFixed(2) + '%';
  1081. }
  1082. // Generate rows
  1083. const fragment = document.createDocumentFragment();
  1084. let sum = 0;
  1085. for (const row of entries) {
  1086. const tr = document.createElement('tr');
  1087. tr.id = row.Id;
  1088. sum += row.Flat;
  1089. addCell(tr, row.FlatFormat);
  1090. addCell(tr, percent(row.Flat));
  1091. addCell(tr, percent(sum));
  1092. addCell(tr, row.CumFormat);
  1093. addCell(tr, percent(row.Cum));
  1094. addCell(tr, row.Name);
  1095. addCell(tr, row.InlineLabel);
  1096. fragment.appendChild(tr);
  1097. }
  1098. rows.textContent = ''; // Remove old rows
  1099. rows.appendChild(fragment);
  1100. }
  1101. // Make different column headers trigger sorting.
  1102. function bindSort(id, column) {
  1103. const hdr = document.getElementById(id);
  1104. if (hdr == null) return;
  1105. const fn = function() { sortBy(column) };
  1106. hdr.addEventListener('click', fn);
  1107. hdr.addEventListener('touch', fn);
  1108. }
  1109. bindSort('flathdr1', 'Flat');
  1110. bindSort('flathdr2', 'Flat');
  1111. bindSort('cumhdr1', 'Cum');
  1112. bindSort('cumhdr2', 'Cum');
  1113. bindSort('namehdr', 'Name');
  1114. }
  1115. viewer(new URL(window.location.href), {{.Nodes}});
  1116. makeTopTable({{.Total}}, {{.Top}});
  1117. </script>
  1118. </body>
  1119. </html>
  1120. {{end}}
  1121. {{define "sourcelisting" -}}
  1122. <!DOCTYPE html>
  1123. <html>
  1124. <head>
  1125. <meta charset="utf-8">
  1126. <title>{{.Title}}</title>
  1127. {{template "css" .}}
  1128. {{template "weblistcss" .}}
  1129. {{template "weblistjs" .}}
  1130. </head>
  1131. <body>
  1132. {{template "header" .}}
  1133. <div id="content" class="source">
  1134. {{.HTMLBody}}
  1135. </div>
  1136. {{template "script" .}}
  1137. <script>viewer(new URL(window.location.href), null);</script>
  1138. </body>
  1139. </html>
  1140. {{end}}
  1141. {{define "plaintext" -}}
  1142. <!DOCTYPE html>
  1143. <html>
  1144. <head>
  1145. <meta charset="utf-8">
  1146. <title>{{.Title}}</title>
  1147. {{template "css" .}}
  1148. </head>
  1149. <body>
  1150. {{template "header" .}}
  1151. <div id="content">
  1152. <pre>
  1153. {{.TextBody}}
  1154. </pre>
  1155. </div>
  1156. {{template "script" .}}
  1157. <script>viewer(new URL(window.location.href), null);</script>
  1158. </body>
  1159. </html>
  1160. {{end}}
  1161. {{define "flamegraph" -}}
  1162. <!DOCTYPE html>
  1163. <html>
  1164. <head>
  1165. <meta charset="utf-8">
  1166. <title>{{.Title}}</title>
  1167. {{template "css" .}}
  1168. <style type="text/css">{{template "d3flamegraphcss" .}}</style>
  1169. <style type="text/css">
  1170. .flamegraph-content {
  1171. width: 90%;
  1172. min-width: 80%;
  1173. margin-left: 5%;
  1174. }
  1175. .flamegraph-details {
  1176. height: 1.2em;
  1177. width: 90%;
  1178. min-width: 90%;
  1179. margin-left: 5%;
  1180. padding: 15px 0 35px;
  1181. }
  1182. </style>
  1183. </head>
  1184. <body>
  1185. {{template "header" .}}
  1186. <div id="bodycontainer">
  1187. <div id="flamegraphdetails" class="flamegraph-details"></div>
  1188. <div class="flamegraph-content">
  1189. <div id="chart"></div>
  1190. </div>
  1191. </div>
  1192. {{template "script" .}}
  1193. <script>viewer(new URL(window.location.href), {{.Nodes}});</script>
  1194. <script>{{template "d3script" .}}</script>
  1195. <script>{{template "d3flamegraphscript" .}}</script>
  1196. <script>
  1197. var data = {{.FlameGraph}};
  1198. var width = document.getElementById('chart').clientWidth;
  1199. var flameGraph = d3.flamegraph()
  1200. .width(width)
  1201. .cellHeight(18)
  1202. .minFrameSize(1)
  1203. .transitionDuration(750)
  1204. .transitionEase(d3.easeCubic)
  1205. .inverted(true)
  1206. .sort(true)
  1207. .title('')
  1208. .tooltip(false)
  1209. .details(document.getElementById('flamegraphdetails'));
  1210. // <full name> (percentage, value)
  1211. flameGraph.label((d) => d.data.f + ' (' + d.data.p + ', ' + d.data.l + ')');
  1212. (function(flameGraph) {
  1213. var oldColorMapper = flameGraph.color();
  1214. function colorMapper(d) {
  1215. // Hack to force default color mapper to use 'warm' color scheme by not passing libtype
  1216. const { data, highlight } = d;
  1217. return oldColorMapper({ data: { n: data.n }, highlight });
  1218. }
  1219. flameGraph.color(colorMapper);
  1220. }(flameGraph));
  1221. d3.select('#chart')
  1222. .datum(data)
  1223. .call(flameGraph);
  1224. function clear() {
  1225. flameGraph.clear();
  1226. }
  1227. function resetZoom() {
  1228. flameGraph.resetZoom();
  1229. }
  1230. window.addEventListener('resize', function() {
  1231. var width = document.getElementById('chart').clientWidth;
  1232. var graphs = document.getElementsByClassName('d3-flame-graph');
  1233. if (graphs.length > 0) {
  1234. graphs[0].setAttribute('width', width);
  1235. }
  1236. flameGraph.width(width);
  1237. flameGraph.resetZoom();
  1238. }, true);
  1239. var search = document.getElementById('search');
  1240. var searchAlarm = null;
  1241. function selectMatching() {
  1242. searchAlarm = null;
  1243. if (search.value != '') {
  1244. flameGraph.search(search.value);
  1245. } else {
  1246. flameGraph.clear();
  1247. }
  1248. }
  1249. function handleSearch() {
  1250. // Delay expensive processing so a flurry of key strokes is handled once.
  1251. if (searchAlarm != null) {
  1252. clearTimeout(searchAlarm);
  1253. }
  1254. searchAlarm = setTimeout(selectMatching, 300);
  1255. }
  1256. search.addEventListener('input', handleSearch);
  1257. </script>
  1258. </body>
  1259. </html>
  1260. {{end}}
  1261. `))
  1262. }