Debian Codegraph @

src/microprofile.html

raw ◀ ▶
1 Debian patch touch this file
•1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>MicroProfile Capture</title>
5 <style>
6 /* about css: http://bit.ly/1eMQ42U */
7 body {margin: 0px;padding: 0px; font: 12px Courier New;background-color:#343434; color:white;overflow:hidden;}
8 ul {list-style-type: none;margin: 0;padding: 0;}
9 li{display: inline; float:left;border:5px; position:relative;text-align:center;}
10 a {
11 float:left;
12 text-decoration:none;
13 display: inline;
14 text-align: center;
15 padding:5px;
16 padding-bottom:0px;
17 padding-top:0px;
18 color: #FFFFFF;
19 background-color: #343434;
20 }
21 a:hover, a:active{
22 background-color: #000000;
23 }
24
25 ul ul {
26 position:absolute;
27 left:0;
28 top:100%;
29 margin-left:-999em;
30 }
31 li:hover ul {
32 margin-left:0;
33 margin-right:0;
34 }
35 ul li ul{ display:block;float:none;}
36 ul li ul li{ display:block;float:none;}
37 li li a{ display:block;float:none;text-align:left;word-break: keep-all;white-space: nowrap;}
38 #nav li:hover div {margin-left:0;}
39 .dropzone {display:flex;justify-content:center;align-items:center;font-size:50px;position: fixed; top: 0; left: 0; z-index: 9999999999; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5);transition: visibility 175ms, opacity 175ms;}
40 .help {position:absolute;z-index:5;text-align:left;padding:2px;background-color: #313131;width:300px;}
41 .helpstart {position:absolute;z-index:5;text-align:left;padding:2px;background-color: #313131;width:300px;display:none}
42 .root {z-index:1;position:absolute;top:0px;left:0px;}
43 .filterinput0{position:fixed;bottom:10px;left:25px;background-color: #313131}
44 .filterinput1{position:fixed;bottom:10px;left:175px;background-color: #313131}
45 .filterinputsearchdiv{position:fixed; background-color: #313131;display:none;}
46 .filterinputsearchdivmenu{position:absolute; background-color: #313131;display:none;}
47 .filterinputsearch{width:100px;}
48 .filtersearchdiv{position:fixed;top:71px;right:75px; display:block;}
49 .filterinputsearch2{width:100px;}
50 </style>
51 </head>
52 <body style="">
53 <input type="file" id="file-input" style="display:none"/>
54 <div style="visibility:hidden; opacity:0" class="dropzone" ondrop="DropHandler(event);" ondragover="DragOverHandler(event);">drop .html file to compare</div>
55 <div class="filtersearchdiv" id="filtersearchdiv"><input type="text" id="FilterInputSearch2" class="filterinputsearch2"></div>
56 <div id='filterinput'>
57 <div class="filterinput0">Group<br><input type="text" id="filtergroup"></div>
58 <div class="filterinput1">Timer/Thread<br><input type="text" id="filtertimer"></div>
59 </div>
60 <div class="filterinputsearchdiv" id="FilterInputDiv">Filter<br><input type="text" id="FilterInput" class="filterinputsearch"></div>
61 <div class="filterinputsearchdivmenu" id="FilterInputMenuDiv">Filter<br><input type="text" id="FilterInputMenu" class="filterinputsearch"></div>
62 <canvas id="History" height="70" style="background-color:#343434;margin:0px;padding:0px;"></canvas>
63 <canvas id="DetailedView" height="200" style="background-color:#343434;margin:0px;padding:0px;"></canvas>
64 <canvas id="CanvasMenu" style="pointer-events:none;position:absolute;top:0;left:0;margin:0px;padding:0px;zIndex:1" height="500" width="500"></canvas>
65 <div class="help" id="divFrameInfo" style="display:none;left:20px;top:300px;width:auto;"></div>
66 <div class="helpstart" id="helpwindow" style="left:20px;top:20px">
67 History View:<br>
68 Click + Drag: Pan View<br>
69 Right Click + Drag : Zoom on region<br>
70 Click Frame : Center on frame<br>
71 <hr>
72 Main View:<br>
73 Ctrl + Mouse up/down: Zoom<br>
74 Mousewheel : Zoom<br>
75 Right Click + Drag: Select region<br>
76 Ctrl + Shift + Drag: Select region<br>
77 Space: Zoom to Selection<br>
78 Ctrl + Drag: Pan<br>
79 Click + Drag: Pan<br>
80 hold alt: Show tooltip from timer view in detailed, detailed in timer<br>
81 x : Toggle View<br>
82 \ : Switch color mode<br>
83 c : toggle collapse mode<br>
84 tab : go to filter view<br>
85 <hr>
86 Detailed View:<br>
87 Tab: Go To Worst Instance<br>
88 Left/Right Arror: Next/Prev Instance<br>
89 Enter: Search for timer in view<br>
90 <hr>
91 Timer Views:<br>
92 Tab: go to filtering<br>
93 Esc: Exit &amp; Clear filter
94 <hr>
95 <table style="width:100%">
96 <tr>
97 <td width="50%" align="left"><a href='javascript:void(0)' onclick="ShowHelp(0, 0);">Close</a></td>
98 <td width="50%" align="right"><a href='javascript:void(0)' onclick="ShowHelp(0, 1);">Close, Never Show</a></td>
99 </tr>
100 </table>
101 </div>
102 <script>
103 /**
104 * From https://gist.github.com/vahidk/05184faf3d92a0aa1b46aeaa93b07786
105 *
106 * @param {string} hexTripletColor
107 */
108 function ConvertRgbToHsl(hexTripletColor) {
109 const color = parseInt(hexTripletColor.substring(1), 16);
110 const r = ((color >> 16) % 256)/255.0;
111 const g = ((color >> 8) % 256)/255.0;
112 const b = ((color >> 0) % 256)/255.0;
113 const max = Math.max(r, g, b);
114 const min = Math.min(r, g, b);
115 const d = max - min;
116 var h;
117 if (d === 0) h = 0;
118 else if (max === r) h = (g - b) / d % 6;
119 else if (max === g) h = (b - r) / d + 2;
120 else if (max === b) h = (r - g) / d + 4;
121 const l = (min + max) / 2;
122 const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
123 return [h * 60, s, l];
124 }
125
126 /**
127 * From https://gist.github.com/vahidk/05184faf3d92a0aa1b46aeaa93b07786
128 *
129 * @param {number} h
130 * @param {number} s
131 * @param {number} l
132 */
133 function ConvertHslToColor(h, s, l) {
134 const c = (1 - Math.abs(2 * l - 1)) * s;
135 const hp = h / 60.0;
136 const x = c * (1 - Math.abs((hp % 2) - 1));
137 let rgb1;
138 if (isNaN(h)) rgb1 = [0, 0, 0];
139 else if (hp <= 1) rgb1 = [c, x, 0];
140 else if (hp <= 2) rgb1 = [x, c, 0];
141 else if (hp <= 3) rgb1 = [0, c, x];
142 else if (hp <= 4) rgb1 = [0, x, c];
143 else if (hp <= 5) rgb1 = [x, 0, c];
144 else if (hp <= 6) rgb1 = [c, 0, x];
145 const m = l - c * 0.5;
146 const color = (Math.round(255 * (rgb1[0] + m)) << 16)
147 | (Math.round(255 * (rgb1[1] + m)) << 8)
148 | Math.round(255 * (rgb1[2] + m));
149 return '#' + ("000000" + color.toString(16)).slice(-6);
150 }
151
152
153 function ConvertColorDark(hexTripletColor)
154 {
155 var color = hexTripletColor;
156 color = color.substring(1); // remove #
157 color = parseInt(color, 16); // convert to integer
158 // console.log(color.toString(16));
159 color = (color >> 1);
160 // console.log(color.toString(16));
161 color = color & 0x7f7f7f;
162 // console.log(color.toString(16));
163 return '#' + ("000000" + color.toString(16)).slice(-6);
164 }
165 function InvertColor(hexTripletColor)
166 {
167 var color = hexTripletColor;
168 color = color.substring(1); // remove #
169 color = parseInt(color, 16); // convert to integer
170 var R = ((color >> 16) % 256)/255.0;
171 var G = ((color >> 8) % 256)/255.0;
172 var B = ((color >> 0) % 256)/255.0;
173 var lum = (0.2126*R + 0.7152*G + 0.0722*B);
174 if(lum < 0.7)
175 {
176 return '#ffffff';
177 }
178 else
179 {
180 return '#333333';
181 }
182 }
183 function InvertColorIndex(hexTripletColor) {
184 var color = hexTripletColor;
185 color = color.substring(1); // remove #
186 color = parseInt(color, 16); // convert to integer
187 var R = ((color >> 16) % 256)/255.0;
188 var G = ((color >> 8) % 256)/255.0;
189 var B = ((color >> 0) % 256)/255.0;
190 var lum = (0.2126*R + 0.7152*G + 0.0722*B);
191 if(lum < 0.7)
192 {
193 return 0;
194 }
195 else
196 {
197 return 1;
198 }
199 }
200
201 function MakeGroup(id, name, category, numtimers, isgpu, total, average, max, color)
202 {
203 if(color == "")
204 {
205 color = ColorFromString(name, 40, 50);
206 }
207 var cid = GetColorIndex(color);
208 var group = {"id":id, "name":name, "category":category, "numtimers":numtimers, "isgpu":isgpu, "total": total, "average" : average, "max" : max, "cid":cid};
209 return group;
210 }
211
212 function MakeGroupCid(id, name, category, numtimers, isgpu, total, average, max, color, cid)
213 {
214 var group = {"id":id, "name":name, "category":category, "numtimers":numtimers, "isgpu":isgpu, "total": total, "average" : average, "max" : max, "cid":cid};
215 return group;
216 }
217
218 function MakeTimer(id, name, group, color, colordark, average, max, min, exclaverage, exclmax, callaverage, callcount, total, meta, metaavg, metamax, flags)
219 {
220 if(color == "#000000")
221 {
222 color = ColorFromString(name + "x" + group, 40, 50);
223 colordark = ColorFromString(name + "x" + group, 25, 50);
224 }
225 var spike = max <= 0 || average <= 0 ? 0 : (100 * max / average);
226 var cid = GetColorIndex(color);
227 var timer = {"id":id, "name":name, "len":name.length, "cid":cid, "timercid":cid, "group":group, "average":average, "max":max, "min":min, "exclaverage":exclaverage, "exclmax":exclmax, "callaverage":callaverage, "callcount":callcount, "spike":spike,"total":total, "meta":meta, "metaavg":metaavg, "metamax":metamax, "worst":0, "worststart":0, "worstend":0, "search":cid, "flags":flags};
228 return timer;
229 }
230
231 function MakeTimerCid(id, name, group, cid, average, max, min, exclaverage, exclmax, callaverage, callcount, total, meta, metaavg, metamax)
232 {
233 var spike = max <= 0 || average <= 0 ? 0 : (100 * max / average);
234 var timer = {"id":id, "name":name, "len":name.length, "cid":cid, "timercid":cid, "group":group, "average":average, "max":max, "min":min, "exclaverage":exclaverage, "exclmax":exclmax, "callaverage":callaverage, "callcount":callcount, "spike":spike,"total":total, "meta":meta, "metaavg":metaavg, "metamax":metamax, "worst":0, "worststart":0, "worstend":0};
235 return timer;
236 }
237
238 function CloneTimer(T)
239 {
240 return MakeTimerCid(T.id, T.name, T.group, T.cid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
241 }
242 function CloneGroup(G)
243 {
244 return MakeGroupCid(G.id, G.name, G.category, G.numtimers, G.isgpu, G.total, G.average, G.max, G.cid);
245 }
246
247 function MakeFrame(id, framestart, frameend, framestartgpu, frameendgpu, ts, tt, ti)
248 {
249 var frame = {"id":id, "framestart":framestart, "frameend":frameend, "framestartgpu":framestartgpu, "frameendgpu":frameendgpu, "ts":ts, "tt":tt, "ti":ti};
250 return frame;
251 }
252 function MakeCounterHistory(id, history, prc)
253 {
254 var counterhistory = {"id":id, "history":history, "prc":prc};
255 return counterhistory;
256 }
257 function MakeCounter(id, parent, sibling, firstchild, level, name, value, minvalue, maxvalue, formatted, limit, formattedlimit, counterprc, boxprc, format, counterhistory)
258 {
259 var counter = { "id":id, "parent":parent, "sibling":sibling, "firstchild":firstchild, "level": level, "name":name, "value":value, "formatted":formatted, "limit":limit, "formattedlimit":formattedlimit, "counterprc":counterprc, "boxprc":boxprc, "counterhistory":counterhistory, "format":format, "minvalue":minvalue, "maxvalue":maxvalue};
260 return counter;
261 }
262 function Clamp(v, low, high)
263 {
264 return v < low ? low : (v > high ? high : v);
265 }
266 function FormatTime(Time)
267 {
268 return Time.toFixed(2);
269 }
270
271
272
273 var g_ColorMap = {};
274 var g_Colors = new Array();
275 var g_ColorsDark = new Array();
276 var g_ColorsTextIndex = new Array();
277 var g_ColorH = new Array();
278 var g_ColorS = new Array();
279 var g_ColorL = new Array();
280
281 function GetColorIndex(color)
282 {
283 if(g_ColorMap[color])
284 {
285 return g_ColorMap[color];
286 }
287 else
288 {
289 var idx = g_Colors.length;
290 g_ColorMap[color] = idx;
291 g_Colors.push(color);
292 g_ColorsDark.push(ConvertColorDark(color));
293 g_ColorsTextIndex.push(InvertColorIndex(color));
294 var hsl = ConvertRgbToHsl(color);
295 g_ColorH.push(hsl[0]);
296 g_ColorS.push(hsl[1]);
297 g_ColorL.push(hsl[2]);
298 return idx;
299 }
300 }
301 //color index 0 reserved for blinking
302 var cidhovercolor = 0;
303 g_Colors.push('#000000');
304 g_ColorsDark.push('#000000');
305 g_ColorsTextIndex.push(0);
306 g_ColorH.push(0);
307 g_ColorS.push(0);
308 g_ColorL.push(0);
309
310 const CIDMatch = GetColorIndex("#AA3333");
311 const CIDFail = GetColorIndex("#555555");
312
313 var S = {};
314 var S2 = {};
315 var Timeline = {};
316 S.TimelineArray = [];
317 S.TimelineIdArray = [];
318 S.TimelineNames = [];
319 S.TimelineColorArray = [];
320
321
322
323 //EBEGIN
324 ____embed____
325 //EEND
326
327 var G_DEBUG = 0;
328
329
330 const MP_LOG_LEAVE=0x0;
331 const MP_LOG_ENTER=0x1;
332 const MP_LOG_EXTENDED=0x2;
333 const MP_LOG_EXTENDED_NO_DATA=0x3;
334
335 const ETOKEN_GPU_CPU_TIMESTAMP=0x3fff;
336 const ETOKEN_GPU_CPU_SOURCE_THREAD=0x3ffe;
337 const ETOKEN_META_MARKER=0x3ffd;
338 const ETOKEN_CUSTOM_NAME=0x3ffc;
339 const ETOKEN_CUSTOM_COLOR=0x3ffb;
340 const ETOKEN_CUSTOM_ID=0x3ffa;
341
342 const ETOKEN_CSTR_PTR = 0x2000;
343 const ETOKEN_MAX = 0x2000;
344
345
346
347 var CanvasDetailedView = document.getElementById('DetailedView');
348 var CanvasHistory = document.getElementById('History');
349 var CanvasMenu = document.getElementById('CanvasMenu');
350 var CanvasDetailedOffscreen = document.createElement('canvas');
351 var FilterInputGroup = document.getElementById('filtergroup');
352 var FilterInputTimer = document.getElementById('filtertimer');
353
354 var FilterInput = document.getElementById('FilterInput');
355 var FilterInputDiv = document.getElementById('FilterInputDiv');
356 var FilterInputDivPos = {"x":-1,"y":-1,"w":-1,"h":-1};
357 var FilterInputMenu = document.getElementById('FilterInputMenu');
358 var FilterInputMenuDiv = document.getElementById('FilterInputMenuDiv');
359 var FilterInputMenuDivPos = {"x":-1,"y":-1,"w":-1,"h":-1};
360 var FilterInputMenuValueLast = '';
361
362 var FilterInputSearch2 = document.getElementById('FilterInputSearch2');
363 var FilterInputSearchValue = '';
364 let FilterInputSearchActive2 = 0;
365
366 const FLAGS_SECTION = 1;
367
368
369 let LastDropTarget = null;
370
371 var FilterInputGroupString = null;
372 var FilterInputTimerString = null;
373 var FilterInputArray = [FilterInputGroup, FilterInputTimer];
374 var FilterGroup = null;
375 var FilterTimer = null;
376 var g_Msg = '0';
377
378 var RedrawRequested = 0;
379 var InsideDraw = 0;
380
381
382
383 var Initialized = 0;
384 var fDetailedOffset = S.Frames[0].framestart;
385 var fDetailedOffsetSecond = 0;
386 var fDetailedRange = S.Frames[S.Frames.length-1].frameend - fDetailedOffset;
387 var nWidth = CanvasDetailedView.width;
388 var nHeight = CanvasDetailedView.height;
389 var ReferenceTimeString = 'auto';
390 var ReferenceTimeAutoString = 'auto';
391 var ReferenceTime = 33;
392 var TargetTime = 16;
393 var TargetTimeString = '16ms';
394 var nHistoryHeight = 70;
395 var nOffsetY = 0;
396 var nOffsetBarsX = 0;
397 var nOffsetBarsY = 0;
398 var nOffsetCountersY = 0;
399 var nOffsetFilterSearch = 0;
400 var nOffsetMenuThreads = 0;
401 var nOffsetMenuGroups = 0;
402 var FilterInputSearchLast = '';
403 var nBarsWidth = 80;
404 var MouseButtonState = [0,0,0,0,0,0,0,0];
405 var KeyShiftDown = 0;
406 var KeyAltDown = 0;
407 var KeyCtrlDown = 0;
408 var MouseDragButton = 0;
409 var ToolTipFlip = 0;
410 var ToolTipCorner = 1;
411 let ToolTipImmediate = null;
412 var DetailedViewMouseX = 0;
413 var DetailedViewMouseY = 0;
414 var DetailedMouseOverButton = 0;
415 var DetailedMouseEvent = null;
416 var HistoryViewMouseX = -1;
417 var HistoryViewMouseY = -1;
418 var GlobalMouseX = -1;
419 var GlobalMouseY = -1;
420 var MouseReleased = false;
421 var MouseHistory = 0;
422 var MouseDetailed = 0;
423 const FontName = 'Courier New';
424 const FontHeight = 10;
425 const FontHeightLarge = 22;
426 const FontHeightFlash = 35;
427 let FontWidth = 1;
428 const FontAscent = 3; //Set manually
429 const Font = 'Bold ' + FontHeight + 'px ' + FontName;
430 const FontLarge = 'Bold ' + FontHeightLarge + 'px ' + FontName;
431 const FontFlash = 'Bold ' + FontHeightFlash + 'px ' + FontName;
432 const BoxHeight = FontHeight + 2;
433 let ThreadsHidden = {};
434 var GroupsDisabled = new Object();
435 var nMinWidth = 0.01;//subpixel width
436 var nMinWidthPan = 1.0;//subpixel width when panning
437 var nContextSwitchEnabled = 1;
438 var DisableLod = 0;
439 var DisableMerge = 0;
440 var GroupColors = 0;
441 var DrawDetailedFlameMode = 0;
442 var DrawDetailedNewDraw = 0;
443 var DrawDetailedCompareReverse = 1;
444 var nModDown = 0;
445 var g_MSG = 'no';
446 var nDrawCount = 0;
447 var nBackColors = ['#292929', '#343434' ];
448 var nBackColorsDark = ['#292929', '#272727' ];
449 var nBackColorOffset = '#404040';
450 var CSwitchColors =["#9DD8AF","#D7B6DA","#EAAC76","#DBDA61","#8AD5E1","#8CE48B","#C4D688","#57E5C4"];//generated by http://tools.medialab.sciences-po.fr/iwanthue/index.php
451 var CSwitchHeight = 5;
452 var FRAME_HISTORY_COLOR_CPU = '#ff7f27';
453 var FRAME_HISTORY_COLOR_GPU = '#ffffff';
454 var ZOOM_TIME = 0.5;
455 var AnimationActive = false;
456 var nHoverCSCpu = -1;
457 var nHoverCSCpuNext = -1;
458 var nHoverCSToolTip = null;
459 var nHoverToken = -1;
460 var HoverTokenOwner = null;
461 //var nHoverFrame = -1;
462 var nHoverTokenIndex = -1;
463 var nHoverTokenLogIndex = -1;
464 var nHoverCounter = 0;
465 var nHoverCounterDelta = 8;
466 var nHoverTokenNext = -1;
467 var nHoverTokenLogIndexNext = -1;
468 var nHoverTokenIndexNext = -1;
469 var HoverTokenNextOwner = null;
470 var nHoverCounter = -1;
471 var nHoverTokenDrawn = -1;
472 var nHideHelp = 0;
473 var fFrameScale = 33.33;
474 var SortColumn = 0;
475 var SortColumnOrderFlip = 0;
476 var SortColumnMouseOver = null;
477 var SortColumnMouseOverNext = null;
478 var ColumnsWidth = [];
479 var ColumnsEnabled = [];
480 let ColumnNames =["Average", "Max", "Total", "Min", "Spike", "Call Average", "Call Count", "Excl Average", "Excl Max"];
481 let NumColumns = ColumnNames.length;
482 while(ColumnsEnabled.length < NumColumns)
483 {
484 ColumnsEnabled.push(1);
485 ColumnsWidth.push(20);
486 }
487 var FilterSearchActive = 0;
488 var FilterSearchSelection = -1;
489 var FilterSearchSelectionMax = 0;
490 var FilterSearchPassIndex = -1;
491 FilterSearchReset();
492 var FilterSearchStartTime = new Date();
493 var IgnoreInput = 0;
494 function RangeInit()
495 {
496 return {"Begin":-1, "End":-1, "YBegin":-1, "YEnd":-1, "Thread": -1 , "Index": -1, "Off": 0, "Second":0};
497 }
498 function RangeValid(Range)
499 {
500 return Range.Begin < Range.End;
501 }
502 function RangeCopy(Dst, Src)
503 {
504 Dst.Begin = Src.Begin;
505 Dst.End = Src.End;
506 Dst.YBegin = Src.YBegin;
507 Dst.YEnd = Src.YEnd;
508 Dst.Thread = Src.Thread;
509 Dst.Off = Src.Off;
510 Dst.Second = Src.Second;
511 }
512 var RangeCpu = RangeInit();
513 var RangeGpu = RangeInit();
514 var RangeSelect = RangeInit();
515
516 var RangeCpuNext = RangeInit();
517 var RangeGpuNext = RangeInit();
518
519 var RangeCpuHistory = RangeInit();
520 var RangeGpuHistory = RangeInit();
521
522 var fRangeBegin = 0;
523 var fRangeEnd = -1;
524 var fRangeThreadId = -1;
525 var fRangeThreadIdNext = -1;
526 var fRangeBeginNext = 0;
527 var fRangeEndNext = 0;
528 var fRangeBeginGpuNext = 0;
529 var fRangeEndGpuNext = 0;
530 var fRangeBeginHistory = -1;
531 var fRangeEndHistory = -1;
532 var fRangeBeginHistoryGpu = -1;
533 var fRangeEndHistoryGpu = -1;
534 var fRangeBeginSelect = 0;
535 var fRangeEndSelect = -1;
536 var ThreadYBegin;
537 var ThreadYEnd;
538
539 var ModeDetailed = 0;
540 var ModeTimers = 1;
541 var ModeTimers_Threads = 2;
542 var ModeTimers_Groups = 3;
543 var ModeCounters = 4;
544 var ModeCount = 5;
545 var Mode = ModeDetailed;
546
547 var DebugDrawQuadCount = 0;
548 var DebugDrawTextCount = 0;
549 var ProfileMode = 0;
550 var ProfileRedraw0 = 0;
551 var ProfileRedraw1 = 0;
552 var ProfileRedraw2 = 0;
553 var ProfileFps = 0;
554 var ProfileFpsAggr = 0;
555 var ProfileFpsCount = 0;
556 var ProfileLastTimeStamp = new Date();
557
558 var ProfileData = {};
559 var ProfileStackTime = {};
560 var ProfileStackName = {};
561 let ProfileDrawStartLast = new Date();
562 let ProfileDrawEndLast = new Date();
563 function CreateEmptyFloatArray(Size)
564 {
565 let a = Array(Size);
566 for(let i = 0; i < Size; ++i)
567 a[i] = 0.0;
568 return a;
569 }
570 let ProfileDrawTime = CreateEmptyFloatArray(120);
571 let ProfileDeltaTime = CreateEmptyFloatArray(120);
572 let ProfileDraw2Draw = CreateEmptyFloatArray(120);
573
574 var Debug = 1;
575
576 var ThreadLogAutoHide = 0;
577 var NumLodSplits = 10;
578 var SplitMin = 100;
579 var SPLIT_LIMIT = 1e20;
580 var DPR = 1;
581 var DetailedRedrawState = {};
582 var OffscreenData;
583 var DetailedFrameCounter = 0;
584 var Invalidate = 0;
585 var GroupOrder = Array();
586 var ThreadOrder = Array();
587 var ThreadOrderNames = Array();
588 var ThreadOrderT = Array();
589 var MetaLengths = Array();
590 var MetaLengthsAvg = Array();
591 var MetaLengthsMax = Array();
592
593 var ZoomActive = 0;
594
595 var StrGroup = "Group";
596 var StrThread = "Thread";
597 var StrTimer = "Timer";
598 var StrAverage = "Average";
599 var StrMax = "Max";
600 var StrTotal = "Total";
601 var StrMin = "Min";
602 var StrSpike = "Spike%";
603 var StrCallAverage = "Call Average";
604 var StrCount = "Count";
605 var StrExclAverage = "Excl Average";
606 var StrExclMax = "Excl Max";
607
608 var GroupRemapReverse = [];
609 var TimerRemapReverse = [];
610 var ThreadRemapReverse = [];
611
612 let SubMenuHelp = 0;
613 let SubMenuMode = 1;
614 let SubMenuReference = 2;
615 let SubMenuTarget = 3;
616 let SubMenuThreads = 4;
617 let SubMenuGroups = 5;
618 let SubMenuColumns = 6;
619 let SubMenuOptions = 7;
620 let SubMenuCompare = 8;
621
622 let MenuRedraw = 0;
623 let SubMenuActive = -1;
624 let SubMenuTimeoutBase = 0.7;
625 let SubMenuMouseX = 0;
626 let SubMenuMouseY = 0;
627 let SubMenuTimeout = new Date();
628 let MenuItems = [];
629 let FilterInputMenuThreadsValue = '';
630 let FilterInputMenuGroupsValue = '';
631 let MouseMoveTime = new Date();
632 let ReferenceTimes = [-1, 5, 10, 15, 16, 20, 30, 33, 50, 100, 250, 500, 1000];
633 let TargetTimes = [5, 10, 15, 16, 20, 30, 33, 50, 100, 250, 500, 1000];
634 let ModeItems = ["Detailed", "Timers", "Threads", "Groups", "Counters"];
635 let HideModeFullyHidden = 0;
636 let HideModeCollapsed = 1;
637 let HideMode = HideModeCollapsed;
638
639
640 function ProfileModeClear()
641 {
642 if(ProfileMode)
643 {
644 ProfileData = new Object();
645 ProfileStackTime = new Array();
646 ProfileStackName = new Array();
647 }
648 }
649 function ProfileEnter(Name)
650 {
651 if(ProfileMode)
652 {
653 ProfileStackTime.push(new Date());
654 ProfileStackName.push(Name);
655 }
656 }
657 function ProfileLeave()
658 {
659 if(ProfileMode)
660 {
661 var Time = new Date();
662 var Delta = Time - ProfileStackTime.pop();
663 var Name = ProfileStackName.pop();
664 var Obj = ProfileData[Name];
665 if(!Obj)
666 {
667 Obj = new Object();
668 Obj.Count = 0;
669 Obj.Name = Name;
670 Obj.Time = 0;
671 ProfileData[Name] = Obj;
672 }
673 Obj.Time += Delta;
674 Obj.Count += 1;
675 }
676 }
677
678 function ProfilePlot(s)
679 {
680 if(ProfileMode)
681 {
682 var A = ProfileData.Plot;
683 if(!A)
684 {
685 ProfileData.Plot = Array();
686 A = ProfileData.Plot;
687 }
688 if(A.length<10)
689 {
690 A.push(s);
691 }
692 }
693 }
694 function ProfileModeDump()
695 {
696 for(var idx in ProfileData)
697 {
698 var Timer = ProfileData[idx];
699 console.log(Timer.Name + " " + Timer.Time + "ms " + Timer.Count);
700 }
701 }
702
703 function ProfileDrawFrameTimeGraph(context)
704 {
705 if(ProfileMode)
706 {
707 let Params = CreateDrawGraphParameters();
708 let Mouse = {};
709 Mouse.X = DetailedViewMouseX;
710 Mouse.Y = DetailedViewMouseY;
711 Params.RangeMin = 0;
712 Params.RangeMax = 50;
713
714 let DrawTimeData = CreateGraphData(ProfileDrawTime, "DrawTime", "#ff2288");
715 let DeltaTimeData = CreateGraphData(ProfileDeltaTime, "DeltaTime", "#2288ee");
716 let Draw2DrawData = CreateGraphData(ProfileDraw2Draw, "Draw2Draw", "#11aa33");
717
718 {
719 Params.Rect = WindowRect(0, nHeight-200, 200, 200);
720
721 DrawGraph(context, Params, [DrawTimeData], Mouse);
722 }
723 {
724 Params.Rect = WindowRect(200, nHeight-200, 200, 200);
725
726 DrawGraph(context, Params, [DeltaTimeData], Mouse);
727 }
728 {
729 Params.Rect = WindowRect(400, nHeight-200, 200, 200);
730 DrawGraph(context, Params, [Draw2DrawData], Mouse);
731 }
732 {
733 Params.Rect = WindowRect(610, nHeight-200, 200, 200);
734 DrawGraph(context, Params, [DrawTimeData, DeltaTimeData,Draw2DrawData], Mouse);
735 }
736 }
737 }
738
739 function ProfileModeDraw(Canvas)
740 {
741 if(ProfileMode)
742 {
743 var StringArray = [];
744 for(var idx in ProfileData)
745 {
746 if(idx == "Plot")
747 continue;
748 var Timer = ProfileData[idx];
749 StringArray.push(Timer.Name);
750 StringArray.push(Timer.Time + "ms");
751 StringArray.push("#");
752 StringArray.push("" + Timer.Count);
753 }
754 StringArray.push("debug");
755 StringArray.push(Debug);
756 var Time = new Date();
757 var Delta = Time - ProfileLastTimeStamp;
758 ProfileLastTimeStamp = Time;
759 StringArray.push("Frame Delta");
760 StringArray.push(Delta + "ms");
761 if(ProfileMode == 2)
762 {
763 ProfileFpsAggr += Delta;
764 ProfileFpsCount ++ ;
765 var AggrFrames = 10;
766 if(ProfileFpsCount == AggrFrames)
767 {
768 ProfileFps = 1000 / (ProfileFpsAggr / AggrFrames);
769 ProfileFpsAggr = 0;
770 ProfileFpsCount = 0;
771 }
772 StringArray.push("FPS");
773 StringArray.push("" + ProfileFps.toFixed(2));
774 }
775 StringArray.push("ProfileRedraw0");
776 StringArray.push("" + ProfileRedraw0);
777 StringArray.push("ProfileRedraw1");
778 StringArray.push("" + ProfileRedraw1);
779 StringArray.push("ProfileRedraw2");
780 StringArray.push("" + ProfileRedraw2);
781 ProfileRedraw0 = 0;
782 ProfileRedraw1 = 0;
783 ProfileRedraw2 = 0;
784
785
786 for(var i = 0; i < ProfileData.Plot; ++i)
787 {
788 StringArray.push("");
789 StringArray.push(ProfileData.Plot[i]);
790 }
791 ProfileData.Plot = Array();
792 DrawToolTip(StringArray, Canvas, 0, 200);
793 }
794 }
795
796 function ToggleDebugMode()
797 {
798 ProfileMode = (ProfileMode+1)%4;
799 console.log('Toggle Debug Mode ' + ProfileMode);
800 }
801
802 function DetailedTotal(S)
803 {
804 var Total = 0;
805 for(var i = 0; i < S.Frames.length; i++)
806 {
807 var frfr = S.Frames[i];
808 Total += frfr.frameend - frfr.framestart;
809 }
810 return Total;
811 }
812
813
814 function InitFrameInfo()
815 {
816
817 var div = document.getElementById('divFrameInfo');
818 var txt = '';
819 txt = txt + 'Timers View' + '<br>';
820 txt = txt + 'Frames:' + S.AggregateInfo.Frames +'<br>';
821 txt = txt + 'Time:' + S.AggregateInfo.Time.toFixed(2) +'ms<br>';
822 txt = txt + '<hr>';
823 txt = txt + 'Detailed View' + '<br>';
824 txt = txt + 'Frames:' + S.Frames.length +'<br>';
825 txt = txt + 'Time:' + DetailedTotal(S).toFixed(2) +'ms<br>';
826 div.innerHTML = txt;
827 }
828 function InitGroups()
829 {
830 for(groupid in S.GroupInfo)
831 {
832 var TimerArray = Array();
833 for(timerid in S.TimerInfo)
834 {
835 if(S.TimerInfo[timerid].group == groupid)
836 {
837 TimerArray.push(timerid);
838 }
839 }
840 S.GroupInfo[groupid].TimerArray = TimerArray;
841 }
842 }
843
844
845 function ThreadOrderMove(Name, Dir, Top)
846 {
847 let idx = ThreadOrderNames.indexOf(Name);
848 let base = idx;
849 idx += Dir;
850 let found = -1;
851 while(idx >= 0 && idx <= ThreadOrderNames.length)
852 {
853 let n = S.ThreadNames.indexOf(ThreadOrderNames[idx]);
854 if(n != -1)
855 {
856 found = idx;
857 if(!Top)
858 break;
859 }
860 idx += Dir;
861 }
862 Dir = -Dir;
863 while(found >= 0 && found <= ThreadOrderNames.length && (Dir > 0 ? (found <= base) : (found >= base)))
864 {
865 let Tmp = ThreadOrderNames[found];
866 ThreadOrderNames[found] = Name;
867 Name = Tmp;
868 found += Dir;
869 }
870 ThreadOrderSort();
871 }
872 function ThreadOrderMoveUp(Name, Top)
873 {
874 ThreadOrderMove(Name, -1, Top);
875 WriteCookie();
876 }
877 function ThreadOrderMoveDown(Name, Top)
878 {
879 ThreadOrderMove(Name, 1, Top);
880 WriteCookie();
881 }
882 function ThreadOrderSort()
883 {
884 for(let i = 0; i < S.ThreadNames.length; ++i)
885 {
886 var name = S.ThreadNames[i];
887 var idx = ThreadOrderNames.indexOf(name);
888 if(idx == -1)
889 {
890 ThreadOrderNames.push(name);
891 }
892 }
893
894 //clear all that are not present??
895 let ThreadOrderX = Array(S.ThreadNames.length);
896 for(let i = 0; i < S.ThreadNames.length; ++i)
897 {
898 let isgpu = S.ISGPU[i]?1:0;
899 var n = ThreadOrderNames.indexOf(S.ThreadNames[i]);
900 if(n == -1)
901 {
902 debugger;
903 }
904 ThreadOrderX[i] = {"i":i, "n": n, "g":isgpu};
905 }
906 ThreadOrderX.sort(function(l,r){if(l.g!=r.g)return r.g-l.g;return l.n-r.n;}); //sort gpu first
907 ThreadOrderT = Array(S.ThreadNames.length);
908 for(let i = 0; i < S.ThreadNames.length; ++i)
909 {
910 ThreadOrderT[i] = ThreadOrderX[i].i;
911 }
912 }
913 function IsThreadActive(ThreadName)
914 {
915 return !ThreadsHidden[ThreadName];
916 }
917
918 function ToggleThread(ThreadName, All, FilterArray, State)
919 {
920 if(ThreadName)
921 {
922 if(ThreadsHidden[ThreadName])
923 {
924 delete ThreadsHidden[ThreadName];
925 }
926 else
927 {
928 ThreadsHidden[ThreadName] = 1;
929 }
930 }
931 else
932 {
933 let Names = All ? S.ThreadNames : FilterArray;
934
935 for(let i in Names)
936 {
937 switch(State)
938 {
939 case 0: if(!ThreadsHidden[Names[i]]){ ThreadsHidden[Names[i]] = 1;} break;
940 case 1: ThreadsHidden[Names[i]] = ThreadsHidden[Names[i]] ? 0 : 1; break;
941 case 2: if(ThreadsHidden[Names[i]]){ delete ThreadsHidden[Names[i]];} break;
942 }
943 }
944 }
945 RequestRedraw();
946 Invalidate = 0;
947 FilterSearchReset();
948 WriteCookie();
949 }
950
951
952 function CreateOrderArray(Source, NameFunc)
953 {
954 var Temp = Array(Source.length);
955 for(var i = 0; i < Source.length; ++i)
956 {
957 Temp[i] = {};
958 Temp[i].index = i;
959 Temp[i].namezz = NameFunc(Source[i]).toLowerCase();
960 }
961 Temp.sort(function(l, r)
962 {
963 if(r.namezz<l.namezz)
964 {return 1;}
965 if(l.namezz<r.namezz)
966 {return -1;}
967 return 0;
968 } );
969 var OrderArray = Array(Source.length);
970 for(var i = 0; i < Source.length; ++i)
971 {
972 OrderArray[i] = Temp[i].index;
973 }
974 return OrderArray;
975 }
976
977 function InitOrderArrays()
978 {
979 ThreadOrder = [];
980 ThreadOrder = CreateOrderArray(S.ThreadNames, function(a){return a;});
981
982
983 let MaxLen = 7;
984 let MenuArray = Array();
985 for(let i = 0; i < S.GroupInfo.length; ++i)
986 {
987 let x = {};
988 x.IsCategory = 0;
989 x.category = S.GroupInfo[i].category;
990 x.name = S.GroupInfo[i].name;
991 x.index = i;
992 MenuArray.push(x);
993 }
994 for(let i = 0; i < S.CategoryInfo.length; ++i)
995 {
996 let x = {};
997 x.IsCategory = 1;
998 x.category = i;
999 x.name = S.CategoryInfo[i];
1000 x.index = i;
1001 MenuArray.push(x);
1002 }
1003 let OrderFunction = function(a){ return a.category + "__" + a.name; };
1004 let OrderFunctionMenu = function(a){ return a.IsCategory ? (a.category + '') : (a.category + "__" + a.name); };
1005 GroupOrder = CreateOrderArray(S.GroupInfo, OrderFunction);
1006 }
1007
1008 function CategoryIndex(CategoryName)
1009 {
1010 for(var i = 0; i < S.CategoryInfo.length; ++i)
1011 {
1012 if(S.CategoryInfo[i] == CategoryName)
1013 {
1014 return i;
1015 }
1016 }
1017 return -1;
1018 }
1019 function IsCategoryActive(CategoryIdx)
1020 {
1021 for(var i = 0; i < S.GroupInfo.length; ++i)
1022 {
1023 if(S.GroupInfo[i].category == CategoryIdx)
1024 {
1025 var Name = S.GroupInfo[i].name;
1026 if(!GroupsActive[Name])
1027 {
1028 return false;
1029 }
1030 }
1031 }
1032 return true;
1033
1034 }
1035 function ToggleCategory(CategoryName, WantRedraw)
1036 {
1037 var CategoryIdx = CategoryIndex(CategoryName);
1038 if(CategoryIdx < 0)
1039 return;
1040 var CategoryActive = IsCategoryActive(CategoryIdx);
1041 for(var i = 0; i < S.GroupInfo.length; ++i)
1042 {
1043 if(S.GroupInfo[i].category == CategoryIdx)
1044 {
1045 var Name = S.GroupInfo[i].name;
1046 if(CategoryActive)
1047 {
1048 delete GroupsDisabled[Name];
1049 }
1050 else
1051 {
1052 GroupsDisabled[Name] = 1;
1053 }
1054 }
1055 }
1056 WriteCookie();
1057 if(WantRedraw)
1058 {
1059 RequestRedraw();
1060 }
1061 }
1062
1063 function ToggleGroup(GroupName, All, FilterArray, State)
1064 {
1065 if(GroupName)
1066 {
1067 if(GroupsDisabled[GroupName])
1068 {
1069 delete GroupsDisabled[GroupName];
1070 }
1071 else
1072 {
1073 GroupsDisabled[GroupName] = 1;
1074 }
1075 }
1076 else
1077 {
1078 let Names = FilterArray;
1079 if(All)
1080 {
1081 Names = [];
1082 for(let i in S.GroupInfo)
1083 {
1084 Names.push(S.GroupInfo[i].name);
1085 }
1086 }
1087
1088 for(let i in Names)
1089 {
1090 let N = Names[i];
1091 switch(State)
1092 {
1093 case 2: if(GroupsDisabled[N]){ delete GroupsDisabled[N];} break;
1094 case 1:
1095 if(GroupsDisabled[N])
1096 {
1097 delete GroupsDisabled[N];
1098 }
1099 else
1100 {
1101 GroupsDisabled[N] = 1;
1102 }
1103
1104 break;
1105 case 0: if(!GroupsDisabled[N]){ GroupsDisabled[N] = 1;} break;
1106 }
1107 }
1108 }
1109 WriteCookie();
1110 }
1111
1112 function UpdateGroupColors()
1113 {
1114 for(var i = 0; i < S.TimerInfo.length; ++i)
1115 {
1116 if(GroupColors == 1)
1117 {
1118 S.TimerInfo[i].cid = S.GroupInfo[S.TimerInfo[i].group].cid;
1119 }
1120 else
1121 {
1122 S.TimerInfo[i].cid = S.TimerInfo[i].timercid;
1123 }
1124 }
1125 }
1126 function ToggleDetailedFlameMode(WantRedraw)
1127 {
1128 DrawDetailedFlameMode = (DrawDetailedFlameMode+1)%3;
1129 WriteCookie();
1130 if(WantRedraw)
1131 {
1132 RequestRedraw();
1133 }
1134 }
1135
1136 function ToggleDetailedNewDraw()
1137 {
1138 DrawDetailedNewDraw = DrawDetailedNewDraw ? 0 : 1;
1139 WriteCookie();
1140 RequestRedraw();
1141 }
1142
1143
1144
1145 function ToggleDetailedSecondReverse(WantRedraw)
1146 {
1147 DrawDetailedCompareReverse = 1-DrawDetailedCompareReverse;
1148 WriteCookie();
1149 if(WantRedraw)
1150 {
1151 RequestRedraw();
1152 }
1153 }
1154
1155 function ToggleGroupColors(WantRedraw)
1156 {
1157 GroupColors = (GroupColors+1)%4;
1158 UpdateGroupColors();
1159 WriteCookie();
1160 if(WantRedraw)
1161 {
1162 RequestRedraw();
1163 }
1164 }
1165
1166 function ShowHelp(Show, Forever)
1167 {
1168 var HelpWindow = document.getElementById('helpwindow');
1169 if(Show)
1170 {
1171 HelpWindow.style['display'] = 'block';
1172 }
1173 else
1174 {
1175 HelpWindow.style['display'] = 'none';
1176 }
1177 if(Forever)
1178 {
1179 nHideHelp = Show ? 0 : 1;
1180 WriteCookie();
1181 }
1182 }
1183 function ToggleMode()
1184 {
1185 Mode = (Mode + 1) % ModeCount;
1186 SetMode(Mode);
1187 }
1188
1189 function SetMode(NewMode, WantRedraw)
1190 {
1191 ResetColumnWidth();
1192 Mode = NewMode;
1193 if(Mode == ModeTimers || Mode == ModeTimers_Groups || Mode == ModeTimers_Threads)
1194 {
1195 SetFilterInput(FilterInputGroupString, FilterInputTimerString);
1196 }
1197 else
1198 {
1199 ShowFilterInput(0);
1200 }
1201 ShowDetailedSearch(Mode == ModeDetailed);
1202
1203 WriteCookie();
1204 if(WantRedraw)
1205 {
1206 RequestRedraw();
1207 }
1208 }
1209
1210
1211 function UpdateReferenceTime()
1212 {
1213 S.CaptureStartTime = S.Frames[0].framestart;
1214 S.CaptureEndTime = S.Frames[S.Frames.length-1].frameend;
1215
1216 if('auto' == ReferenceTimeString.substring(0,4))
1217 {
1218 let Max = 0.1;
1219 for(var i = 0; i < S.Frames.length; ++i)
1220 {
1221 let T = S.Frames[i].frameend - S.Frames[i].framestart;
1222 Max = Math.max(T, Max);
1223 }
1224 ReferenceTime = Max*1.20;
1225 if(TargetTime>0)
1226 {
1227 ReferenceTime = Math.max(ReferenceTime, TargetTime * 1.33);
1228 }
1229 ReferenceTimeAutoString = 'auto [' + Max.toFixed(2) + 'ms]';
1230 }
1231 else
1232 {
1233 ReferenceTime = parseInt(ReferenceTimeString);
1234 }
1235 }
1236
1237 function SetReferenceTime(TimeString, WantRedraw)
1238 {
1239 ReferenceTimeString = TimeString;
1240 UpdateReferenceTime();
1241 WriteCookie();
1242 if(WantRedraw)
1243 {
1244 RequestRedraw();
1245 }
1246 }
1247
1248 function SetTargetTime(TimeString, WantRedraw)
1249 {
1250 TargetTimeString = TimeString;
1251 TargetTime = parseInt(TargetTimeString);
1252 WriteCookie();
1253 if(WantRedraw)
1254 {
1255 RequestRedraw();
1256 }
1257 }
1258
1259 function ToggleContextSwitch()
1260 {
1261 SetContextSwitch(nContextSwitchEnabled ? 0 : 1);
1262 }
1263
1264 function SetContextSwitch(Enabled, WantRedraw)
1265 {
1266 nContextSwitchEnabled = Enabled ? 1 : 0;
1267 WriteCookie();
1268 if(WantRedraw)
1269 {
1270 RequestRedraw();
1271 }
1272 }
1273 function PushIntoArray(A, v)
1274 {
1275 A.shift();
1276 A.push(v);
1277 }
1278 function ToggleDebug()
1279 {
1280 Debug = (Debug + 1) % 2;
1281 }
1282
1283 function ToggleDisableMerge()
1284 {
1285 DisableMerge = DisableMerge ? 0 : 1;
1286 }
1287 function ToggleDisableLod()
1288 {
1289 DisableLod = DisableLod ? 0 : 1;
1290 }
1291
1292 function GatherHoverMetaCounters(TimerIndex, StartIndex, nLog, nFrameLast)
1293 {
1294 var HoverInfo = new Object();
1295 return HoverInfo;
1296 var StackPos = 1;
1297 //search backwards, count meta counters
1298 for(var i = nFrameLast; i >= 0; i--)
1299 {
1300 var fr = S.Frames[i];
1301 var ts = fr.ts[nLog];
1302 var ti = fr.ti[nLog];
1303 var tt = fr.tt[nLog];
1304 var start = i == nFrameLast ? StartIndex-1-fr.LogStart[nLog] : ts.length-1;
1305
1306 for(var j = start; j >= 0; j--)
1307 {
1308 var type = tt[j];
1309 var index = ti[j];
1310 var time = ts[j];
1311 if(type == 1)
1312 {
1313 StackPos--;
1314 if(StackPos == 0 && index == TimerIndex)
1315 {
1316 return HoverInfo;
1317 }
1318 }
1319 else if(type == 0)
1320 {
1321 StackPos++;
1322 }
1323 else if(type > 1)
1324 {
1325 // var nMetaCount = type - 3;
1326 // var nMetaIndex = MetaNames[index];
1327 // if(nMetaIndex in HoverInfo)
1328 // {
1329 // HoverInfo[nMetaIndex] += nMetaCount;
1330 // }
1331 // else
1332 // {
1333 // HoverInfo[nMetaIndex] = nMetaCount;
1334 // }
1335 }
1336 }
1337 }
1338 }
1339 function CalculateAllTimers(fBegin, fEnd)
1340 {
1341 var Sum = [];
1342 var Count = [];
1343 var Sorted = [];
1344 for(var i = 0; i < S.TimerInfo.length; ++i)
1345 {
1346 Sum.push(0.0);
1347 Count.push(0);
1348 Sorted.push(i);
1349 }
1350 var nFrameFirst = 0;
1351 var nFrameLast = S.Frames.length;
1352
1353 var nNumLogs = S.Frames[0].ts.length;
1354 var StackPosArray = Array(nNumLogs);
1355 var StackArray = Array(nNumLogs);
1356 for(var i = 0; i < nNumLogs; ++i)
1357 {
1358 StackPosArray[i] = 0;
1359 StackArray[i] = Array(20);
1360 }
1361
1362 for(var i = nFrameFirst; i < nFrameLast; i++)
1363 {
1364 var fr = S.Frames[i];
1365 for(nLog = 0; nLog < nNumLogs; nLog++)
1366 {
1367 var StackPos = StackPosArray[nLog];
1368 var Stack = StackArray[nLog];
1369 var ts = fr.ts[nLog];
1370 var ti = fr.ti[nLog];
1371 var tt = fr.tt[nLog];
1372 var count = ts.length;
1373 for(j = 0; j < count; j++)
1374 {
1375 var type = tt[j];
1376 var index = ti[j];
1377 var time = ts[j];
1378 if(type == 1 && time < fEnd) //enter
1379 {
1380 Stack[StackPos] = time < fBegin ? fBegin : time;
1381 if(StackArray[nLog][StackPos] != time)
1382 {
1383 console.log('fail fail fail');
1384 }
1385 StackPos++;
1386 }
1387 else if(type == 0) // leave
1388 {
1389 if(StackPos>0)
1390 {
1391 var timeend = time;
1392 StackPos--;
1393 timestart = Stack[StackPos];
1394 var TimeDelta = timeend - timestart;
1395 Sum[index] += TimeDelta;
1396 Count[index]++;
1397 }
1398 }
1399 }
1400 StackPosArray[nLog] = StackPos;
1401 }
1402 }
1403 Sorted.sort(function(a,b){ return Sum[b] - Sum[a]; } );
1404 var Result = {"Sorted" : Sorted, "Sum" : Sum, "Count" : Count};
1405 return Result;
1406 }
1407
1408 function CalculateTimers2(Result, TimerIndex, Time, SContext)
1409 {
1410 let nFrame = -1;
1411 for(var i = 0; i < SContext.Frames.length; ++i)
1412 {
1413 let F = SContext.Frames[i];
1414 if(Time > F.framestart && Time <= F.frameend)
1415 {
1416 nFrame = i;
1417 break;
1418 }
1419 }
1420 CalculateTimers(Result, TimerIndex, nFrame, nFrame+1, SContext);
1421 return nFrame;
1422 }
1423
1424 function CalculateTimers(Result, TimerIndex, nFrameFirst, nFrameLast, SContext)
1425 {
1426 if(!SContext)
1427 SContext = S;
1428 if(!nFrameFirst || nFrameFirst < 0)
1429 nFrameFirst = 0;
1430 if(!nFrameLast || nFrameLast > SContext.Frames.length)
1431 nFrameLast = SContext.Frames.length;
1432 var FrameCount = nFrameLast - nFrameFirst;
1433 if(0 == FrameCount)
1434 return;
1435 var CallCount = 0;
1436 var Sum = 0;
1437 var Max = 0;
1438 var FrameMax = 0;
1439
1440 var nNumLogs = SContext.Frames[0].ts.length;
1441 var StackPosArray = Array(nNumLogs);
1442 var StackArray = Array(nNumLogs);
1443 let StackIndexArray = Array(nNumLogs);
1444 for(var i = 0; i < nNumLogs; ++i)
1445 {
1446 StackPosArray[i] = 0;
1447 StackArray[i] = Array(32);
1448 StackIndexArray[i] = Array(32);
1449 }
1450
1451 for(var i = nFrameFirst; i < nFrameLast; i++)
1452 {
1453 let FrameSum = 0;
1454 let fr = SContext.Frames[i];
1455 for(nLog = 0; nLog < nNumLogs; nLog++)
1456 {
1457 let StackPos = StackPosArray[nLog];
1458 let Stack = StackArray[nLog];
1459 let StackIndex = StackIndexArray[nLog];
1460 var ts = fr.ts[nLog];
1461 var ti = fr.ti[nLog];
1462 var tt = fr.tt[nLog];
1463 var count = ts.length;
1464 for(var j = 0; j < count; j++)
1465 {
1466 var type = tt[j];
1467 var index = ti[j];
1468 var time = ts[j];
1469 if(index < ETOKEN_MAX)
1470 {
1471 if(type == 1) //enter
1472 {
1473 //push
1474 Stack[StackPos] = time;
1475 StackIndex[StackPos] = index;
1476 if(StackArray[nLog][StackPos] != time)
1477 {
1478 console.log('fail fail fail');
1479 }
1480 StackPos++;
1481 }
1482 else if(type == 0) // leave
1483 {
1484 var timestart;
1485 var timeend = time;
1486 if(StackPos>0)
1487 {
1488 StackPos--;
1489 timestart = Stack[StackPos];
1490 }
1491 else
1492 {
1493 timestart = SContext.Frames[nFrameFirst].framestart;
1494 }
1495 if(index == TimerIndex)
1496 {
1497 let TimeDelta = timeend - timestart;
1498 CallCount++;
1499 FrameSum += TimeDelta;
1500 Sum += TimeDelta;
1501 if(TimeDelta > Max)
1502 Max = TimeDelta;
1503 }
1504 }
1505 else
1506 {
1507 //meta
1508 }
1509 }
1510 }
1511 if(i == nFrameLast - 1)
1512 {
1513 for(var j = 0; j < StackPos; ++j)
1514 {
1515 if(StackIndex[j] == TimerIndex)
1516 {
1517 let LastFrameEnd = SContext.Frames[nFrameLast-1].frameend;
1518 let TimeDelta = LastFrameEnd - Stack[j];
1519 CallCount++;
1520 FrameSum += TimeDelta;
1521 Sum += TimeDelta;
1522 if(TimeDelta > Max)
1523 Max = TimeDelta;
1524 break;
1525 }
1526 }
1527
1528 }
1529 if(FrameSum > FrameMax)
1530 {
1531 FrameMax = FrameSum;
1532 }
1533 StackPosArray[nLog] = StackPos;
1534 }
1535 }
1536
1537 Result.CallCount = CallCount;
1538 Result.Sum = Sum.toFixed(3);
1539 Result.Max = Max.toFixed(3);
1540 Result.Average = (Sum / CallCount).toFixed(3);
1541 Result.FrameAverage = (Sum / FrameCount).toFixed(3);
1542 Result.FrameCallAverage = (CallCount / FrameCount).toFixed(3);
1543 Result.FrameMax = FrameMax.toFixed(3);
1544 return Result;
1545 }
1546
1547 function PreprocessCalculateAllTimers()
1548 {
1549 ProfileEnter("CalculateAllTimers");
1550 var nFrameFirst = 0;
1551 var nFrameLast = S.Frames.length;
1552 var FrameCount = nFrameLast - nFrameFirst;
1553 if(0 == FrameCount)
1554 return;
1555 for(var j = 0; j < S.TimerInfo.length; j++)
1556 {
1557 S.TimerInfo[j].CallCount = 0;
1558 S.TimerInfo[j].Sum = 0;
1559 S.TimerInfo[j].Max = 0;
1560 S.TimerInfo[j].FrameMax = 0;
1561 }
1562
1563
1564 var nNumLogs = S.Frames[0].ts.length;
1565 var StackPosArray = Array(nNumLogs);
1566 var StackArray = Array(nNumLogs);
1567 for(var i = 0; i < nNumLogs; ++i)
1568 {
1569 StackPosArray[i] = 0;
1570 StackArray[i] = Array(20);
1571 }
1572
1573 for(var i = nFrameFirst; i < nFrameLast; i++)
1574 {
1575 for(var j = 0; j < S.TimerInfo.length; j++)
1576 {
1577 S.TimerInfo[j].FrameSum = 0;
1578 }
1579
1580 var fr = S.Frames[i];
1581 for(nLog = 0; nLog < nNumLogs; nLog++)
1582 {
1583 var StackPos = StackPosArray[nLog];
1584 var Stack = StackArray[nLog];
1585 var ts = fr.ts[nLog];
1586 var ti = fr.ti[nLog];
1587 var tt = fr.tt[nLog];
1588 var count = ts.length;
1589 for(j = 0; j < count; j++)
1590 {
1591 var type = tt[j];
1592 var index = ti[j];
1593 var time = ts[j];
1594 if(index < ETOKEN_MAX && index >= 0)
1595 {
1596 if(type == 1) //enter
1597 {
1598 //push
1599 Stack[StackPos] = time;
1600 if(StackArray[nLog][StackPos] != time)
1601 {
1602 console.log('fail fail fail');
1603 }
1604 StackPos++;
1605 }
1606 else if(type == 0) // leave
1607 {
1608 var timestart;
1609 var timeend = time;
1610 if(StackPos>0)
1611 {
1612 StackPos--;
1613 timestart = Stack[StackPos];
1614 }
1615 else
1616 {
1617 timestart = S.Frames[nFrameFirst].framestart;
1618 }
1619 // if(index == TimerIndex)
1620 {
1621 var TimeDelta = timeend - timestart;
1622 S.TimerInfo[index].CallCount++;
1623 S.TimerInfo[index].FrameSum += TimeDelta;
1624 S.TimerInfo[index].Sum += TimeDelta;
1625 if(TimeDelta > S.TimerInfo[index].Max)
1626 {
1627 S.TimerInfo[index].Max = TimeDelta;
1628 S.TimerInfo[index].worst = TimeDelta;
1629 S.TimerInfo[index].worststart = timestart;
1630 S.TimerInfo[index].worstend = timeend;
1631 S.TimerInfo[index].worstthread = nLog;
1632 }
1633 }
1634 }
1635 }
1636 else
1637 {
1638 //meta
1639 }
1640 }
1641 for(var j = 0; j < S.TimerInfo.length; j++)
1642 {
1643 if(S.TimerInfo[j].FrameSum > S.TimerInfo[j].FrameMax)
1644 {
1645 S.TimerInfo[j].FrameMax = S.TimerInfo[j].FrameSum;
1646 }
1647 }
1648 StackPosArray[nLog] = StackPos;
1649 }
1650
1651
1652 }
1653
1654 for(var j = 0; j < S.TimerInfo.length; j++)
1655 {
1656 var CallCount = S.TimerInfo[j].CallCount;
1657 var Sum = S.TimerInfo[j].Sum.toFixed(3);
1658 var Max = S.TimerInfo[j].Max.toFixed(3);
1659 var Average = (S.TimerInfo[j].Sum / S.TimerInfo[j].CallCount).toFixed(3);
1660 var FrameAverage = (S.TimerInfo[j].Sum / FrameCount).toFixed(3);
1661 var FrameCallAverage = (S.TimerInfo[j].CallCount / FrameCount).toFixed(3);
1662 var FrameMax = S.TimerInfo[j].FrameMax.toFixed(3);
1663 S.TimerInfo[j].CallCount = CallCount;
1664 S.TimerInfo[j].Sum = Sum;
1665 S.TimerInfo[j].Max = Max ;
1666 S.TimerInfo[j].Average = Average;
1667 S.TimerInfo[j].FrameAverage = FrameAverage;
1668 S.TimerInfo[j].FrameCallAverage = FrameCallAverage;
1669 S.TimerInfo[j].FrameMax = FrameMax;
1670 }
1671 ProfileLeave();
1672 }
1673
1674 var FlashFrames = 10;
1675 var FlashFrameCounter = 0;
1676 var FlashMessage = '';
1677 function TimeString(Diff)
1678 {
1679 var DiffString = "0 sec";
1680 var DiffTable = [1,60,60*60,60*60*24];
1681 var DiffNameTable = ["sec", "min", "hr", "day"];
1682 for(var i = 0; i < DiffTable.length; ++i)
1683 {
1684 if(Diff >= DiffTable[i])
1685 {
1686 DiffString = Math.floor(Diff / DiffTable[i]) + " " + DiffNameTable[i];
1687 }
1688 }
1689 return DiffString;
1690
1691 }
1692 function ShowFlashMessage(Message, FrameCount)
1693 {
1694 FlashMessage = Message;
1695 FlashFrameCounter = FrameCount;
1696 }
1697 function OnPageReady()
1698 {
1699 var DumpDate = S.DumpUtcCaptureTime;
1700 var CurrentDate = Date.now() / 1000;
1701 var Diff = CurrentDate - DumpDate;
1702 var Limit = 10*60;//flash old message when loading captures older than 10 minutes
1703 if(Diff > Limit)
1704 {
1705 ShowFlashMessage("Captured " + TimeString(Diff) + " ago", 100);
1706 }
1707 }
1708
1709 function DrawFlashMessage(context)
1710 {
1711 if(FlashFrameCounter > 0)
1712 {
1713 if(FlashFrameCounter>1)
1714 {
1715 var FlashPrc = Math.sin(FlashFrameCounter / FlashFrames);
1716 context.font = FontFlash;
1717 context.globalAlpha = FlashPrc * 0.35 + 0.5;
1718 context.textAlign = 'center';
1719 context.fillStyle = 'red';
1720 context.fillText(FlashMessage, nWidth * 0.5, 50);
1721 context.globalAlpha = 1;
1722 context.textAlign = 'left';
1723 context.font = Font;
1724 }
1725 FlashFrameCounter -= 1;
1726
1727 }
1728 }
1729
1730 function DrawCaptureInfo(context)
1731 {
1732 context.fillStyle = 'white';
1733 context.textAlign = 'right';
1734 context.font = Font;
1735 var DumpDate = S.DumpUtcCaptureTime;
1736 var CurrentDate = Date.now() / 1000;
1737 var Diff = CurrentDate - DumpDate;
1738 var DiffString = TimeString(Diff) + " ago";
1739 context.fillText(new Date(DumpDate*1000).toLocaleString(), nWidth, FontHeight);
1740 if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
1741 {
1742 context.fillText("Timer Frames: " + S.AggregateInfo.Frames, nWidth, FontHeight*2);
1743 }
1744 else
1745 {
1746 context.fillText("Detailed Frames "+ S.Frames.length, nWidth, FontHeight*2);
1747 }
1748 context.fillText(S.DumpHost, nWidth, FontHeight*3);
1749 context.fillText(DiffString, nWidth, FontHeight*4);
1750 context.textAlign = 'left';
1751 DrawFlashMessage(context);
1752 }
1753
1754 function DrawDetailedFrameHistory()
1755 {
1756 ProfileEnter("DrawDetailedFrameHistory");
1757 var x = HistoryViewMouseX;
1758
1759 var context = CanvasHistory.getContext('2d');
1760 context.clearRect(0, 0, CanvasHistory.width, CanvasHistory.height);
1761
1762 let HistoryHeight = CanvasHistory.height;
1763
1764 var GreenTime = (TargetTime * 0.9);
1765 var RedBegin = (TargetTime * 1.1);
1766 var LerpDist = 1.0 / (RedBegin - GreenTime);
1767
1768
1769 var fHeight = nHistoryHeight;
1770 var fWidth = nWidth / S.Frames.length;
1771 var fHeightScale = fHeight / ReferenceTime;
1772 var fX = 0;
1773 var FrameIndex = -1;
1774 var MouseDragging = MouseDragState != MouseDragOff;
1775 RangeCpuHistory = RangeInit();
1776 RangeGpuHistory = RangeInit()
1777
1778 var FrameFirst = -1;
1779 var FrameLast = nWidth;
1780 var fDetailedOffsetEnd = fDetailedOffset + fDetailedRange;
1781 for(i = 0; i < S.Frames.length; i++)
1782 {
1783 var fMs = S.Frames[i].frameend - S.Frames[i].framestart;
1784
1785 var fPrc = (fMs - GreenTime) * LerpDist;
1786 fPrc = Clamp(fPrc, 0, 1);
1787 var color = LerpColor(fPrc);
1788
1789
1790
1791 if(fDetailedOffset <= S.Frames[i].frameend && fDetailedOffset >= S.Frames[i].framestart)
1792 {
1793 var lerp = (fDetailedOffset - S.Frames[i].framestart) / (S.Frames[i].frameend - S.Frames[i].framestart);
1794 FrameFirst = fX + fWidth * lerp;
1795 }
1796 if(fDetailedOffsetEnd <= S.Frames[i].frameend && fDetailedOffsetEnd >= S.Frames[i].framestart)
1797 {
1798 var lerp = (fDetailedOffsetEnd - S.Frames[i].framestart) / (S.Frames[i].frameend - S.Frames[i].framestart);
1799 FrameLast = fX + fWidth * lerp;
1800 }
1801 var fH = fHeightScale * fMs;
1802 var bMouse = x > fX && x < fX + fWidth;
1803 if(bMouse && !MouseDragging)
1804 {
1805 context.fillStyle = FRAME_HISTORY_COLOR_GPU;
1806 RangeCpuHistory.Begin = S.Frames[i].framestart;
1807 RangeCpuHistory.End = S.Frames[i].frameend;
1808 if(S.Frames[i].framestartgpu)
1809 {
1810 RangeGpuHistory.Begin = S.Frames[i].framestartgpu;
1811 RangeGpuHistory.End = S.Frames[i].frameendgpu;
1812 }
1813 FrameIndex = i;
1814 }
1815 else
1816 {
1817 context.fillStyle = color;
1818 }
1819 context.fillRect(fX, fHeight - fH, fWidth-1, fH);
1820 fX += fWidth;
1821 }
1822
1823 var fRangeHistoryBegin = FrameFirst;
1824 var fRangeHistoryEnd = FrameLast;
1825 var X = fRangeHistoryBegin;
1826 var Y = 0;
1827 var W = fRangeHistoryEnd - fRangeHistoryBegin;
1828 context.globalAlpha = 0.35;
1829 context.fillStyle = '#009900';
1830 context.fillRect(X, Y, W, fHeight);
1831 context.globalAlpha = 1;
1832 context.strokeStyle = '#00ff00';
1833 context.beginPath();
1834 context.moveTo(X, Y);
1835 context.lineTo(X, Y+fHeight);
1836 context.moveTo(X+W, Y);
1837 context.lineTo(X+W, Y+fHeight);
1838 context.stroke();
1839
1840 {
1841 var fH = fHeight - fHeightScale * TargetTime;
1842 context.fillStyle = 'wheat';
1843 context.strokeStyle = 'wheat';
1844 context.beginPath();
1845 context.moveTo(0, fH);
1846 context.lineTo(nWidth, fH);
1847 // context.closePath();
1848 context.stroke();
1849 var YText;
1850 if(fH > HistoryHeight * 0.25)
1851 {
1852 YText = fH - FontAscent;
1853 }
1854 else
1855 {
1856 YText = fH + FontHeight;
1857 }
1858 context.fillText(TargetTime + 'ms', 3, YText);
1859 context.textAlign='right';
1860 context.fillText(FormatTime(ReferenceTime) + 'ms', nWidth, FontHeight);
1861 context.textAlign='left';
1862 }
1863
1864
1865 DrawCaptureInfo(context);
1866
1867 if(FrameIndex>=0 && !MouseDragging)
1868 {
1869 var StringArray = [];
1870 StringArray.push("Frame");
1871 StringArray.push("" + FrameIndex);
1872 StringArray.push("Time");
1873 StringArray.push("" + (S.Frames[FrameIndex].frameend - S.Frames[FrameIndex].framestart).toFixed(3));
1874
1875 DrawToolTip(StringArray, CanvasHistory, HistoryViewMouseX, HistoryViewMouseY+20);
1876
1877 }
1878 ProfileLeave();
1879 }
1880 function TimeToMsString(Time)
1881 {
1882 return Time.toFixed(3) + "ms";
1883 }
1884 function TimeToString(Time)
1885 {
1886 if(Time > 1000)
1887 {
1888 return (Time/1000.0).toFixed(0) +"s";
1889 }
1890 else if(Time > 0.9)
1891 {
1892 return Time.toFixed(0) + "ms";
1893 }
1894 else if(Time > 0.0009)
1895 {
1896 return (Time*1000).toFixed(0) + "us";
1897 }
1898 else
1899 {
1900 return (Time*1000000).toFixed(0) + "ns";
1901 }
1902 }
1903
1904 function DrawDetailedBackground(context)
1905 {
1906 var fMs = fDetailedRange;
1907 var fMsEnd = fMs + fDetailedOffset;
1908 var fMsToScreen = nWidth / fMs;
1909 var fRate = Math.floor(2*((Math.log(fMs)/Math.log(10))-1))/2;
1910 var fStep = Math.pow(10, fRate);
1911 var fRcpStep = 1.0 / fStep;
1912 var nColorIndex = Math.floor(fDetailedOffset * fRcpStep) % 2;
1913 if(nColorIndex < 0)
1914 nColorIndex = -nColorIndex;
1915 var fStart = Math.floor(fDetailedOffset * fRcpStep) * fStep;
1916 var fHeight = CanvasDetailedView.height;
1917 var fScaleX = nWidth / fDetailedRange;
1918 var HeaderString = TimeToString(fStep);
1919 context.textAlign = 'center';
1920 for(f = fStart; f < fMsEnd; )
1921 {
1922 var fNext = f + fStep;
1923 var X = (f - fDetailedOffset) * fScaleX;
1924 var W = (fNext-f)*fScaleX;
1925 context.fillStyle = nBackColors[nColorIndex];
1926 context.fillRect(X, 0, W+2, fHeight);
1927 nColorIndex = 1 - nColorIndex;
1928 context.fillStyle = '#777777'
1929 context.fillText(HeaderString, X + W * 0.5, 10);
1930 context.fillText(HeaderString, X + W * 0.5, nHeight - 10);
1931 f = fNext;
1932 }
1933 context.textAlign = 'left';
1934 var fScaleX = nWidth / fDetailedRange;
1935 context.globalAlpha = 0.5;
1936 context.strokeStyle = '#bbbbbb';
1937 context.beginPath();
1938 for(var i = 0; i < S.Frames.length; i++)
1939 {
1940 var frfr = S.Frames[i];
1941 if(frfr.frameend < fDetailedOffset || frfr.framestart > fDetailedOffset + fDetailedRange)
1942 {
1943 continue;
1944 }
1945 var X = (frfr.framestart - fDetailedOffset) * fScaleX;
1946 if(X >= 0 && X < nWidth)
1947 {
1948 context.moveTo(X, 0);
1949 context.lineTo(X, nHeight);
1950 }
1951 }
1952 context.stroke();
1953 context.globalAlpha = 1;
1954
1955 }
1956
1957 function DrawToolTip(StringArray, Canvas, x, y, bSecondary)
1958 {
1959 var context = Canvas.getContext('2d');
1960 context.font = Font;
1961 var WidthArray = Array(StringArray.length);
1962 var nMaxWidth = 0;
1963 var nHeight = 0;
1964 for(i = 0; i < StringArray.length; i += 2)
1965 {
1966 var nWidth0 = context.measureText(StringArray[i]).width;
1967 var nWidth1 = context.measureText(StringArray[i+1]).width;
1968 var nSum = nWidth0 + nWidth1;
1969 WidthArray[i] = nWidth0;
1970 WidthArray[i+1] = nWidth1;
1971 if(nSum > nMaxWidth)
1972 {
1973 nMaxWidth = nSum;
1974 }
1975 nHeight += BoxHeight;
1976 }
1977 nMaxWidth += 15;
1978 //bounds check.
1979 if(!bSecondary)
1980 {
1981 var CanvasRect = Canvas.getBoundingClientRect();
1982 if(y + nHeight > CanvasRect.height)
1983 {
1984 y = CanvasRect.height - nHeight;
1985 x += 20;
1986 }
1987 if(x + nMaxWidth > CanvasRect.width)
1988 {
1989 x = CanvasRect.width - nMaxWidth;
1990 }
1991 }
1992 else
1993 {
1994 x -= nMaxWidth;
1995 }
1996 context.fillStyle = 'black';
1997 context.fillRect(x-1, y, nMaxWidth+2, nHeight);
1998 context.fillStyle = 'white';
1999
2000 var XPos = x;
2001 var XPosRight = x + nMaxWidth;
2002 var YPos = y + BoxHeight-2;
2003 for(i = 0; i < StringArray.length; i += 2)
2004 {
2005 context.fillText(StringArray[i], XPos, YPos);
2006 context.fillText(StringArray[i+1], XPosRight - WidthArray[i+1], YPos);
2007 YPos += BoxHeight;
2008 }
2009 return {"x":x, "y":y};
2010 }
2011
2012 function BuildToolTipDetailed(S, nHoverToken, HoverTokenOwner, bSecond)
2013 {
2014 var StringArray = [];
2015 var groupid = S.TimerInfo[nHoverToken].group;
2016 if(nHoverToken > -1)
2017 {
2018 StringArray.push("Timer");
2019 StringArray.push(S.TimerInfo[nHoverToken].name);
2020 StringArray.push("Group");
2021 StringArray.push(S.GroupInfo[groupid].name);
2022 }
2023 else
2024 {
2025 StringArray.push("");
2026 StringArray.push("");
2027 StringArray.push("");
2028 StringArray.push("");
2029 }
2030 StringArray.push("");
2031 StringArray.push("");
2032
2033 if(S == HoverTokenOwner)
2034 {
2035 StringArray.push("Time");
2036 StringArray.push((RangeCpu.End-RangeCpu.Begin).toFixed(3));
2037 }
2038 else
2039 {
2040 StringArray.push("");
2041 StringArray.push("");
2042 }
2043
2044 StringArray.push("");
2045 StringArray.push("");
2046 StringArray.push("Total");
2047 StringArray.push("" + S.TimerInfo[nHoverToken].Sum);
2048 StringArray.push("Max");
2049 StringArray.push("" + S.TimerInfo[nHoverToken].Max);
2050 StringArray.push("Average");
2051 StringArray.push("" + S.TimerInfo[nHoverToken].Average);
2052 StringArray.push("Count");
2053 StringArray.push("" + S.TimerInfo[nHoverToken].CallCount);
2054
2055 StringArray.push("");
2056 StringArray.push("");
2057
2058 StringArray.push("Max/Frame");
2059 StringArray.push("" + S.TimerInfo[nHoverToken].FrameMax);
2060
2061 StringArray.push("Average Time/Frame");
2062 StringArray.push("" + S.TimerInfo[nHoverToken].FrameAverage);
2063
2064 StringArray.push("Average Count/Frame");
2065 StringArray.push("" + S.TimerInfo[nHoverToken].FrameCallAverage);
2066
2067
2068 let Time = fDetailedOffset + fDetailedRange * (DetailedViewMouseX / nWidth);
2069 if(bSecond)
2070 Time += fDetailedOffsetSecond;
2071 let FrameTime = new Object();
2072 let Frame = CalculateTimers2(FrameTime, nHoverToken, Time, S);
2073 StringArray.push("");
2074 StringArray.push("");
2075 if(Frame>-1)
2076 {
2077 StringArray.push("Frame " + Frame);
2078 StringArray.push("");
2079 StringArray.push("Total");
2080 StringArray.push("" + FrameTime.Sum);
2081 StringArray.push("Count");
2082 StringArray.push("" + FrameTime.CallCount);
2083 StringArray.push("Average");
2084 StringArray.push("" + FrameTime.Average);
2085 StringArray.push("Max");
2086 StringArray.push("" + FrameTime.Max);
2087 }
2088 else
2089 {
2090 for(var i = 0; i < 10; ++i)
2091 StringArray.push("");
2092 }
2093
2094 StringArray.push("");
2095 StringArray.push("");
2096
2097 StringArray.push("Detailed Capture");
2098 StringArray.push("");
2099 StringArray.push("Frames");
2100 StringArray.push(S.Frames.length);
2101 StringArray.push("Time");
2102 StringArray.push(DetailedTotal(S).toFixed(2) + "ms");
2103 return StringArray;
2104
2105
2106
2107 }
2108
2109
2110 function DrawHoverToolTip()
2111 {
2112 ProfileEnter("DrawHoverToolTip");
2113 let StringArray = [];
2114 let StringArray2;
2115 if(ToolTipImmediate != null)
2116 {
2117 DrawToolTip(ToolTipImmediate, CanvasDetailedView, DetailedViewMouseX, DetailedViewMouseY+20);
2118 ToolTipImmediate = null;
2119
2120 }
2121 else if(nHoverToken != -1)
2122 {
2123
2124 let bShowTimers = Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups;
2125 // this confused alot of people.
2126 // if(ToolTipFlip == 1)
2127 // {
2128 // bShowTimers = !bShowTimers;
2129 // }
2130 if(bShowTimers)
2131 {
2132 // var StringArray = [];
2133 let groupid = S.TimerInfo[nHoverToken].group;
2134 StringArray.push("Timer");
2135 StringArray.push(S.TimerInfo[nHoverToken].name);
2136 StringArray.push("Group");
2137 StringArray.push(S.GroupInfo[groupid].name);
2138
2139 StringArray.push("");
2140 StringArray.push("");
2141 let Timer = S.TimerInfo[nHoverToken];
2142 StringArray.push("Average");
2143 StringArray.push(Timer.average);
2144 StringArray.push("Max");
2145 StringArray.push(Timer.max);
2146 StringArray.push("Excl Max");
2147 StringArray.push(Timer.exclmax);
2148 StringArray.push("Excl Average");
2149 StringArray.push(Timer.exclaverage);
2150 StringArray.push("Call Average");
2151 StringArray.push(Timer.callaverage);
2152 StringArray.push("Call Count");
2153 StringArray.push(Timer.callcount);
2154
2155 StringArray.push("");
2156 StringArray.push("");
2157
2158
2159 StringArray.push("Group");
2160 StringArray.push(S.GroupInfo[groupid].name);
2161 StringArray.push("Average");
2162 StringArray.push(S.GroupInfo[groupid].average);
2163 StringArray.push("Max");
2164 StringArray.push(S.GroupInfo[groupid].max);
2165
2166 StringArray.push("");
2167 StringArray.push("");
2168
2169 StringArray.push("Timer Capture");
2170 StringArray.push("");
2171 StringArray.push("Frames");
2172 StringArray.push(S.AggregateInfo.Frames);
2173 StringArray.push("Time");
2174 StringArray.push(S.AggregateInfo.Time.toFixed(2) + "ms");
2175
2176
2177 }
2178 else
2179 {
2180 StringArray = BuildToolTipDetailed(S, nHoverToken, HoverTokenOwner, 0);
2181 let nCompareHoverToken = TimerRemapReverse[nHoverToken];
2182 if(nCompareHoverToken > -1)
2183 {
2184 StringArray2 = BuildToolTipDetailed(S2, nCompareHoverToken, HoverTokenOwner, 1);
2185 }
2186 }
2187 if(ToolTipCorner)
2188 {
2189 let R = DrawToolTip(StringArray, CanvasDetailedView, nWidth, nHeight);
2190 if(StringArray2)
2191 DrawToolTip(StringArray2, CanvasDetailedView, R.x-15, R.y, 1);
2192 }
2193 else
2194 {
2195 let R = DrawToolTip(StringArray, CanvasDetailedView, DetailedViewMouseX, DetailedViewMouseY+20);
2196 if(StringArray2)
2197 DrawToolTip(StringArray2, CanvasDetailedView, R.x-15, R.y, 1);
2198 }
2199 }
2200 else if(nHoverCSCpu >= 0)
2201 {
2202 StringArray = [];
2203 StringArray.push("Context Switch");
2204 StringArray.push("");
2205 StringArray.push("");
2206 StringArray.push("");
2207 StringArray.push("Cpu");
2208 StringArray.push("" + nHoverCSCpu);
2209 StringArray.push("Begin");
2210 StringArray.push("" + RangeCpu.Begin);
2211 StringArray.push("End");
2212 StringArray.push("" + RangeCpu.End);
2213 if(ToolTipCorner)
2214 {
2215 DrawToolTip(StringArray, CanvasDetailedView, nWidth, nHeight);
2216 }
2217 else
2218 DrawToolTip(StringArray, CanvasDetailedView, DetailedViewMouseX, DetailedViewMouseY+20);
2219 }
2220 ProfileLeave();
2221 }
2222
2223 function FormatMeta(Value, Dec)
2224 {
2225 if(!Value)
2226 {
2227 Value = "0";
2228 }
2229 else
2230 {
2231 Value = '' + Value.toFixed(Dec);
2232 }
2233 return Value;
2234 }
2235
2236 function FilterMatch(FilterArray, value)
2237 {
2238 if(!FilterArray)
2239 return true;
2240 for(var i = 0; i < FilterArray.length; ++i)
2241 {
2242 var res = value.search(FilterArray[i]);
2243 if(res<0)
2244 return false;
2245 }
2246 return true;
2247 }
2248
2249
2250 function DrawBarView()
2251 {
2252 ProfileEnter("DrawBarView");
2253 Invalidate++;
2254 nHoverToken = -1;
2255 var context = CanvasDetailedView.getContext('2d');
2256 context.clearRect(0, 0, nWidth, nHeight);
2257
2258 var Height = BoxHeight;
2259 var Width = nWidth;
2260 var NameWidth = Math.max(S.TimerNameWidth, S.GroupNameWidth) + 20;
2261
2262 //clamp offset to prevent scrolling into the void
2263 var nTotalRows = 0;
2264 for(var groupid in S.GroupInfo)
2265 {
2266 if(!GroupsDisabled[S.GroupInfo[groupid].name])
2267 {
2268 nTotalRows += S.GroupInfo[groupid].TimerArray.length + 1;
2269 }
2270 }
2271 var nTotalRowPixels = nTotalRows * Height;
2272 var nFrameRows = nHeight - BoxHeight;
2273
2274 if(nOffsetBarsY + nFrameRows > nTotalRowPixels && nTotalRowPixels > nFrameRows)
2275 {
2276 nOffsetBarsY = nTotalRowPixels - nFrameRows;
2277 }
2278 var ColumnsWidthBefore = new Array(ColumnsWidth.length);
2279 for(var i = 0; i < ColumnsWidth.length; ++i)
2280 {
2281 ColumnsWidthBefore[i] = ColumnsWidth[i];
2282 }
2283
2284 var Y = -nOffsetBarsY + BoxHeight;
2285 let TimersGroups = Mode == ModeTimers_Threads || Mode == ModeTimers_Groups;
2286 if(TimersGroups)
2287 {
2288 nOffsetBarsX = 0;
2289 }
2290 var XBase = -nOffsetBarsX;
2291 var nColorIndex = 0;
2292
2293 context.fillStyle = 'white';
2294 context.font = Font;
2295 var bMouseIn = 0;
2296 var RcpReferenceTime = 1.0 / ReferenceTime;
2297 var CountWidth = 12 * FontWidth;
2298 var nMetaLen = S.TimerInfo[0].meta.length;
2299 var nMetaCharacters = 10;
2300 var InnerBoxHeight = BoxHeight-2;
2301 var TimerLen = 8; //todo: fix max digits.
2302 var TimerWidth = TimerLen * FontWidth;
2303 var nWidthBars = nBarsWidth+2;
2304 var nWidthMs = TimerWidth+2+10;
2305 var R = 0;
2306 var AllColumns = TimersGroups != 0;
2307
2308
2309
2310 for(var i = 0; i < nMetaLen; ++i)
2311 {
2312 if(nMetaCharacters < MetaNames[i].length)
2313 nMetaCharacters = MetaNames[i].length;
2314 }
2315 var nWidthMeta = nMetaCharacters * FontWidth + 6;
2316 function HeaderMouseHandle(XBegin, X, Header)
2317 {
2318 var bMouseIn = DetailedViewMouseY >= 0 && DetailedViewMouseY < BoxHeight && DetailedViewMouseX < X && DetailedViewMouseX > XBegin;
2319 if(bMouseIn)
2320 {
2321 SortColumnMouseOverNext = Header;
2322 }
2323 }
2324 function HeaderString(Header)
2325 {
2326 if(Header == SortColumnMouseOver)
2327 {
2328 return Header + (SortColumnOrderFlip ? '<' : '>');
2329 }
2330 else
2331 {
2332 return Header;
2333 }
2334
2335 }
2336 function DrawHeaderSplit(Header)
2337 {
2338 if(ColumnsEnabled[R]||AllColumns)
2339 {
2340 context.fillStyle = 'white';
2341 context.fillText(HeaderString(Header), X, Height-FontAscent);
2342 var XBegin = X;
2343 X += nWidthBars;
2344 context.fillStyle = nBackColorOffset;
2345 X += ColumnsWidth[R];
2346 if(X >= NameWidth)
2347 {
2348 context.fillRect(X-3, 0, 1, nHeight);
2349 }
2350 HeaderMouseHandle(XBegin, X, Header);
2351 }
2352 R++;
2353 }
2354 function DrawHeaderSplitSingle(Header, Col)
2355 {
2356 if(ColumnsEnabled[Col]||AllColumns)
2357 {
2358 context.fillStyle = 'white';
2359 context.fillText(HeaderString(Header), X, Height-FontAscent);
2360 var XBegin = X;
2361 X += ColumnsWidth[R];
2362 context.fillStyle = nBackColorOffset;
2363 if(X >= NameWidth)
2364 {
2365 context.fillRect(X-3, 0, 1, nHeight);
2366 }
2367 HeaderMouseHandle(XBegin, X, Header);
2368 }
2369 R++;
2370 }
2371 function DrawHeaderSplitLeftRight(HeaderLeft, HeaderRight, Width)
2372 {
2373 context.textAlign = 'left';
2374 context.fillStyle = 'white';
2375 context.fillText(HeaderLeft, X, Height-FontAscent);
2376 var XBegin = X;
2377 X += Width;
2378 context.textAlign = 'right';
2379 context.fillText(HeaderRight, X-5, Height-FontAscent);
2380 context.textAlign = 'left';
2381 context.fillStyle = nBackColorOffset;
2382 if(X >= NameWidth)
2383 {
2384 context.fillRect(X-3, 0, 1, nHeight);
2385 }
2386 HeaderMouseHandle(XBegin, X, HeaderLeft);
2387 }
2388 function DrawTimer(Value, Color)
2389 {
2390 if(ColumnsEnabled[R]||AllColumns)
2391 {
2392 var Prc = Value * RcpReferenceTime;
2393 var YText = Y+Height-FontAscent;
2394 if(Prc > 1)
2395 {
2396 Prc = 1;
2397 }
2398 context.textAlign = 'left';
2399 context.fillStyle = Color;
2400 context.fillRect(X+1, Y+1, Prc * nBarsWidth, InnerBoxHeight);
2401 var TimerText = Value.toFixed(2);
2402 var W = context.measureText(TimerText).width + FontWidth;
2403 ColumnsWidth[R] = Math.max(W, ColumnsWidth[R]);
2404 X += nWidthBars;
2405 X += ColumnsWidth[R];
2406 context.fillStyle = 'white';
2407 context.textAlign = 'right';
2408 context.fillText(TimerText, X - FontWidth, YText);
2409 context.textAlign = 'left';
2410 }
2411 R++;
2412 }
2413 function DrawCount(Str)
2414 {
2415 if(ColumnsEnabled[R]||AllColumns)
2416 {
2417 X += ColumnsWidth[R];
2418 context.fillStyle = 'white';
2419 context.textAlign = 'right';
2420 var YText = Y+Height-FontAscent;
2421 context.fillText(Str, X-6, YText);
2422 var W = Math.max(80, context.measureText(Str).width + FontWidth * 2);
2423 ColumnsWidth[R] = Math.max(W, ColumnsWidth[R]);
2424 }
2425 R++;
2426
2427 }
2428
2429
2430 function DrawMeta(Value, Width, Dec, YText, Col)
2431 {
2432 if(ColumnsEnabled[Col]||AllColumns)
2433 {
2434 Value = FormatMeta(Value, Dec);
2435 X += (FontWidth*Width);
2436 ColumnsWidth[R] = FontWidth*Width;
2437 context.textAlign = 'right';
2438 context.fillText(Value, X-FontWidth, YText);
2439 context.textAlign = 'left';
2440 }
2441 R++;
2442 }
2443
2444
2445
2446 function DrawTimerRow(timerid, showgroup)
2447 {
2448 R = 0;
2449 var Timer = S.TimerInfo[timerid];
2450 var Average = Timer.average;
2451 var Max = Timer.max;
2452 var Min = Timer.min;
2453 var Spike = Timer.spike;
2454 var ExclusiveMax = Timer.exclmax;
2455 var ExclusiveAverage = Timer.exclaverage;
2456 var CallAverage = Timer.callaverage;
2457 var CallCount = Timer.callcount;
2458 var YText = Y+Height-FontAscent;
2459 var Color = g_Colors[Timer.cid];
2460 X = NameWidth + XBase;
2461
2462 nColorIndex = 1-nColorIndex;
2463 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;
2464 if(bMouseIn)
2465 {
2466 nHoverToken = timerid;
2467 }
2468 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2469 context.fillRect(0, Y, Width, FontHeight+2);
2470
2471 DrawTimer(Average, Color);
2472 DrawTimer(Max, Color);
2473 DrawTimer(Timer.total, Color);
2474 DrawTimer(Min, Color);
2475 DrawCount(Spike.toFixed(2) + '%');
2476 DrawTimer(CallAverage, Color);
2477 DrawCount(CallCount);
2478 DrawTimer(ExclusiveAverage, Color);
2479 DrawTimer(ExclusiveMax, Color);
2480
2481 context.fillStyle = 'white';
2482 var Col = R;
2483 for(var j = 0; j < nMetaLen; ++j)
2484 {
2485 DrawMeta(Timer.meta[j], MetaLengths[j], 0, YText, Col + j);
2486 DrawMeta(Timer.metaavg[j], MetaLengthsAvg[j], 2, YText, Col + j);
2487 DrawMeta(Timer.metamax[j], MetaLengthsMax[j], 0, YText, Col + j);
2488 }
2489 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2490 context.fillRect(0, Y, NameWidth, Height);
2491 context.textAlign = 'right';
2492 context.fillStyle = Color;
2493 context.fillText(Timer.name, NameWidth - 5, YText);
2494 context.textAlign = 'left';
2495 if(showgroup)
2496 {
2497 context.fillStyle = 'white';
2498 context.fillText(S.GroupInfo[Timer.group].name, 1, YText);
2499 }
2500 }
2501 if(SortColumn && Mode == ModeTimers)
2502 {
2503 var OrderArray = new Array(S.TimerInfo.length);
2504 var KeyArray = new Array(S.TimerInfo.length);
2505 for(var idx in GroupOrder)
2506 {
2507 var Group = S.GroupInfo[idx];
2508 if((!GroupsDisabled[Group.name]) && FilterMatch(FilterGroup, Group.name))
2509 {
2510 var TimerArray = Group.TimerArray;
2511 for(var timerindex in TimerArray)
2512 {
2513 var timerid = TimerArray[timerindex];
2514 if(FilterMatch(FilterTimer, S.TimerInfo[timerid].name))
2515 {
2516 OrderArray.push(timerid);
2517 NameWidth = Math.max(S.TimerInfo[timerid].wtotal, NameWidth);
2518 }
2519 }
2520 }
2521 }
2522 var KeyFunc = null;
2523 switch(SortColumn)
2524 {
2525 case 1: KeyFunc = function (a) { return S.TimerInfo[a].average; }; break;
2526 case 2: KeyFunc = function (a) { return S.TimerInfo[a].max; }; break;
2527 case 3: KeyFunc = function (a) { return S.TimerInfo[a].total; }; break;
2528 case 4: KeyFunc = function (a) { return S.TimerInfo[a].min; }; break;
2529 case 5: KeyFunc = function (a) { return S.TimerInfo[a].spike; }; break;
2530 case 6: KeyFunc = function (a) { return S.TimerInfo[a].callaverage; }; break;
2531 case 7: KeyFunc = function (a) { return S.TimerInfo[a].callcount; }; break;
2532 case 8: KeyFunc = function (a) { return S.TimerInfo[a].exclaverage; }; break;
2533 case 9: KeyFunc = function (a) { return S.TimerInfo[a].exclmax; }; break;
2534 }
2535
2536 var Flip = SortColumnOrderFlip == 1 ? -1 : 1;
2537 OrderArray.sort(function(a,b) { return Flip * (KeyFunc(b) - KeyFunc(a)); } );
2538
2539 for(var i in OrderArray)
2540 {
2541 DrawTimerRow(OrderArray[i], 1);
2542 Y += Height;
2543 }
2544
2545 }
2546 else if(Mode == ModeTimers_Threads)
2547 {
2548 for(var i = 0; i < S.ThreadNames.length; ++i)
2549 {
2550 if((IsThreadActive(S.ThreadNames[i])) && FilterMatch(FilterTimer, S.ThreadNames[i]))
2551 {
2552 var X = 0;
2553 var YText = Y+Height-FontAscent;
2554 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;
2555 nColorIndex = 1-nColorIndex;
2556 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2557 context.fillRect(0, Y, Width, FontHeight+2);
2558 var ThreadColor = CSwitchColors[i % CSwitchColors.length];
2559 context.fillStyle = ThreadColor;
2560 context.fillText(S.ThreadNames[i], 1, YText);
2561 context.textAlign = 'left';
2562 Y += Height;
2563 for(var idx in GroupOrder)
2564 {
2565 R = 0;
2566 var groupid = GroupOrder[idx];
2567 var Group = S.GroupInfo[groupid];
2568 var PerThreadTimer = S.ThreadGroupTimeArray[i][groupid];
2569 var PerThreadTimerTotal = S.ThreadGroupTimeTotalArray[i][groupid];
2570 if((PerThreadTimer > 0.0001|| PerThreadTimerTotal>0.1) && (!GroupsDisabled[Group.name]) && FilterMatch(FilterGroup, Group.name))
2571 {
2572 var GColor = GroupColors ? g_Colors[S.GroupInfo[groupid].cid] : 'white';
2573 var X = 0;
2574 nColorIndex = 1-nColorIndex;
2575 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;
2576 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2577 context.fillRect(0, Y, Width, nHeight);
2578 context.fillStyle = GColor;
2579 context.textAlign = 'right';
2580 context.fillText(Group.name, NameWidth - 5, Y+Height-FontAscent);
2581 context.textAlign = 'left';
2582 X += NameWidth;
2583 DrawTimer(PerThreadTimer, GColor);
2584 DrawTimer(PerThreadTimerTotal, GColor);
2585 Y += Height;
2586 }
2587 }
2588 }
2589 }
2590 }
2591 else
2592 {
2593 for(var idx in GroupOrder)
2594 {
2595 var groupid = GroupOrder[idx];
2596 var Group = S.GroupInfo[groupid];
2597 var GColor = GroupColors ? g_Colors[S.GroupInfo[groupid].cid] : 'white';
2598 if((!GroupsDisabled[Group.name]) && FilterMatch(FilterGroup, Group.name))
2599 {
2600 R = 0;
2601 var TimerArray = Group.TimerArray;
2602 var X = XBase;
2603 nColorIndex = 1-nColorIndex;
2604 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;
2605 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2606 context.fillRect(0, Y, Width, FontHeight+2);
2607 context.fillStyle = GColor;
2608 context.fillText(Group.name, 1, Y+Height-FontAscent);
2609 X += NameWidth;
2610 DrawTimer(Group.average, GColor);
2611 DrawTimer(Group.max, GColor);
2612 DrawTimer(Group.total, GColor);
2613
2614 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2615 context.fillRect(0, Y, NameWidth, FontHeight+2);
2616 context.fillStyle = GColor;
2617 context.fillText(Group.name, 1, Y+Height-FontAscent);
2618
2619 Y += Height;
2620 let TimersGroups = Mode == ModeTimers_Threads || Mode == ModeTimers_Groups;
2621 if(TimersGroups)
2622 {
2623 for(var i = 0; i < S.ThreadNames.length; ++i)
2624 {
2625 R = 0;
2626 var PerThreadTimer = S.ThreadGroupTimeArray[i][groupid];
2627 var PerThreadTimerTotal = S.ThreadGroupTimeTotalArray[i][groupid];
2628 if((PerThreadTimer > 0.0001|| PerThreadTimerTotal>0.1) && (IsThreadActive(S.ThreadNames[i])) && FilterMatch(FilterTimer, S.ThreadNames[i]))
2629 {
2630 var YText = Y+Height-FontAscent;
2631 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;
2632 nColorIndex = 1-nColorIndex;
2633 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2634 context.fillRect(0, Y, Width, FontHeight+2);
2635 var ThreadColor = CSwitchColors[i % CSwitchColors.length];
2636 context.fillStyle = ThreadColor;
2637 context.textAlign = 'right';
2638 context.fillText(S.ThreadNames[i], NameWidth - 5, YText);
2639 context.textAlign = 'left';
2640 X = NameWidth;
2641 DrawTimer(PerThreadTimer, ThreadColor);
2642 X += nWidthBars + ColumnsWidth[R++];
2643 DrawTimer(PerThreadTimerTotal, ThreadColor);
2644 Y += Height;
2645 }
2646 }
2647 }
2648 else
2649 {
2650 for(var timerindex in TimerArray)
2651 {
2652 var timerid = TimerArray[timerindex];
2653 if(FilterMatch(FilterTimer, S.TimerInfo[timerid].name))
2654 {
2655 DrawTimerRow(timerid, 0);
2656 Y += Height;
2657 }
2658 }
2659 }
2660 }
2661 }
2662 }
2663 X = 0;
2664 R = 0;
2665 context.fillStyle = nBackColorOffset;
2666 context.fillRect(0, 0, Width, Height);
2667 context.fillStyle = 'white';
2668 SortColumnMouseOverNext = null;
2669
2670 if(Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
2671 {
2672 if(Mode == ModeTimers_Threads)
2673 {
2674 DrawHeaderSplitLeftRight(StrThread, StrGroup, NameWidth);
2675 DrawHeaderSplit(StrAverage);
2676 DrawHeaderSplit(StrTotal);
2677 }
2678 else
2679 {
2680 DrawHeaderSplitLeftRight(StrGroup, StrThread, NameWidth);
2681 DrawHeaderSplit(StrAverage);
2682 DrawHeaderSplit(StrMax);
2683 DrawHeaderSplit(StrTotal);
2684 }
2685 }
2686 else
2687 {
2688 X = NameWidth + XBase;
2689 DrawHeaderSplit(StrAverage);
2690 DrawHeaderSplit(StrMax);
2691 DrawHeaderSplit(StrTotal);
2692 DrawHeaderSplit(StrMin);
2693 DrawHeaderSplitSingle(StrSpike, R);
2694 DrawHeaderSplit(StrCallAverage);
2695 DrawHeaderSplitSingle(StrCount, R);
2696 DrawHeaderSplit(StrExclAverage);
2697 DrawHeaderSplit(StrExclMax);
2698 var Col = R;
2699 for(var i = 0; i < nMetaLen; ++i)
2700 {
2701 DrawHeaderSplitSingle(MetaNames[i], Col + i);
2702 DrawHeaderSplitSingle(MetaNames[i] + " Avg", Col + i);
2703 DrawHeaderSplitSingle(MetaNames[i] + " Max", Col + i);
2704 }
2705 X = 0;
2706 context.fillStyle = nBackColorOffset;
2707 context.fillRect(0, 0, NameWidth, Height);
2708 context.fillStyle = 'white';
2709
2710 DrawHeaderSplitLeftRight(StrGroup, StrTimer, NameWidth);
2711
2712 }
2713
2714 var ColumnsChanged = false;
2715 for(var i = 0; i < ColumnsWidth.length; ++i)
2716 {
2717 if(ColumnsWidthBefore[i] != ColumnsWidth[i])
2718 {
2719 ColumnsChanged = true;
2720 }
2721 }
2722 if(ColumnsChanged)
2723 {
2724 Invalidate = 0;
2725 }
2726
2727
2728
2729
2730 ProfileLeave();
2731 }
2732
2733 var CounterNameWidth = 100;
2734 var CounterValueWidth = 100;
2735 var CounterLimitWidth = 100;
2736
2737 var FormatCounterDefault = 0;
2738 var FormatCounterBytes = 1;
2739 var FormatCounterBytesExt = [ "b","kb","mb","gb","tb","pb", "eb","zb", "yb" ];
2740
2741 function ShiftRight10(v)
2742 {
2743 if(v > 1024)
2744 {
2745 return v / 1024.0;
2746 }
2747 else
2748 {
2749 return v >> 10;
2750 }
2751 }
2752
2753
2754 function FormatCounter(Format, Counter)
2755 {
2756 if(!Counter)
2757 {
2758 return '0';
2759 }
2760 var Negative = 0;
2761 if(Counter < 0)
2762 {
2763 Counter = -Counter;
2764 Negative = 1;
2765 if(Counter < 0) // handle INT_MIN
2766 {
2767 Counter = -(Counter+1);
2768 if(Counter < 0)
2769 {
2770 return '?';
2771 }
2772 }
2773 }
2774 var str = Negative ? '-' :'' ;
2775 if(Format == FormatCounterDefault)
2776 {
2777 var Seperate = 0;
2778 var result = '';
2779 while (Counter)
2780 {
2781 if (Seperate)
2782 {
2783 result += '.';
2784 }
2785 Seperate = 1;
2786 for (var i = 0; Counter && i < 3; ++i)
2787 {
2788 var Digit = Math.floor(Counter % 10);
2789 Counter = Math.floor(Counter / 10);
2790 result += '' + Digit;
2791 }
2792 }
2793
2794 for(var i = 0; i < result.length; ++i)
2795 {
2796 str += result[result.length-1-i];
2797 }
2798 return str;
2799 }
2800 else if(Format == FormatCounterBytes)
2801 {
2802 var Shift = 0;
2803 var Divisor = 1;
2804 var CountShifted = ShiftRight10(Counter);
2805 while(CountShifted)
2806 {
2807 Divisor <<= 10;
2808 CountShifted = ShiftRight10(CountShifted);
2809 Shift++;
2810 }
2811 if(Shift)
2812 {
2813 return str + (Counter / Divisor).toFixed(2) + '' + FormatCounterBytesExt[Shift];
2814 }
2815 else
2816 {
2817 return str + Counter.toFixed(2) + '' + FormatCounterBytesExt[0];
2818 }
2819 }
2820 return '?'
2821 }
2822 function DrawCounterView()
2823 {
2824 ProfileEnter("DrawCounterView");
2825 Invalidate++;
2826 nHoverToken = -1;
2827 var context = CanvasDetailedView.getContext('2d');
2828 context.clearRect(0, 0, nWidth, nHeight);
2829
2830 var Height = BoxHeight;
2831 var Width = nWidth;
2832 //clamp offset to prevent scrolling into the void
2833 var nTotalRows = S.CounterInfo.length;
2834 var nTotalRowPixels = nTotalRows * Height;
2835 var nFrameRows = nHeight - BoxHeight;
2836 if(nOffsetCountersY + nFrameRows > nTotalRowPixels && nTotalRowPixels > nFrameRows)
2837 {
2838 nOffsetCountersY = nTotalRowPixels - nFrameRows;
2839 }
2840
2841 var CounterNameWidthTemp = 10;
2842 var CounterValueWidthTemp = 10;
2843 var CounterLimitWidthTemp = 10;
2844
2845 var CounterWidth = 150;
2846 var Y = -nOffsetCountersY + BoxHeight;
2847 var X = 0;
2848 var nColorIndex = 0;
2849 context.fillStyle = 'white';
2850 context.font = Font;
2851 var bMouseIn = 0;
2852 function DrawHeaderSplitSingle(Header, Width)
2853 {
2854 context.fillStyle = 'white';
2855 context.fillText(Header, X, Height-FontAscent);
2856 X += Width;
2857 context.fillStyle = nBackColorOffset;
2858 context.fillRect(X-3, 0, 1, nHeight);
2859 }
2860 function DrawHeaderSplitSingleRight(Header, Width)
2861 {
2862 X += Width;
2863 context.fillStyle = 'white';
2864 context.textAlign = 'right';
2865 context.fillText(Header, X - FontWidth, Height-FontAscent);
2866 context.fillStyle = nBackColorOffset;
2867 context.fillRect(X, 0, 1, nHeight);
2868 context.textAlign = 'left';
2869 }
2870 var TimerLen = 6;
2871 var TimerWidth = TimerLen * FontWidth;
2872 nHoverCounter = -1;
2873 function CounterIndent(Level)
2874 {
2875 return Level * 4 * FontWidth;
2876 }
2877 function Max(a, b)
2878 {
2879 return a > b ? a : b;
2880 }
2881
2882 function DrawCounterRecursive(Index)
2883 {
2884 var Counter = S.CounterInfo[Index];
2885 var Indent = CounterIndent(Counter.level);
2886 CounterNameWidthTemp = Max(CounterNameWidthTemp, Counter.name.length+1 + Indent / (FontWidth+1));
2887 CounterValueWidthTemp = Max(CounterValueWidthTemp, Counter.formatted.length);
2888 CounterLimitWidthTemp = Max(CounterLimitWidthTemp, Counter.formattedlimit.length);
2889
2890 var X = 0;
2891 nColorIndex = 1-nColorIndex;
2892 var HeightExpanded = Counter.Expanded ? Height * 5 : Height
2893
2894 bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + HeightExpanded;
2895 if(bMouseIn)
2896 {
2897 nHoverCounter = Index;
2898 }
2899 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
2900 context.fillStyle = bgcolor;
2901 context.fillRect(0, Y, Width, HeightExpanded);
2902 context.fillStyle = 'white';
2903 var c = Counter.closed ? '*' : ' ';
2904 context.fillText(c + Counter.name, Indent, Y+Height-FontAscent);
2905 X += CounterNameWidth;
2906 X += CounterValueWidth - FontWidth;
2907 context.textAlign = 'right';
2908 context.fillText(Counter.formatted, X, Y+Height-FontAscent);
2909 context.textAlign = 'left';
2910 X += FontWidth * 4;
2911 var Y0 = Y + 1;
2912 if(Counter.limit != 0)
2913 {
2914 context.fillText(Counter.formattedlimit, X, Y+Height-FontAscent);
2915 X += CounterLimitWidth;
2916 var X0 = X + 1;
2917 context.fillStyle = 'white';
2918 context.fillRect(X0, Y0, Counter.boxprc * (CounterWidth-2), Height-2);
2919 context.fillStyle = bgcolor;
2920 context.fillRect(X0+1, Y0+1, Counter.boxprc * (CounterWidth-4), Height-4);
2921 context.fillStyle = 'cyan';
2922 context.fillRect(X0+1, Y0+1, Counter.counterprc * (CounterWidth-4), Height-4);
2923 X += CounterWidth + 10;
2924 }
2925 else
2926 {
2927 X += CounterLimitWidth;
2928 X += CounterWidth + 10;
2929 }
2930 var CounterHistory = Counter.counterhistory;
2931 if(CounterHistory)
2932 {
2933 var Prc = CounterHistory.prc;
2934
2935 context.fillStyle = 'cyan';
2936 context.strokeStyle = 'cyan';
2937 context.globalAlpha = 0.5;
2938 context.beginPath();
2939 var x = X;
2940 var YBase = Y0 + HeightExpanded-1;
2941 var YOffset = -(HeightExpanded-2);
2942
2943 context.moveTo(X, Y0);
2944 for(var i = 0; i < Prc.length; ++i)
2945 {
2946 context.moveTo(x, YBase);
2947 context.lineTo(x, YBase + Prc[i] * YOffset);
2948
2949 x += 1;
2950 }
2951 context.stroke();
2952
2953 x = X;
2954 context.globalAlpha = 1.0;
2955 context.beginPath();
2956 context.moveTo(X, YBase);
2957
2958 for(var i = 0; i < Prc.length; ++i)
2959 {
2960 context.lineTo(x, YBase + Prc[i] * YOffset);
2961 x += 1;
2962 }
2963 context.stroke();
2964 if(bMouseIn)
2965 {
2966 var MouseGraphX = Math.floor(DetailedViewMouseX - X);
2967 if(MouseGraphX >= 0 && MouseGraphX < CounterHistory.history.length)
2968 {
2969 context.fillStyle = 'white';
2970 var Formatted = FormatCounter(Counter.format, CounterHistory.history[MouseGraphX]);
2971 context.fillText(Formatted, X, Y+Height-FontAscent);
2972 }
2973 context.strokeStyle = 'orange';
2974 context.beginPath();
2975 var CrossX = X + MouseGraphX;
2976 var CrossY = YBase + Prc[MouseGraphX] * YOffset;
2977 context.moveTo(CrossX-2, CrossY-2);
2978 context.lineTo(CrossX+2, CrossY+2);
2979 context.moveTo(CrossX+2, CrossY-2);
2980 context.lineTo(CrossX-2, CrossY+2);
2981 context.stroke();
2982
2983 }
2984 X += Prc.length + 5;
2985 context.fillStyle = 'white';
2986 context.fillText( FormatCounter(Counter.format, Counter.minvalue), X, Y + Height - FontAscent);
2987 X += CounterWidth + 5;
2988 context.fillText( FormatCounter(Counter.format, Counter.maxvalue), X, Y + Height - FontAscent);
2989 X += CounterWidth + 5;
2990 }
2991
2992 Y += HeightExpanded;
2993
2994 if(!Counter.closed)
2995 {
2996 var ChildIndex = Counter.firstchild;
2997 while(ChildIndex != -1)
2998 {
2999 DrawCounterRecursive(ChildIndex);
3000 ChildIndex = S.CounterInfo[ChildIndex].sibling;
3001 }
3002 }
3003 }
3004
3005 for(var i = 0; i < S.CounterInfo.length; ++i)
3006 {
3007 if(S.CounterInfo[i].parent == -1)
3008 {
3009 DrawCounterRecursive(i);
3010 }
3011 }
3012
3013 X = 0;
3014 context.fillStyle = nBackColorOffset;
3015 context.fillRect(0, 0, Width, Height);
3016 context.fillStyle = 'white';
3017 DrawHeaderSplitSingle('Name', CounterNameWidth);
3018 DrawHeaderSplitSingleRight('Value', CounterValueWidth + (FontWidth+1));
3019 DrawHeaderSplitSingle('Limit', CounterLimitWidth + CounterWidth + 3 * (FontWidth+1));
3020
3021
3022
3023
3024
3025 var CounterNameWidthNew = CounterNameWidthTemp * (FontWidth+1);
3026 var CounterValueWidthNew = CounterValueWidthTemp * (FontWidth+1);
3027 var CounterLimitWidthNew = CounterLimitWidthTemp * (FontWidth+1);
3028 if(CounterNameWidthNew != CounterNameWidth || CounterValueWidthNew != CounterValueWidth || CounterLimitWidthNew != CounterLimitWidth)
3029 {
3030 // console.log('requesting redraw 0' + CounterNameWidthNew + '= ' + CounterNameWidth );
3031 // console.log('requesting redraw 1' + CounterValueWidthNew + '= ' + CounterValueWidth );
3032 // console.log('requesting redraw 2' + CounterLimitWidthNew + '= ' + CounterLimitWidth );
3033 CounterNameWidth = CounterNameWidthNew;
3034 CounterValueWidth = CounterValueWidthNew;
3035 CounterLimitWidth = CounterLimitWidthNew;
3036 Invalidate = 0;
3037 }
3038
3039 ProfileLeave();
3040 }
3041
3042
3043 //preprocess context switch data to contain array per thread
3044 function PreprocessContextSwitchCacheItem(ThreadId)
3045 {
3046 var CSObject = S.CSwitchCache[ThreadId];
3047 if(ThreadId > 0 && !CSObject)
3048 {
3049 CSArrayIn = new Array();
3050 CSArrayOut = new Array();
3051 CSArrayCpu = new Array();
3052 var nCount = S.CSwitchTime.length;
3053 var j = 0;
3054 var TimeIn = -1.0;
3055 for(var i = 0; i < nCount; ++i)
3056 {
3057 var ThreadIn = S.CSwitchThreadInOutCpu[j];
3058 var ThreadOut = S.CSwitchThreadInOutCpu[j+1];
3059 var Cpu = S.CSwitchThreadInOutCpu[j+2];
3060 if(TimeIn < 0)
3061 {
3062 if(ThreadIn == ThreadId)
3063 {
3064 TimeIn = S.CSwitchTime[i];
3065 }
3066 }
3067 else
3068 {
3069 if(ThreadOut == ThreadId)
3070 {
3071 var TimeOut = S.CSwitchTime[i];
3072 CSArrayIn.push(TimeIn);
3073 CSArrayOut.push(TimeOut);
3074 CSArrayCpu.push(Cpu);
3075 TimeIn = -1;
3076 }
3077 }
3078 j += 3;
3079 }
3080 CSObject = new Object();
3081 CSObject.Size = CSArrayIn.length;
3082 CSObject.In = CSArrayIn;
3083 CSObject.Out = CSArrayOut;
3084 CSObject.Cpu = CSArrayCpu;
3085 S.CSwitchCache[ThreadId] = CSObject;
3086 }
3087
3088 }
3089 function PreprocessContextSwitchCache()
3090 {
3091 ProfileEnter("PreprocessContextSwitchCache");
3092 var AllThreads = {};
3093 var nCount = S.CSwitchTime.length;
3094 for(var i = 0; i < nCount; ++i)
3095 {
3096 var nThreadIn = S.CSwitchThreadInOutCpu[i];
3097 if(!AllThreads[nThreadIn])
3098 {
3099 AllThreads[nThreadIn] = '' + nThreadIn;
3100 var FoundThread = false;
3101 for(var i = 0; i < S.ThreadIds.length; ++i)
3102 {
3103 if(S.ThreadIds[i] == nThreadIn)
3104 {
3105 FoundThread = true;
3106 }
3107 }
3108 if(!FoundThread)
3109 {
3110 S.CSwitchOnlyThreads.push(nThreadIn);
3111 }
3112 }
3113 }
3114 for(var i = 0; i < S.CSwitchOnlyThreads.length; ++i)
3115 {
3116 PreprocessContextSwitchCacheItem(S.CSwitchOnlyThreads[i]);
3117 }
3118 for(var i = 0; i < S.ThreadIds.length; ++i)
3119 {
3120 PreprocessContextSwitchCacheItem(S.ThreadIds[i]);
3121 }
3122 function HandleMissingThread(a)
3123 {
3124 if(!S.CSwitchThreads[a])
3125 {
3126 S.CSwitchThreads[a] = {'tid':a, 'pid':-1, 't':'?', 'p':'?'}
3127 }
3128 }
3129 function CompareThreadInfo(a, b)
3130 {
3131 if(a.pid != b.pid)
3132 return a.pid - b.pid;
3133 else
3134 return a.tid - b.tid;
3135 }
3136 S.CSwitchOnlyThreads.sort( function(a, b){
3137 HandleMissingThread(a);
3138 HandleMissingThread(b);
3139 return CompareThreadInfo(S.CSwitchThreads[a], S.CSwitchThreads[b]);
3140 } );
3141
3142 ProfileLeave();
3143 }
3144
3145 function DrawContextSwitchBars(context, ThreadId, fScaleX, fOffsetY, fDetailedOffset, nHoverColor, MinWidth, bDrawEnabled, bSecond)
3146 {
3147 ProfileEnter("DrawContextSwitchBars");
3148 var CSObject = S.CSwitchCache[ThreadId];
3149 if(CSObject && CSObject.Size > 0)
3150 {
3151 var Size = CSObject.Size;
3152 var In = CSObject.In;
3153 var Out = CSObject.Out;
3154 var Cpu = CSObject.Cpu;
3155 var nNumColors = CSwitchColors.length;
3156 for(var i = 0; i < Size; ++i)
3157 {
3158 var TimeIn = In[i];
3159 var TimeOut = Out[i];
3160 var ActiveCpu = Cpu[i];
3161
3162 var X = (TimeIn - fDetailedOffset) * fScaleX;
3163 if(X > nWidth)
3164 {
3165 break;
3166 }
3167 var W = (TimeOut - TimeIn) * fScaleX;
3168 if(W > MinWidth && X+W > 0)
3169 {
3170 if(nHoverCSCpu == ActiveCpu || bDrawEnabled)
3171 {
3172 if(nHoverCSCpu == ActiveCpu)
3173 {
3174 context.fillStyle = nHoverColor;
3175 }
3176 else
3177 {
3178 context.fillStyle = CSwitchColors[ActiveCpu % nNumColors];
3179 }
3180 context.fillRect(X, fOffsetY, W, CSwitchHeight);
3181 }
3182 if(DetailedViewMouseX >= X && DetailedViewMouseX <= X+W && DetailedViewMouseY < fOffsetY+CSwitchHeight && DetailedViewMouseY >= fOffsetY)
3183 {
3184 nHoverCSCpuNext = ActiveCpu;
3185 RangeCpuNext.Off = bSecond ? fDetailedOffsetSecond : 0;
3186 RangeCpuNext.Begin = TimeIn;
3187 RangeCpuNext.End = TimeOut;
3188 RangeCpuNext.Thread = ThreadId;
3189 RangeGpuNext.Begin = RangeGpuNext.End = -1;
3190 }
3191 }
3192 }
3193 }
3194 else
3195 {
3196 //debug: draw context switch without cswitch
3197 // for(var i = 0; i < 8; ++i)
3198 // {
3199 // context.fillStyle = CSwitchColors[i];
3200 // context.fillRect((nWidth * i / 8) + 10, fOffsetY, nWidth / 8 - 20, CSwitchHeight);
3201 // }
3202 }
3203 ProfileLeave();
3204 }
3205
3206 function DrawDetailedButtons(context, X, Y, Names, Callbacks, Align)
3207 {
3208 if(!Align)
3209 {
3210 Align = "left";
3211 }
3212 var Dir = 1;
3213 var Offset = 0;
3214 var OffsetText = 0;
3215 if(Align == "right")
3216 {
3217 Dir = -1;
3218 }
3219 else if(Align == "center")
3220 {
3221 Offset = -0.5;
3222 Align = "left";
3223 }
3224 let W = Array(Names.length);
3225 var w = 0;
3226 for(let i = 0; i < Names.length; ++i)
3227 {
3228 W[i] = context.measureText(Names[i]).width;
3229 w += W[i];
3230 }
3231 X += w * Offset;
3232
3233 // context.textBaseline = 'top';
3234 context.textAlign = Align;
3235 context.fillStyle = 'white';
3236 var mx = DetailedViewMouseX;
3237 var my = DetailedViewMouseY;
3238 for(let i = 0; i < Names.length; ++i)
3239 {
3240 let w = W[i];
3241 let x0_ = X + w * Dir;
3242 let x0 = Math.min(X, x0_);
3243 let x1 = Math.max(X, x0_);
3244 let y0 = Y;
3245 let y1 = Y + FontHeight;
3246 context.fillStyle = nBackColors[0];
3247 context.fillRect(x0, y0, x1 - x0, y1 - y0);
3248
3249 if(mx >= x0 && mx <= x1 && my >= y0 && my <= y1)
3250 {
3251 DetailedMouseOverButton = 1;
3252 context.fillStyle = 'cyan';
3253 DetailedAddMouseEvent(99, function(){ Callbacks[i](); } );
3254 }
3255 else
3256 {
3257 context.fillStyle = 'white';
3258 }
3259
3260 context.fillText(Names[i], X, Y + FontHeight - 2);
3261 X += Dir * (w+FontWidth);
3262 }
3263
3264 context.fillStyle = 'white';
3265 context.textAlign = 'left';
3266 }
3267
3268 function DrawDetailedViewLargeHeader(context, Text, Y)
3269 {
3270 context.textAlign = "left";
3271 context.fillStyle = "grey";
3272 context.strokeStyle = "grey";
3273 context.textBaseline = "top";
3274 context.font = FontLarge;
3275 context.beginPath();
3276 context.moveTo(0, Y);
3277 context.lineTo(nWidth, Y);
3278 context.stroke();
3279 context.fillText(Text, 0, Y + 2);
3280 context.font = Font;
3281 context.textBaseline = "alphabetic";
3282 return Y + 2 + FontHeightLarge;
3283 }
3284
3285 function DrawDetailedView(S, S0, context, MinWidth, bDrawEnabled)
3286 {
3287 if(!S || !S.Frames)
3288 {
3289 return;
3290 }
3291 let bSecond = S != S0;
3292 if(bDrawEnabled && !bSecond)
3293 {
3294 DrawDetailedBackground(context);
3295 }
3296
3297 let colors = [ '#ff0000', '#ff00ff', '#ffff00'];
3298 let fScaleX = nWidth / fDetailedRange;
3299 let fOffsetY = -nOffsetY + BoxHeight;
3300
3301
3302 let nHoverTokenStack = -1;
3303 if(S == S0)
3304 {
3305 nHoverCounter += nHoverCounterDelta;
3306 if(nHoverCounter >= 255)
3307 {
3308 nHoverCounter = 255;
3309 nHoverCounterDelta = -nHoverCounterDelta;
3310 }
3311 if(nHoverCounter < 128)
3312 {
3313 nHoverCounter = 128;
3314 nHoverCounterDelta = -nHoverCounterDelta;
3315 }
3316 }
3317 let nHoverHigh = nHoverCounter.toString(16);
3318 let nHoverLow = (127+255-nHoverCounter).toString(16);
3319 let nHoverColor = '#' + nHoverHigh + nHoverHigh + nHoverHigh;
3320 let nHoverColorIndex;
3321
3322 context.fillStyle = 'black';
3323 context.font = Font;
3324 // context.textBaseline = 'alphabetic';
3325
3326 let nNumLogs = S.Frames[0].ts.length;
3327 if(S0)
3328 {
3329 let l0 = S0.Frames[0].ts.length;
3330 let l1 = S.Frames[0].ts.length
3331 if(l1 != l0)
3332 debugger;
3333 }
3334 let Off = fDetailedOffset;
3335 let XOffset = 0;
3336 if(bSecond)
3337 {
3338 XOffset = fDetailedOffsetSecond;
3339 Off += XOffset;
3340 }
3341 let fTimeEnd = Off + fDetailedRange;
3342
3343 let FirstFrame = 0;
3344 for(let i = 0; i < S.Frames.length ; i++)
3345 {
3346 if(S.Frames[i].frameend < Off)
3347 {
3348 FirstFrame = i;
3349 }
3350 }
3351
3352 let BoxHeightScaled = BoxHeight;
3353 let Scale = 1;
3354 let fExtra = 0;
3355 let Padding = 15;
3356 let SecondReverseOffset = 0;
3357 if(DrawDetailedFlameMode == 1)
3358 {
3359 BoxHeightScaled = Math.ceil(BoxHeight*0.5);
3360 fExtra = 0.5;
3361 }
3362 else if(DrawDetailedFlameMode == 2)
3363 {
3364 BoxHeightScaled = 0;
3365 fExtra = 1;
3366 }
3367 if(DrawDetailedCompareReverse && bSecond)
3368 {
3369 Scale = -1;
3370 BoxHeightScaled = -BoxHeightScaled;
3371 SecondReverseOffset = 5-BoxHeight;
3372 }
3373 let BoxHeightScaledPos = Math.abs(BoxHeightScaled);
3374 let BatchesTxtColor = ['#ffffff', '#333333'];
3375 let TotalBatches = 0;
3376 let BatchData = {};
3377 {
3378 let L = BatchData;
3379 L.Batches = new Array(g_Colors.length+1);
3380 L.BatchesTxt = new Array();
3381 L.BatchesTxtPos = new Array();
3382 for(let i = 0; i < 2; ++i)
3383 {
3384 L.BatchesTxt[i] = Array();
3385 L.BatchesTxtPos[i] = Array();
3386 }
3387 for(let i = 0; i < L.Batches.length; ++i)
3388 {
3389 L.Batches[i] = Array();
3390 }
3391 }
3392 let AddBatch = function(StackPos, index, X, Y, W, Name, NameLen, Duration, Opacity)
3393 {
3394 TotalBatches++;
3395 let L = BatchData;
3396 let O = Opacity ? Opacity : 1.0;
3397 O = 1-((1-O)*(1-O));
3398 let B = L.Batches[index];
3399 let txtidx = g_ColorsTextIndex[index];
3400 if(txtidx < 0 || txtidx > 1)
3401 debugger;
3402 let BTxt = L.BatchesTxt[txtidx];
3403 let BTxtPos = L.BatchesTxtPos[txtidx];
3404 B.push(X);
3405 B.push(Y);
3406 B.push(W);
3407 B.push(O);
3408 DebugDrawQuadCount++;
3409
3410 let XText = X < 0 ? 0 : X;
3411 let WText = W - (XText-X);
3412 if(XText + WText > nWidth)
3413 {
3414 WText = nWidth - XText;
3415 }
3416 let BarTextLen = Math.floor((WText-2)/FontWidth);
3417
3418 if(BarTextLen >= 2)
3419 {
3420 let TimeText = TimeToMsString(Duration);
3421 let TimeTextLen = TimeText.length;
3422 if(BarTextLen < NameLen)
3423 Name = Name.substr(0, BarTextLen);
3424 let YPos = Y+BoxHeight-FontAscent;
3425 BTxt.push(Name);
3426 BTxtPos.push(XText+2);
3427
3428 BTxtPos.push(YPos);
3429 DebugDrawTextCount++;
3430 if(BarTextLen - NameLen > TimeTextLen)
3431 {
3432 BTxt.push(TimeText);
3433 BTxtPos.push(XText+WText-2 - TimeTextLen * FontWidth);
3434 BTxtPos.push(YPos);
3435 DebugDrawTextCount++;
3436 }
3437 }
3438 };
3439 {
3440 let Times = Timeline.Times;
3441 let Colors = Timeline.Colors;
3442 let Ends = Timeline.Ends;
3443 let Positions = Timeline.Positions;
3444 let Names = Timeline.Names;
3445 let SearchMatch = Timeline.SearchMatch;
3446 let off = 0.7;
3447 let off2 = 2*off;
3448 let MaxPosition = 1;
3449 if(Timeline.Positions.length)
3450 {
3451 fOffsetY = DrawDetailedViewLargeHeader(context, "Timeline", fOffsetY);
3452 }
3453
3454 for(let i = 0; i < Timeline.Positions.length; ++i)
3455 {
3456 let TimeStart = Times[i];
3457 let TimeEnd = Ends[i];
3458 let Position = Positions[i];
3459 if(Position >= 0)
3460 {
3461 MaxPosition = Math.max(Position, MaxPosition);
3462 let Color = Colors[i];
3463 let Name = Names[i];
3464 let P = Positions[i];
3465 let X = (TimeStart - Off) * fScaleX;
3466 let Y = fOffsetY + P * (BoxHeight+2);
3467 let W = (TimeEnd-TimeStart)*fScaleX;
3468 if(FilterInputSearchActive2)
3469 {
3470 Color = SearchMatch[i] ? CIDMatch : CIDFail;
3471 }
3472 if(!bSecond)
3473 {
3474 if(DetailedViewMouseX >= X && DetailedViewMouseX <= X+W && DetailedViewMouseY < Y+BoxHeight && DetailedViewMouseY >= Y)
3475 {
3476 RangeCpuNext.Off = 0;
3477 RangeCpuNext.Begin = TimeStart;
3478 RangeCpuNext.End = TimeEnd;
3479 RangeCpuNext.Thread = -1;
3480 nHoverColorIndex = Color;
3481 Color = cidhovercolor;
3482 }
3483 AddBatch(0, Color, X, Y, W, Name, Name.length, TimeEnd-TimeStart);
3484 }
3485 }
3486 }
3487 fOffsetY += (1+MaxPosition) * (BoxHeight+3);
3488 }
3489 let nMinTimeMs = MinWidth / fScaleX;
3490 let AutoHideCount = 0;
3491 let VisibleThreadCount = 0;
3492 let DrawGuides = 1;
3493 let CurrentHeading;
3494 {
3495 if(!ThreadYBegin)
3496 {
3497 ThreadYBegin = Array(S0.ThreadNames.length);
3498 ThreadYEnd = Array(S0.ThreadNames.length);
3499 }
3500
3501 for(let i = 0; i < nNumLogs; i++)
3502 {
3503 let nLog = ThreadOrderT[i];
3504 let ThreadName = S0.ThreadNames[nLog];
3505 let LogIsGPU = S0.ISGPU[nLog];
3506 let HeadingString = LogIsGPU ? "GPU" : "CPU";
3507 let Active = IsThreadActive(ThreadName) && 0 == S.ThreadLogAutoHidden[nLog];
3508 let ThreadColors = S0.ThreadColors[nLog];
3509 if(HeadingString != CurrentHeading)
3510 {
3511 fOffsetY = DrawDetailedViewLargeHeader(context, HeadingString, fOffsetY);
3512 CurrentHeading = HeadingString;
3513 }
3514
3515
3516 if(0 != S.ThreadLogAutoHidden[nLog] && HideMode == HideModeFullyHidden)
3517 {
3518 AutoHideCount++;
3519 continue;
3520 }
3521 if(HideMode == HideModeFullyHidden && !Active)
3522 {
3523 AutoHideCount++;
3524 continue;
3525 }
3526 VisibleThreadCount++;
3527 let SMul = 2;
3528 let LogHeight = (S0.MaxStack[nLog]) * BoxHeightScaledPos + BoxHeight;
3529 let LogHeight2 = (S0.MaxStack2[nLog]) * BoxHeightScaledPos + BoxHeight;
3530 if(nContextSwitchEnabled)
3531 {
3532 LogHeight += (CSwitchHeight+4);
3533 LogHeight2 += (CSwitchHeight+4);
3534 }
3535 if(!S0.SecondActive)
3536 {
3537 LogHeight2 = 0;
3538 }
3539 let OY = fOffsetY;
3540 if(!bSecond)
3541 {
3542 OY += LogHeight2+1;
3543 }
3544 else
3545 {
3546 if(DrawDetailedCompareReverse)
3547 {
3548 OY += LogHeight2 - 5;
3549 }
3550 }
3551
3552 let fOffsetYDelta = Active ? (LogHeight + LogHeight2 + Padding) : BoxHeight;
3553
3554 ThreadYBegin[nLog] = fOffsetY;
3555 ThreadYEnd[nLog] = fOffsetY + fOffsetYDelta;
3556
3557 let ThreadHover = false;
3558 if(bDrawEnabled)
3559 {
3560 if(Active || !bSecond)
3561 {
3562 let Color = bSecond ? ThreadColors.coloroff : ThreadColors.color;
3563 let ColorLine = !bSecond ? ThreadColors.colordark : ThreadColors.color;
3564 let BaseY = (bSecond||!Active) ? (fOffsetY+1) : (fOffsetY+1+LogHeight2);
3565 let HeightY = !Active ? BoxHeight : (bSecond ? LogHeight2 : (LogHeight + Padding));
3566 let TransparentLine = S2.Frames != null && !bSecond;
3567 if(TransparentLine)
3568 {
3569 context.globalAlpha = 0.4;
3570 }
3571 context.strokeStyle = ColorLine;
3572 context.beginPath();
3573 context.moveTo(0, BaseY+HeightY-1);
3574 context.lineTo(nWidth, BaseY+HeightY-1);
3575 context.stroke();
3576 if(TransparentLine)
3577 {
3578 context.globalAlpha = 1.0;
3579 }
3580 let Gradient = context.createLinearGradient(0,BaseY,0,40 + BaseY);
3581 Gradient.addColorStop(0, ThreadColors.colortrans);
3582 Gradient.addColorStop(1,'transparent');
3583 if(bSecond)
3584 ThreadColors.gradientoff = Gradient;
3585 else
3586 ThreadColors.gradient = Gradient;
3587 context.fillStyle = Gradient;
3588 context.fillRect(0,BaseY,nWidth,HeightY);
3589 }
3590 }
3591 let D = fOffsetY + BoxHeight - DetailedViewMouseY;
3592
3593 if(bDrawEnabled && G_DEBUG && 0)
3594 {
3595 debugger;
3596 }
3597 if(!bSecond)
3598 {
3599 if(D > 0 && D < BoxHeight)
3600 {
3601 if(!bDrawEnabled)
3602 {
3603 context.globalAlpha = 0.3;
3604 context.fillStyle = 'grey';
3605 context.fillRect(0, fOffsetY+2, nWidth, Active ? LogHeight2 + LogHeight + Padding : BoxHeight);
3606 context.globalAlpha = 1.0;
3607 }
3608 ThreadHover = 1;
3609 }
3610 }
3611 let HasSetHover = 0;
3612
3613
3614 if(Active)
3615 {
3616 if(DrawDetailedNewDraw)
3617 {
3618 OY += 4;
3619
3620 if(nContextSwitchEnabled)
3621 {
3622 DrawContextSwitchBars(context, S.ThreadIds[nLog], fScaleX, OY, Off, nHoverColor, MinWidth, bDrawEnabled, bSecond);
3623 OY += Scale * (CSwitchHeight+2);
3624 }
3625 OY += SecondReverseOffset;
3626 // Duration of 1 pixel
3627 let ThresholdPixelDuration = fDetailedRange / nWidth;
3628 let ThresholdLimit = ThresholdPixelDuration * 1.0; // if below this we dont go further down
3629 let Rows = S.LogRows[nLog];
3630 for(let r in Rows)
3631 {
3632 {
3633 let Row = Rows[r];
3634 let Size = Row.Tree.length;
3635 let Tree = Row.Tree;
3636 const Y = OY + r * BoxHeightScaled;
3637 const MY = DetailedViewMouseY < Y+BoxHeight && DetailedViewMouseY >= Y;
3638
3639
3640 let DrawRange = function(Depth, Begin, End)
3641 {
3642 let TreeLevel = Tree[Depth];
3643 for(let j = Begin; j < End; ++j)
3644 {
3645 let TimeBegin = TreeLevel.Begin[j];
3646 let Duration = TreeLevel.Duration[j];
3647 let TimeEnd = TimeBegin + Duration;
3648 if(TimeBegin < fTimeEnd && TimeEnd > Off)
3649 {
3650
3651 if(Depth > 0 && TreeLevel.Duration[j] > ThresholdLimit)
3652 {
3653 DrawRange(Depth-1, j*2, j*2 + 2);
3654 }
3655 else
3656 {
3657 let Index = TreeLevel.Index[j];
3658 let cid = TreeLevel.ColorIds[j];
3659 let Opacity = Depth == 0 ? 1.0 : TreeLevel.SumDuration[j] / TreeLevel.Duration[j];
3660
3661 if(FilterInputSearchActive2)
3662 {
3663 if(Depth == 0)
3664 cid = S0.TimerInfo[Index].search;
3665 else
3666 cid = CIDFail;
3667 }
3668 else
3669 {
3670 if(GroupColors == 1 && Depth == 0)
3671 cid = S0.TimerInfo[Index].cid;
3672 if(GroupColors == 2)
3673 cid = ThreadColors.colordark_cid;
3674 if(GroupColors == 3)
3675 cid = TreeLevel.SectionColor[j];
3676 }
3677 if(Index == nHoverToken)
3678 {
3679 nHoverColorIndex = cid;
3680 cid = cidhovercolor;
3681 }
3682
3683
3684 let Name = Depth == 0 ? S0.TimerInfo[Index].name : "";
3685 let NameLen = Depth == 0 ? S0.TimerInfo[Index].len : 0;
3686 let X = (TimeBegin - Off) * fScaleX;
3687 let W = (TimeEnd-TimeBegin)*fScaleX;
3688 if(W > 1 || Opacity > 0.1)
3689 {
3690 AddBatch(Depth, cid, X, Y, W, Name, NameLen, TimeEnd-TimeBegin, Opacity);
3691 }
3692
3693 const M = MY && DetailedViewMouseX >= X && DetailedViewMouseX <= X+W;
3694 if(Depth == 0 && M)
3695 {
3696 RangeCpuNext.Off = bSecond ? fDetailedOffsetSecond : 0;
3697 RangeCpuNext.Begin = TimeBegin;
3698 RangeCpuNext.End = TimeEnd;
3699 RangeCpuNext.Thread = nLog;
3700 RangeCpuNext.Off = XOffset;
3701 if(TreeLevel.CpuDuration && TreeLevel.CpuDuration[j]) // detect if its a gpu marker, with embedded cpu ticks.
3702 {
3703 RangeGpuNext.Begin = RangeCpuNext.Begin;
3704 RangeGpuNext.End = RangeCpuNext.End;
3705 RangeGpuNext.Thread = nLog;
3706 RangeGpuNext.Off = XOffset;
3707
3708 RangeCpuNext.Begin = TreeLevel.CpuBegin[j];
3709 RangeCpuNext.End = TreeLevel.CpuBegin[j] + TreeLevel.CpuDuration[j];
3710 RangeCpuNext.Thread = TreeLevel.CpuThread[j];
3711 RangeCpuNext.Off = XOffset;
3712 }
3713 else
3714 {
3715 RangeGpuNext.Begin = -1;
3716 RangeGpuNext.End = -1
3717 }
3718 nHoverTokenNext = Index;
3719 nHoverTokenStack = r;
3720 nHoverTokenIndexNext = TreeLevel.Source[j];
3721 nHoverTokenLogIndexNext = nLog;
3722 HoverTokenNextOwner = S;
3723 HasSetHover = 1;
3724
3725
3726 if(Index == FilterSearchPassIndex)
3727 {
3728 console.log("kill this");
3729 let Range = RangeInit();
3730 Range.Begin = TimeBegin;
3731 Range.End = TimeEnd;
3732 Range.Thread = nLog;
3733 Range.YBegin = Y - ThreadYBegin[nLog];
3734 Range.Second = bSecond;
3735
3736 if(FilterSearchArray.length < 500)
3737 {
3738 FilterSearchArray.push(Range);
3739 if(FilterSearchArray.length == 500)
3740 {
3741 ShowFlashMessage('Capping Search Result to 500', 30);
3742 }
3743 }
3744 }
3745
3746
3747
3748 }
3749 }
3750 }
3751 }
3752 }
3753 DrawRange(Size-1, 0, Tree[Size-1].Length);
3754 // if tree is uneven, the tails won't have parents.
3755 for(let i = Size-2; i >= 0; --i)
3756 {
3757 let TreeLen = Tree[i].Length;
3758 if((TreeLen % 2) == 1)
3759 DrawRange(i, TreeLen-1, TreeLen);
3760 }
3761
3762 }
3763 }
3764 }
3765 else
3766 {
3767
3768 let LodIndex = 0;
3769 let MinDelta = 0;
3770 let NextLod = 1;
3771 while(NextLod < S.LodData.length && S.LodData[NextLod].MinDelta[nLog] < nMinTimeMs)
3772 {
3773 LodIndex = NextLod;
3774 NextLod = NextLod + 1;
3775 MinDelta = S.LodData[LodIndex].MinDelta[nLog];
3776 }
3777 if(LodIndex == S.LodData.length)
3778 {
3779 LodIndex = S.LodData.length-1;
3780 }
3781 if(DisableLod || FilterSearchPassIndex != -1)
3782 {
3783 LodIndex = 0;
3784 }
3785
3786 OY += 4;
3787
3788 if(nContextSwitchEnabled)
3789 {
3790 DrawContextSwitchBars(context, S.ThreadIds[nLog], fScaleX, OY, Off, nHoverColor, MinWidth, bDrawEnabled, bSecond);
3791 OY += Scale * (CSwitchHeight+2);
3792 }
3793 OY += SecondReverseOffset;
3794 let MaxDepth = 1;
3795 let StackPos = 0;
3796 let Stack = Array(20);
3797 let Lod = S.LodData[LodIndex];
3798
3799 let TypeArray = Lod.TypeArray[nLog];
3800 let IndexArray = Lod.IndexArray[nLog];
3801 let TimeArray = Lod.TimeArray[nLog];
3802
3803 let LocalFirstFrame = S.Frames[FirstFrame].FirstFrameIndex[nLog];
3804 let IndexStart = S.ISGPU[nLog] ? 0 : Lod.LogStart[LocalFirstFrame][nLog];
3805 let IndexEnd = TimeArray.length;
3806 IndexEnd = TimeArray.length;
3807
3808
3809
3810 for(let j = IndexStart; j < IndexEnd; ++j)
3811 {
3812 let type = TypeArray[j];
3813 let index = IndexArray[j];
3814 let time = TimeArray[j];
3815 if(type == 1)
3816 {
3817 //push
3818 Stack[StackPos] = j;
3819 StackPos++;
3820 if(StackPos > MaxDepth)
3821 {
3822 MaxDepth = StackPos;
3823 }
3824 }
3825 else if(type == 0)
3826 {
3827 if(StackPos>0)
3828 {
3829 StackPos--;
3830
3831 let StartIndex = Stack[StackPos];
3832 let timestart = TimeArray[StartIndex];
3833 let timeend = time;
3834 let X = (timestart - Off) * fScaleX;
3835 let Y = OY + StackPos * BoxHeightScaled;
3836
3837 let W = (timeend-timestart)*fScaleX;
3838
3839 if(X < nWidth && X+W > 0)
3840 {
3841 if(index == FilterSearchPassIndex)
3842 {
3843 let Range = RangeInit();
3844 Range.Begin = timestart;
3845 Range.End = timeend;
3846 Range.Thread = nLog;
3847 Range.YBegin = Y - ThreadYBegin[nLog];
3848 Range.Second = bSecond;
3849
3850 if(FilterSearchArray.length < 500)
3851 {
3852 FilterSearchArray.push(Range);
3853 if(FilterSearchArray.length == 500)
3854 {
3855 ShowFlashMessage('Capping Search Result to 500', 30);
3856 }
3857 }
3858 }
3859 if(W > MinWidth)
3860 {
3861 if(bDrawEnabled || index == nHoverToken)
3862 {
3863 let cid = GroupColors == 2 ? ThreadColors.colordark_cid : S0.TimerInfo[index].cid;
3864 if(index == nHoverToken)
3865 {
3866 nHoverColorIndex = cid;
3867 cid = cidhovercolor;
3868 }
3869 AddBatch(StackPos, cid, X, Y, W, S0.TimerInfo[index].name, S0.TimerInfo[index].len, timeend-timestart);
3870 }
3871
3872
3873 if(DetailedViewMouseX >= X && DetailedViewMouseX <= X+W && DetailedViewMouseY < Y+BoxHeight && DetailedViewMouseY >= Y && StackPos > nHoverTokenStack)
3874 {
3875 RangeCpuNext.Off = bSecond ? fDetailedOffsetSecond : 0;
3876 RangeCpuNext.Begin = timestart;
3877 RangeCpuNext.End = timeend;
3878 RangeCpuNext.Thread = nLog;
3879 RangeCpuNext.Off = XOffset;
3880 if((TypeArray[StartIndex+1]&3) == 3 && (TypeArray[j+1]&3) == 3)
3881 {
3882 RangeGpuNext.Begin = RangeCpuNext.Begin;
3883 RangeGpuNext.End = RangeCpuNext.End;
3884 RangeGpuNext.Thread = nLog;
3885 RangeGpuNext.Off = XOffset;
3886 //cpu tick is stored following
3887 RangeCpuNext.Begin = TimeArray[StartIndex+1];
3888 RangeCpuNext.End = TimeArray[j+1];
3889 RangeCpuNext.Thread = IndexArray[StartIndex+1];
3890 RangeCpuNext.Off = XOffset;
3891 }
3892 else
3893 {
3894 RangeGpuNext.Begin = -1;
3895 RangeGpuNext.End = -1
3896 }
3897
3898 nHoverTokenNext = index;
3899 nHoverTokenStack = StackPos;
3900 nHoverTokenIndexNext = j;
3901 nHoverTokenLogIndexNext = nLog;
3902 HoverTokenNextOwner = S;
3903 HasSetHover = 1;
3904 }
3905 }
3906 }
3907 if(StackPos == 0 && time > fTimeEnd)
3908 break;
3909 }
3910 }
3911 }
3912 // if(HasSetHover)
3913 // {
3914 // for(let i = 0; i < S.Frames.length-1; ++i)
3915 // {
3916 // let IndexStart = Lod.LogStart[i][nLog];
3917 // if(nHoverTokenIndexNext >= IndexStart)
3918 // {
3919 // nHoverFrame = i;
3920 // }
3921 // }
3922 // }
3923 }
3924 }
3925 let w = context.measureText(ThreadName).width;
3926 context.fillStyle = nBackColors[0];
3927 context.fillStyle = 'white';
3928 context.fillText(ThreadName, 0, fOffsetY+FontHeight-1);
3929 if(ThreadHover)
3930 {
3931 DrawDetailedButtons(context, nWidth, fOffsetY+1, ["\u2191\u2191\u2191", "\u2193\u2193\u2193", "\u2191", "\u2193"],
3932 [function(){ThreadOrderMoveUp(ThreadName,1);}, function(){ThreadOrderMoveDown(ThreadName,1);},
3933 function(){ThreadOrderMoveUp(ThreadName);}, function(){ThreadOrderMoveDown(ThreadName);}],
3934 "right");
3935 // DetailedAddMouseEvent(1, function(){ Callbacks[i](); } );
3936 DetailedAddMouseEvent(1, function()
3937 {
3938 ToggleThread(ThreadName);
3939 });
3940 }
3941 // context.textBaseline = 'alphabetic';
3942 fOffsetY += fOffsetYDelta;
3943 // ThreadY[nLog+1] = fOffsetY;
3944 }
3945 if(AutoHideCount)
3946 {
3947 fOffsetY += FontHeight;
3948 let Text = AutoHideCount + " Threads Auto Hidden. Toggle in Thread Menu to show";
3949 let w = context.measureText(Text).width;
3950 context.fillStyle = "orange";
3951 context.fillText(Text, 0, fOffsetY+FontHeight-1);
3952 }
3953 if(VisibleThreadCount == 0 && HideMode == HideModeFullyHidden)
3954 {
3955 fOffsetY += FontHeight;
3956 let Text = "All Threads Hidden. Toggle in Thread Menu to show";
3957 let w = context.measureText(Text).width;
3958 context.fillStyle = "red";
3959 context.fillText(Text, 0, fOffsetY+FontHeight-1);
3960 }
3961
3962 if(nContextSwitchEnabled && !bSecond) //non instrumented threads.
3963 {
3964 let CurrentPid = -112;
3965 let ContextSwitchThreads = S.CSwitchOnlyThreads;
3966 function DrawHeader(str, X, Y)
3967 {
3968 let width = str.length * FontWidth;
3969 context.globalAlpha = 0.5;
3970 context.fillStyle = 'grey';
3971 context.fillRect(X, Y-FontHeight + 2, width, FontHeight);
3972 context.globalAlpha = 1.0;
3973 context.fillStyle = 'white';
3974 context.fillText(str, X, Y);
3975
3976
3977 }
3978 for(let i = 0; i < ContextSwitchThreads.length; ++i)
3979 {
3980 let ThreadId = ContextSwitchThreads[i];
3981 let ThreadName = '' + ThreadId;
3982 let TI = S.CSwitchThreads[ThreadId];
3983
3984 if(TI)
3985 {
3986 if(CurrentPid != TI.pid)
3987 {
3988 fOffsetY += BoxHeight + 1;
3989 CurrentPid = TI.pid;
3990 let str = TI.pid.toString(16) +':' +TI.p;
3991 DrawHeader(str, 0, fOffsetY+5);
3992 fOffsetY += BoxHeight + 1;
3993 }
3994 }
3995
3996 DrawContextSwitchBars(context, ThreadId, fScaleX, fOffsetY, Off, nHoverColor, MinWidth, bDrawEnabled);
3997
3998 if(TI)
3999 {
4000 DrawHeader(TI.tid.toString(16) +':' +TI.t, 10, fOffsetY+5);
4001 }
4002 fOffsetY += BoxHeight + 1;
4003 }
4004 }
4005 {
4006 let h = nHeight;
4007
4008 }
4009 let TOP_LIMIT = 100;
4010 if(fOffsetY < TOP_LIMIT)
4011 {
4012 let Diff = fOffsetY - TOP_LIMIT;
4013 nOffsetY += Math.floor(Diff);
4014 nOffsetY = Math.max(0, nOffsetY);
4015 }
4016 let FillRects = function(a, color, colordark)
4017 {
4018 context.fillStyle = color;
4019 let opac = -1;
4020 for(let j = 0; j < a.length; j += 4)
4021 {
4022 let X = a[j];
4023 let Y = a[j+1];
4024 let W = a[j+2];
4025 let O = a[j+3];
4026 if(O != opac)
4027 {
4028 opac = O;
4029 context.globalAlpha = opac;
4030 }
4031 context.fillRect(X, Y, W, BoxHeight-1);
4032 }
4033 };
4034 let rect_calls = 0;
4035 let text_calls = 0;
4036
4037 {
4038 let Batches = BatchData.Batches;
4039 for(let i = 0; i < Batches.length; ++i)
4040 {
4041 let a = Batches[i];
4042 if(a.length)
4043 {
4044 let Color = i == 0 ? nHoverColor : g_Colors[i];
4045 let ColorDark = i == 0 ? nHoverColor : g_ColorsDark[i];
4046 if(i == 0)
4047 {
4048 if(nHoverColorIndex)
4049 {
4050 let mult = nHoverCounter / 255.0;
4051 let m2 =mult -0.5;
4052 let m4 = m2 * 0.5;
4053 let f = function()
4054 {
4055 let H = g_ColorH[nHoverColorIndex];
4056 let S = g_ColorS[nHoverColorIndex];
4057 let L = g_ColorL[nHoverColorIndex];
4058 let offset = 0;
4059 if(S> 0.5)
4060 offset = 0.5 - S;
4061 let offsetL = 0;
4062 if(L > 0.75)
4063 offsetL = 0.75 - L;
4064 L = L + m4 + offsetL;
4065 L = L > 1 ? 1 : (L < 0 ? 0 : L);
4066 S = S + m2 + offset;
4067 S = S > 1 ? 1 : (S < 0 ? 0 : S);
4068 return ConvertHslToColor(H, S, L);
4069 };
4070 let ColorCV = f();
4071 ColorDark = Color = ColorCV; ;
4072 }
4073 }
4074 FillRects(a, Color, ColorDark);
4075 rect_calls += a.length;
4076
4077 }
4078 }
4079 context.globalAlpha = 1.0;
4080 let BatchesTxt = BatchData.BatchesTxt;
4081 let BatchesTxtPos = BatchData.BatchesTxtPos;
4082 for(let i = 0; i < BatchesTxt.length; ++i)
4083 {
4084 context.fillStyle = BatchesTxtColor[i];
4085 let TxtArray = BatchesTxt[i];
4086 let PosArray = BatchesTxtPos[i];
4087 for(let j = 0; j < TxtArray.length; ++j)
4088 {
4089 let k = j * 2;
4090 context.fillText(TxtArray[j], PosArray[k],PosArray[k+1]);
4091
4092 }
4093 text_calls += TxtArray.length;
4094 }
4095
4096 }
4097 // console.log("rect_calls ", rect_calls, " text_calls ", text_calls);
4098
4099 }
4100 // console.log("Total Batches ", TotalBatches);
4101
4102 }
4103
4104
4105 function DrawTextBox(context, text, x, y, align)
4106 {
4107 let textsize = context.measureText(text).width;
4108 let offsetx = 0;
4109 let offsety = -FontHeight;
4110 if(align == 'center')
4111 {
4112 offsetx = -textsize / 2.0;
4113 }
4114 else if(align == 'right')
4115 {
4116 offsetx = -textsize;
4117 }
4118 context.fillStyle = nBackColors[0];
4119 context.fillRect(x + offsetx, y + offsety, textsize+2, FontHeight + 2);
4120 context.fillStyle = 'white';
4121 context.fillText(text, x, y);
4122
4123 }
4124
4125 function DrawFilterSearchRanges(context, Ranges, ColorBack, ColorFront, ThreadY)
4126 {
4127 if(0 == Ranges.length)
4128 return;
4129 //todo: arrow key support
4130 var MarginTop = 1.0 * FontHeight;
4131 var MarginBottom = nHeight - 1.0 * FontHeight;
4132
4133
4134 var Time = new Date();
4135 var Delta = Time - FilterSearchStartTime;
4136 var BlinkTime = 2.5 * 1000;
4137 var Blinks = 5;
4138 var HoverFloat = 0.2;
4139 var Blinking = 0;
4140 if(Delta < BlinkTime)
4141 {
4142 Blinking = 1;
4143 var b0 = Blinks* Math.PI * Delta;
4144 var b1 = b0 / BlinkTime;
4145 var Mag = Math.abs(Math.sin(b1));
4146 HoverFloat = Mag * 0.5 + 0.2;
4147 }
4148 var Lines = new Array();
4149 var Rects = new Array();
4150
4151
4152 for(var i = 0; i < Ranges.length; ++i)
4153 {
4154 var Range = Ranges[i];
4155 let Off = Range.Second ? fDetailedOffsetSecond : 0
4156 var fBegin = Range.Begin - Off;
4157 var fEnd = Range.End - Off;
4158 var OffsetTop = Range.YBegin + ThreadY[Range.Thread];
4159 var OffsetBottom = OffsetTop + BoxHeight;
4160
4161 if(fBegin < fEnd)
4162 {
4163 {
4164 OffsetTop = Math.max(OffsetTop, 0);
4165 OffsetBottom = Math.max(OffsetBottom, MarginTop);
4166 OffsetTop = Math.min(OffsetTop, MarginBottom);
4167 OffsetBottom = Math.min(OffsetBottom, nHeight);
4168 var fScaleX = nWidth / fDetailedRange;
4169 var X = (fBegin - fDetailedOffset) * fScaleX;
4170 var Y = OffsetTop;
4171 var W = (fEnd - fBegin) * fScaleX;
4172 if(W > 1)
4173 {
4174 Rects.push(X-3);
4175 Rects.push(OffsetTop-3);
4176 Rects.push(W+5);
4177 Rects.push(5 + OffsetBottom - OffsetTop);
4178 }
4179 else
4180 {
4181 X += W * 0.5;
4182 Lines.push(X);
4183 context.beginPath();
4184 context.moveTo(X, 0);
4185 context.lineTo(X, nHeight);
4186 context.stroke();
4187 }
4188 }
4189 }
4190 }
4191
4192 context.fillStyle = ColorBack;
4193 context.strokeStyle = ColorBack;
4194
4195 context.globalAlpha = HoverFloat;
4196
4197 for(var i = 0; i < Rects.length;)
4198 {
4199 var X = Rects[i++];
4200 var Y = Rects[i++];
4201 var W = Rects[i++];
4202 var H = Rects[i++];
4203 context.fillRect(X, Y, W, H);
4204 }
4205 context.globalAlpha = 1;
4206 for(var i = 0; i < Rects.length;)
4207 {
4208 var X = Rects[i++];
4209 var Y = Rects[i++];
4210 var W = Rects[i++];
4211 var H = Rects[i++];
4212 context.strokeRect(X, Y, W, H);
4213 }
4214
4215 for(var i = 0; i < Lines.length; ++i)
4216 {
4217 context.beginPath();
4218 context.moveTo(Lines[i], 0);
4219 context.lineTo(Lines[i], nHeight);
4220 context.stroke();
4221 }
4222 if(Blinking>0)
4223 {
4224 Invalidate = 1;
4225 }
4226
4227 }
4228
4229
4230 function DrawRange(context, Range, ColorBack, ColorFront, Name, Offset)
4231 {
4232 if(!Offset)
4233 Offset = 0;
4234 var fBegin = Range.Begin;
4235 var fEnd = Range.End;
4236 var OffsetTop = Range.YBegin;
4237 var OffsetBottom = Range.YEnd;
4238 var Off = Range.Off + fDetailedOffset;
4239 if(fBegin < fEnd)
4240 {
4241 var MarginTop = (1.0+Offset) * (FontHeight+1);
4242 var MarginBottom = nHeight - (Offset+1.5) * (FontHeight+1);
4243 if(OffsetTop < MarginTop)
4244 {
4245 Offset += 1;
4246 OffsetTop = MarginTop;
4247 }
4248 if(OffsetBottom > MarginBottom)
4249 {
4250 OffsetBottom = MarginBottom;
4251 }
4252 var fRulerOffset = FontHeight * 0.5;
4253 var fScaleX = nWidth / fDetailedRange;
4254 var X = (fBegin - Off) * fScaleX;
4255 var YSpace = (FontHeight+2);
4256 var Y = OffsetTop;
4257 var YBottom = OffsetBottom;
4258 var W = (fEnd - fBegin) * fScaleX;
4259 context.globalAlpha = 0.1;
4260 context.fillStyle = ColorBack;
4261 context.fillRect(X, OffsetTop + fRulerOffset, W, OffsetBottom - OffsetTop);
4262 context.globalAlpha = 1;
4263 context.strokeStyle = ColorFront;
4264 context.beginPath();
4265 context.moveTo(X, 0);
4266 context.lineTo(X, nHeight);
4267 context.moveTo(X+W, 0);
4268 context.lineTo(X+W, nHeight);
4269 context.stroke();
4270 var Duration = (fEnd - fBegin).toFixed(2) + "ms";
4271 var Center = ((fBegin + fEnd) / 2.0) - Off;
4272 var DurationWidth = context.measureText(Duration+ " ").width;
4273
4274 context.fillStyle = 'white';
4275 context.textAlign = 'right';
4276 var TextPosY = Y + YSpace;
4277 DrawTextBox(context, (fBegin-Range.Off).toFixed(2), X-3, TextPosY, 'right');
4278 var YS = [Y, YBottom];
4279 for(var i = 0; i < YS.length; ++i)
4280 {
4281 var Y = YS[i];
4282 var Y0 = Y + fRulerOffset;
4283 var W0 = W - DurationWidth + FontWidth*1.5;
4284 if(W0 > 6)
4285 {
4286 context.textAlign = 'center';
4287 DrawTextBox(context, Duration,Center * fScaleX, Y + YSpace, 'center');
4288 W0 = W0 / 2.0;
4289 var X0 = X + W0;
4290 var X1 = X + W - W0;
4291 context.strokeStyle = ColorFront;
4292 context.beginPath();
4293 context.moveTo(X, Y0);
4294 context.lineTo(X0, Y0);
4295 context.moveTo(X0, Y0-2);
4296 context.lineTo(X0, Y0+2);
4297 context.moveTo(X1, Y0-2);
4298 context.lineTo(X1, Y0+2);
4299 context.moveTo(X1, Y0);
4300 context.lineTo(X + W, Y0);
4301 context.stroke();
4302 }
4303 else
4304 {
4305 if(i == 1)
4306 {
4307 context.textAlign = 'right';
4308 DrawTextBox(context, Duration, X - 3, Y0, 'right');
4309 context.textAlign = 'left';
4310 DrawTextBox(context, Duration, X + W + 2, Y0, 'left');
4311 }
4312 context.strokeStyle = ColorFront;
4313 context.beginPath();
4314 context.moveTo(X, Y0);
4315 context.lineTo(X+W, Y0);
4316 context.stroke();
4317 }
4318 }
4319 context.textAlign = 'left';
4320 DrawTextBox(context, (fEnd-Range.Off).toFixed(2), X + W + 2, TextPosY, 'left');
4321 DrawTextBox(context, Name, X + W + 2, OffsetTop + YSpace + FontHeight, 'left');
4322 }
4323 return Offset;
4324 }
4325 function DetailedAddMouseEvent(P, E)
4326 {
4327 if(!DetailedMouseEvent)
4328 {
4329 DetailedMouseEvent = {"P":P, "E":E};
4330 }
4331 else if(DetailedMouseEvent.P < P)
4332 {
4333 DetailedMouseEvent.P = P;
4334 DetailedMouseEvent.E = E;
4335 }
4336
4337 }
4338
4339 function CreateGraphData(Samples, Name, Color)
4340 {
4341 let gd = {};
4342 gd.Samples = Samples;
4343 gd.Name = Name;
4344 gd.Color = Color;
4345 return gd;
4346 }
4347
4348 function CreateDrawGraphParameters()
4349 {
4350 let P = {};
4351 P.Rect = WindowRect(0, 0, 1, 1);
4352 P.RangeMin = 0.0;
4353 P.RangeMax = 0.0;
4354 P.Mark = [16.66, 33.33];
4355 P.Ext = "ms";
4356 P.Border = 2;
4357 P.Frame = 1;
4358 return P;
4359 }
4360
4361
4362
4363 function DrawGraph(context, Parameters, data, Mouse)
4364 {
4365
4366 ProfileEnter("DrawGraph");
4367 let Rect = Parameters.Rect;
4368 let RangeMin = Parameters.RangeMin;
4369 let RangeMax = Parameters.RangeMax;
4370 let MaxLen = 0;
4371 let MaxSample = 0;
4372 let MinSample = 1e25;
4373 for(let i in data)
4374 {
4375 let d = data[i];
4376 MaxLen = Math.max(MaxLen, d.Samples.length);
4377 for(let j in d.Samples)
4378 {
4379 MaxSample = Math.max(MaxSample, d.Samples[j]);
4380 MinSample = Math.max(MinSample, d.Samples[j]);
4381 }
4382 }
4383 if(0 == MaxLen)
4384 return;
4385
4386 if(RangeMax <= RangeMin)
4387 {
4388 RangeMin = MinSample;
4389 RangeMax = MaxSample;
4390 }
4391
4392
4393 let Ext = Parameters.Ext;
4394 let Border = Parameters.Border;
4395 let Frame = Parameters.Frame;
4396 if(Frame)
4397 Border += 10;
4398
4399 let wx = Rect.x;
4400 let wy = Rect.y;
4401 let wh = Rect.h;
4402 let ww = Rect.w;
4403
4404 let x = Rect.x + Border;
4405 let y = Rect.y + Border;
4406 let h = Rect.h - 2*Border;
4407 let w = Rect.w - 2*Border;
4408
4409 let MouseX = Mouse.X-x;
4410 let MouseY = Mouse.Y-y;
4411 let MouseInside = Mouse.X >= x && Mouse.Y >= y && Mouse.X < x + w && Mouse.Y < y + h;
4412 let MouseXPrc = (Mouse.X - x) / (w-1);
4413
4414 context.clearRect(wx, wy, ww, wh);
4415
4416
4417 let SampleWidth = w / (MaxLen-1);
4418 let MouseIndex = Math.max(0, Math.min(MaxLen-1, Math.floor(MouseXPrc * MaxLen)));
4419
4420 let HeightScale = h / (RangeMax-RangeMin);
4421 let Y = y + h;
4422 let YStart = Y;
4423
4424 for(let dataindex in data)
4425 {
4426 let LocalElement = data[dataindex];
4427 let Samples = LocalElement.Samples;
4428 let X = x + w - (Samples.length-1)*SampleWidth;
4429 Y = y + h;
4430
4431 context.globalAlpha = 1;
4432 context.strokeStyle = LocalElement.Color;
4433 context.fillStyle = LocalElement.Color;
4434 context.beginPath();
4435 for(let i = 0; i < Samples.length; ++i)
4436 {
4437 Y = Math.max(YStart - Samples[i] * HeightScale, y);
4438 if(i == 0)
4439 context.moveTo(X, Y);
4440 else
4441 context.lineTo(X, Y);
4442 X += SampleWidth;
4443
4444 }
4445 let GRAPH_ALPHA = 0.2;
4446 context.stroke();
4447 context.lineTo(X-SampleWidth, YStart);
4448 context.lineTo(x, YStart);
4449 context.globalAlpha = GRAPH_ALPHA;
4450 context.fill();
4451
4452 if(MouseInside)
4453 {
4454 let MouseSample = Samples[MouseIndex];
4455 let Y = Math.max(YStart - MouseSample * HeightScale, y);
4456 let X = x + w + (MouseIndex - (Samples.length-1))*SampleWidth;
4457
4458 context.globalAlpha = 0.8;
4459 context.beginPath();
4460 context.arc(X, Y, 2, 0, 2 * Math.PI);
4461 context.fill();
4462
4463 context.globalAlpha = 1;
4464
4465 context.beginPath();
4466 context.arc(X, Y, 3, 0, 2 * Math.PI);
4467 context.stroke();
4468 }
4469
4470
4471 }
4472 context.globalAlpha = 1;
4473 context.fillStyle = 'wheat';
4474 context.strokeStyle = 'wheat';
4475 context.textAlign='right';
4476 context.fillText(RangeMax + Ext, x+w, y + FontHeight);
4477 for(let m in Parameters.Mark)
4478 {
4479 let Sample = Parameters.Mark[m];
4480 let Y = YStart - Sample * HeightScale;
4481 context.fillText(Sample + Ext, x+w, Y + FontHeight);
4482 }
4483
4484
4485 context.globalAlpha = 0.4;
4486 for(let m in Parameters.Mark)
4487 {
4488 let Sample = Parameters.Mark[m];
4489 let Y = YStart - Sample * HeightScale;
4490 {
4491 context.beginPath();
4492 context.moveTo(x-(Frame?5:0), Y);
4493 context.lineTo(x+w, Y);
4494 context.stroke();
4495 }
4496 }
4497 context.globalAlpha = 1;
4498 if(Frame)
4499 {
4500 context.beginPath();
4501 context.moveTo(x-5, YStart);
4502 context.lineTo(x+w+5, YStart);
4503 context.stroke();
4504
4505 context.beginPath();
4506 context.moveTo(x, YStart+5);
4507 context.lineTo(x, YStart-h-5);
4508 context.stroke();
4509
4510 context.beginPath();
4511 context.moveTo(x, YStart-h);
4512 context.lineTo(x-5, YStart-h);
4513 context.stroke();
4514 }
4515
4516 for(let dataindex = 0; dataindex < data.length; ++dataindex)
4517 {
4518 let LocalElement = data[dataindex];
4519 context.textAlign='left';
4520 context.strokeStyle = LocalElement.Color;
4521 context.fillStyle = LocalElement.Color;
4522 context.fillText(LocalElement.Name, x+2, y + FontHeight * (dataindex+1));
4523 }
4524
4525 if(MouseInside)
4526 {
4527 ToolTipImmediate = new Array();
4528 for(let dataindex in data)
4529 {
4530 let LocalElement = data[dataindex];
4531 let Samples = LocalElement.Samples;
4532 ToolTipImmediate.push(LocalElement.Name);
4533 ToolTipImmediate.push(FormatTime(Samples[MouseIndex])+ Parameters.Ext);
4534 }
4535 }
4536
4537 ProfileLeave();
4538 }
4539
4540 function DrawDetailed(Animation)
4541 {
4542 DetailedMouseEvent = null;
4543
4544 if(!Initialized)
4545 {
4546 return;
4547 }
4548 ProfileEnter("DrawDetailed");
4549 DetailedMouseOverButton = false;
4550
4551 DebugDrawQuadCount = 0;
4552 DebugDrawTextCount = 0;
4553 nHoverCSCpuNext = -1;
4554
4555 RangeCpuNext = RangeInit();
4556 RangeGpuNext = RangeInit();
4557
4558 var start = new Date();
4559 nDrawCount++;
4560
4561 var context = CanvasDetailedView.getContext('2d');
4562 var offscreen = CanvasDetailedOffscreen.getContext('2d');
4563 var fScaleX = nWidth / fDetailedRange;
4564 var fOffsetY = -nOffsetY + BoxHeight;
4565 if(DetailedRedrawState.fOffsetY == fOffsetY && DetailedRedrawState.fDetailedOffset == fDetailedOffset && DetailedRedrawState.fDetailedRange == fDetailedRange && !KeyCtrlDown && !KeyShiftDown && !KeyAltDown && !MouseDragButton && !RedrawRequested)
4566 {
4567 Invalidate++;
4568 }
4569 else
4570 {
4571 Invalidate = 0;
4572 DetailedRedrawState.fOffsetY = fOffsetY;
4573 DetailedRedrawState.fDetailedOffset = fDetailedOffset;
4574 DetailedRedrawState.fDetailedRange = fDetailedRange;
4575 }
4576 if(nHoverTokenDrawn != nHoverToken)
4577 {
4578 Invalidate = 1;
4579 }
4580 nHoverTokenDrawn = nHoverToken;
4581 nHoverTokenNext = -1;
4582 HoverTokenNextOwner = null;
4583 nHoverTokenLogIndexNext = -1;
4584 nHoverTokenIndexNext = -1;
4585
4586
4587
4588 if(DrawDetailedNewDraw || Invalidate == 0) //when panning, only draw bars that are a certain width to keep decent framerate
4589 {
4590 context.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);
4591 DrawDetailedView(S, S, context, nMinWidthPan, true);
4592 DrawDetailedView(S2, S, context, nMinWidthPan, true, 1);
4593 ProfileRedraw0++;
4594 }
4595 else if(Invalidate == 1) //draw full and store
4596 {
4597 offscreen.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);
4598 DrawDetailedView(S, S, offscreen, nMinWidth, true);
4599 DrawDetailedView(S2, S, offscreen, nMinWidth, true, 1);
4600 OffscreenData = offscreen.getImageData(0, 0, CanvasDetailedOffscreen.width, CanvasDetailedOffscreen.height);
4601 ProfileRedraw1++;
4602 }
4603 else//reuse stored result untill next time viewport is changed.
4604 {
4605 context.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);
4606 context.putImageData(OffscreenData, 0, 0);
4607 DrawDetailedView(S, S, context, nMinWidth, false);
4608 DrawDetailedView(S2, S, context, nMinWidth, false, 1);
4609 ProfileRedraw2++;
4610 }
4611
4612 if(KeyShiftDown || KeyCtrlDown || MouseDragSelectRange() || ZoomActive || FilterSearchActive)
4613 {
4614 nHoverToken = -1;
4615 nHoverTokenIndex = -1;
4616 nHoverTokenLogIndex = -1;
4617 HoverTokenOwner = null;
4618 RangeCpu = RangeInit();
4619 RangeGpu = RangeInit();
4620 }
4621 else
4622 {
4623 nHoverToken = nHoverTokenNext;
4624 HoverTokenOwner = HoverTokenNextOwner;
4625 nHoverTokenIndex = nHoverTokenIndexNext;
4626 nHoverTokenLogIndex = nHoverTokenLogIndexNext;
4627 if(RangeValid(RangeCpuHistory))
4628 {
4629 RangeCopy(RangeCpu, RangeCpuHistory);
4630 RangeCopy(RangeGpu, RangeGpuHistory);
4631 }
4632 else
4633 {
4634 RangeCopy(RangeCpu, RangeCpuNext);
4635 RangeCopy(RangeGpu, RangeGpuNext);
4636 }
4637 }
4638
4639 DrawTextBox(context, TimeToMsString(fDetailedOffset), 0, FontHeight, 'left');
4640 context.textAlign = 'right';
4641 DrawTextBox(context, TimeToMsString(fDetailedOffset + fDetailedRange), nWidth, FontHeight, 'right');
4642 context.textAlign = 'left';
4643
4644 if(!FilterSearchActive && !IgnoreInput && SubMenuActive == -1)
4645 {
4646 let Colors = GroupColors == 3 ? "Color[Section]" : (GroupColors == 2 ? "Color[thread]" : (GroupColors ? "Color[group]" : "Color[timer]"));
4647 DrawDetailedButtons(context, nWidth * 0.5, 0, [Colors],[function(){ToggleGroupColors(1);}], "center");
4648 }
4649
4650
4651 var YBegin = ThreadYBegin[fRangeThreadIdNext];
4652 var YEnd = ThreadYEnd[fRangeThreadIdNext];
4653 var YBeginGpu = YBegin;
4654 var YEndGpu = YEnd;
4655 function RangeSet(R)
4656 {
4657 if(R.Thread >= 0)
4658 {
4659 R.YBegin = ThreadYBegin[R.Thread];
4660 R.YEnd = ThreadYEnd[R.Thread];
4661 }
4662 else
4663 {
4664 R.YBegin = 0;
4665 R.YEnd = nHeight;
4666 }
4667 }
4668 RangeSet(RangeSelect);
4669 RangeSet(RangeCpu);
4670 RangeSet(RangeGpu);
4671 var Offset = 0;
4672 Offset = DrawRange(context, RangeSelect, '#59d0ff', '#00ddff', "Selection", Offset);
4673 Offset = DrawRange(context, RangeCpu, '#009900', '#00ff00', "Cpu", Offset);
4674 Offset = DrawRange(context, RangeGpu, '#996600', '#775500', "Gpu", Offset);
4675
4676 DrawFilterSearchRanges(context, FilterSearchArray, '#ff9900', '#ff9900', ThreadYBegin);
4677
4678 nHoverCSCpu = nHoverCSCpuNext;
4679
4680 DrawFilterSearch();
4681
4682 ProfileDrawFrameTimeGraph(context);
4683
4684 ProfileLeave();
4685 }
4686 function ZoomToHighlight(NoGpu)
4687 {
4688 if(RangeValid(RangeGpu) && !NoGpu)
4689 {
4690 ZoomToRange(RangeGpu);
4691 }
4692 else if(RangeValid(RangeCpu))
4693 {
4694 ZoomToRange(RangeCpu);
4695 }
4696 RangeCpu = RangeInit();
4697 RangeGpu = RangeInit();
4698 }
4699
4700 function MoveToNext(Direction) //1 forward, -1 backwards
4701 {
4702 var fTimeBegin, fTimeEnd, nLog;
4703 var Index = nHoverToken;
4704
4705 if(nHoverToken != -1 && nHoverTokenLogIndex != -1)
4706 {
4707 fTimeBegin = RangeCpu.Begin;
4708 fTimeEnd = RangeCpu.End;
4709 nLog = nHoverTokenLogIndex;
4710 }
4711 else if(RangeValid(RangeSelect))
4712 {
4713 fTimeBegin = RangeSelect.Begin;
4714 fTimeEnd = RangeSelect.End;
4715 nLog = RangeSelect.Thread;
4716 Index = RangeSelect.Index;
4717 }
4718 else
4719 {
4720 return;
4721 }
4722 if(nLog<0)
4723 {
4724 return;
4725 }
4726 var Forward = Direction && Direction < 0 ? 0 : 1;
4727 var bFound = false;
4728 var nStackPos = 0;
4729 var fResultTimeBegin, fResultTimeEnd;
4730 var TypeBegin = Forward ? 1 : 0;
4731 var TypeEnd = Forward ? 0 : 1;
4732 var SearchTimeBegin = Forward ? fTimeBegin : fTimeEnd;
4733
4734 var istart = Forward ? 0 : S.Frames.length-1;
4735 var iend = Forward ? S.Frames.length : -1;
4736 var idelta = Forward ? 1 : -1;
4737 for(var i = istart; i != iend; i += idelta)
4738 {
4739 var fr = S.Frames[i];
4740 var ts = fr.ts[nLog];
4741 var ti = fr.ti[nLog];
4742 var tt = fr.tt[nLog];
4743 var jstart = Forward ? 0 : ts.length-1;
4744 var jend = Forward ? ts.length : -1;
4745 var jdelta = Forward ? 1 : -1;
4746 for(var j = jstart; j != jend; j += jdelta)
4747 {
4748 if(!bFound)
4749 {
4750 if(tt[j] == TypeBegin && Index == ti[j])
4751 {
4752 if(SearchTimeBegin == ts[j])
4753 {
4754 bFound = true;
4755 }
4756 }
4757 }
4758 else
4759 {
4760 if(Index == ti[j])
4761 {
4762 var type = tt[j];
4763 if(type == TypeBegin)
4764 {
4765 if(0 == nStackPos)
4766 {
4767 fResultTimeBegin = ts[j];
4768 }
4769 nStackPos++;
4770 }
4771 else if(type == TypeEnd && nStackPos)
4772 {
4773 nStackPos--;
4774 if(0 == nStackPos)
4775 {
4776 fResultTimeEnd = ts[j];
4777 if(0 == Forward)
4778 {
4779 var Tmp = fResultTimeBegin;
4780 fResultTimeBegin = fResultTimeEnd;
4781 fResultTimeEnd = Tmp;
4782 }
4783 RangeSelect.Begin = fResultTimeBegin;
4784 RangeSelect.End = fResultTimeEnd;
4785 RangeSelect.Thread = nLog;
4786 RangeSelect.Index = Index;
4787 MoveTo(fResultTimeBegin,fResultTimeEnd);
4788 return;
4789 }
4790 }
4791 }
4792 }
4793 }
4794 }
4795 }
4796
4797 function MoveTo(fMoveBegin, fMoveEnd, YTop, YBottom)
4798 {
4799 var nOffsetYBottom = YBottom - nHeight;
4800 var nOffsetYDest = nOffsetY;
4801 if(nOffsetYDest < nOffsetYBottom)
4802 {
4803 nOffsetYDest = nOffsetYBottom;
4804 }
4805 if(nOffsetYDest > YTop)
4806 {
4807 nOffsetYDest = YTop;
4808 }
4809 var fRange = fDetailedRange;
4810 var fMinRange = (fMoveEnd-fMoveBegin) * 2.0;
4811 if(fRange < fMinRange)
4812 {
4813 fRange = fMinRange;
4814 }
4815 var fMoveCenter = (fMoveBegin + fMoveEnd) * 0.5;
4816 fMoveBegin = fMoveCenter - 0.5 * fRange;
4817 fMoveEnd = fMoveCenter + 0.5 * fRange;
4818 var nOffset;
4819 if(nOffsetYDest != nOffsetY)
4820 nOffset = nOffsetYDest;
4821 ZoomTo(fMoveBegin, fMoveEnd, nOffsetYDest, -1);
4822 }
4823
4824 function ZoomToRange(R)
4825 {
4826 ZoomTo(R.Begin, R.End, 0, 0, R.Off);
4827 }
4828
4829 let ZoomCallback = null;
4830
4831 function ZoomTo(fZoomBegin, fZoomEnd, OffsetYDest, ZoomTime, fOffset)
4832 {
4833 if(fZoomBegin < fZoomEnd)
4834 {
4835 if(fOffset)
4836 {
4837 fZoomBegin -= fOffset;
4838 fZoomEnd -= fOffset;
4839 }
4840 AnimationActive = true;
4841 var fDetailedOffsetOriginal = fDetailedOffset;
4842 var fDetailedRangeOriginal = fDetailedRange;
4843 var fDetailedOffsetTarget = fZoomBegin;
4844 var fDetailedRangeTarget = fZoomEnd - fZoomBegin;
4845 var OffsetYOriginal = nOffsetY;
4846 var OffsetYTarget = OffsetYDest;
4847 var TimestampStart = new Date();
4848 var count = 0;
4849 if(!ZoomTime)
4850 {
4851 ZoomTime = ZOOM_TIME;
4852 }
4853
4854 function ZoomFunc()
4855 {
4856 ZoomActive = 1;
4857 var fPrc = (new Date() - TimestampStart) / (ZoomTime * 1000.0);
4858 if(fPrc > 1.0 || ZoomTime < 0.01)
4859 {
4860 fPrc = 1.0;
4861 }
4862 fPrc = Math.pow(fPrc, 0.3);
4863 fDetailedOffset = fDetailedOffsetOriginal + (fDetailedOffsetTarget - fDetailedOffsetOriginal) * fPrc;
4864 fDetailedRange = fDetailedRangeOriginal + (fDetailedRangeTarget - fDetailedRangeOriginal) * fPrc;
4865 if(OffsetYDest)
4866 {
4867 nOffsetY = OffsetYOriginal + (OffsetYTarget - OffsetYOriginal) * fPrc;
4868 }
4869 if(fPrc >= 1.0)
4870 {
4871 AnimationActive = false;
4872 fDetailedOffset = fDetailedOffsetTarget;
4873 fDetailedRange = fDetailedRangeTarget;
4874 if(OffsetYDest)
4875 {
4876 nOffsetY = OffsetYTarget;
4877 }
4878 ZoomCallback = null;
4879 }
4880 else
4881 {
4882 RequestRedraw();
4883 }
4884 return 1;
4885 }
4886 ZoomCallback = ZoomFunc;
4887 RequestRedraw();
4888 }
4889 }
4890
4891 function RequestAnimationFrame(cb)
4892 {
4893 if(!RedrawRequested)
4894 {
4895 let RedrawCallback = function(foo)
4896 {
4897 RedrawRequested = 0;
4898 cb(foo);
4899 };
4900 RedrawRequested = 1;
4901 requestAnimationFrame(RedrawCallback);
4902 }
4903 }
4904
4905 function RequestRedraw(FullRedraw)
4906 {
4907 if(!RedrawRequested)
4908 {
4909 RequestAnimationFrame(Draw);
4910 }
4911 }
4912
4913 function UpdateFilterSearch()
4914 {
4915 let Value = FilterInputSearch2.value;
4916 if(Value != FilterInputSearchValue)
4917 {
4918 FilterInputSearchValue = Value;
4919 let FilterSearch = CreateFilter(FilterInputSearchValue);
4920 if(!FilterSearch)
4921 {
4922 FilterInputSearchActive2 = false;
4923 }
4924 else
4925 {
4926 FilterInputSearchActive2 = true;
4927 let States = new Array();
4928 States.push(S);
4929 if(S2 && S2.TimerInfo)
4930 States.push(S2);
4931 for(let i in States)
4932 {
4933 let State = States[i];
4934 for(let j in State.TimerInfo)
4935 {
4936 let TI = State.TimerInfo[j];
4937 let Name = TI.name;
4938 if(FilterMatch(FilterSearch, Name))
4939 {
4940 TI.search = CIDMatch;
4941 }
4942 else
4943 {
4944 TI.search = CIDFail;
4945 }
4946 }
4947 }
4948 for(let i = 0; i < Timeline.Names.length; ++i)
4949 {
4950 Timeline.SearchMatch[i] = FilterMatch(FilterSearch, Timeline.Names[i]);
4951 }
4952 }
4953 }
4954 }
4955
4956
4957 function Draw()
4958 {
4959 let ProfileDrawStart = new Date();
4960
4961 UpdateFilterSearch();
4962 let RedrawMode = 1;
4963 let RedrawAgain = 0;
4964 RedrawMode = 1;
4965 if(Mode == ModeDetailed)
4966 {
4967 if(ProfileMode == 2 || ((nHoverCSCpu >= 0 || nHoverToken != -1) && !KeyCtrlDown && !KeyShiftDown && !MouseDragButton)||(Invalidate<2 && !KeyCtrlDown && !KeyShiftDown && !MouseDragButton))
4968 {
4969 RedrawMode = 1;
4970 RedrawAgain = 1;
4971 }
4972 }
4973 else
4974 {
4975 if(Invalidate < 1)
4976 {
4977 RedrawMode = 1;
4978 }
4979 }
4980
4981 if(!Initialized)
4982 {
4983 return;
4984 }
4985 if(InsideDraw)
4986 {
4987 debugger;
4988 return;
4989 }
4990 let ZoomActive = 0;
4991 if(ZoomCallback)
4992 {
4993 ZoomActive = ZoomCallback();
4994 }
4995 InsideDraw = 1;
4996 if(ProfileMode)
4997 {
4998 ProfileModeClear();
4999 ProfileEnter("Total");
5000 }
5001
5002 if(ZoomActive)
5003 {
5004 DrawDetailed(true);
5005 }
5006 else if(RedrawMode == 1)
5007 {
5008 if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
5009 {
5010 DrawBarView();
5011 DrawHoverToolTip();
5012 }
5013 else if(Mode == ModeDetailed)
5014 {
5015 DrawDetailed(false);
5016 DrawHoverToolTip();
5017 }
5018 else if(Mode == ModeCounters)
5019 {
5020 DrawCounterView();
5021 DrawHoverToolTip();
5022 }
5023 }
5024 DrawDetailedFrameHistory();
5025 DrawMenu();
5026
5027
5028 if(ProfileMode)
5029 {
5030 ProfileLeave();
5031 ProfileModeDraw(CanvasDetailedView);
5032 }
5033
5034 InsideDraw = 0;
5035 {
5036 let ProfileDrawEnd = new Date();
5037 let DrawTime = ProfileDrawEnd - ProfileDrawStart;
5038 let Delta = ProfileDrawStart - ProfileDrawStartLast;
5039 let Draw2Draw = ProfileDrawStart - ProfileDrawEndLast;
5040
5041 if(ProfileMode != 3)
5042 {
5043 PushIntoArray(ProfileDrawTime, DrawTime);
5044 PushIntoArray(ProfileDeltaTime, Delta);
5045 PushIntoArray(ProfileDraw2Draw, Draw2Draw);
5046 }
5047 ProfileDrawStartLast = ProfileDrawStart;
5048 ProfileDrawEndLast = ProfileDrawEnd;
5049 }
5050
5051 if(RedrawAgain)
5052 {
5053 RequestRedraw();
5054 }
5055 MouseReleased = false;
5056 }
5057
5058 function MoveFilterInputMenuDiv(x, y, w)
5059 {
5060 if(FilterInputMenuDivPos.x != x || FilterInputMenuDivPos.y != y || FilterInputMenuDivPos.w != w)
5061 {
5062 FilterInputMenuDivPos.x = x;
5063 FilterInputMenuDivPos.y = y;
5064 FilterInputMenuDivPos.w = w;
5065 FilterInputMenuDiv.style['left'] = x + 'px';
5066 FilterInputMenuDiv.style['top'] = y + 'px';
5067 FilterInputMenu.style['width'] = w + 'px';
5068 }
5069 }
5070 function MoveFilterInputDiv(x, y, w)
5071 {
5072 if(FilterInputDivPos.x != x || FilterInputDivPos.y != y || FilterInputDivPos.w != w)
5073 {
5074 FilterInputDivPos.x = x;
5075 FilterInputDivPos.y = y;
5076 FilterInputDivPos.w = w;
5077 FilterInputDiv.style['left'] = x + 'px';
5078 FilterInputDiv.style['top'] = (y + (CanvasHistory.height / DPR)) + 'px';
5079 FilterInput.style['width'] = w + 'px';
5080 }
5081 }
5082
5083
5084 function MakeMenuItem(name, f, visible)
5085 {
5086 var Item = {};
5087 Item.name = name;
5088 Item.f = f;
5089 Item.w = name.length;
5090 Item.x = 0;
5091 Item.y = 0;
5092 Item.visible = visible;
5093 return Item;
5094 }
5095 function EnableMenu(m)
5096 {
5097 if(m != SubMenuActive)
5098 {
5099 if(SubMenuActive == SubMenuThreads)
5100 {
5101 FilterInputMenuThreadsValue = FilterInputMenu.value;
5102 }
5103 else if(SubMenuActive == SubMenuGroups)
5104 {
5105 FilterInputMenuGroupsValue = FilterInputMenu.value;
5106 }
5107
5108 SubMenuActive = m;
5109 SubMenuTimeout = new Date();
5110
5111 if(SubMenuActive == SubMenuThreads)
5112 {
5113 FilterInputMenu.value = FilterInputMenuThreadsValue;
5114 FilterInputMenu.focus();
5115 }
5116 else if(SubMenuActive == SubMenuGroups)
5117 {
5118 FilterInputMenu.value = FilterInputMenuGroupsValue;
5119 FilterInputMenu.focus();
5120 }
5121 FilterInputMenuValueLast = FilterInput.value;
5122 // if(m == SubMenuHelp)
5123 {
5124 let info = document.getElementById("divFrameInfo");
5125 info.display = 'inline';
5126 }
5127 }
5128 if(m == -1)
5129 {
5130 SubMenuTimeout = 0;
5131 }
5132 if(SubMenuActive == SubMenuGroups || SubMenuActive == SubMenuThreads)
5133 {
5134 FilterInputMenuDiv.style['display'] = 'inline';
5135 FilterInputMenu.focus();
5136 }
5137 else
5138 {
5139 FilterInputMenuDiv.style['display'] = 'none';
5140 }
5141 }
5142 function InitMenu()
5143 {
5144 MenuItems = [];
5145 MenuItems.push(MakeMenuItem("?", function(){EnableMenu(SubMenuHelp); } ));
5146 MenuItems.push(MakeMenuItem("Mode", function(){EnableMenu(SubMenuMode); } ));
5147 MenuItems.push(MakeMenuItem("Reference", function(){EnableMenu(SubMenuReference); } ));
5148 MenuItems.push(MakeMenuItem("Target", function(){EnableMenu(SubMenuTarget); } ));
5149 MenuItems.push(MakeMenuItem("Threads", function(){ EnableMenu(SubMenuThreads); }, function(){ return Mode != ModeCounters && Mode != ModeTimers_Groups; }));
5150 MenuItems.push(MakeMenuItem("Groups", function(){ EnableMenu(SubMenuGroups); }, function() { return Mode != ModeDetailed && Mode != ModeCounters && Mode != ModeTimers_Threads; } ));
5151 MenuItems.push(MakeMenuItem("Columns", function(){ EnableMenu(SubMenuColumns); }, function(){return Mode == ModeTimers; } ));
5152 MenuItems.push(MakeMenuItem("Options", function(){ EnableMenu(SubMenuOptions); } ));
5153 MenuItems.push(MakeMenuItem("Compare", function(){ EnableMenu(SubMenuCompare); } ));
5154 }
5155 function DrawTopMenu(context)
5156 {
5157 MenuItems[SubMenuMode].name = "Mode[" + ModeItems[Mode] + "]";
5158 let X = 2;
5159 let Y = 0;
5160 let MouseInY = GlobalMouseY < BoxHeight;
5161 for(let i = 0; i < MenuItems.length; ++i)
5162 {
5163 let Item = MenuItems[i];
5164 if(Item.visible == null || Item.visible())
5165 {
5166 let w = context.measureText(Item.name).width + 4;
5167 let MouseIn = MouseInY && GlobalMouseX >= X && GlobalMouseX < X + w;
5168 let color = MouseIn ? nBackColors[1] : "black";
5169 Item.x = X;
5170 Item.y = Y + BoxHeight;
5171 if(MouseIn)
5172 {
5173 context.fillStyle = 'white';
5174 context.fillRect(X-2, Y, w+4, BoxHeight);
5175 // Enable
5176 EnableMenu(i);
5177 }
5178 context.fillStyle = color;
5179 context.fillRect(X, Y, w, BoxHeight);
5180 context.fillStyle = "white";
5181 context.fillText(Item.name, X+2, Y+BoxHeight-FontAscent);
5182 if(MouseIn && MouseReleased)
5183 {
5184 Item.f();
5185 }
5186 X += w + 6;
5187 }
5188 }
5189
5190 return WindowRect(0, 0, X, BoxHeight);
5191 }
5192 function MenuSize(w)
5193 {
5194 return WindowRect(nWidth / 2 - w / 2, HistoryHeight + 50,w, nHeight);
5195 }
5196 function MouseInRect(Rect)
5197 {
5198 return MouseInside(Rect.x, Rect.y, Rect.w, Rect.h);
5199 }
5200 function MouseInside(X, Y, W, H)
5201 {
5202 return GlobalMouseX >= X && GlobalMouseX <= X + W && GlobalMouseY >= Y && GlobalMouseY <= Y + H;
5203 }
5204
5205 function DrawMenuGeneric(Elements, Active, OnClick, x, y, Elements2)
5206 {
5207 let context = CanvasMenu.getContext('2d');
5208 let nColorIndex = 0;
5209 if(Elements2 && Elements2.length != Elements.length)
5210 {
5211 Elements2 = null;
5212 }
5213 let h = FontHeight * Elements.length;
5214 let w = 20;
5215 let w2 = 0;
5216 for(let i = 0; i < Elements.length; ++i)
5217 {
5218 let m = context.measureText(Elements[i]).width;
5219 w = w > m ? w : m;
5220 if(Elements2)
5221 {
5222 m = context.measureText(Elements2[i]).width;
5223 w2 = w2 > m ? w2 : m;
5224 }
5225 }
5226 w += 10 + w2;
5227 let SizeInfo = MenuSize(w);
5228 SizeInfo.x = x;
5229 SizeInfo.y = y;
5230 let X = x;
5231 let Y = y;
5232
5233
5234 for(let i = 0; i < Elements.length; ++i)
5235 {
5236 let Selected = Active(i);
5237 let Name = Elements[i];
5238 let bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight;
5239 let bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5240 let TextY = Y+BoxHeight-FontAscent;
5241 context.fillStyle = Selected?'white':bgcolor;
5242 context.fillRect(X-2, Y, w+4, BoxHeight);
5243 context.fillStyle = bgcolor;
5244 context.fillRect(X, Y, w, BoxHeight);
5245 context.fillStyle = 'white';
5246 context.fillText(Name, X + 2, TextY);
5247 if(Elements2)
5248 {
5249 context.textAlign = "right";
5250 context.fillText(Elements2[i], X + w , TextY);
5251 context.textAlign = "left";
5252 }
5253 context.fillText(Name, X + 2, TextY);
5254 if(bMouseIn && MouseReleased)
5255 {
5256 OnClick(i, Name);
5257 }
5258 Y += BoxHeight;
5259 nColorIndex = 1-nColorIndex;
5260 }
5261 SizeInfo.h = Y - SizeInfo.y;
5262 return SizeInfo;
5263 }
5264
5265 function DrawMenuReference()
5266 {
5267 let Names = [];
5268 let ActiveIdx = 0;
5269 for(let i in ReferenceTimes)
5270 {
5271 let v = ReferenceTimes[i];
5272 if(v < 0)
5273 {
5274 Names.push(ReferenceTimeAutoString);
5275 }
5276 else
5277 {
5278 if(ReferenceTime == ReferenceTimes[i])
5279 {
5280 ActiveIdx = i;
5281 }
5282 Names.push(v + "ms");
5283 }
5284 }
5285 let Click = function(idx, name)
5286 {
5287 SetReferenceTime(Names[idx]);
5288 RequestRedraw();
5289 Invalidate = 0;
5290
5291 };
5292 let x = MenuItems[SubMenuReference].x;
5293 let y = MenuItems[SubMenuReference].y;
5294 let Active = function(Idx) { return ActiveIdx == Idx; };
5295 return DrawMenuGeneric(Names, Active, Click, x, y, null);
5296 }
5297 function DrawMenuTarget()
5298 {
5299 let Names = [];
5300 for(let i in TargetTimes)
5301 {
5302 Names.push(TargetTimes[i] + "ms");
5303 }
5304 let Click = function(idx, name)
5305 {
5306 SetTargetTime(Names[idx]);
5307 RequestRedraw();
5308 Invalidate = 0;
5309
5310 };
5311 let x = MenuItems[SubMenuTarget].x;
5312 let y = MenuItems[SubMenuTarget].y;
5313 let Active = function(Idx) { return TargetTimes[Idx] == TargetTime; };
5314 return DrawMenuGeneric(Names, Active, Click, x, y, null);
5315 }
5316
5317 function DrawMenuMode()
5318 {
5319 let Click = function(idx, name)
5320 {
5321 SetMode(idx,false);
5322 MenuItems[SubMenuMode].name = "Mode[" + ModeItems[idx] + "]";
5323 RequestRedraw();
5324 Invalidate = 0;
5325
5326 };
5327 let x = MenuItems[SubMenuMode].x;
5328 let y = MenuItems[SubMenuMode].y;
5329 let Active = function(Idx) { return Idx == Mode; };
5330 return DrawMenuGeneric(ModeItems, Active, Click, x, y, null);
5331 }
5332 function DrawMenuOptions()
5333 {
5334 let DrawMode = DrawDetailedNewDraw ? "DrawMode[New]":"DrawMode[Old]";
5335 let OptionNames =["Context Switch", "MergeDisable", "LodDisable", "Flame Mode", "Compare Reverse", "Help",DrawMode];
5336 let Click = function(idx, name)
5337 {
5338 switch(idx)
5339 {
5340 case 0: ToggleContextSwitch(); break;
5341 case 1: ToggleDisableMerge(); break;
5342 case 2: ToggleDisableLod(); break;
5343 case 3: ToggleDetailedFlameMode(); break;
5344 case 4: ToggleDetailedSecondReverse(); break;
5345 case 5: ShowHelp(1,1); break;
5346 case 6: ToggleDetailedNewDraw(); break;
5347 }
5348 RequestRedraw();
5349 Invalidate = 0;
5350
5351 };
5352 let x = MenuItems[SubMenuOptions].x;
5353 let y = MenuItems[SubMenuOptions].y;
5354 let Active = function(Idx) { return false; };
5355 return DrawMenuGeneric(OptionNames, Active, Click, x, y, null);
5356 }
5357
5358 function DrawMenuColumns()
5359 {
5360 let Click = function(idx, name)
5361 {
5362 ToggleColumn(idx);
5363
5364 };
5365 let x = MenuItems[SubMenuColumns].x;
5366 let y = MenuItems[SubMenuColumns].y;
5367 let Active = function(Idx) { return ColumnsEnabled[Idx]; };
5368 return DrawMenuGeneric(ColumnNames, Active, Click, x, y, null);
5369
5370 }
5371
5372 function GroupMenuSize()
5373 {
5374 return MenuSize(300);
5375 }
5376
5377 function ThreadMenuSize()
5378 {
5379 return MenuSize(S.ThreadNameWidth + S.ThreadCategoryWidth + 10);
5380 }
5381
5382 function DrawMenuSeparator(context, X, Y, W, Height)
5383 {
5384 context.fillStyle = 'grey';
5385 context.fillRect(X-2, Y, W+2, Height);
5386 }
5387
5388 function DrawMultiMenu(context, X, Y, W, Elements, Callbacks)
5389 {
5390 let A = Array();
5391 let wtemp = W;
5392 let bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight;
5393
5394 for(let i = 0; i < Elements.length; ++i)
5395 {
5396 let wElement = context.measureText(Elements[i]).width;
5397 if(i > 0)
5398 {
5399 wElement += 15;
5400 wtemp -= wElement;
5401 }
5402 A.push(wElement);
5403 }
5404 A[0] = Math.max(wtemp, 0);
5405
5406 context.fillStyle = nBackColors[0];
5407 context.fillRect(X-2, Y, W, BoxHeight);
5408 let XOff = 0;
5409 let TextY = Y+BoxHeight-FontAscent;
5410 for(let i = 0; i < Elements.length; ++i)
5411 {
5412 let width = A[i];
5413 let Inside = i != 0 && bMouseIn && GlobalMouseX > XOff + X && GlobalMouseX <= XOff + X + width;
5414 context.fillStyle = Inside ? nBackColorOffset : nBackColors[0];
5415 context.fillRect(X+XOff, Y, width, BoxHeight);
5416 context.fillStyle = 'white';
5417 context.textAlign = 'center';
5418 context.fillText(Elements[i], X+XOff + width * 0.5, TextY);
5419 XOff += width;
5420 if(Inside && MouseReleased && Callbacks[i])
5421 {
5422 Callbacks[i]();
5423 }
5424 }
5425 context.textAlign = 'left';
5426 }
5427
5428 function DrawMenuThreads()
5429 {
5430 if(FilterInputMenuValueLast != FilterInputMenu.value)
5431 {
5432 nOffsetMenuThreads = 0;
5433 }
5434 FilterInputMenuValueLast = FilterInputMenu.value;
5435 let FilterArray = CreateFilter(FilterInputMenu.value);
5436 let context = CanvasMenu.getContext('2d');
5437 let nColorIndex = 0;
5438 let SizeInfo = ThreadMenuSize();
5439 SizeInfo.x = MenuItems[SubMenuThreads].x;
5440 SizeInfo.y = MenuItems[SubMenuThreads].y;
5441 let Y = SizeInfo.y;
5442 let Width = SizeInfo.w;
5443 let Selection = null;
5444 let X = SizeInfo.x;
5445 MoveFilterInputMenuDiv(SizeInfo.x, SizeInfo.y, SizeInfo.w);
5446 Y += 35;
5447
5448 let bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight;
5449 let bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5450 let TextY = Y+BoxHeight-FontAscent;
5451 let YClear = Y;
5452 let TextYClear = TextY;
5453 let YStart = Y;
5454 let MatchCount = 0;
5455 let MouseTaken = bMouseIn;
5456
5457 Y += (BoxHeight) * 5 + 3 * 2;
5458 nColorIndex = 1-nColorIndex;
5459
5460 Y -= nOffsetMenuThreads;
5461 let CPULogs = [];
5462 let GPULogs = [];
5463 for(let i = 0; i < S.ThreadNames.length; ++i)
5464 {
5465 let Name = S.ThreadNames[i];
5466 if(S.ISGPU[i])
5467 GPULogs.push(Name);
5468 else
5469 CPULogs.push(Name);
5470 let ParentName = "ThreadCategory";
5471 if(FilterMatch(FilterArray, ParentName + " " + Name))
5472 {
5473 if(Y > YStart)
5474 {
5475 let ParentColor = 'white';
5476 let E = IsThreadActive(Name);
5477 let AutoHidden = S.ThreadLogAutoHidden[i];
5478 bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight && !MouseTaken;
5479 bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5480 TextY = Y+BoxHeight-FontAscent;
5481 context.fillStyle = E ? (AutoHidden?'orange':'white') :bgcolor;
5482 context.fillRect(X-2, Y, Width+4, BoxHeight);
5483 context.fillStyle = bgcolor;
5484 context.fillRect(X, Y, Width, BoxHeight);
5485 context.fillStyle = ParentColor;
5486 context.fillText(ParentName, X + 2, TextY);
5487 context.fillStyle = S.ThreadColors[i].color;
5488 context.textAlign = 'right';
5489 context.fillText(Name, X + Width - 2, TextY);
5490 context.textAlign = 'left';
5491 if(bMouseIn && MouseReleased)
5492 {
5493 ToggleThread(Name);
5494 RequestRedraw();
5495 }
5496 }
5497 Y += BoxHeight;
5498 nColorIndex = 1-nColorIndex;
5499 MatchCount++;
5500 }
5501 }
5502 let TextAll = "All [" + S.ThreadNames.length + "]";
5503 let TextFiltered = "Filtered [" + MatchCount +"]";
5504 let TextCPU = "CPU [" + CPULogs.length + "]";
5505 let TextGPU = "GPU [" + GPULogs.length + "]";
5506
5507 let ElementsAll = [TextAll, "Off", "Flip", "On"];
5508 let ElementsFiltered = [TextFiltered, "Off", "Flip", "On"];
5509 let ElementsCPU = [TextCPU, "Off", "Flip", "On"];
5510 let ElementsGPU = [TextGPU, "Off", "Flip", "On"];
5511
5512 let CallbacksAll = [null,
5513 function(){ ToggleThread(0, 1, 0, 0); },
5514 function(){ ToggleThread(0, 1, 0, 1); },
5515 function(){ ToggleThread(0, 1, 0, 2); },
5516 ];
5517
5518 let CallbacksCPU = [null,
5519 function(){ ToggleThread(0, 0, CPULogs, 0); },
5520 function(){ ToggleThread(0, 0, CPULogs, 1); },
5521 function(){ ToggleThread(0, 0, CPULogs, 2); },
5522 ];
5523 let CallbacksGPU = [null,
5524 function(){ ToggleThread(0, 0, GPULogs, 0); },
5525 function(){ ToggleThread(0, 0, GPULogs, 1); },
5526 function(){ ToggleThread(0, 0, GPULogs, 2); },
5527 ];
5528
5529
5530 let CreateFilteredArray = function()
5531 {
5532 if(!FilterArray) return S.ThreadNames;
5533 let A = [];
5534 for(let i = 0; i < S.ThreadNames.length; ++i)
5535 {
5536 let Name = S.ThreadNames[i];
5537 let ParentName = "ThreadCategory";
5538 if(FilterMatch(FilterArray, ParentName + " " + Name))
5539 {
5540 A.push(Name);
5541 }
5542 }
5543 return A;
5544 };
5545 let CallbacksFiltered = [null,
5546 function(){let F = CreateFilteredArray(); ToggleThread(0, 0, F, 0); },
5547 function(){let F = CreateFilteredArray(); ToggleThread(0, 0, F, 1); },
5548 function(){let F = CreateFilteredArray(); ToggleThread(0, 0, F, 2); },
5549 ];
5550
5551
5552 let ElementsOptions = ["Options", "Hide mode:" + (HideMode==HideModeCollapsed ? "Collapsed" : "Invisible"), "AutoHide Empty:" + (ThreadLogAutoHide ? "On": "Off")];
5553 let CallbacksOptions = [null,
5554 function(){
5555 HideMode = HideMode == HideModeCollapsed ? HideModeFullyHidden : HideModeCollapsed;
5556 RequestRedraw();
5557 Invalidate = 0;
5558 },
5559 function(){
5560 ThreadLogAutoHide = ThreadLogAutoHide ? 0 : 1; UpdateThreadLogAutoHide()
5561 RequestRedraw();
5562 Invalidate = 0;
5563 }
5564 ];
5565
5566 DrawMultiMenu(context, X, YClear, Width, ElementsOptions, CallbacksOptions);
5567 YClear += BoxHeight;
5568 DrawMenuSeparator(context, X, YClear, Width, 2);
5569 YClear += 2;
5570 DrawMultiMenu(context, X, YClear, Width, ElementsAll, CallbacksAll);
5571 YClear += BoxHeight;
5572 DrawMultiMenu(context, X, YClear, Width, ElementsFiltered, CallbacksFiltered);
5573 YClear += BoxHeight;
5574 DrawMenuSeparator(context, X, YClear, Width, 2);
5575 YClear += 2;
5576 DrawMultiMenu(context, X, YClear, Width, ElementsGPU, CallbacksGPU);
5577 YClear += BoxHeight;
5578 DrawMultiMenu(context, X, YClear, Width, ElementsCPU, CallbacksCPU);
5579 YClear += BoxHeight;
5580 DrawMenuSeparator(context, X, YClear, Width, 2);
5581 YClear += 2;
5582
5583 SizeInfo.h = Y-SizeInfo.y;
5584 return SizeInfo;
5585 }
5586
5587 function DrawMenuGroups()
5588 {
5589 if(FilterInputMenuValueLast != FilterInputMenu.value)
5590 {
5591 nOffsetMenuThreads = 0;
5592 }
5593 FilterInputMenuValueLast = FilterInputMenu.value;
5594 let FilterArray = CreateFilter(FilterInputMenu.value);
5595 let context = CanvasMenu.getContext('2d');
5596 let nColorIndex = 0;
5597 let SizeInfo = ThreadMenuSize();
5598 SizeInfo.x = MenuItems[SubMenuGroups].x;
5599 SizeInfo.y = MenuItems[SubMenuGroups].y;
5600 let Y = SizeInfo.y;
5601 let Width = SizeInfo.w;
5602 let Selection = null;
5603 let X = SizeInfo.x;
5604 MoveFilterInputMenuDiv(SizeInfo.x, SizeInfo.y, SizeInfo.w);
5605 Y += 35;
5606
5607 let bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight;
5608 let bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5609 let TextY = Y+BoxHeight-FontAscent;
5610 let YClear = Y;
5611 let TextYClear = TextY;
5612 let YStart = Y;
5613 let MatchCount = 0;
5614 let MouseTaken = bMouseIn;
5615
5616 Y += BoxHeight * 2;
5617 nColorIndex = 1-nColorIndex;
5618
5619 Y -= nOffsetMenuThreads;
5620
5621
5622
5623 for(var i = 0; i < S.GroupInfo.length; ++i)
5624 {
5625 let Name = S.GroupInfo[i].name;
5626 let ParentName = S.CategoryInfo[S.GroupInfo[i].category];
5627 let Color = g_Colors[ S.GroupInfo[i].cid ];
5628 if(FilterMatch(FilterArray, ParentName + " " + Name))
5629 {
5630 if(Y > YStart)
5631 {
5632 var ParentColor = 'white';
5633 let E = !GroupsDisabled[Name];
5634 bMouseIn = GlobalMouseY >= Y && GlobalMouseY < Y + BoxHeight && !MouseTaken;
5635 bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5636 TextY = Y+BoxHeight-FontAscent;
5637 context.fillStyle = E ? 'white' :bgcolor;
5638 context.fillRect(X-2, Y, Width+4, BoxHeight);
5639 context.fillStyle = bgcolor;
5640 context.fillRect(X, Y, Width, BoxHeight);
5641 context.fillStyle = ParentColor;
5642 context.fillText(ParentName, X + 2, TextY);
5643 context.fillStyle = Color;
5644 context.textAlign = 'right';
5645 context.fillText(Name, X + Width - 2, TextY);
5646 context.textAlign = 'left';
5647 if(bMouseIn && MouseReleased)
5648 {
5649 ToggleGroup(Name);
5650 RequestRedraw();
5651 }
5652 }
5653 Y += BoxHeight;
5654 nColorIndex = 1-nColorIndex;
5655 MatchCount++;
5656 }
5657 }
5658 let TextAll = "All [" + S.GroupInfo.length + "]";
5659 let TextFiltered = "Filtered [" + MatchCount +"]";
5660
5661
5662
5663 let ElementsAll = [TextAll, "Off", "Flip", "On"];
5664 let CallbacksAll = [null,
5665 function(){ ToggleGroup(0, 1, 0, 0); },
5666 function(){ ToggleGroup(0, 1, 0, 1); },
5667 function(){ ToggleGroup(0, 1, 0, 2); },
5668 ];
5669 let ElementsFiltered = [TextFiltered, "Off", "Flip", "On"];
5670 let CreateFilteredArray = function()
5671 {
5672 let A = [];
5673 for(let i = 0; i < S.GroupInfo.length; ++i)
5674 {
5675 let Name = S.GroupInfo[i].name;
5676 let ParentName = S.CategoryInfo[S.GroupInfo[i].category];
5677 if(FilterMatch(FilterArray, ParentName + " " + Name))
5678 {
5679 A.push(Name);
5680 }
5681 }
5682 return A;
5683 };
5684 let CallbacksFiltered = [null,
5685 function(){let F = CreateFilteredArray(); ToggleGroup(0, 0, F, 0); },
5686 function(){let F = CreateFilteredArray(); ToggleGroup(0, 0, F, 1); },
5687 function(){let F = CreateFilteredArray(); ToggleGroup(0, 0, F, 2); },
5688 ];
5689
5690
5691 DrawMultiMenu(context, X, YClear, Width, ElementsAll, CallbacksAll);
5692 DrawMultiMenu(context, X, YClear+BoxHeight, Width, ElementsFiltered, CallbacksFiltered);
5693
5694 SizeInfo.h = Y-SizeInfo.y;
5695 return SizeInfo;
5696
5697
5698 }
5699
5700 function DrawMenu()
5701 {
5702 MenuRedraw = 0;
5703
5704 var context = CanvasMenu.getContext('2d');
5705 context.clearRect(0, 0, CanvasMenu.width, CanvasMenu.height);
5706
5707 var nColorIndex = 0;
5708 var Y = 50;
5709 var Width = 300;
5710 var Selection = null;
5711
5712 ProfileEnter("DrawMenu");
5713 let MenuRect = DrawTopMenu(context);
5714 if(SubMenuActive != -1)
5715 {
5716 MouseMoveTime = new Date();
5717 }
5718 if(SubMenuActive == SubMenuHelp)
5719 {
5720 if(MouseReleased)
5721 {
5722 ToggleDebugMode();
5723 }
5724 }
5725 if(SubMenuActive == SubMenuMode)
5726 {
5727 MenuRect = DrawMenuMode();
5728 }
5729 else if(SubMenuActive == SubMenuReference)
5730 {
5731 MenuRect = DrawMenuReference();
5732 }
5733 else if(SubMenuActive == SubMenuTarget)
5734 {
5735 MenuRect = DrawMenuTarget();
5736 }
5737 else if(SubMenuActive == SubMenuThreads)
5738 {
5739 MenuRect = DrawMenuThreads();
5740 }
5741 else if(SubMenuActive == SubMenuGroups)
5742 {
5743 MenuRect = DrawMenuGroups();
5744 }
5745 else if(SubMenuActive == SubMenuOptions)
5746 {
5747 MenuRect = DrawMenuOptions();
5748 }
5749 else if(SubMenuActive == SubMenuCompare)
5750 {
5751 if(MouseReleased)
5752 {
5753 ComparePrompt();
5754 }
5755 }
5756 else if(SubMenuActive == SubMenuColumns)
5757 {
5758 MenuRect = DrawMenuColumns();
5759 }
5760 var Grow = 10;
5761 MenuRect.x -= Grow;
5762 MenuRect.y -= Grow;
5763 MenuRect.h += 2*Grow;
5764 MenuRect.w += 2*Grow;
5765 var MouseMoved = GlobalMouseX != SubMenuMouseX || GlobalMouseY != SubMenuMouseY;
5766
5767 if(MouseInRect(MenuRect) || !MouseMoved)
5768 {
5769 SubMenuTimeout = new Date();
5770 SubMenuMouseX = GlobalMouseX;
5771 SubMenuMouseY = GlobalMouseY;
5772 }
5773 else
5774 {
5775 var Time = new Date() - SubMenuTimeout;
5776 var Dest = SubMenuTimeoutBase * 1000;
5777 if(Time > Dest)
5778 {
5779 EnableMenu(-1);
5780 }
5781 }
5782 if(0)//debugging of menu extents. dont delete
5783 {
5784 context.strokeStyle = 'red';
5785 context.beginPath();
5786 context.moveTo(MenuRect.x,MenuRect.y);
5787 context.lineTo(MenuRect.x + MenuRect.w,MenuRect.y);
5788 context.lineTo(MenuRect.x + MenuRect.w,MenuRect.y+MenuRect.h);
5789 context.lineTo(MenuRect.x,MenuRect.y+MenuRect.h);
5790 context.lineTo(MenuRect.x,MenuRect.y);
5791 context.stroke();
5792 } // SpinnerDraw(SpinnerShow(), context, SpinnerCorner, 0, nHeight-20, 20, 20);
5793 ProfileLeave();
5794 }
5795
5796
5797 function ZoomGraph(nZoom)
5798 {
5799 var fOldRange = fDetailedRange;
5800 if(nZoom>0)
5801 {
5802 fDetailedRange *= Math.pow(nModDown ? 1.40 : 1.03, nZoom);
5803 }
5804 else
5805 {
5806 var fNewDetailedRange = fDetailedRange / Math.pow((nModDown ? 1.40 : 1.03), -nZoom);
5807 if(fNewDetailedRange < 0.0001) //100ns
5808 fNewDetailedRange = 0.0001;
5809 fDetailedRange = fNewDetailedRange;
5810 }
5811
5812 var fDiff = fOldRange - fDetailedRange;
5813 var fMousePrc = DetailedViewMouseX / nWidth;
5814 if(fMousePrc < 0)
5815 {
5816 fMousePrc = 0;
5817 }
5818 fDetailedOffset += fDiff * fMousePrc;
5819
5820 }
5821
5822 function MeasureFont()
5823 {
5824 var context = CanvasDetailedView.getContext('2d');
5825 context.font = Font;
5826 FontWidth = context.measureText('W').width;
5827
5828 }
5829 function ResizeCanvas()
5830 {
5831 nWidth = window.innerWidth;
5832 nHeight = window.innerHeight - CanvasHistory.height-2;
5833 DPR = window.devicePixelRatio;
5834
5835 if(DPR)
5836 {
5837 CanvasDetailedView.style.width = nWidth + 'px';
5838 CanvasDetailedView.style.height = nHeight + 'px';
5839 CanvasDetailedView.width = nWidth * DPR;
5840 CanvasDetailedView.height = nHeight * DPR;
5841 CanvasHistory.style.width = window.innerWidth + 'px';
5842 CanvasHistory.style.height = 70 + 'px';
5843 CanvasHistory.width = window.innerWidth * DPR;
5844 CanvasHistory.height = 70 * DPR;
5845 CanvasMenu.style.width = window.innerWidth + 'px';
5846 CanvasMenu.style.height = window.innerHeight + 'px';
5847 CanvasMenu.width = window.innerWidth * DPR;
5848 CanvasMenu.height = window.innerHeight * DPR;
5849 CanvasHistory.getContext('2d').scale(DPR,DPR);
5850 CanvasDetailedView.getContext('2d').scale(DPR,DPR);
5851 CanvasMenu.getContext('2d').scale(DPR,DPR);
5852
5853 CanvasDetailedOffscreen.style.width = nWidth + 'px';
5854 CanvasDetailedOffscreen.style.height = nHeight + 'px';
5855 CanvasDetailedOffscreen.width = nWidth * DPR;
5856 CanvasDetailedOffscreen.height = nHeight * DPR;
5857 CanvasDetailedOffscreen.getContext('2d').scale(DPR,DPR);
5858
5859 }
5860 else
5861 {
5862 DPR = 1;
5863 CanvasDetailedView.width = nWidth;
5864 CanvasDetailedView.height = nHeight;
5865 CanvasDetailedOffscreen.width = nWidth;
5866 CanvasDetailedOffscreen.height = nHeight;
5867
5868 CanvasMenu.width = window.innerWidth;
5869 CanvasMenu.height = window.innerHeight;
5870 CanvasHistory.width = window.innerWidth;
5871 }
5872 RequestRedraw();
5873 }
5874
5875
5876 var MouseDragOff = 0;
5877 var MouseDragDown = 1;
5878 var MouseDragUp = 2;
5879 var MouseDragMove = 3;
5880 var MouseDragState = MouseDragOff;
5881 var MouseDragTarget = 0;
5882 var MouseDragButton = 0;
5883 var MouseDragButtonNext = 0;
5884 var MouseDragKeyShift = 0;
5885 var MouseDragKeyCtrl = 0;
5886 var MouseDragKeyAlt = 0;
5887 var MouseDragX = 0;
5888 var MouseDragY = 0;
5889 var MouseDragXLast = 0;
5890 var MouseDragYLast = 0;
5891 var MouseDragXStart = 0;
5892 var MouseDragYStart = 0;
5893
5894 function clamp(number, min, max)
5895 {
5896 return Math.max(min, Math.min(number, max));
5897 }
5898
5899 function MouseDragPan()
5900 {
5901 return (MouseDragButton == 1 && !MouseDragKeyCtrl) || MouseDragKeyShift || MouseDragKeyAlt;
5902 }
5903 function MouseDragSelectRange()
5904 {
5905 return MouseDragState == MouseDragMove && (MouseDragButton == 3 || (MouseDragKeyShift && MouseDragKeyCtrl));
5906 }
5907 function MouseHandleDrag()
5908 {
5909 if(MouseDragTarget == CanvasDetailedView)
5910 {
5911 if(Mode == ModeDetailed)
5912 {
5913
5914 if(FilterSearchActive)
5915 {
5916 if(MouseDragKeyShift || MouseDragButton == 1)
5917 {
5918 var Y = MouseDragY - MouseDragYLast;
5919 nOffsetFilterSearch -= Y;
5920 if(nOffsetFilterSearch < 0)
5921 {
5922 nOffsetFilterSearch = 0;
5923 }
5924 }
5925 }
5926 else
5927 {
5928 if(MouseDragSelectRange())
5929 {
5930 var xStart = MouseDragXStart;
5931 var xEnd = MouseDragX;
5932 if(xStart > xEnd)
5933 {
5934 var Temp = xStart;
5935 xStart = xEnd;
5936 xEnd = Temp;
5937 }
5938 if(xEnd - xStart > 1)
5939 {
5940 RangeCpu.Begin = fDetailedOffset + fDetailedRange * (xStart / nWidth);
5941 RangeCpu.End = fDetailedOffset + fDetailedRange * (xEnd / nWidth);
5942 RangeSelect.Begin = fDetailedOffset + fDetailedRange * (xStart / nWidth);
5943 RangeSelect.End = fDetailedOffset + fDetailedRange * (xEnd / nWidth);
5944 RangeSelect.Thread = -1;
5945 RangeSelect.Index = -1;
5946 }
5947 }
5948 else if(MouseDragPan())
5949 {
5950 var X = MouseDragX - MouseDragXLast;
5951 var Y = MouseDragY - MouseDragYLast;
5952 if(X)
5953 {
5954 if(MouseDragKeyAlt)
5955 {
5956 fDetailedOffsetSecond += -X * fDetailedRange / nWidth;
5957 }
5958 else
5959 {
5960 fDetailedOffset += -X * fDetailedRange / nWidth;
5961 }
5962 }
5963 if(!MouseDragKeyAlt)
5964 {
5965 nOffsetY -= Y;
5966 }
5967 if(nOffsetY < 0)
5968 {
5969 nOffsetY = 0;
5970 }
5971 }
5972 else if(MouseDragKeyCtrl)
5973 {
5974 if(MouseDragY != MouseDragYLast)
5975 {
5976 ZoomGraph(MouseDragY - MouseDragYLast);
5977 }
5978 }
5979 }
5980 }
5981 else if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
5982 {
5983 if(MouseDragKeyShift || MouseDragButton == 1)
5984 {
5985 var X = MouseDragX - MouseDragXLast;
5986 var Y = MouseDragY - MouseDragYLast;
5987 nOffsetBarsY -= Y;
5988 nOffsetBarsX -= X;
5989 if(nOffsetBarsY < 0)
5990 {
5991 nOffsetBarsY = 0;
5992 }
5993 if(nOffsetBarsX < 0)
5994 {
5995 nOffsetBarsX = 0;
5996 }
5997 }
5998 }
5999 else if(Mode == ModeCounters)
6000 {
6001 if(MouseDragKeyShift || MouseDragButton == 1)
6002 {
6003 var Y = MouseDragY - MouseDragYLast;
6004 nOffsetCountersY -= Y;
6005 if(nOffsetCountersY < 0)
6006 {
6007 nOffsetCountersY = 0;
6008 }
6009 }
6010 }
6011
6012 }
6013 else if(MouseDragTarget == CanvasHistory)
6014 {
6015 function HistoryFrameTime(x)
6016 {
6017 var NumFrames = S.Frames.length;
6018 var fBarWidth = nWidth / NumFrames;
6019 var Index = clamp(Math.floor(NumFrames * x / nWidth), 0, NumFrames-1);
6020 var Lerp = clamp((x/fBarWidth - Index) , 0, 1);
6021 var time = S.Frames[Index].framestart + (S.Frames[Index].frameend - S.Frames[Index].framestart) * Lerp;
6022 return time;
6023 }
6024 if(MouseDragSelectRange())
6025 {
6026 RangeCpu = RangeInit();
6027 RangeGpu = RangeInit();
6028
6029 var xStart = MouseDragXStart;
6030 var xEnd = MouseDragX;
6031 if(xStart > xEnd)
6032 {
6033 var Temp = xStart;
6034 xStart = xEnd;
6035 xEnd = Temp;
6036 }
6037 if(xEnd - xStart > 2)
6038 {
6039 var timestart = HistoryFrameTime(xStart);
6040 var timeend = HistoryFrameTime(xEnd);
6041 fDetailedOffset = timestart;
6042 fDetailedRange = timeend-timestart;
6043 }
6044 }
6045 else if(MouseDragPan())
6046 {
6047 var Time = HistoryFrameTime(MouseDragX);
6048 fDetailedOffset = Time - fDetailedRange / 2.0;
6049 }
6050 }
6051 }
6052 function MouseHandleDragEnd()
6053 {
6054 if(MouseDragTarget == CanvasDetailedView)
6055 {
6056
6057 }
6058 else if(MouseDragTarget == CanvasHistory)
6059 {
6060 if(!MouseDragSelectRange() && !MouseDragPan())
6061 {
6062 ZoomToHighlight(1);
6063 }
6064 }
6065 }
6066
6067 function MouseHandleDragClick()
6068 {
6069 if(MouseDragTarget == CanvasDetailedView)
6070 {
6071 if(Mode == ModeCounters)
6072 {
6073 if(nHoverCounter != -1)
6074 {
6075 if(S.CounterInfo[nHoverCounter].firstchild != -1)
6076 {
6077 S.CounterInfo[nHoverCounter].closed = !S.CounterInfo[nHoverCounter].closed;
6078 }
6079 else
6080 {
6081 S.CounterInfo[nHoverCounter].Expanded = !S.CounterInfo[nHoverCounter].Expanded;
6082 }
6083 Draw(1);
6084 }
6085 }
6086 else if(Mode == ModeDetailed && FilterSearchSelection >= 0)
6087 {
6088 FilterInputCommit();
6089 }
6090 else
6091 {
6092 if(DetailedMouseEvent)
6093 {
6094 DetailedMouseEvent.E();
6095 }
6096 else if(!DetailedMouseOverButton)
6097 {
6098 ZoomToHighlight();
6099 }
6100 }
6101 }
6102 else if(MouseDragTarget == CanvasHistory)
6103 {
6104 if(Mode == ModeDetailed)
6105 {
6106 ZoomToHighlight(1);
6107 }
6108 }
6109 }
6110
6111 function MapMouseButton(event)
6112 {
6113 if(event.button == 1 || event.which == 1)
6114 {
6115 return 1;
6116 }
6117 else if(event.button == 3 || event.which == 3)
6118 {
6119 return 3;
6120 }
6121 else
6122 {
6123 return 0;
6124 }
6125 }
6126
6127 function MouseDragIsActive()
6128 {
6129 return MouseDragState != MouseDragOff && MouseDragState != MouseDragDown;
6130 }
6131 function MouseDragReset()
6132 {
6133 MouseDragState = MouseDragOff;
6134 MouseDragTarget = 0;
6135 MouseDragKeyShift = 0;
6136 MouseDragKeyCtrl = 0;
6137 MouseDragKeyAlt = 0;
6138 MouseDragButton = 0;
6139 }
6140 function MouseDragKeyUp()
6141 {
6142 if((MouseDragKeyShift && !KeyShiftDown) || (MouseDragKeyCtrl && !KeyCtrlDown) || (MouseDragKeyAlt && !KeyAltDown) || SubMenuActive != -1)
6143 {
6144 MouseHandleDragEnd();
6145 MouseDragReset();
6146 }
6147 }
6148 function MouseDrag(Source, Event)
6149 {
6150 if(Source == MouseDragOff || (MouseDragTarget && MouseDragTarget != Event.target) || SubMenuActive != -1)
6151 {
6152 MouseDragReset();
6153 return;
6154 }
6155 if(G_DEBUG)
6156 {
6157 debugger;
6158 }
6159 var LocalRect = Event.target.getBoundingClientRect();
6160 MouseDragX = Event.clientX - LocalRect.left;
6161 MouseDragY = Event.clientY - LocalRect.top;
6162 if(MouseDragState == MouseDragMove)
6163 {
6164 var dx = Math.abs(MouseDragX - MouseDragXStart);
6165 var dy = Math.abs(MouseDragY - MouseDragYStart);
6166 if((Source == MouseDragUp && MapMouseButton(Event) == MouseDragButton) ||
6167 (MouseDragKeyCtrl && !KeyCtrlDown) ||
6168 (MouseDragKeyShift && !KeyShiftDown) ||
6169 (MouseDragKeyAlt && !KeyAltDown))
6170 {
6171 MouseHandleDragEnd();
6172 MouseDragReset();
6173 return;
6174 }
6175 else
6176 {
6177 MouseHandleDrag();
6178 }
6179 }
6180 else if(MouseDragState == MouseDragOff)
6181 {
6182 if(Source == MouseDragDown || KeyShiftDown || KeyCtrlDown|| KeyAltDown)
6183 {
6184 MouseDragTarget = Event.target;
6185 MouseDragButton = MapMouseButton(Event);
6186 MouseDragState = MouseDragDown;
6187 MouseDragXStart = MouseDragX;
6188 MouseDragYStart = MouseDragY;
6189 MouseDragKeyCtrl = 0;
6190 MouseDragKeyShift = 0;
6191 MouseDragKeyAlt = 0;
6192
6193 if(KeyShiftDown || KeyCtrlDown || KeyAltDown)
6194 {
6195 MouseDragKeyAlt = KeyAltDown;
6196 MouseDragKeyShift = KeyShiftDown;
6197 MouseDragKeyCtrl = KeyCtrlDown;
6198 MouseDragState = MouseDragMove;
6199 }
6200 }
6201 }
6202 else if(MouseDragState == MouseDragDown)
6203 {
6204 if(Source == MouseDragUp)
6205 {
6206 MouseHandleDragClick();
6207 MouseDragReset();
6208 }
6209 else if(Source == MouseDragMove)
6210 {
6211 var dx = Math.abs(MouseDragX - MouseDragXStart);
6212 var dy = Math.abs(MouseDragY - MouseDragYStart);
6213 if(dx+dy>1)
6214 {
6215 MouseDragState = MouseDragMove;
6216 }
6217 }
6218 }
6219 MouseDragXLast = MouseDragX;
6220 MouseDragYLast = MouseDragY;
6221 }
6222
6223 function MouseMove(evt)
6224 {
6225 evt.preventDefault();
6226
6227 ZoomActive = 0;
6228 MouseDrag(MouseDragMove, evt);
6229 MouseHistory = 0;
6230 MouseDetailed = 0;
6231 HistoryViewMouseX = HistoryViewMouseY = -1;
6232 var rect = evt.target.getBoundingClientRect();
6233 var x = evt.clientX - rect.left;
6234 var y = evt.clientY - rect.top;
6235 GlobalMouseX = evt.pageX;
6236 GlobalMouseY = evt.pageY;
6237 if(evt.target == CanvasDetailedView)
6238 {
6239 if(!MouseDragSelectRange())
6240 {
6241 RangeCpu = RangeInit();
6242 }
6243 DetailedViewMouseX = x;
6244 DetailedViewMouseY = y;
6245 }
6246 else if(evt.target = CanvasHistory)
6247 {
6248 var Rect = CanvasHistory.getBoundingClientRect();
6249 HistoryViewMouseX = x;
6250 HistoryViewMouseY = y;
6251
6252 DetailedViewMouseX = -1;
6253 DetailedViewMouseY = -1;
6254
6255 }
6256 RequestRedraw();
6257 }
6258
6259 function MouseSortClick()
6260 {
6261 if(SortColumnMouseOverNext)
6262 {
6263 if(SortColumnMouseOverNext == SortColumnMouseOver)
6264 {
6265 SortColumnOrderFlip = 1 - SortColumnOrderFlip;
6266 }
6267 else
6268 {
6269 SortColumnOrderFlip = 0;
6270 }
6271
6272 SortColumnMouseOver = SortColumnMouseOverNext;
6273 SortColumnMouseOverNext = null;
6274 if(SortColumnMouseOver == StrAverage)
6275 {
6276 SortColumn = 1;
6277 }
6278 else if(SortColumnMouseOver == StrMax)
6279 {
6280 SortColumn = 2;
6281 }
6282 else if(SortColumnMouseOver == StrTotal)
6283 {
6284 SortColumn = 3;
6285 }
6286 else if(SortColumnMouseOver == StrMin)
6287 {
6288 SortColumn = 4;
6289 }
6290 else if(SortColumnMouseOver == StrSpike)
6291 {
6292 SortColumn = 5;
6293 }
6294 else if(SortColumnMouseOver == StrCallAverage)
6295 {
6296 SortColumn = 6;
6297 }
6298 else if(SortColumnMouseOver == StrCount)
6299 {
6300 SortColumn = 7;
6301 }
6302 else if(SortColumnMouseOver == StrExclAverage)
6303 {
6304 SortColumn = 8;
6305 }
6306 else if(SortColumnMouseOver == StrExclMax)
6307 {
6308 SortColumn = 9;
6309 }
6310 else if(SortColumnMouseOver == StrGroup)
6311 {
6312 SortColumn = 0;
6313 }
6314 RequestRedraw();
6315 }
6316 }
6317
6318 function MouseButton(bPressed, evt)
6319 {
6320 evt.preventDefault();
6321 MouseReleased = !bPressed;
6322 MouseDrag(bPressed ? MouseDragDown : MouseDragUp, evt);
6323 if(!bPressed && SubMenuActive == -1)
6324 MouseSortClick();
6325 RequestRedraw();
6326 }
6327
6328 function MouseOut(evt)
6329 {
6330 MouseDrag(MouseDragOff, evt);
6331 KeyCtrlDown = 0;
6332 KeyShiftDown = 0;
6333 KeyAltDown = 0;
6334 MouseDragButton = 0;
6335 nHoverToken = -1;
6336 RangeCpu = RangeInit();
6337 }
6338
6339 function MouseWheel(e)
6340 {
6341 var e = window.event || e;
6342 var delta = (e.wheelDelta || e.detail * (-120));
6343 ZoomGraph((-4 * delta / 120.0) | 0);
6344 Draw(1);
6345 }
6346
6347 function ShowDetailedSearch(bShow)
6348 {
6349 if(bShow)
6350 {
6351 FilterInputSearch2.style['display'] = 'block';
6352 }
6353 else
6354 {
6355 FilterInputSearch2.style['display'] = 'none';
6356 }
6357 }
6358
6359 function ShowFilterInput(bShow)
6360 {
6361 if(bShow)
6362 {
6363 document.getElementById('filterinput').style['display'] = 'block';
6364 }
6365 else
6366 {
6367 document.getElementById('filterinput').style['display'] = 'none';
6368 }
6369 }
6370
6371 function SetFilterInput(group, timer)
6372 {
6373 FilterInputGroupString = group;
6374 FilterInputTimerString = timer;
6375 FilterInputGroup.value = group?group:'';
6376 FilterInputTimer.value = timer?timer:'';
6377 FilterUpdate();
6378 if(group || timer)
6379 {
6380 ShowFilterInput(1);
6381 }
6382 else
6383 {
6384 ShowFilterInput(0);
6385 }
6386
6387 }
6388
6389 function ToggleFilterInput(escape)
6390 {
6391 var ActiveElement = -1;
6392 for(var i = 0; i < FilterInputArray.length; ++i)
6393 {
6394 if(FilterInputArray[i] == document.activeElement)
6395 {
6396 ActiveElement = i;
6397 }
6398 }
6399 var OldActiveElement = ActiveElement;
6400 if(ActiveElement >= 0)
6401 {
6402 FilterInputArray[ActiveElement].blur();
6403 }
6404 ActiveElement++;
6405 if(!escape)
6406 {
6407 if(ActiveElement < FilterInputArray.length)
6408 {
6409 ShowFilterInput(1);
6410 FilterInputArray[ActiveElement].focus();
6411 }
6412 }
6413 else
6414 {
6415 if(-1 == OldActiveElement)
6416 {
6417 SetFilterInput();
6418 }
6419 }
6420 }
6421
6422 function KeyUp(evt)
6423 {
6424 //console.log("keyup ", evt.keyCode);
6425 if(evt.keyCode== 84)
6426 {
6427 G_DEBUG = 1;
6428 }
6429 if(evt.keyCode == 18)
6430 {
6431 ToolTipFlip = 0;
6432 }
6433 if(!FilterSearchActive && !IgnoreInput && SubMenuActive == -1)
6434 {
6435 if(evt.keyCode == 112)
6436 {
6437 ShowHelp(1, 0);
6438 }
6439 if(evt.keyCode == 39)
6440 {
6441 MoveToNext(1);
6442 }
6443 if(evt.keyCode == 37)
6444 {
6445 MoveToNext(-1);
6446 }
6447 if(evt.keyCode == 90)
6448 {
6449 ToolTipCorner = 1-ToolTipCorner;
6450 }
6451 if(evt.keyCode == 187)
6452 {
6453 DrawDetailedFlameMode = (DrawDetailedFlameMode+1) % 3;
6454 FilterSearchReset();
6455 }
6456 if(evt.keyCode == 189)
6457 {
6458 DrawDetailedCompareReverse = 1-DrawDetailedCompareReverse;
6459 FilterSearchReset();
6460 }
6461 if(evt.keyCode == 32)
6462 {
6463 if(RangeSelect.Begin < RangeSelect.End)
6464 {
6465 ZoomToRange(RangeSelect);
6466 RangeSelect = RangeInit();
6467 MouseHandleDragEnd();
6468 }
6469 }
6470 if(evt.keyCode == 192)
6471 {
6472 if(Mode == ModeDetailed)
6473 {
6474 FilterInputSearch2.focus();
6475 }
6476 else if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
6477 {
6478 ToggleFilterInput(0);
6479 evt.preventDefault();
6480 }
6481 }
6482 if(evt.keyCode == 9)
6483 {
6484 evt.preventDefault();
6485 if(Mode == ModeDetailed)
6486 {
6487 var Token = nHoverToken;
6488 if(Token == -1 && RangeValid(RangeSelect) && RangeSelect.Index >= 0)
6489 {
6490 Token = RangeSelect.Index;
6491 }
6492 if(Token != -1 && Token < S.TimerInfo.length)
6493 {
6494 var start = S.TimerInfo[Token].worststart;
6495 var end = S.TimerInfo[Token].worstend;
6496 RangeSelect.Begin = start;
6497 RangeSelect.End = end;
6498 RangeSelect.Thread = S.TimerInfo[Token].worstthread;
6499 RangeSelect.Index = Token;
6500 ShowFlashMessage('Worst: ' + (end-start).toFixed(2) + 'ms', 100);
6501 MoveTo(RangeSelect.Begin, RangeSelect.End, ThreadYBegin[RangeSelect.Thread] + nOffsetY, ThreadYEnd[RangeSelect.Thread+1] + nOffsetY);
6502 MouseHandleDragEnd();
6503 }
6504 else
6505 {
6506 FilterInputSearch2.focus();
6507 }
6508
6509 }
6510 else if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
6511 {
6512 ToggleFilterInput(0);
6513 evt.preventDefault();
6514 }
6515
6516 }
6517 if(evt.keyCode == 88)
6518 {
6519 ToggleMode();
6520 }
6521 if(evt.keyCode == 220 && Mode == ModeDetailed)
6522 {
6523 ToggleGroupColors(true);
6524 }
6525 if(evt.keyCode == 67 && Mode == ModeDetailed)
6526 {
6527 HideMode = HideMode == HideModeCollapsed ? HideModeFullyHidden : HideModeCollapsed;
6528 RequestRedraw();
6529 Invalidate = 0;
6530 }
6531 }
6532 if(evt.keyCode == 18)
6533 {
6534 KeyAltDown = 0;
6535 MouseDragKeyUp();
6536 }
6537 else if(evt.keyCode == 17)
6538 {
6539 KeyCtrlDown = 0;
6540 MouseDragKeyUp();
6541 }
6542 else if(evt.keyCode == 16)
6543 {
6544 KeyShiftDown = 0;
6545 MouseDragKeyUp();
6546 }
6547
6548
6549 if(evt.keyCode == 27)
6550 {
6551 if(Mode == ModeDetailed)
6552 {
6553 let SearchString = FilterInputSearch2.value;
6554 if(SearchString.length > 0)
6555 {
6556 //when search is active, esc clears in the following order:
6557 //focus from search
6558 //clears active range
6559 //clears search
6560 if(document.activeElement == FilterInputSearch2)
6561 {
6562 document.activeElement.blur();
6563 }
6564 else
6565 {
6566 if(RangeValid(RangeSelect))
6567 {
6568 RangeSelect = RangeInit();
6569 }
6570 else
6571 {
6572 FilterInputSearch2.value = "";
6573 }
6574 }
6575 }
6576 else
6577 {
6578 RangeSelect = RangeInit();
6579 }
6580 }
6581
6582 SortColumn = 0;
6583 SortColumnMouseOver = "";
6584 if(Mode == ModeTimers || Mode == ModeTimers_Threads || Mode == ModeTimers_Groups)
6585 {
6586 ToggleFilterInput(1);
6587 evt.preventDefault();
6588 }
6589 if(SubMenuActive != -1)
6590 {
6591 if(FilterInputMenu.value.trim() != "")
6592 {
6593 FilterInputMenu.value = "";
6594 }
6595 else
6596 {
6597 EnableMenu(-1);
6598 }
6599 }
6600
6601 if(FilterSearchActive)
6602 {
6603 if(FilterInput.value != '')
6604 {
6605 FilterInput.value = '';
6606 }
6607 else
6608 {
6609 FilterInputHide();
6610 }
6611 }
6612 else
6613 {
6614 FilterSearchReset();
6615 }
6616 }
6617
6618
6619 if(evt.keyCode == 13 && !IgnoreInput)
6620 {
6621 if(FilterSearchActive)
6622 {
6623 FilterInputCommit();
6624 }
6625 else
6626 {
6627 FilterInputShow();
6628 }
6629 }
6630 RequestRedraw();
6631 Invalidate = 0;
6632 }
6633 function FilterInputUpdate()
6634 {
6635 Invalidate = 0;
6636 if(FilterSearchActive == 1)
6637 {
6638 FilterInputDiv.style['display'] = 'inline';
6639 FilterInput.focus();
6640 }
6641 else
6642 {
6643 FilterSearchSelection = -1;
6644 FilterInputDiv.style['display'] = 'none';
6645 }
6646 }
6647 function FilterInputShow()
6648 {
6649 FilterSearchActive = 1;
6650 FilterInputUpdate();
6651 RequestRedraw();
6652 }
6653 function FilterInputHide()
6654 {
6655 FilterSearchActive = 0;
6656 FilterInputUpdate();
6657 }
6658
6659 function FilterInputCommit()
6660 {
6661 if(FilterSearchSelection >= 0)
6662 {
6663 FilterSearchReset();
6664 FilterSearchPassIndex = FilterSearchSelection;
6665 FilterSearchStartTime = new Date();
6666 }
6667 FilterInputHide();
6668 }
6669 function FilterSearchReset()
6670 {
6671 FilterSearchArray = new Array();
6672 }
6673 function CreateFilter(Filter)
6674 {
6675 if(!Filter || Filter.length == 0)
6676 {
6677 return null;
6678 }
6679 Filter = Filter.split(' ');
6680
6681 var regexp = "";
6682 for(var i = 0; i < Filter.length; ++i)
6683 {
6684 regexp = regexp + ".*" + Filter[i];
6685 }
6686 Filter = new Array();
6687 regexp = regexp + ".*";
6688 Filter.push(new RegExp(regexp, "i"));
6689 return Filter;
6690 }
6691 function FilterKeyUp()
6692 {
6693 FilterInputTimerString = FilterInputTimer.value;
6694 FilterInputGroupString = FilterInputGroup.value;
6695 FilterUpdate();
6696 }
6697
6698 function FilterUpdate()
6699 {
6700 FilterTimer = CreateFilter(FilterInputTimerString);
6701 FilterGroup = CreateFilter(FilterInputGroupString);
6702 }
6703
6704 function KeyDown(evt)
6705 {
6706 //console.log("keydown ", evt.keyCode);
6707 if(evt.keyCode == 18)
6708 {
6709 KeyAltDown = 1;
6710 }
6711 else if(evt.keyCode == 17)
6712 {
6713 KeyCtrlDown = 1;
6714 }
6715 else if(evt.keyCode == 16)
6716 {
6717 KeyShiftDown = 1;
6718 }
6719 else if(evt.keyCode == 9)
6720 {
6721 evt.preventDefault();
6722 }
6723 else if(evt.keyCode == 13)
6724 {
6725 evt.preventDefault();
6726 }
6727 if(evt.keyCode == 91) // z/tab to toggle tooltip
6728 {
6729 ToolTipFlip = 1;
6730 }
6731
6732
6733 Invalidate = 0;
6734 }
6735 function ParseCookie(str)
6736 {
6737 if(!str) return null;
6738 var result = str.match(/fisk=([^;]+)/);
6739 // console.log("cookie is " + str);
6740 if(result && result.length > 0)
6741 {
6742 var Obj = JSON.parse(result[1]);
6743 if(!Obj.offline)
6744 {
6745 var C = {};
6746 C.offline = Obj;
6747 Obj = C;
6748 }
6749 return Obj;
6750 }
6751 return null;
6752 }
6753
6754 function GetCookie()
6755 {
6756 var Obj = ParseCookie(localStorage.getItem("microprofile_fisk"));
6757 if(!Obj)
6758 {
6759 Obj = ParseCookie(document.cookie);
6760 }
6761 if(!Obj)
6762 {
6763 return {offline:{},live:{}};
6764 }
6765 return Obj;
6766 }
6767
6768 function ReadCookie()
6769 {
6770 var C = GetCookie();
6771 var NewMode = ModeDetailed;
6772 if(C.offline)
6773 {
6774 var Obj = C.offline;
6775 if(Obj.Mode)
6776 {
6777 NewMode = Obj.ModeX;
6778 }
6779 if(Obj.ReferenceTimeString)
6780 {
6781 ReferenceTimeString = Obj.ReferenceTimeString;
6782 }
6783 if(Obj.TargetTimeString)
6784 {
6785 TargetTimeString = Obj.TargetTimeString;
6786 }
6787 if(Obj.ThreadsHidden)
6788 {
6789 ThreadsHidden = Obj.ThreadsHidden;
6790 }
6791 if(Obj.GroupsAllActive || Obj.GroupsAllActive == 0 || Obj.GroupsAllActive)
6792 {
6793 GroupsAllActive = Obj.GroupsAllActive;
6794 }
6795 else
6796 {
6797 GroupsAllActive = 1;
6798 }
6799 if(Obj.GroupsDisabled)
6800 {
6801 GroupsDisabled = Obj.GroupsDisabled;
6802 }
6803 if(Obj.nContextSwitchEnabled)
6804 {
6805 nContextSwitchEnabled = Obj.nContextSwitchEnabled;
6806 }
6807 else
6808 {
6809 nContextSwitchEnabled = 1;
6810 }
6811 if(Obj.GroupColors)
6812 {
6813 GroupColors = Obj.GroupColors;
6814 }
6815 else
6816 {
6817 GroupColors = 0;
6818 }
6819 if(Obj.nHideHelp)
6820 {
6821 nHideHelp = 1;
6822 }
6823 if(Obj.ColumnsEnabled)
6824 {
6825 ColumnsEnabled = Obj.ColumnsEnabled;
6826 }
6827 if(Obj.ToolTipCorner)
6828 {
6829 ToolTipCorner = Obj.ToolTipCorner;
6830 }
6831 if(Obj.DrawDetailedFlameMode)
6832 {
6833 DrawDetailedFlameMode = Obj.DrawDetailedFlameMode;
6834 }
6835 if(Obj.DrawDetailedCompareReverse)
6836 {
6837 DrawDetailedCompareReverse = Obj.DrawDetailedCompareReverse;
6838 }
6839 if(Obj.ThreadOrderNames)
6840 {
6841 ThreadOrderNames = Obj.ThreadOrderNames;
6842 }
6843 if(Obj.ThreadLogAutoHide)
6844 {
6845 ThreadLogAutoHide = Obj.ThreadLogAutoHide;
6846 }
6847 if(Obj.DrawDetailedNewDraw)
6848 {
6849 DrawDetailedNewDraw = Obj.DrawDetailedNewDraw;
6850 }
6851
6852 }
6853 SetContextSwitch(nContextSwitchEnabled);
6854 SetMode(NewMode);
6855 SetReferenceTime(ReferenceTimeString);
6856 SetTargetTime(TargetTimeString);
6857 UpdateGroupColors();
6858 UpdateThreadLogAutoHide();
6859 }
6860 function WriteCookie()
6861 {
6862 var C = GetCookie();
6863 var Obj = new Object();
6864 Obj.ModeX = Mode;
6865 Obj.ReferenceTimeString = ReferenceTimeString;
6866 Obj.TargetTimeString = TargetTimeString;
6867 Obj.ThreadsHidden = ThreadsHidden;
6868 Obj.GroupsDisabled = GroupsDisabled;
6869 Obj.GroupsAllActive = GroupsAllActive;
6870 Obj.nContextSwitchEnabled = nContextSwitchEnabled;
6871 Obj.GroupColors = GroupColors;
6872 Obj.ColumnsEnabled = ColumnsEnabled;
6873 Obj.ToolTipCorner = ToolTipCorner;
6874 Obj.DrawDetailedFlameMode = DrawDetailedFlameMode;
6875 Obj.DrawDetailedCompareReverse = DrawDetailedCompareReverse;
6876 Obj.ThreadOrderNames = ThreadOrderNames;
6877 Obj.ThreadLogAutoHide = ThreadLogAutoHide;
6878 Obj.DrawDetailedNewDraw = DrawDetailedNewDraw;
6879 if(nHideHelp)
6880 {
6881 Obj.nHideHelp = 1;
6882 }
6883 C.offline = Obj;
6884 var date = new Date();
6885 date.setFullYear(2099);
6886 var cookie = 'fisk=' + JSON.stringify(C) + ';expires=' + date;
6887 document.cookie = cookie;
6888 localStorage.setItem("microprofile_fisk", cookie);
6889 }
6890
6891 function WindowRect(x,y,w,h)
6892 {
6893 var s = {};
6894 s.x = x;
6895 s.y = y;
6896 s.w = w;
6897 s.h = h;
6898 return s;
6899 }
6900
6901 function MenuSize(w)
6902 {
6903 return WindowRect(nWidth / 2 - w / 2, 5, w, nHeight);
6904 }
6905
6906 function TimerMenuSize()
6907 {
6908 return MenuSize(200 + 5 + FontWidth); //fix menu size
6909 }
6910
6911 function DrawFilterSearch()
6912 {
6913 FilterSearchSelection = -1;
6914 FilterSearchPassIndex = -1;
6915 FilterSearchSelectionMax = 0;
6916 if(!FilterSearchActive)
6917 return;
6918 nHoverToken = -1;
6919
6920 if(FilterInputSearchLast != FilterInput.value)
6921 {
6922 nOffsetFilterSearch = 0;
6923 }
6924 FilterInputSearchLast = FilterInput.value;
6925
6926 var FilterArray = CreateFilter(FilterInput.value);
6927 var context = CanvasDetailedView.getContext('2d');
6928 var nColorIndex = 0;
6929 var SizeInfo = TimerMenuSize();
6930 var Y = SizeInfo.y;
6931 var Width = S.TimerNameWidth + S.GroupNameWidth;
6932 SizeInfo.w = Width;
6933 var X = SizeInfo.x;
6934
6935 MoveFilterInputDiv(SizeInfo.x, SizeInfo.y, SizeInfo.w);
6936 var YStart = Y;
6937 Y += 35; //todo: measure somehow?
6938 var MouseX = DetailedViewMouseX;
6939 var MouseY = DetailedViewMouseY;
6940
6941 Y -= nOffsetFilterSearch;
6942 var Count = 0;
6943 for(var i = 0; i < S.TimerInfo.length; ++i)
6944 {
6945 var v = S.TimerInfo[i];
6946 {
6947 var Name = v.name;
6948 var ParentName = S.GroupInfo[v.group].name;
6949 if(FilterMatch(FilterArray, ParentName + " " + Name))
6950 {
6951 if(Y >= YStart)
6952 {
6953 Count++;
6954 var ParentName = S.GroupInfo[v.group].name;
6955 var ParentColor = 'white';
6956 var bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
6957 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
6958 var TextY = Y+BoxHeight-FontAscent;
6959 context.fillStyle = bgcolor;
6960 context.fillRect(X, Y, Width, BoxHeight);
6961 context.fillStyle = ParentColor;
6962 context.fillText(ParentName, X + 2, TextY);
6963 context.fillStyle = g_Colors[v.cid];
6964 context.textAlign = 'right';
6965 context.fillText(Name, X + Width - 2, TextY);
6966 context.textAlign = 'left';
6967 if(bMouseIn)
6968 {
6969 FilterSearchSelection = i;
6970 }
6971 }
6972 Y += BoxHeight;
6973 if(Y > nHeight)
6974 break;
6975 nColorIndex = 1-nColorIndex;
6976 }
6977 }
6978 }
6979 FilterSearchSelectionMax = Count;
6980 SizeInfo.h = Y-SizeInfo.y;
6981 RequestRedraw();
6982 return SizeInfo;
6983 }
6984
6985 function CalcAverage()
6986 {
6987 var Sum = 0;
6988 var Count = 0;
6989 for(nLog = 0; nLog < nNumLogs; nLog++)
6990 {
6991 StackPos = 0;
6992 for(var i = 0; i < S.Frames.length; i++)
6993 {
6994 var Frame_ = S.Frames[i];
6995 var tt = Frame_.tt[nLog];
6996 var ts = Frame_.ts[nLog];
6997
6998 var count = tt.length;
6999 for(var j = 0; j < count; j++)
7000 {
7001 var type = tt[j];
7002 var time = ts[j];
7003 if(type == 1)
7004 {
7005 Stack[StackPos] = time;//store the frame which it comes from
7006 StackPos++;
7007 }
7008 else if(type == 0)
7009 {
7010 if(StackPos>0)
7011 {
7012
7013 StackPos--;
7014 var localtime = time - Stack[StackPos];
7015 Count++;
7016 Sum += localtime;
7017 }
7018 }
7019 }
7020 }
7021 }
7022 return Sum / Count;
7023
7024 }
7025
7026 function CheckExtType(value, Checked)
7027 {
7028 if((value&3) != 3)
7029 return false;
7030 return (value >> 2) == Checked;
7031
7032 }
7033
7034 function MakeLod(index, MinDelta, TimeArray, TypeArray, IndexArray, LogStart)
7035 {
7036 if(S.LodData[index])
7037 {
7038 console.log("error!!");
7039 }
7040 var o = new Object();
7041 o.MinDelta = MinDelta;
7042 o.TimeArray = TimeArray;
7043 o.TypeArray = TypeArray;
7044 o.IndexArray = IndexArray;
7045 o.LogStart = LogStart;
7046 S.LodData[index] = o;
7047 }
7048
7049 function PreprocessBuildSplitArray()
7050 {
7051 var nNumLogs = S.Frames[0].ts.length;
7052
7053 ProfileEnter("PreprocessBuildSplitArray");
7054 var SplitArrays = new Array(nNumLogs);
7055
7056 for(nLog = 0; nLog < nNumLogs; ++nLog)
7057 {
7058 console.log("source log " + nLog + " size " + S.LodData[0].TypeArray[nLog].length);
7059 }
7060
7061
7062 for(nLog = 0; nLog < nNumLogs; nLog++)
7063 {
7064 var MaxDepth = 1;
7065 var StackPos = 0;
7066 var Stack = Array(20);
7067 var TypeArray = S.LodData[0].TypeArray[nLog];
7068 var TimeArray = S.LodData[0].TimeArray[nLog];
7069 var DeltaTimes = new Array(TypeArray.length);
7070
7071 for(var j = 0; j < TypeArray.length; ++j)
7072 {
7073 var type = TypeArray[j];
7074 var time = TimeArray[j];
7075 if(type == 1)
7076 {
7077 //push
7078 Stack[StackPos] = time;
7079 StackPos++;
7080 }
7081 else if(type == 0)
7082 {
7083 if(StackPos>0)
7084 {
7085 StackPos--;
7086 DeltaTimes[j] = time - Stack[StackPos];
7087 }
7088 else
7089 {
7090 DeltaTimes[j] = 0;
7091 }
7092 }
7093 }
7094 DeltaTimes.sort(function(a,b){return b-a;});
7095 var SplitArray = Array(NumLodSplits);
7096 var SplitIndex = DeltaTimes.length;
7097
7098 var j = 0;
7099 for(j = 0; j < NumLodSplits; ++j)
7100 {
7101 SplitIndex = Math.floor(SplitIndex / 2);
7102 while(SplitIndex > 0 && !DeltaTimes[SplitIndex])
7103 {
7104 SplitIndex--;
7105 }
7106 if(SplitIndex < SplitMin)
7107 {
7108 break;
7109 }
7110 //search.. if 0
7111 var SplitTime = DeltaTimes[SplitIndex];
7112 if(SplitTime>=0)
7113 {
7114 SplitArray[j] = SplitTime;
7115 }
7116 else
7117 {
7118 SplitArray[j] = SPLIT_LIMIT;
7119 }
7120 if(j>0)
7121 {
7122 console.assert(SplitArray[j-1] <= SplitArray[j], "must be less");
7123 }
7124
7125 }
7126 for(; j < NumLodSplits; ++j)
7127 {
7128 SplitArray[j] = SPLIT_LIMIT;
7129 }
7130
7131
7132 SplitArrays[nLog] = SplitArray;
7133 }
7134 ProfileLeave();
7135 return SplitArrays;
7136 }
7137
7138 function PreprocessBuildDurationArray()
7139 {
7140 var nNumLogs = S.Frames[0].ts.length;
7141 ProfileEnter("PreprocessBuildDurationArray");
7142 var DurationArrays = new Array(nNumLogs);
7143 for(nLog = 0; nLog < nNumLogs; ++nLog)
7144 {
7145 var MaxDepth = 1;
7146 var StackPos = 0;
7147 var Stack = Array(20);
7148 var StackIndex = Array(20);
7149 var TypeArray = S.LodData[0].TypeArray[nLog];
7150 var TimeArray = S.LodData[0].TimeArray[nLog];
7151 var DurationArray = Array(S.LodData[0].TypeArray[nLog].length);
7152 for(var j = 0; j < TypeArray.length; ++j)
7153 {
7154 var type = TypeArray[j];
7155 var time = TimeArray[j];
7156 if(type == 1)
7157 {
7158 //push
7159 Stack[StackPos] = time;
7160 StackIndex[StackPos] = j;
7161 StackPos++;
7162 }
7163 else if(type == 0)
7164 {
7165 if(StackPos>0)
7166 {
7167 StackPos--;
7168 var Duration = time - Stack[StackPos];
7169 DurationArray[StackIndex[StackPos]] = Duration;
7170 DurationArray[j] = Duration;
7171 }
7172 else
7173 {
7174 DurationArray[j] = 0;
7175 }
7176 }
7177 }
7178 for(var j = 0; j < StackPos; ++j)
7179 {
7180 DurationArray[j] = 0;
7181 }
7182 DurationArrays[nLog] = DurationArray;
7183 }
7184 ProfileLeave();
7185 return DurationArrays;
7186
7187 }
7188 function PreprocessLods()
7189 {
7190 ProfileEnter("PreprocessLods");
7191 var nNumLogs = S.Frames[0].ts.length;
7192 var SplitArrays = PreprocessBuildSplitArray();
7193 var DurationArrays = PreprocessBuildDurationArray();
7194 var Source = S.LodData[0];
7195 var SourceLogStart = Source.LogStart;
7196 var NumFrames = SourceLogStart.length;
7197
7198 for(var i = 0; i < NumLodSplits-1; ++i)
7199 {
7200 var DestLogStart = Array(SourceLogStart.length);
7201 for(var j = 0; j < DestLogStart.length; ++j)
7202 {
7203 DestLogStart[j] = Array(nNumLogs);
7204 }
7205 var MinDelta = Array(nNumLogs);
7206 var TimeArray = Array(nNumLogs);
7207 var IndexArray = Array(nNumLogs);
7208 var TypeArray = Array(nNumLogs);
7209
7210
7211
7212 for(nLog = 0; nLog < nNumLogs; ++nLog)
7213 {
7214 var SourceTypeArray = Source.TypeArray[nLog];
7215 var SourceTimeArray = Source.TimeArray[nLog];
7216 var SourceIndexArray = Source.IndexArray[nLog];
7217 var Duration = DurationArrays[nLog];
7218 console.assert(Duration.length == SourceTypeArray.length, "must be equal!");
7219 var SplitTime = SplitArrays[nLog][i];
7220
7221 MinDelta[nLog] = SplitTime;
7222 if(SplitTime < SPLIT_LIMIT)
7223 {
7224 var SourceCount = SourceTypeArray.length;
7225 var DestTypeArray = Array();
7226 var DestTimeArray = Array();
7227 var DestIndexArray = Array();
7228 var RemapArray = Array(SourceCount);
7229 var DiscardLast = 0;
7230
7231 for(var j = 0; j < SourceCount; ++j)
7232 {
7233 RemapArray[j] = DestTypeArray.length;
7234 if(Duration[j] >= SplitTime || ((SourceTypeArray[j]&3) == 3 && 0 == DiscardLast))
7235 {
7236 DiscardLast = 0;
7237 DestTypeArray.push(SourceTypeArray[j]);
7238 DestTimeArray.push(SourceTimeArray[j]);
7239 DestIndexArray.push(SourceIndexArray[j]);
7240 }
7241 else
7242 {
7243 DiscardLast = 1;
7244 }
7245 }
7246 TimeArray[nLog] = DestTimeArray;
7247 IndexArray[nLog] = DestIndexArray;
7248 TypeArray[nLog] = DestTypeArray;
7249 for(var j = 0; j < NumFrames; ++j)
7250 {
7251 var OldStart = SourceLogStart[j][nLog];
7252 var NewStart = RemapArray[OldStart];
7253 var FrameArray = DestLogStart[j];
7254 FrameArray[nLog] = NewStart;
7255 }
7256 }
7257 else
7258 {
7259
7260 for(var j = 0; j < NumFrames; ++j)
7261 {
7262 var FrameArray = DestLogStart[j];
7263
7264 FrameArray[nLog] = 0;
7265 }
7266
7267 }
7268
7269 }
7270 MakeLod(i+1, MinDelta, TimeArray, TypeArray, IndexArray, DestLogStart);
7271 }
7272 ProfileLeave();
7273 }
7274
7275
7276 function HistogramCreate(MaxTime)
7277 {
7278 let Histogram = new Object();
7279 Histogram.MaxTime = MaxTime;
7280 Histogram.MaxOccurence = 0;
7281 Histogram.Occurences = new Uint32Array(100);
7282 return Histogram;
7283 }
7284 function HistogramAdd(Histogram, Value)
7285 {
7286 if(Value > Histogram.MaxTime)
7287 debugger;
7288 let Index = Math.floor(Value / Histogram.MaxTime);
7289 Index = Math.max(0, Math.min(99, Index));
7290 Occurrences[Index]++;
7291 Histogram.MaxOccurence = Math.max(Histogram.MaxOccurence, Occurrences[Index]);
7292
7293 }
7294
7295 function PreprocessLogBarArray()
7296 {
7297 ProfileEnter("PreprocessLogBarArray");
7298
7299 let NumLogs = S.NumLogs;
7300 let Stack = Array(20);
7301
7302 let LogRows = new Array(NumLogs);
7303 S.LogRows = LogRows;
7304
7305 for(let nLog = 0; nLog < NumLogs; nLog++)
7306 {
7307 let MaxStack = S.MaxStack[nLog];
7308 let SectionColorStack = new Array(MaxStack);
7309 SectionColorStack[0] = CIDFail;
7310 let StackPos = 0;
7311 let SectionColorStackPos = 1;
7312
7313 let Rows = new Array(MaxStack);
7314 LogRows[nLog] = Rows;
7315 for(let i = 0; i < MaxStack; ++i)
7316 {
7317 Row = new Object();
7318 //Note; This has always got implied begin / end tied together
7319 Row.Offset = i;
7320 Row.Tree = new Array()
7321 Row.Tree[0] = new Object();
7322 Row.Tree[0].Source = new Array();
7323 Row.Tree[0].Index_ = new Array();
7324 Row.Tree[0].ColorIds_ = new Array();
7325 Row.Tree[0].Begin_ = new Array();
7326 Row.Tree[0].Duration_ = new Array();
7327 Row.Tree[0].MaxDuration_ = new Array();
7328 Row.Tree[0].SumDuration_ = new Array();
7329 Row.Tree[0].SectionColor_ = new Array();
7330 Row.Tree[0].Parent_ = -1;
7331 Row.Tree[0].Tail = 0;
7332 Row.Tree[0].Length = 0;
7333
7334 Rows[i] = Row;
7335 }
7336 let RootSectionColor = CIDFail;
7337
7338 let SrcTypeArray = S.TypeArray[nLog];
7339 let SrcTimeArray = S.TimeArray[nLog];
7340 let SrcIndexArray = S.IndexArray[nLog];
7341 let len = SrcTypeArray.length;
7342
7343 for(let i = 0; i < len; ++i)
7344 {
7345 let type = SrcTypeArray[i];
7346 let time = SrcTimeArray[i];
7347 let index = SrcIndexArray[i];
7348 let skipsection = false;
7349
7350 let TimerInfo = type < 2 ? S.TimerInfo[index] : null;
7351 if(type == 1)
7352 {
7353 let IsSection = TimerInfo.flags & FLAGS_SECTION;
7354 if(IsSection)
7355 {
7356 SectionColorStack[SectionColorStackPos] = TimerInfo.cid;
7357 SectionColorStackPos++;
7358 }
7359 if(!IsSection)
7360 {
7361 Stack[StackPos] = i;
7362 StackPos++;
7363 }
7364
7365 }
7366 else if(type == 0)
7367 {
7368 let IsSection = TimerInfo.flags & FLAGS_SECTION;
7369 if(IsSection)
7370 {
7371 if(SectionColorStackPos > 1)
7372 {
7373 SectionColorStackPos--;
7374 }
7375 else
7376 {
7377 //debugger;
7378 // Hitting a close, without a start. tag all previously untagged to belong to this section.
7379 for(let i = 0; i < MaxStack; ++i)
7380 {
7381 let sc = Rows[i].Tree[0].SectionColor_;
7382 for(let j = 0; j < sc.length; ++j)
7383 {
7384 if(sc[j] == CIDFail)
7385 {
7386 sc[j] = TimerInfo.cid;
7387 }
7388 }
7389 }
7390
7391 }
7392
7393 }
7394 if(!IsSection && StackPos > 0)
7395 {
7396 StackPos--;
7397 let stackindex = Stack[StackPos];
7398 let sectioncolor = SectionColorStack[SectionColorStackPos-1];
7399 let begintype = SrcTypeArray[stackindex];
7400 let begintime = SrcTimeArray[stackindex];
7401 let beginindex = SrcIndexArray[stackindex];
7402
7403 if(type != 0)
7404 debugger;
7405 if(begintype != 1)
7406 debugger;
7407 if(index != beginindex)
7408 debugger;
7409 if(StackPos >= MaxStack || StackPos < 0)
7410 debugger;
7411 let rt0 = Rows[StackPos].Tree[0];
7412 rt0.Source.push(i);
7413 rt0.Index_.push(beginindex);
7414 rt0.ColorIds_.push(S.TimerInfo[beginindex].cid);
7415 rt0.Begin_.push(begintime);
7416 let Duration = time - begintime;
7417 rt0.Duration_.push(Duration);
7418 rt0.SumDuration_.push(Duration);
7419 rt0.MaxDuration_.push(Duration);
7420 rt0.SectionColor_.push(sectioncolor);
7421 if(CheckExtType(SrcTypeArray[stackindex+1],ETOKEN_GPU_CPU_TIMESTAMP)) // (SrcTypeArray[stackindex+1]&3) == 3) // this is a gpu log with a cpu marker appended
7422 {
7423 //if((SrcTypeArray[stackindex+2]&3) != 3)
7424 if(!CheckExtType(SrcTypeArray[stackindex+2], ETOKEN_GPU_CPU_SOURCE_THREAD))
7425 debugger; //should be matching triplets
7426
7427 if(!CheckExtType(SrcTypeArray[i+1], ETOKEN_GPU_CPU_TIMESTAMP))
7428 debugger; //should be matching pairs
7429
7430 let CustomToken1 = SrcTypeArray[stackindex+1] >> 2;
7431 let CustomToken2 = SrcTypeArray[stackindex+2] >> 2;
7432
7433 if(CustomToken1 != ETOKEN_GPU_CPU_TIMESTAMP)
7434 debugger;
7435 if(CustomToken2 != ETOKEN_GPU_CPU_SOURCE_THREAD)
7436 debugger;
7437
7438
7439 let CpuBegin = SrcTimeArray[stackindex+1];
7440 let CpuEnd = SrcTimeArray[i+1];
7441 let Thread = SrcIndexArray[stackindex+2];
7442 if(!rt0.CpuDuration) //only there for gpu logs, so created on demand
7443 {
7444 rt0.CpuBegin = new Array();
7445 rt0.CpuDuration = new Array();
7446 rt0.CpuThread = new Array();
7447 for(let j = 0; j < rt0.Length; ++j)
7448 {
7449 rt0.CpuBegin.push(0);
7450 rt0.CpuDuration.push(0);
7451 rt0.CpuThread.push(0);
7452 }
7453 }
7454 rt0.CpuBegin.push(CpuBegin);
7455 rt0.CpuDuration.push(CpuEnd - CpuBegin);
7456 rt0.CpuThread.push(Thread);
7457 }
7458 else if(rt0.CpuDuration)
7459 {
7460 rt0.CpuBegin.push(0);
7461 rt0.CpuDuration.push(0);
7462 rt0.CpuThread.push(0);
7463 }
7464
7465 rt0.Length++;
7466 }
7467
7468 }
7469 else if(type != 0)
7470 {
7471 }
7472 }
7473
7474 for(let r = 0; r < Rows.length; ++r)
7475 {
7476 let Row = Rows[r];
7477 let RowTreeIndex = 0;
7478
7479 Row.Tree[0].Index = new Int32Array(Row.Tree[0].Index_);
7480 Row.Tree[0].ColorIds = new Int32Array(Row.Tree[0].ColorIds_);// = new Array();
7481 Row.Tree[0].Begin = new Float32Array(Row.Tree[0].Begin_);
7482 Row.Tree[0].Duration = new Float32Array(Row.Tree[0].Duration_);
7483 Row.Tree[0].MaxDuration = new Float32Array(Row.Tree[0].MaxDuration_);
7484 Row.Tree[0].SumDuration = new Float32Array(Row.Tree[0].SumDuration_);
7485 Row.Tree[0].SectionColor = new Int32Array(Row.Tree[0].SectionColor_);
7486
7487 // stop at 100 elements...
7488 while(Row.Tree[RowTreeIndex].Begin.length > 10)
7489 {
7490
7491 //Use RowTreeIndex to build RowTreeIndex+1 with half as much data.
7492 let RowTreeLevelParent = Row.Tree[RowTreeIndex];
7493 let Size = Math.floor(RowTreeLevelParent.Index.length / 2);
7494 let Tail = RowTreeLevelParent.Index.length % 2;
7495 if(Size < 0)
7496 debugger;
7497
7498 let RowTreeLevel = new Object();
7499 RowTreeLevel.Index = new Int32Array(Size);
7500 RowTreeLevel.ColorIds = new Int32Array(Size);
7501 RowTreeLevel.Begin = new Float32Array(Size);
7502 RowTreeLevel.Duration = new Float32Array(Size);
7503 RowTreeLevel.SumDuration = new Float32Array(Size);
7504 RowTreeLevel.MaxDuration = new Float32Array(Size);
7505 RowTreeLevel.SectionColor = new Int32Array(Size);
7506 RowTreeLevel.Parent = RowTreeIndex;
7507 RowTreeLevel.Tail = Tail;
7508 RowTreeLevel.Length = 0;
7509
7510 for(let i = 0; i < Size; ++i)
7511 {
7512 let i0 = i * 2;
7513 let i1 = i0 + 1;
7514 //Should do fancy color merging, but hey just taking the color of the largest seems to work well enough.
7515 if(RowTreeLevelParent.MaxDuration[i1] > RowTreeLevelParent.MaxDuration[i0])
7516 {
7517 RowTreeLevel.Index[i] = i1;
7518 RowTreeLevel.ColorIds[i] = RowTreeLevelParent.ColorIds[i1];
7519 RowTreeLevel.MaxDuration[i] = RowTreeLevelParent.MaxDuration[i1];
7520 RowTreeLevel.SectionColor[i] = RowTreeLevelParent.SectionColor[i1];
7521 }
7522 else
7523 {
7524 RowTreeLevel.Index[i] = i0;
7525 RowTreeLevel.ColorIds[i] = RowTreeLevelParent.ColorIds[i0];
7526 RowTreeLevel.MaxDuration[i] = RowTreeLevelParent.MaxDuration[i0];
7527 RowTreeLevel.SectionColor[i] = RowTreeLevelParent.SectionColor[i0];
7528 }
7529 RowTreeLevel.SumDuration[i] = RowTreeLevelParent.SumDuration[i0] + RowTreeLevelParent.SumDuration[i1];
7530 RowTreeLevel.Begin[i] = RowTreeLevelParent.Begin[i0];
7531 RowTreeLevel.Duration[i] = RowTreeLevelParent.Begin[i1] - RowTreeLevelParent.Begin[i0] + RowTreeLevelParent.Duration[i1];
7532 RowTreeLevel.Length++;
7533 }
7534
7535
7536 if(Row.Tree.length != RowTreeIndex+1)
7537 debugger;
7538 Row.Tree.push(RowTreeLevel);
7539 Row.MaxTree = Row.Tree.length;
7540 RowTreeIndex++;
7541 }
7542 }
7543 }
7544 ProfileLeave();
7545 }
7546
7547 function PreprocessGlobalArray()
7548 {
7549 ProfileEnter("PreprocessGlobalArray");
7550 var nNumLogs = S.Frames[0].ts.length;
7551 var CaptureStart = S.Frames[0].framestart;
7552 var CaptureEnd = S.Frames[S.Frames.length-1].frameend;
7553 S.TypeArray = new Array(nNumLogs);
7554 S.TimeArray = new Array(nNumLogs);
7555 S.IndexArray = new Array(nNumLogs);
7556 S.NumLogs = nNumLogs;
7557 var LogStartArray = new Array(S.Frames.length);
7558 for(var i = 0; i < S.Frames.length; i++)
7559 {
7560 S.Frames[i].LogStart = new Array(nNumLogs);
7561 LogStartArray[i] = S.Frames[i].LogStart;
7562
7563 S.Frames[i].LogEnd = new Array(nNumLogs);
7564 }
7565 var MinDelta = Array(nNumLogs);
7566 for(nLog = 0; nLog < nNumLogs; nLog++)
7567 {
7568 MinDelta[nLog] = 0;
7569 var Discard = 0;
7570 var TypeArray = new Array();
7571 var TimeArray = new Array();
7572 var IndexArray = new Array();
7573 for(var i = 0; i < S.Frames.length; i++)
7574 {
7575 var Frame_ = S.Frames[i];
7576 Frame_.LogStart[nLog] = TimeArray.length;
7577 var CanDiscard = !S.ISGPU[nLog] || Frame_.frameendgpu > 0; //in case of no reference, we cannot discard gpu markers. This happens when there is no gpu/cpu tick reference
7578
7579 var FrameDiscard = (S.ISGPU[nLog] ? Frame_.frameendgpu : Frame_.frameend) + 33;//if timestamps are more than 33ms after current frame, we assume buffer has wrapped.
7580 var tt = Frame_.tt[nLog];
7581 var ts = Frame_.ts[nLog];
7582 var ti = Frame_.ti[nLog];
7583 var len = tt.length;
7584 var DiscardLast = 0;
7585 for(var xx = 0; xx < len; ++xx)
7586 {
7587 var Skip = (tt[i]&3 == 3) ? DiscardLast : (CanDiscard && ts[xx] > FrameDiscard);
7588 if(Skip)
7589 {
7590 Discard++;
7591 DiscardLast = 1;
7592 }
7593 else
7594 {
7595 DiscardLast = 0;
7596 TypeArray.push(tt[xx]);
7597 TimeArray.push(ts[xx]);
7598 IndexArray.push(ti[xx]);
7599 }
7600 }
7601 Frame_.LogEnd[nLog] = TimeArray.length;
7602 }
7603 S.TypeArray[nLog] = TypeArray;
7604 S.TimeArray[nLog] = TimeArray;
7605 S.IndexArray[nLog] = IndexArray;
7606 if(Discard)
7607 {
7608 console.log('discarded ' + Discard + ' markers from ' + S.ThreadNames[nLog]);
7609 }
7610 }
7611 MakeLod(0, MinDelta, S.TimeArray, S.TypeArray, S.IndexArray, LogStartArray);
7612 ProfileLeave();
7613 }
7614
7615 function InitThreadLogAutoHidden()
7616 {
7617 let nNumLogs = S.Frames[0].ts.length;
7618 if(!S.ThreadLogAutoHidden)
7619 {
7620 S.ThreadLogAutoHidden = Array();
7621 }
7622 while(S.ThreadLogAutoHidden.length < nNumLogs)
7623 {
7624 S.ThreadLogAutoHidden.push(0);
7625 }
7626 if(!S.ThreadLogTypesUsed)
7627 {
7628 S.ThreadLogTypesUsed = Array();
7629 }
7630 while(S.ThreadLogTypesUsed.length < nNumLogs)
7631 {
7632 S.ThreadLogTypesUsed.push([]);
7633 }
7634 }
7635
7636 function UpdateThreadLogAutoHide()
7637 {
7638 let AutoHide = ThreadLogAutoHide;
7639 let nNumLogs = S.Frames[0].ts.length;
7640 InitThreadLogAutoHidden();
7641 for(let nLog = 0; nLog < nNumLogs; ++nLog)
7642 {
7643 if(AutoHide)
7644 {
7645 let TypesUsed = S.ThreadLogTypesUsed[nLog];
7646 S.ThreadLogAutoHidden[nLog] = 1;
7647 for(let i = 0; i < TypesUsed.length; ++i)
7648 {
7649 if(TypesUsed[i])
7650 {
7651 S.ThreadLogAutoHidden[nLog] = 0;
7652 break;
7653 }
7654 }
7655 }
7656 else
7657 {
7658 S.ThreadLogAutoHidden[nLog] = 0;
7659 }
7660 console.log("AutoHide ", nLog, " ", S.ThreadLogAutoHidden[nLog]);
7661 }
7662 }
7663
7664 function PreprocessGatherLogTypes()
7665 {
7666 ProfileEnter("PreprocessGatherLogTypes");
7667 let TimerCount = S.TimerInfo.length;
7668 let nNumLogs = S.Frames[0].ts.length;
7669 InitThreadLogAutoHidden();
7670 for(let nLog = 0; nLog < nNumLogs; nLog++)
7671 {
7672 S.ThreadLogAutoHidden[nLog] = 0;
7673 let TypesUsed = Array(TimerCount);
7674 for(let i = 0; i < TypesUsed.length; ++i)
7675 {
7676 TypesUsed[i] = 0;
7677 }
7678 for(let i = 0; i < S.Frames.length; i++)
7679 {
7680 let F = S.Frames[i];
7681 console.assert(F.tt.length == nNumLogs);
7682 let Data = F.ti[nLog];
7683 for(let j in Data)
7684 {
7685 let t = Data[j];
7686 console.assert(t < TimerCount);
7687 TypesUsed[t] = 1;
7688 }
7689 }
7690 S.ThreadLogTypesUsed[nLog] = TypesUsed;
7691 }
7692 ProfileLeave();
7693 }
7694
7695 function PreprocessFindFirstFrames()
7696 {
7697 ProfileEnter("PreprocesFindFirstFrames");
7698 //create arrays that show how far back we need to start search in order to get all markers.
7699 let nNumLogs = S.Frames[0].ts.length;
7700 for(let i = 0; i < S.Frames.length; i++)
7701 {
7702 S.Frames[i].FirstFrameIndex = new Array(nNumLogs);
7703 for(let j = 0; j < S.Frames[i].FirstFrameIndex.length; ++j)
7704 {
7705 S.Frames[i].FirstFrameIndex[j] = 0;
7706 }
7707 }
7708
7709 let StackPos = 0;
7710 let Stack = Array(20);
7711 S.MaxStack = Array(nNumLogs);
7712
7713 for(nLog = 0; nLog < nNumLogs; nLog++)
7714 {
7715 let MaxStack = 0;
7716 StackPos = 0;
7717 for(let i = 0; i < S.Frames.length; i++)
7718 {
7719 let Frame_ = S.Frames[i];
7720 let tt = Frame_.tt[nLog];
7721 let count = tt.length;
7722
7723 let FirstFrame = i;
7724 if(StackPos>0)
7725 {
7726 FirstFrame = Stack[0];
7727 }
7728 S.Frames[i].FirstFrameIndex[nLog] = FirstFrame;
7729
7730 for(let j = 0; j < count; j++)
7731 {
7732 let type = tt[j];
7733 if(type == 1)
7734 {
7735 Stack[StackPos] = i;//store the frame which it comes from
7736 StackPos++;
7737 if(StackPos > MaxStack)
7738 {
7739 MaxStack = StackPos;
7740 }
7741 }
7742 else if(type == 0)
7743 {
7744 if(StackPos>0)
7745 {
7746 StackPos--;
7747 }
7748 }
7749 }
7750 }
7751 S.MaxStack[nLog] = MaxStack;
7752 }
7753 S.MaxStack2 = Array(S.MaxStack.length);
7754 for(let i = 0; i < S.MaxStack2.length; ++i)
7755 S.MaxStack2[i] = 0;
7756 S.SecondActive = 0;
7757 ProfileLeave();
7758 }
7759 function PreprocessMeta()
7760 {
7761 return;
7762 MetaLengths = Array(MetaNames.length);
7763 MetaLengthsAvg = Array(MetaNames.length);
7764 MetaLengthsMax = Array(MetaNames.length);
7765 for(var i = 0; i < MetaNames.length; ++i)
7766 {
7767 MetaLengths[i] = MetaNames[i].length+1;
7768 MetaLengthsAvg[i] = MetaNames[i].length+5;
7769 MetaLengthsMax[i] = MetaNames[i].length+5;
7770 if(MetaLengths[i]<12)
7771 MetaLengths[i] = 12;
7772 if(MetaLengthsAvg[i]<12)
7773 MetaLengthsAvg[i] = 12;
7774 if(MetaLengthsMax[i]<12)
7775 MetaLengthsMax[i] = 12;
7776 }
7777 for(var i = 0; i < S.TimerInfo.length; ++i)
7778 {
7779 var Timer = S.TimerInfo[i];
7780 for(var j = 0; j < MetaNames.length; ++j)
7781 {
7782 var Len = FormatMeta(Timer.meta[j],0).length + 2;
7783 var LenAvg = FormatMeta(Timer.meta[j],2).length + 2;
7784 var LenMax = FormatMeta(Timer.meta[j],0).length + 2;
7785 if(Len > MetaLengths[j])
7786 {
7787 MetaLengths[j] = Len;
7788 }
7789 if(LenAvg > MetaLengthsAvg[j])
7790 {
7791 MetaLengthsAvg[j] = LenAvg;
7792 }
7793 if(LenMax > MetaLengthsMax[j])
7794 {
7795 MetaLengthsMax[j] = LenMax;
7796 }
7797 }
7798 }
7799 }
7800
7801 function StringHash(s) //note: matching code in microprofile.cpp: uint32_t MicroProfileStringHash(const char* pString)
7802 {
7803 let h = 0xfeedba3e;
7804 for(let i = 0; i < s.length; ++i)
7805 {
7806 h = s.charCodeAt(i) + (h << 5) - h;
7807 h = h & h;
7808 }
7809 return Math.abs(h);
7810 }
7811
7812 function StringColorIndex(Name)
7813 {
7814 let h = StringHash(Name);
7815 let cidx = Math.floor(360*(h / (1<<32-1)) );
7816 return cidx;
7817 }
7818
7819 function ColorFromString(Name, S, L)
7820 {
7821 let H = StringColorIndex(Name);
7822 return "hsl(" + H + "," + S + "%, " + L+ "%)";
7823 }
7824 function LerpColor(v)
7825 {
7826 let R_0 = 0;
7827 let G_0 = 1;
7828 let B_0 = 0;
7829
7830 let R_1 = 1;
7831 let G_1 = 0.5;
7832 let B_1 = 0;
7833
7834 let R_2 = 1;
7835 let G_2 = 0;
7836 let B_3 = 0;
7837 let R;
7838 let G;
7839 if(v < 0.5)
7840 {
7841 v *= 2;
7842 let v0 = (1-v);
7843 R = R_0 * v0 + R_1 * v;
7844 G = G_0 * v0 + G_1 * v;
7845
7846 }
7847 else
7848 {
7849 v = (v-0.5) * 2;
7850 let v0 = (1-v);
7851 R = R_1 * v0 + R_2 * v;
7852 G = G_1 * v0 + G_2 * v;
7853 }
7854 R *= 255;
7855 G *= 255;
7856 return "rgb(" + R.toFixed(0) + "," + G.toFixed(0) + ",0)";
7857
7858 }
7859
7860 function PreprocessThreadColors(S)
7861 {
7862 S.ThreadColors = Array(S.ThreadNames.length);
7863 for(let i = 0; i < S.ThreadNames.length; ++i)
7864 {
7865 var cidx = StringColorIndex(S.ThreadNames[i]);
7866 var color = "hsl(" + cidx + ",50%, 60%)";
7867 var coloroff = "hsl(" + cidx + ",85%, 50%)";
7868 var colordark = "hsl(" + cidx + ",80%, 30%)";
7869 var colordark_cid = GetColorIndex(colordark);
7870 var colortrans = "hsla(" + cidx + ",55%, 80%, 0.2)";
7871 S.ThreadColors[i] = {"color":color, "colordark":colordark, "cidx":cidx, "gradient":null,"gradientoff":null, "coloroff":coloroff, "colordark_cid":colordark_cid, "colortrans":colortrans};
7872 }
7873 }
7874
7875 function PreprocessWidths()
7876 {
7877 let context = CanvasHistory.getContext('2d');
7878 context.font = Font;
7879 S.TimerNameWidth = 0;
7880 S.GroupNameWidth = 0;
7881
7882 for(let i in S.TimerInfo)
7883 {
7884 let str = S.GroupInfo[S.TimerInfo[i].group].name + "XXX" + S.TimerInfo[i].name;
7885 let width = context.measureText(str).width;
7886 let widthname = context.measureText(S.TimerInfo[i].name).width;
7887 S.TimerInfo[i].wtotal = width;
7888 S.TimerInfo[i].w = widthname;
7889 S.TimerNameWidth = Math.max(S.TimerNameWidth, widthname);
7890 }
7891 for(let i in S.GroupInfo)
7892 {
7893 let widthname = context.measureText(S.TimerInfo[i].name).width;
7894 S.GroupNameWidth = Math.max(S.GroupNameWidth, widthname);
7895 }
7896 for(let i in S.ThreadNames)
7897 {
7898 let w = context.measureText(S.ThreadNames[i]).width;
7899 S.ThreadNameWidth = Math.max(S.ThreadNameWidth, w);
7900 }
7901 for(let i in S.CategoryInfo)
7902 {
7903 let w = context.measureText(S.CategoryInfo[i]).width;
7904 S.ThreadCategoryWidth = Math.max(S.ThreadCategoryWidth, w);
7905 }
7906 }
7907
7908 function PreprocessTimeline()
7909 {
7910 Timeline.Times = S.TimelineArray;
7911 Timeline.Ids = S.TimelineIdArray;
7912 Timeline.Colors = new Array(S.TimelineArray.length);
7913 Timeline.Names = S.TimelineNames;
7914 Timeline.Ends = new Array(S.TimelineArray.length);
7915 Timeline.Pairs = new Array(S.TimelineArray.length);
7916 Timeline.SearchMatch = new Array(S.TimelineArray.length);
7917 Timeline.Tracks = new Array();
7918 Timeline.Positions = new Array();
7919 for(var i = 0; i < Timeline.Times.length; ++i)
7920 {
7921 Timeline.Positions[i] = -1;
7922 Timeline.Ends[i] = -1;
7923 Timeline.Pairs[i] = -1;
7924 Timeline.SearchMatch[i] = false;
7925 var Color = S.TimelineColorArray[i]
7926 if(!Color || Color == '')
7927 {
7928 Color = '#777777'
7929 }
7930 Timeline.Colors[i] = GetColorIndex(Color);
7931 if(null == Timeline.Colors[i])
7932 debugger;
7933 Timeline.Colors[i] = GetColorIndex(Color);
7934 }
7935
7936
7937 var LinearizeTrack = function(Track)
7938 {
7939 var b = new Array();
7940 var e = new Array();
7941 // var n = new Array();
7942 var k = new Array();
7943 var h = Track.h;
7944 while(h != -1)
7945 {
7946 b.push(Track.b[h]);
7947 e.push(Track.e[h]);
7948 k.push(Track.k[h]);
7949
7950 h = Track.n[h];
7951 }
7952 }
7953
7954 var CreateTrack = function()
7955 {
7956 var Track = {};
7957 Track.b = new Array();
7958 Track.e = new Array();
7959 Track.n = new Array();
7960 Track.k = new Array();
7961 Track.h = -1;
7962 return Track;
7963 }
7964
7965
7966 var TryAddToTrack = function(Track, b, e, k)
7967 {
7968 var Invalid = 0;
7969 var prev = -1;
7970 var next = Track.h;
7971 while(next != -1)
7972 {
7973 var B = Track.b[next];
7974 var E = Track.e[next];
7975 if(Math.max(B, b) < Math.min(E, e))
7976 {
7977 Invalid = 1;
7978 break;
7979 }
7980 if(E < b)
7981 {
7982 //should be after next, continue
7983 }else if(e < B)
7984 {
7985 //insert at this spot
7986 break;
7987 }
7988 prev = next;
7989 next = Track.n[next];
7990 }
7991 if(!Invalid)
7992 {
7993 var idx = Track.b.length;
7994 Track.b.push(b);
7995 Track.e.push(e);
7996 Track.k.push(k);
7997 Track.n.push(next);
7998 if(prev == -1)
7999 {
8000 Track.h = idx;
8001 }
8002 else
8003 {
8004 var h = Track.n[prev];
8005 if(h != next)
8006 {
8007 debugger;
8008 }
8009 Track.n[prev] = idx;
8010 }
8011 return true;
8012 }
8013 else
8014 {
8015 return false;
8016 }
8017 };
8018
8019
8020 var AddToTrack = function(b, e, k)
8021 {
8022 var Tracks = Timeline.Tracks;
8023
8024 for(var i = 0; i < Tracks.length; ++i)
8025 {
8026 var Track = Tracks[i];
8027 if(TryAddToTrack(Track, b, e, k))
8028 {
8029 return i;
8030 }
8031 }
8032 var NewTrack = CreateTrack();
8033 var i = Timeline.Tracks.length;
8034 Timeline.Tracks.push(NewTrack);
8035 if(!TryAddToTrack(NewTrack, b, e, k))
8036 {
8037 debugger;
8038 }
8039 return i;
8040
8041 };
8042
8043 let HasMatchingName = function(index)
8044 {
8045 let name = Timeline.Names[index];
8046 return name && name.length > 0;
8047 };
8048
8049
8050
8051
8052
8053 var Matching = {};
8054 var Pairs = Timeline.Pairs;
8055 var Ids = Timeline.Ids;
8056 var Ends = Timeline.Ends;
8057 var Times = Timeline.Times;
8058 if(Ids)
8059 {
8060 for(var i = 0; i < Ids.length; ++i)
8061 {
8062 Pairs[i] = -1;
8063 var ID = Ids[i];
8064 var match = Matching[ID];
8065 if(match >= 0)
8066 {
8067 if(match > Ids.length || match < 0)
8068 debugger;
8069 Pairs[match] = i;
8070 Pairs[i] = match;
8071 if(match > i)
8072 debugger;
8073 Ends[match] = Times[i];
8074 var Track = AddToTrack(Times[match], Ends[match], match);
8075 Timeline.Positions[match] = Track;
8076 delete Matching[ID];
8077 }
8078 else
8079 {
8080 if(HasMatchingName(i))
8081 {
8082 Matching[ID] = i;
8083 }
8084 }
8085 }
8086 }
8087 // add any unclosed markers
8088 for(let id in Matching)
8089 {
8090 let index = Matching[id];
8091 let name = Timeline.Names[index];
8092 if(HasMatchingName(index)) // only close if there is a matching name...
8093 {
8094 let StartTime = Times[index];
8095 let EndTime = S.CaptureEndTime;
8096 if(StartTime >= EndTime)
8097 {
8098 EndTime = EndTime + 42;
8099 console.log("End marker after captureend time. this should not happen. adding 42");
8100 debugger;
8101 }
8102
8103 Ends[index] = S.CaptureEndTime;
8104 let Track = AddToTrack(Times[index], Ends[index], index);
8105 Timeline.Positions[index] = Track;
8106 }
8107 }
8108 }
8109
8110 function Preprocess_S()
8111 {
8112 console.log('preprocessing\n');
8113 S.LodData = new Array();
8114 S.CSwitchCache = {};
8115 S.CSwitchOnlyThreads = [];
8116 S.GroupNameWidth = 200;
8117 S.TimerNameWidth = 200;
8118 S.ThreadNameWidth = 150;
8119 S.ThreadCategoryWidth = 150;
8120
8121 PreprocessCalculateAllTimers();
8122 PreprocessFindFirstFrames();
8123 PreprocessGatherLogTypes();
8124
8125 PreprocessGlobalArray();
8126 PreprocessLogBarArray();
8127 PreprocessLods();//kill
8128 PreprocessMeta();//kill
8129 PreprocessThreadColors(S);
8130
8131 PreprocessContextSwitchCache();
8132 PreprocessWidths();
8133
8134 UpdateThreadLogAutoHide();
8135
8136 console.log('preprocessing done\n');
8137 console.log("SS " + S.LodData.length);
8138 }
8139 function Preprocess()
8140 {
8141 var ProfileModeOld = ProfileMode;
8142 ProfileMode = 1;
8143 ProfileModeClear();
8144 ProfileEnter("Preprocess");
8145 Preprocess_S();
8146 UpdateReferenceTime();
8147
8148 ProfileLeave();
8149 ProfileModeDump();
8150 ProfileMode = ProfileModeOld;
8151 PreprocessTimeline();
8152 Initialized = 1;
8153 }
8154
8155 function ToggleColumn(idx, isMeta)
8156 {
8157 ColumnsEnabled[idx] = !ColumnsEnabled[idx];
8158 UpdateColumnsMenu();
8159 WriteCookie();
8160 Invalidate = 0;
8161 }
8162 function UpdateColumnsMenu()
8163 {
8164 var ulColumnMenu = document.getElementById('ColumnsSubMenu');
8165 var Lis = ulColumnMenu.getElementsByTagName('li');
8166 for(var i = 0; i < Lis.length; ++i)
8167 {
8168 if(ColumnsEnabled[i])
8169 {
8170 Lis[i].style['text-decoration'] = 'underline';
8171 }
8172 else
8173 {
8174 Lis[i].style['text-decoration'] = 'none';
8175 }
8176 }
8177 }
8178
8179 function ResetColumnWidth()
8180 {
8181 if(ColumnsWidth)
8182 {
8183 for(var i = 0; i < ColumnsWidth.length; ++i)
8184 {
8185 ColumnsWidth[i] = 0;
8186 }
8187 }
8188 }
8189 var Comp0 = new Date();
8190 var Comp1 = new Date();
8191 var Comp2 = new Date();
8192 var Comp3 = new Date();
8193
8194 function SetGlobal(Name, Value)
8195 {
8196 this[Name] = Value;
8197 }
8198
8199
8200 //compare todo:
8201 // **Match threads
8202 // **match tokens.
8203 // **Calculate shared screen positions.
8204 // **Invert second pass
8205 // **fix hovertoken
8206 // **fix range display
8207 // todo: isgpu
8208 // todo: group numtimers.
8209 // implement timer view
8210
8211 function CompareFixup(S0, S1) // S0 is the reference
8212 {
8213 var GroupRemap = Array(S1.GroupInfo.length);
8214 var ThreadRemap = Array(S1.ThreadNames.length);
8215 var TimerRemap = Array(S1.TimerInfo.length);
8216 GroupRemapReverse = Array(S0.GroupInfo.length + S1.GroupInfo.length);
8217 TimerRemapReverse = Array(S0.TimerInfo.length + S1.TimerInfo.length);
8218 ThreadRemapReverse = Array(S0.ThreadNames.length + S1.ThreadNames.length);
8219
8220 for(var i = 0; i < GroupRemapReverse.length; ++i)
8221 GroupRemapReverse[i] = -1;
8222 for(var i = 0; i < TimerRemapReverse.length; ++i)
8223 TimerRemapReverse[i] = -1;
8224 for(var i = 0; i < ThreadRemapReverse.length; ++i)
8225 ThreadRemapReverse[i] = -1;
8226
8227
8228
8229 // var dump = function(SS, str)
8230 // {
8231 // console.log(str);
8232 // for(var i = 0; i < SS.GroupInfo.length; ++i)
8233 // {
8234 // console.log("G" + i + ":" + SS.GroupInfo[i].name);
8235 // }
8236 // for(var i = 0; i < SS.TimerInfo.length; ++i)
8237 // {
8238 // console.log("T" + i + ":" + SS.TimerInfo[i].name);
8239 // }
8240
8241 // };
8242 // dump(S0, "S0be4");
8243 // dump(S1, "S1be4");
8244
8245 for(var i = 0; i < S1.GroupInfo.length; ++i)
8246 {
8247 var n = S1.GroupInfo[i].name;
8248 var idx = S0.GroupInfo.findIndex(function(G){ return G.name == n; });
8249 if(idx != -1)
8250 {
8251 GroupRemap[i] = idx;
8252 }
8253 else
8254 {
8255 GroupRemap[i] = S0.GroupInfo.length;
8256 S0.GroupInfo.push(S1.GroupInfo[i]);
8257 }
8258 GroupRemapReverse[GroupRemap[i]] = i;
8259 }
8260 // for(var i = 0; i < S0.TimerInfo.length; ++i)
8261 // {
8262 // var n = S0.TimerInfo[i].name;
8263 // console.log('OG ', n, ' idx ', i);
8264 // }
8265
8266 for(var i = 0; i < S1.TimerInfo.length; ++i)
8267 {
8268 var TI = S1.TimerInfo[i];
8269 var n = TI.name;
8270 var g = GroupRemap[TI.group];
8271 var idx = S0.TimerInfo.findIndex(function(T){ return T.name == n && T.group == g; });
8272 TI.group = GroupRemap[TI.group];
8273 if(idx != -1)
8274 {
8275 TimerRemap[i] = idx;
8276 }
8277 else
8278 {
8279 console.log('added timer ' + TI.name + ' idx ' + S0.TimerInfo.length);
8280 TimerRemap[i] = S0.TimerInfo.length;
8281 TI.id = S0.TimerInfo.length;
8282 S0.TimerInfo.push(TI);
8283 }
8284 TimerRemapReverse[TimerRemap[i]] = i;
8285 }
8286
8287 var NumThreads = S0.ThreadNames.length;
8288
8289
8290 for(var i = 0; i < S1.ThreadNames.length; ++i)
8291 {
8292 var n = S1.ThreadNames[i];
8293 var idx = S0.ThreadNames.indexOf(n);
8294 if(idx != -1)
8295 {
8296 ThreadRemap[i] = idx;
8297 }
8298 else
8299 {
8300 ThreadRemap[i] = S0.ThreadNames.length;
8301 S0.ThreadNames.push(n);
8302 NumThreads++;
8303 }
8304 ThreadRemapReverse[ThreadRemap[i]] = i;
8305 }
8306
8307
8308 PreprocessThreadColors(S0);
8309 PreprocessThreadColors(S1);
8310
8311 var Fix = function(a, r)
8312 {
8313 for(var i in a)
8314 {
8315 a[i] = r[a[i]];
8316 }
8317 };
8318 var FixArray = function(a, s)
8319 {
8320 if(!s)
8321 return;
8322 for(var i = 0; i < a.length; ++i)
8323 {
8324 if(!a[i])
8325 a[i] = [];
8326 }
8327 while(a.length != s)
8328 a.push([]);
8329 };
8330
8331 for(var i in S0.Frames)
8332 {
8333 var F = S0.Frames[i];
8334 FixArray(F.ti, NumThreads);
8335 FixArray(F.ts, NumThreads);
8336 FixArray(F.tt, NumThreads);
8337 }
8338
8339 for(var i in S1.Frames)
8340 {
8341 var F = S1.Frames[i];
8342 var ti = F.ti;
8343 var ts = F.ts;
8344 var tt = F.tt;
8345
8346 F.ti = new Array(NumThreads);
8347 F.ts = new Array(NumThreads);
8348 F.tt = new Array(NumThreads);
8349
8350 for(var j in ti)
8351 {
8352
8353 Fix(ti[j], TimerRemap);
8354 F.ti[ThreadRemap[j]] = ti[j];
8355 }
8356 FixArray(F.ti, NumThreads);
8357 for(var i = 0; i < NumThreads; ++i)
8358 {
8359 if(!F.ti[i])
8360 debugger;
8361 }
8362 for(var j in ts)
8363 {
8364 F.ts[ThreadRemap[j]] = ts[j];
8365 }
8366 FixArray(F.ts, NumThreads);
8367 for(var i = 0; i < NumThreads; ++i)
8368 {
8369 if(!F.ts[i])
8370 debugger;
8371 }
8372 for(var j in tt)
8373 {
8374 F.tt[ThreadRemap[j]] = tt[j];
8375 }
8376 FixArray(F.tt, NumThreads);
8377
8378 for(var i = 0; i < NumThreads; ++i)
8379 {
8380 if(!F.tt[i])
8381 debugger;
8382 }
8383 //assert length is the same
8384 if(F.tt.length != S0.Frames[0].tt.length)
8385 {
8386 debugger;
8387 }
8388 if(F.ti.length != S0.Frames[0].ti.length)
8389 {
8390 debugger;
8391 }
8392 if(F.ts.length != S0.Frames[0].ts.length)
8393 {
8394 debugger;
8395 }
8396 // console.log('log ' + i + ':', F.ts.length, ':', F.ti.length, ':', F.tt.length);
8397 }
8398
8399 var NewTimerInfo = Array(S0.TimerInfo.length);
8400 for(var i = 0; i < S1.TimerInfo.length; ++i)
8401 {
8402 let xx = TimerRemap[i];
8403 NewTimerInfo[xx] = S1.TimerInfo[i];
8404 NewTimerInfo[xx].id = xx;
8405 NewTimerInfo[xx].group = S0.TimerInfo[xx].group;
8406
8407 if(NewTimerInfo[xx].id != S0.TimerInfo[xx].id)
8408 {
8409 debugger;
8410 }
8411 if(NewTimerInfo[xx].group != S0.TimerInfo[xx].group)
8412 {
8413 debugger;
8414 }
8415
8416 }
8417 for(var i = 0; i < NewTimerInfo.length; ++i)
8418 {
8419 if(!NewTimerInfo[i])
8420 {
8421 NewTimerInfo[i] = CloneTimer(S0.TimerInfo[i]);
8422 NewTimerInfo[i].id = i;
8423 if(NewTimerInfo[i].id != S0.TimerInfo[i].id)
8424 {
8425 debugger;
8426 }
8427 if(NewTimerInfo[i].group != S0.TimerInfo[i].group)
8428 {
8429 debugger;
8430 }
8431
8432 }
8433 }
8434 S1.TimerInfo = NewTimerInfo;
8435 var NewGroupInfo = Array(S0.GroupInfo.length);
8436
8437 for(let i = 0; i < S1.GroupInfo.length; ++i)
8438 {
8439 let xx = GroupRemap[i];
8440 NewGroupInfo[xx] = S1.GroupInfo[i];
8441 NewGroupInfo[xx].id = xx;
8442 }
8443 for(let i = 0; i < NewGroupInfo.length; ++i)
8444 {
8445 if(!NewGroupInfo[i])
8446 {
8447 NewGroupInfo[i] = CloneGroup(S0.GroupInfo[i]);
8448 NewGroupInfo[i].id = i;
8449 }
8450 }
8451 S1.GroupInfo = NewGroupInfo;
8452 for(let i = 0; i < S1.GroupInfo.length; ++i)
8453 {
8454 if(S1.GroupInfo[i].id != i)
8455 debugger;
8456 if(S0.GroupInfo[i].id != i)
8457 debugger;
8458 }
8459
8460 //debugging:
8461 if(S0.TimerInfo.length != S1.TimerInfo.length)
8462 debugger;
8463 for(let i = 0; i < S0.TimerInfo.length; ++i)
8464 {
8465 let t0 = S0.TimerInfo[i];
8466 let t1 = S1.TimerInfo[i];
8467 if(t0.id != t1.id)
8468 debugger;
8469 if(t0.name != t1.name)
8470 debugger;
8471 if(t0.group != t1.group)
8472 debugger;
8473 }
8474
8475 if(S0.GroupInfo.length != S1.GroupInfo.length)
8476 debugger;
8477 for(let i = 0; i < S0.GroupInfo.length; ++i)
8478 {
8479 let t0 = S0.GroupInfo[i];
8480 let t1 = S1.GroupInfo[i];
8481 if(t0.id != t1.id)
8482 debugger;
8483 if(t0.name != t1.name)
8484 debugger;
8485 }
8486 }
8487
8488 function ReadHtmlFile(File)
8489 {
8490 if (!File)
8491 {
8492 return;
8493 }
8494 var Reader = new FileReader();
8495 Reader.onload = function(e) {
8496 if(!ParseCompareData(e.target.result))
8497 {
8498 ShowFlashMessage("Failed to parse file", 50);
8499 }
8500 };
8501 Reader.onprogress = function(e)
8502 {
8503 var m = e.loaded + ":" + e.total + " :: " + e.lengthComputable;
8504 console.log(m);
8505 };
8506 Reader.readAsText(File);
8507 }
8508
8509 function ReadHtmlFileHandler(e)
8510 {
8511 ReadHtmlFile(e.target.files[0]);
8512 }
8513
8514 function ParseCompareData(Data)
8515 {
8516 S.AA = "Original";
8517 Comp1 = new Date();
8518
8519 var idxbegin = Data.indexOf("//EBEGIN");
8520 if(idxbegin == -1)
8521 return false;
8522 idxbegin += "//EBEGIN".length + 1;
8523 var idxend = Data.indexOf("//EEND", idxbegin);
8524 if(idxend == -1)
8525 return false;
8526
8527 Comp2 = new Date();
8528 var SOriginal = S;
8529 S = {};
8530
8531 var idx = idxbegin;
8532 while(idx < idxend)
8533 {
8534 var idx0 = Data.indexOf('\n', idx);
8535 var s = Data.substring(idx, idx0);
8536 // console.log(s);
8537 eval(s);
8538 idx = idx0+1;
8539 }
8540
8541 S.AA = "Parsed";
8542 var SParsed = S; //note: the calls to eval, will make a new "S" in local scope.
8543 SetGlobal("S", S); //Set global S to point to new object, while its preprocessed
8544 Comp3 = new Date();
8545
8546
8547 CompareFixup(SOriginal, SParsed);
8548 Preprocess_S();
8549
8550 var MaxStack2 = SParsed.MaxStack;
8551
8552 var Comp4 = new Date();
8553 SetGlobal("S2", SParsed);
8554 SetGlobal("S", SOriginal);
8555
8556 Preprocess_S(); //since indices are rebased, a repreprocessing is needed.
8557
8558 SOriginal.MaxStack2 = SParsed.MaxStack;
8559 SParsed.MaxStack2 = SOriginal.MaxStack;
8560 SOriginal.SecondActive = 1;
8561
8562
8563 ThreadOrderSort();
8564
8565 console.log('file loaded ' + idxbegin + ' ' + idxend );
8566 console.log('time ' + (Comp1 - Comp0));
8567 console.log('time ' + (Comp2 - Comp1));
8568 console.log('time ' + (Comp3 - Comp2).toFixed(2));
8569 console.log('time ' + (Comp4 - Comp3).toFixed(2));
8570 document.getElementById('file-input').removeEventListener('change', ReadHtmlFileHandler, false);
8571 let fname = document.getElementById('file-input').value;
8572 let index = 1+Math.max(fname.lastIndexOf('/'), fname.lastIndexOf('\\'));
8573 if(index < fname.length)
8574 fname = fname.substring(index);
8575 let CompStr = 'Compare [' + fname + ']';
8576 RequestRedraw();
8577 return true;
8578 }
8579
8580 function ComparePrompt()
8581 {
8582 document.getElementById('file-input').addEventListener('change', ReadHtmlFileHandler, false);
8583 document.getElementById('file-input').click();
8584 }
8585
8586
8587 // magic from stack-overflow somewhere..
8588 function WindowDragEnter(e)
8589 {
8590 LastDropTarget = e.target;
8591 document.querySelector(".dropzone").style.visibility = "";
8592 document.querySelector(".dropzone").style.opacity = 1;
8593 };
8594
8595 function WindowDragLeave(e)
8596 {
8597 if(e.target === LastDropTarget || e.target === document)
8598 {
8599 document.querySelector(".dropzone").style.visibility = "hidden";
8600 document.querySelector(".dropzone").style.opacity = 0;
8601 }
8602 };
8603 function DropHandler(ev)
8604 {
8605 document.querySelector(".dropzone").style.visibility = "hidden";
8606 document.querySelector(".dropzone").style.opacity = 0;
8607 LastDropTarget = null;
8608
8609 if(ev.dataTransfer.files.length > 0)
8610 {
8611 let File = ev.dataTransfer.files[0];
8612 let Name = File.name
8613 let ExtMatch = Name.match(/\.[0-9a-zA-Z]+$/);
8614 let Ext = ExtMatch ? ExtMatch[0] : "";
8615 if(Ext.toLowerCase() == ".html")
8616 {
8617 ReadHtmlFile(File);
8618 }
8619 else
8620 {
8621 window.alert("Not a .html file!\n" + Name);
8622 }
8623 }
8624 ev.preventDefault();
8625 }
8626
8627 function DragOverHandler(ev)
8628 {
8629 ev.preventDefault();
8630 }
8631
8632 var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
8633
8634 CanvasDetailedView.addEventListener('mousemove', MouseMove, false);
8635 CanvasDetailedView.addEventListener('mousedown', function(evt) { MouseButton(true, evt); });
8636 CanvasDetailedView.addEventListener('mouseup', function(evt) { MouseButton(false, evt); } );
8637 CanvasDetailedView.addEventListener('mouseout', MouseOut);
8638 CanvasDetailedView.addEventListener("contextmenu", function (e) { e.preventDefault(); }, false);
8639 CanvasDetailedView.addEventListener(mousewheelevt, MouseWheel, false);
8640 CanvasHistory.addEventListener('mousemove', MouseMove);
8641 CanvasHistory.addEventListener('mousedown', function(evt) { MouseButton(true, evt); });
8642 CanvasHistory.addEventListener('mouseup', function(evt) { MouseButton(false, evt); } );
8643 CanvasHistory.addEventListener('mouseout', MouseOut);
8644 CanvasHistory.addEventListener("contextmenu", function (e) { e.preventDefault(); }, false);
8645 CanvasHistory.addEventListener(mousewheelevt, MouseWheel, false);
8646 CanvasMenu.addEventListener('mousemove', MouseMove);
8647 CanvasMenu.addEventListener('mousedown', function(evt) { MouseButton(true, evt); });
8648 CanvasMenu.addEventListener('mouseup', function(evt) { MouseButton(false, evt); } );
8649 CanvasMenu.addEventListener('mouseout', MouseOut);
8650 CanvasMenu.addEventListener("contextmenu", function (e) { e.preventDefault(); }, false);
8651 CanvasMenu.addEventListener(mousewheelevt, MouseWheel, false);
8652 FilterInputTimer.addEventListener('keyup', FilterKeyUp);
8653 FilterInputGroup.addEventListener('keyup', FilterKeyUp);
8654
8655 window.addEventListener('keydown', KeyDown);
8656 window.addEventListener('keyup', KeyUp);
8657 window.addEventListener('resize', ResizeCanvas, false);
8658 window.addEventListener("dragenter", WindowDragEnter);
8659 window.addEventListener("dragleave", WindowDragLeave);
8660
8661
8662 InitGroups();
8663 ReadCookie();
8664 MeasureFont();
8665 ThreadOrderSort();
8666 InitOrderArrays();
8667 InitMenu();
8668 InitFrameInfo();
8669 ResizeCanvas();
8670 Preprocess();
8671 OnPageReady();
8672 Draw(1);
8673
8674
8675 </script>
8676 </body>
8677 </html>