Debian Codegraph @

src/microprofilelive.html

raw ◀ ▶
1 Debian patch touch this file
•1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>MicroProfile Live</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;width:100%;}
36 ul li ul li{ display:block;float:none;width:100%;}
37 li li a{ display:block;float:none;width:100%;text-align:left;}
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;margin-left:-999em;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 .filterinputsearchdiv{position:fixed; background-color: #313131;display:none;}
44 .filterinputsearch{width:100px;}
45 </style>
46 </head>
47 <body style="">
48 <div style="visibility:hidden; opacity:0" class="dropzone" ondrop="DropHandler(event);" ondragover="DragOverHandler(event);">drop .csv files to view CSV data</div>
49 <div class="filterinputsearchdiv" id="FilterInputDiv">Filter<br><input type="text" id="FilterInput" class="filterinputsearch"></div>
50 <div class="helpstart" id="helpwindow" style="left:20px;top:20px">
51 History View:<br>
52 Right Click + Drag : Select Region<br>
53 Click + Drag: Move Selection<br>
54 Click Frame : Center on frame<br>
55 <hr>
56 Main View:<br>
57 space: Freeze capturing<br>
58 x : Toggle View<br>
59 / : Rotate connection port % 3<br>
60 Ctrl + Drag: Pan<br>
61 Click + Drag: Pan<br>
62 Enter: Capture selection/Next N Frames
63 <hr>
64 <table style="width:100%">
65 <tr>
66 <td width="50%" align="left"><a href='javascript:void(0)' onclick="ShowHelp(0);">Close</a></td>
67 </tr>
68 </table>
69 </div>
70 <canvas id="DetailedView" height="100%" style="background-color:#343434;margin:0px;padding:0px;"></canvas>
71 <script>
72 "use strict"
73
74 var FRAME_HISTORY_COLOR_CPU = '#ff7f27';
75 var FRAME_HISTORY_COLOR_GPU = '#ffffff';
76
77 var Settings = {};
78 var Cookie = {};
79
80 const PERCENTILE_SAMPLES = 1000;
81
82 var HistoryHeight = 100;
83 var CanvasDetailedView = document.getElementById('DetailedView');
84 var CanvasDetailedOffscreen = document.createElement('canvas');
85 var FilterInput = document.getElementById('FilterInput');
86 var FilterInputDiv = document.getElementById('FilterInputDiv');
87 var FilterInputDivPos = {"x":-1,"y":-1,"w":-1,"h":-1};
88 var FilterInputValueLast = '';
89
90 var CanvasArray0 = [];
91 var CanvasArray1 = [];
92 var Views = [];
93
94 var ViewIndex = 0;
95
96 var nWidth = CanvasDetailedView.width;
97 var nHeight = CanvasDetailedView.height;
98 var nBackColors = ['#292929', '#343434' ];
99 var nBackColorsDark = ['#292929', '#272727' ];
100 var nBackColorOffset = '#404040';
101 var FontHeight = 10;
102 var FontHeightLarge = 12;
103 var FontWidth = 1;
104 var FontAscent = 3; //Set manually
105 var Font = 'Bold ' + FontHeight + 'px Courier New';
106 var FontLarge = 'Bold ' + FontHeightLarge + 'px Courier New';
107 var FontFlash = 'Bold ' + 35 + 'px Courier New';
108 var BoxHeight = FontHeight + 2;
109 var MouseX = 0;
110 var MouseY = 0;
111 var MouseReleased = false;
112 var MouseMoveTime = new Date();
113
114 var nBarsWidth = 80;
115 var nOffsetBarsX = 0;
116 var nOffsetBarsY = 0;
117 var nOffsetCountersY = 0;
118 var nOffsetMenuTimers = 0;
119 var nOffsetMenuGroup = 0;
120 var nOffsetMenuFunctions = 0;
121 var nOffsetMenuModules = 0;
122 var nOffsetMenuPatched = 0;
123
124 var nHoverCounter = -1;
125
126 var MouseDragOff = 0;
127 var MouseDragDown = 1;
128 var MouseDragUp = 2;
129 var MouseDragMove = 3;
130 var MouseDragState = MouseDragOff;
131 var MouseDragTarget = 0;
132 var MouseDragButton = 0;
133 var MouseDragKeyShift = 0;
134 var MouseDragKeyCtrl = 0;
135 var MouseDragX = 0;
136 var MouseDragY = 0;
137 var MouseDragXLast = 0;
138 var MouseDragYLast = 0;
139 var MouseDragXStart = 0;
140 var MouseDragYStart = 0;
141
142 var MouseDragActiveXStart = 0;
143 var MouseDragActiveXEnd = -1;
144 var MouseInCaptureButton = 0;
145
146 var ToolTipCallback = null;
147
148 var DPR = 0;
149 var C_HUGE = 1e10;
150
151 var ActivePreset = "Default";
152 var ActivePresetRO = 0;
153 var PresetPending = 0;
154 var Presets = [];
155 var PresetsCache = {};
156 var ReadOnlyPresets = [];
157 var ReadOnlyPresetsCache = {};
158
159 Settings.SubGraphSettings = {};
160 Settings.ReferenceTime = 50.0;
161 var ReferencePresets = [5.0, 10.0, 15.0, 20, 30, 33.33, 50, 66.66,100.0,250.0,500,1000.0];
162 var PercentilePresets = [0.0, 1.0, 5.0, 10.0, 50.0, 75.0, 99.0];
163 var ReferenceTimeTweak = -1;
164 var PercentileTweak = -1;
165
166 Settings.TargetTime = 30;
167 var TargetTimeTweak = -1;
168
169
170 var AggregateFrames = 60;
171 Settings.AggregateFrames = 60;
172 var AggregatePresets = [0, 10,20,30,60,90,120,500];
173 var AggregateHistorySize = 5;
174 var AggregateTweak = -1;
175 var AggregateCurrent = 0;
176
177 var AutoCaptureCooldown = -1;
178 var AutoCaptureEnabled = 0;
179 var AutoCaptureDefaultThreshold = 66;
180 Settings.AutoCaptureTheshold = AutoCaptureDefaultThreshold;
181 Settings.AutoCaptureRepeat = 1;
182 var AutoCaptureThesholdPresets = [1,3,5,10,15,30,50,66,90,100,250,500,1000];
183 var AutoCaptureRepeatPresets = [1,2,3,4,5,6,7,8,9,10, 25, 50, 100];
184 var AutoCaptureTweak = -1;
185 var AutoCaptureRepeatTweak = -1;
186 var AutoCaptureSourceTweak = -1;
187 var AutoCaptureSourceIndex = -1;
188
189 var CaptureFramesDefault = 30;
190 Settings.CaptureFrames = CaptureFramesDefault;
191 Settings.CaptureDelay = 0;
192 var CaptureFramesPresets = [5,10,15,30,50,66,90,100];
193 var CaptureDelayPresets = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
194 var CaptureTweak = -1;
195 var CaptureDelayTweak = -1;
196
197 var CaptureTriggerTime = null;
198 var CaptureTriggerTimeType = 0;
199 var CaptureTriggerDelta = 0;
200
201 let LastDropTarget = null;
202
203
204
205 var ProfileData = {};
206 var ProfileStackTime = [];
207 var ProfileStackName = [];
208 var ProfileMode = 0;
209 var ProfileRedraw0 = 0;
210 var ProfileRedraw1 = 0;
211 var ProfileRedraw2 = 0;
212 var ProfileFps = 0;
213 var ProfileMs = 0;
214 var ProfileFpsAggr = 0;
215 var ProfileFpsCount = 0;
216 var ProfileLastTimeStamp = new Date();
217 var PlotfArray = new Array();
218
219 var ConnectionStr = ["\\", "|", "/", "-" ];
220 var ConnectionIdx = 0;
221 var EnabledArray = [];
222
223
224 var FrameData = {};
225 var FRAME_COUNT = 256;
226 var FramePending = 0;
227
228 var WSConnected = 0;
229 var WSIsOpen = 0;
230 var WSSeconds = 0;
231 var WSFail = 0;
232 var WS;
233 var WSHost = location.hostname ? location.hostname : "localhost";
234 var WSPort = location.port ? location.port : 1338;
235 var WSPath;
236
237 var CaptureButtonX = 0;
238 var CaptureButtonY = 0;
239 var GroupsEnabled = 0;
240 var TimersEnabled = 0;
241
242 var TimersActiveOnly = 0;
243
244
245 var MSG_TIMER_TREE = 1;
246 var MSG_ENABLED = 2;
247 var MSG_FRAME = 3;
248 var MSG_LOADSETTINGS = 4;
249 var MSG_PRESETS = 5;
250 var MSG_CURRENTSETTINGS = 6;
251 var MSG_COUNTERS = 7;
252 var MSG_FUNCTION_RESULTS = 8;
253 var MSG_INACTIVE_FRAME = 9;
254 var MSG_FUNCTION_NAMES = 10;
255 var MSG_INSTRUMENT_ERROR = 11;
256 // var MSG_MODULE_NAME = 12;
257
258
259 var TYPE_NONE = 0;
260 var TYPE_TIMER = 1;
261 var TYPE_GROUP = 2;
262 var TYPE_CATEGORY = 3;
263 var TYPE_SETTING = 4;
264 var TYPE_COUNTER = 5;
265
266
267 var WSSend = 0;
268 var WSReceive = 0;
269 var WSSendBytes = 0;
270 var WSReceiveBytes = 0;
271 var WSOpenTime = 0;
272
273
274 var TimerArray = [];
275 var CounterArray = [];
276 var Empty = {"id":0, "w":0, "depth":0, "sibling":-1,"parent":-1,"firstchild":-1};
277 var WidthArray = [];
278 var FunctionQueryArray = [];
279 var FunctionQueryPending = null;
280 var FunctionQueryLastRequest = 0;
281 var FunctionQueryReceived = 0;
282 var WidthTree = 0;
283 Settings.ViewActive = 0;
284 Settings.ViewCompressed = 0;
285 Settings.AllowHighDPI = 1;
286 var ViewNames = ["Graph", "Graph", "Graph", "Bars", "Bars", "Bars", "Counters"];
287 var ViewNames2 = ["[split]", "[percentile]","[group/thread]","[table]", "[all]", "[single]", ""];
288
289 var VIEW_GRAPH_SPLIT = 0;
290 // var VIEW_GRAPH = 1;
291 var VIEW_GRAPH_PERCENTILE = 1;
292 var VIEW_GRAPH_THREAD_GROUP = 2;
293 var VIEW_BAR = 3;
294 var VIEW_BAR_ALL = 4;
295 var VIEW_BAR_SINGLE = 5;
296 var VIEW_COUNTERS = 6;
297 var VIEW_SIZE = 7;
298
299 var GRAPH_ALPHA = 0.5;
300
301
302 // Settings.FancyGraph = 1;
303 Settings.AutomaticReference = 1;
304 Cookie.CodeReportMode = 0; // 0: prompt, 1:always send, 2: never send, never prompt
305
306
307 var ReferenceHistory = 0;
308 var ReferenceGraph = 0;
309 var ReferenceBar = 0;
310 var ReferenceHistoryAutomatic = 0;
311 var ReferenceGraphAutomatic = 0;
312 var ReferenceGraphAutomaticGroup = 0;
313 var ReferenceBarAutomatic = 0;
314
315 var SingleTimerBars = 0;
316 var History;
317 var MainView;
318 var X7Views;
319 var X7LegendView;
320 var X7BarColumnRemap = [0,1,2,3,4,5,6];
321 var X7BarColumnMask = -1;
322 var X7LegendOffset = 25;
323 var X7BarLastView = -1;
324 var X7BarFirstView = -1;
325
326
327 var ViewBarMaxMsTextLength = 0;
328
329 Settings.SortColumnOrderFlip = 0;
330 Settings.SortColumnName = "";
331 var SortColumnMouseOverNext = "";
332
333
334 var KeyShiftDown = 0;
335 var KeyCtrlDown = 0;
336
337 var IsFrozen = 0;
338
339 var PresetToLoad;
340 var PresetToLoadRO = 0;
341 var HelpFade;
342
343
344 TimerArray.push(Empty); // 0 is root of tree
345
346 var StrTime = "Time";
347 var StrExclusive = "Excl Time";
348 var StrGroup = "Group";
349 var StrThread = "Thread";
350 var StrTimer = "Timer";
351 var StrAverage = "Average";
352 var StrMax = "Max";
353 var StrTotal = "Total";
354 var StrExclTotal = "Excl Total";
355 var StrMin = "Min";
356 var StrSpike = "Spike%";
357 var StrCallAverage = "Call Average";
358 var StrCount = "Count";
359 var StrExclAverage = "Excl Average";
360 var StrExclMax = "Excl Max";
361 var StrExclMin = "Excl Max";
362 var StrCallExclAverage = "Call Excl Avg";
363
364
365 var CounterNameWidth = 100;
366 var CounterValueWidth = 100;
367 var CounterLimitWidth = 100;
368
369 var FormatCounterDefault = 0;
370 var FormatCounterBytes = 1;
371 var FormatCounterBytesExt = ["b","kb","mb","gb","tb","pb","eb","zb","yb"];
372
373 var BarColumnNamesTable = [StrTime, StrExclusive, StrAverage, StrMax, StrMin, StrTotal, StrExclAverage, StrExclMax, StrExclTotal, StrSpike, StrCallAverage, StrCallExclAverage, StrCount];
374 var BarColumnNamesMulti = [StrTime, StrAverage, StrMax, StrMin, StrExclAverage, StrExclMax, StrExclMin];
375 var BarColumnNamesSingle = [StrAverage, StrMax, StrMin, StrExclAverage, StrExclMax, StrExclMin, StrCallAverage];
376
377 // var SYMBOLSTATE_DEFAULT = 0;
378 // var SYMBOLSTATE_LOADING = 1;
379 // var SYMBOLSTATE_DONE = 2;
380
381
382 var SymbolState;
383 var ModuleState = [];
384
385 var FunctionsInstrumented = [];
386 var FunctionsInstrumentedUnmangled = [];
387 var FunctionsInstrumentedModule = [];
388 var PopupsAllowed = 0;
389 var PopupsFailed = 0;
390 var PopupTestPending = 0;
391
392 var ThreadInfo = {};
393
394 /**
395 * From https://gist.github.com/vahidk/05184faf3d92a0aa1b46aeaa93b07786
396 *
397 * @param {number} h
398 * @param {number} s
399 * @param {number} l
400 */
401 function ConvertHslToRGB(h, s, l) {
402 const c = (1 - Math.abs(2 * l - 1)) * s;
403 const hp = h / 60.0;
404 const x = c * (1 - Math.abs((hp % 2) - 1));
405 let rgb1;
406 if (isNaN(h)) rgb1 = [0, 0, 0];
407 else if (hp <= 1) rgb1 = [c, x, 0];
408 else if (hp <= 2) rgb1 = [x, c, 0];
409 else if (hp <= 3) rgb1 = [0, c, x];
410 else if (hp <= 4) rgb1 = [0, x, c];
411 else if (hp <= 5) rgb1 = [x, 0, c];
412 else if (hp <= 6) rgb1 = [c, 0, x];
413 const m = l - c * 0.5;
414 const color = (Math.round(255 * (rgb1[0] + m)) << 16)
415 | (Math.round(255 * (rgb1[1] + m)) << 8)
416 | Math.round(255 * (rgb1[2] + m));
417 return ("000000" + color.toString(16)).slice(-6);
418 }
419
420
421 function GetBarColumnNames()
422 {
423 if(Settings.ViewActive == VIEW_BAR_ALL)
424 {
425 return BarColumnNamesMulti;
426 }
427 else if(Settings.ViewActive == VIEW_BAR_SINGLE)
428 {
429 return BarColumnNamesSingle;
430 }
431 else
432 {
433 return BarColumnNamesTable;
434 }
435 }
436 function GetBarColumnEnabled()
437 {
438 if(Settings.ViewActive == VIEW_BAR_ALL)
439 {
440 return Settings.BarColumnEnabledMulti;
441 }
442 else if(Settings.ViewActive == VIEW_BAR_SINGLE)
443 {
444 return Settings.BarColumnEnabledSingle;
445 }
446 else
447 {
448 return Settings.BarColumnEnabledTable;
449 }
450 }
451
452 Settings.BarColumnEnabledTable = new Array(BarColumnNamesTable.length);
453 Settings.BarColumnEnabledSingle = new Array(BarColumnNamesSingle.length);
454 Settings.BarColumnEnabledMulti = new Array(BarColumnNamesMulti.length);
455 var ColumnsWidth = new Array(BarColumnNamesTable.length);
456 function ClearEnabled(E)
457 {
458 for(var i = 0; i < E.length; ++i)
459 {
460 E[i] = 1;
461 ColumnsWidth[i] = 10;
462 }
463 }
464 ClearEnabled(Settings.BarColumnEnabledTable);
465 ClearEnabled(Settings.BarColumnEnabledSingle);
466 ClearEnabled(Settings.BarColumnEnabledMulti);
467
468 function Plotf(str)
469 {
470 PlotfArray.push(str);
471 }
472 function PlotfClear()
473 {
474 PlotfArray = new Array();
475 }
476
477 function ProfileModeClear()
478 {
479 if(ProfileMode)
480 {
481 for(var idx in ProfileData)
482 {
483 if(idx == "Plot")
484 continue;
485 var Timer = ProfileData[idx];
486 Timer.Count = 0;
487 Timer.Time = 0;
488 }
489
490 // ProfileData = new Object();
491 ProfileStackTime = new Array();
492 ProfileStackName = new Array();
493 }
494 }
495 function ProfileEnter(Name)
496 {
497 if(ProfileMode)
498 {
499 ProfileStackTime.push(performance.now());
500 ProfileStackName.push(Name);
501 }
502 }
503 function ProfileLeave()
504 {
505 if(ProfileMode)
506 {
507 var Time = performance.now();
508 var Delta = Time - ProfileStackTime.pop();
509 var Name = ProfileStackName.pop();
510 var Obj = ProfileData[Name];
511 if(!Obj)
512 {
513 Obj = new Object();
514 Obj.Count = 0;
515 Obj.Name = Name;
516 Obj.Time = 0;
517 Obj.AggrCount = 0;
518 Obj.AggrTime = 0;
519 Obj.AggrMax = 0;
520 Obj.AvgTime = 0;
521 Obj.MaxTime = 0;
522 Obj.TotalTime = 0;
523 ProfileData[Name] = Obj;
524 }
525 Obj.Time += Delta;
526 Obj.Count += 1;
527 }
528 }
529
530 function ProfilePlot(s)
531 {
532 if(ProfileMode)
533 {
534 var A = ProfileData.Plot;
535 if(!A)
536 {
537 ProfileData.Plot = Array();
538 A = ProfileData.Plot;
539 }
540 if(A.length<10)
541 {
542 A.push(s);
543 }
544 }
545 }
546 function ProfileModeDump()
547 {
548 for(var idx in ProfileData)
549 {
550 var Timer = ProfileData[idx];
551 console.log(Timer.Name + " " + Timer.Time + "ms " + Timer.Count);
552 }
553
554 }
555 function ProfileModeDraw(Canvas)
556 {
557 if(ProfileMode)
558 {
559 ProfileFpsCount ++ ;
560 var AggrFrames = 60;
561 var StringArray = [];
562 function FormatTime(f)
563 {
564 return (" " + f.toFixed(2)).slice(-12);
565 }
566 function FormatStr(t, count, avg, max, total)
567 {
568 var str = FormatTime(t) + "ms " + (" #" + count).slice(-8) +
569 "" + FormatTime(avg) + "ms " + FormatTime(max) + "ms " + FormatTime(total) + "ms";
570 return str;
571 }
572 StringArray.push("");
573 StringArray.push("time count avg max total/" + AggrFrames + " ");
574
575 for(var idx in ProfileData)
576 {
577 if(idx == "Plot")
578 continue;
579 var Timer = ProfileData[idx];
580 Timer.AggrCount += Timer.Count;
581 Timer.AggrTime += Timer.Time;
582 Timer.AggrMax = Math.max(Timer.AggrMax, Timer.Time);
583 if(ProfileFpsCount == AggrFrames)
584 {
585 Timer.AvgTime = Timer.AggrTime / AggrFrames;
586 Timer.MaxTime = Timer.AggrMax;
587 Timer.TotalTime = Timer.AggrTime;
588 Timer.AggrCount = 0;
589 Timer.AggrTime = 0;
590 Timer.AggrMax = 0;
591 }
592 StringArray.push(Timer.Name);
593 StringArray.push(FormatStr(Timer.Time, Timer.Count, Timer.AvgTime, Timer.MaxTime, Timer.TotalTime));
594 }
595 var Time = new Date();
596 var Delta = Time - ProfileLastTimeStamp;
597 ProfileLastTimeStamp = Time;
598 StringArray.push("Frame Delta");
599 StringArray.push(Delta + "ms");
600 {
601 ProfileFpsAggr += Delta;
602
603 if(ProfileFpsCount == AggrFrames)
604 {
605 ProfileMs = ProfileFpsAggr / AggrFrames;
606 ProfileFps = 1000 / (ProfileFpsAggr / AggrFrames);
607 ProfileFpsAggr = 0;
608 ProfileFpsCount = 0;
609 }
610 StringArray.push("Avg FPS");
611 StringArray.push("" + ProfileFps.toFixed(2));
612 StringArray.push("Avg MS");
613 StringArray.push("" + ProfileMs.toFixed(2));
614 }
615 for(var i = 0; i < ProfileData.Plot; ++i)
616 {
617 StringArray.push("");
618 StringArray.push(ProfileData.Plot[i]);
619 }
620 ProfileData.Plot = Array();
621 DrawToolTip(StringArray, Canvas, 0, 200);
622 }
623 }
624
625
626
627 function MeasureFont()
628 {
629 var context = CanvasDetailedView.getContext('2d');
630 context.font = Font;
631 FontWidth = context.measureText('W').width;
632
633 }
634 function ResizeCanvasDPR(w, h, c)
635 {
636 DPR = Settings.AllowHighDPI ? window.devicePixelRatio : 0;
637 if(DPR)
638 {
639 c.style.width = w + 'px';
640 c.style.height = h + 'px';
641 c.width = w * DPR;
642 c.height = h * DPR;
643 c.getContext('2d').scale(DPR,DPR);
644 }
645 else
646 {
647 DPR = 1;
648 c.width = w;
649 c.height = h;
650 }
651
652 }
653
654 function ResizeCanvasDPR2(w, h, c)
655 {
656 DPR = window.devicePixelRatio;
657 if(DPR)
658 {
659 c.style.width = w + 'px';
660 c.style.height = h + 'px';
661 c.width = w * DPR;
662 c.height = h * DPR;
663 c.getContext('2d').scale(DPR,DPR);
664 }
665 else
666 {
667 c.width = w;
668 c.height = h;
669 }
670
671 }
672 function ResizeView(View, x, y, w, h)
673 {
674 View.x = x;
675 View.y = y;
676 View.w = w;
677 View.h = h;
678 var c0 = View.Canvas[0];
679 var c1 = View.Canvas[1];
680 ResizeCanvasDPR(w, h, c0);
681 ResizeCanvasDPR(w, h, c1);
682 c0.getContext('2d').clearRect(0, 0, w, h);
683 c1.getContext('2d').clearRect(0, 0, w, h);
684 View.OffscreenData[0] = c0.getContext('2d').getImageData(0, 0, c0.width, c0.height);
685 View.OffscreenData[1] = c1.getContext('2d').getImageData(0, 0, c1.width, c1.height);
686
687 }
688 function CreateView(x, y, w, h, name, DisplayFunc, visible, index)
689 {
690 var idx = Views.length;
691 var c0 = CanvasArray0[idx];
692 var c1 = CanvasArray1[idx];
693 if(!c0)
694 {
695 c0 = document.createElement('canvas');
696 CanvasArray0[idx] = c0;
697 }
698 if(!c1)
699 {
700 c1 = document.createElement('canvas');
701 CanvasArray1[idx] = c1;
702 }
703 var View = {};
704 View.x = x;
705 View.y = y;
706 View.w = w;
707 View.h = h;
708 View.Canvas = [c0, c1];
709 View.OffscreenData = [null, null];
710 View.visible = visible;
711 View.index = index;
712 ResizeCanvasDPR(w, h, c0);
713 ResizeCanvasDPR(w, h, c1);
714
715 c0.getContext('2d').clearRect(0, 0, w, h);
716 c1.getContext('2d').clearRect(0, 0, w, h);
717 View.OffscreenData[0] = c0.getContext('2d').getImageData(0, 0, c0.width, c0.height);
718 View.OffscreenData[1] = c1.getContext('2d').getImageData(0, 0, c1.width, c1.height);
719 View.BackBuffer = 0;
720 View.DisplayFunc = DisplayFunc;
721 Views.push(View);
722 return View;
723 }
724
725 function CreateViews(Width, Height, ViewCompressed)
726 {
727 Views = [];
728 var HistoryH = ViewCompressed ? 0 : HistoryHeight;
729 History = CreateView(0, 0, Width, HistoryHeight, "History", DrawHistory, true, 0);
730 History.visible = !ViewCompressed;
731 MainView = CreateView(0, HistoryH, Width, Height-HistoryH, "Main", DrawGraphSplit, true);
732 X7Views = [];
733 var w = Width / 7;
734 var x = 0;
735 X7Views.push(CreateView(w*0, HistoryH, w, Height - HistoryH, "x5_0", DrawBars, false, 0) );
736 X7Views.push(CreateView(w*1, HistoryH, w, Height - HistoryH, "x5_1", DrawBars, false, 1) );
737 X7Views.push(CreateView(w*2, HistoryH, w, Height - HistoryH, "x5_2", DrawBars, false, 2) );
738 X7Views.push(CreateView(w*3, HistoryH, w, Height - HistoryH, "x5_3", DrawBars, false, 3) );
739 X7Views.push(CreateView(w*4, HistoryH, w, Height - HistoryH, "x5_4", DrawBars, false, 4) );
740 X7Views.push(CreateView(w*5, HistoryH, w, Height - HistoryH, "x5_3", DrawBars, false, 5) );
741 X7Views.push(CreateView(w*6, HistoryH, w, Height - HistoryH, "x5_3", DrawBars, false, 6) );
742 X7LegendView = CreateView(0, Height-X7LegendOffset, Width, X7LegendOffset, "x7_legend", DrawBarsLegend, false, 0);
743
744 }
745
746 function ResizeCanvas()
747 {
748 nWidth = window.innerWidth;
749 nHeight = window.innerHeight;
750 DPR = Settings.AllowHighDPI ? window.devicePixelRatio : 0;
751 ResizeCanvasDPR(nWidth, nHeight, CanvasDetailedView);
752 ResizeCanvasDPR(nWidth, nHeight, CanvasDetailedOffscreen);
753
754 if(DPR)
755 {
756 CanvasDetailedView.style.width = nWidth + 'px';
757 CanvasDetailedView.style.height = nHeight + 'px';
758 CanvasDetailedView.width = nWidth * DPR;
759 CanvasDetailedView.height = nHeight * DPR;
760 CanvasDetailedView.getContext('2d').scale(DPR,DPR);
761
762 CanvasDetailedOffscreen.style.width = nWidth + 'px';
763 CanvasDetailedOffscreen.style.height = nHeight + 'px';
764 CanvasDetailedOffscreen.width = nWidth * DPR;
765 CanvasDetailedOffscreen.height = nHeight * DPR;
766 CanvasDetailedOffscreen.getContext('2d').scale(DPR,DPR);
767
768 }
769 else
770 {
771 DPR = 1;
772 CanvasDetailedView.width = nWidth;
773 CanvasDetailedView.height = nHeight;
774 CanvasDetailedOffscreen.width = nWidth;
775 CanvasDetailedOffscreen.height = nHeight;
776 }
777 MeasureFont();
778 CreateViews(nWidth, nHeight, Settings.ViewCompressed);
779 ActivateView(Settings.ViewActive);
780 }
781
782
783 function FormatTime(Time)
784 {
785 return Time.toFixed(2);
786 }
787 var hh = 0;
788
789
790 function DrawBarsLegend(View, LocalMouseX, LocalMouseY, SubIndex)
791 {
792 ProfileEnter("DrawBar");
793 var TimerMap = FrameData.TimerMap;
794 if(!TimerMap)
795 return;
796 if(Settings.ViewCompressed)
797 return;
798 var Canvas = View.Canvas[View.BackBuffer];
799 var context = Canvas.getContext('2d');
800 context.clearRect(0, 0, View.w, View.h);
801 var X = 0;
802 var Y = View.h/2;
803 var XSpace = 5;
804 var XSpace2 = XSpace * 2;
805 function DrawEntry(T)
806 {
807 X += XSpace2*2;
808 context.fillStyle = T.color;
809 context.fillRect(X-XSpace,Y-XSpace,XSpace2,XSpace2);
810 X += XSpace + 2;
811 context.fillStyle = 'white';
812 var w = context.measureText(T.name).width;
813 context.fillText(T.name, X, Y + FontHeight/2);
814 X += w;
815 }
816
817 if(SingleTimerBars == 0)
818 {
819 for(var key in TimerMap)
820 {
821 var idx = GetTimer(key);
822 var T = TimerArray[idx];
823 if(T.e)
824 {
825 DrawEntry(T);
826 }
827 }
828 }
829 else if(EnabledArray.length > 0)
830 {
831 var idx = EnabledArray[0];
832 var T = TimerArray[idx];
833 DrawEntry(T);
834 }
835 }
836
837 function DrawBars(View, LocalMouseX, LocalMouseY, SubIndex)
838 {
839 var TimerMap = FrameData.TimerMap;
840 if(!TimerMap)
841 return;
842 if(!SubIndex)
843 SubIndex = 0;
844
845 ProfileEnter("DrawBar");
846 var Canvas = View.Canvas[View.BackBuffer];
847 var context = Canvas.getContext('2d');
848
849 context.clearRect(0, 0, View.w, View.h);
850 var bgcolor = nBackColors[ViewIndex%2];
851 context.fillStyle = bgcolor;
852 context.fillRect(0, 0, View.w, View.h);
853 var Title = "?";
854 var TitleName = null;
855 var nNumBars = 0;
856 var BarNames = [];
857 var BarTimes = [];
858 var BarColors = [];
859 var AggregateIndex = Settings.AggregateFrames <= 0 ? AggregateHistorySize-1 : AggregateHistorySize-2; //fix med
860 var GetTime = null;
861 var SubIndex = X7BarColumnRemap[SubIndex];
862
863 if(SingleTimerBars == 0)
864 {
865 if(SubIndex == 0)
866 {
867 Title = "Time";
868 GetTime = function(FD){ return FD.FrameTime; };
869 }
870 else if(SubIndex == 1)
871 {
872 Title = "Average";
873 GetTime = function(FD){ return FD.TimeAvg[AggregateIndex]; };
874 }
875 else if(SubIndex == 2)
876 {
877 Title = "Max";
878 GetTime = function(FD){ return FD.TimeMax[AggregateIndex]; };
879 }
880 else if(SubIndex == 3)
881 {
882 Title = "Min";
883 GetTime = function(FD){ return FD.TimeMin[AggregateIndex]; };
884 }
885 else if(SubIndex == 4)
886 {
887 Title = "Exclusive Avg";
888 GetTime = function(FD){ return FD.TimeExclAvg[AggregateIndex]; };
889 }
890 else if(SubIndex == 5)
891 {
892 Title = "Exclusive Max";
893 GetTime = function(FD){ return FD.TimeExclMax[AggregateIndex]; };
894 }
895 else if(SubIndex == 6)
896 {
897 Title = "Exclusive Min";
898 GetTime = function(FD){ return FD.TimeExclMin[AggregateIndex]; };
899 }
900 for(var key in TimerMap)
901 {
902 var idx = GetTimer(key);
903 var T = TimerArray[idx];
904 if(T.e)
905 {
906 nNumBars++;
907 var FD = TimerMap[key];
908 var Time = GetTime(FD);
909 BarNames.push(T.name);
910 BarTimes.push(Time);
911 BarColors.push(T.color);
912 }
913 }
914
915 }
916 else if(EnabledArray.length > 0)
917 {
918 var idx = EnabledArray[0];
919 var T = TimerArray[idx];
920 var FD = GetFrameData(T.id);
921 var Property = null;
922 if(SubIndex == 0)
923 {
924 Title = "Average";
925 Property = "TimeAvg";
926 }
927 else if(SubIndex == 1)
928 {
929 Title = "Max";
930 Property = "TimeMax";
931 }
932 else if(SubIndex == 2)
933 {
934 Title = "Min";
935 Property = "TimeMin";
936 }
937 else if(SubIndex == 3)
938 {
939 Title = "Exclusive Average";
940 Property = "TimeExclAvg";
941 }
942 else if(SubIndex == 4)
943 {
944 Title = "Exclusive Max";
945 Property = "TimeExclMax";
946 }
947 else if(SubIndex == 5)
948 {
949 Title = "Exclusive Min";
950 Property = "TimeExclMin";
951 }
952 else if(SubIndex == 6)
953 {
954 Title = "Call Average";
955 Property = "TimeCallAvg";
956 }
957 else if(SubIndex == 7)
958 {
959 Title = "Call Excl Average";
960 Property = "TimeCallExclAvg";
961 }
962 TitleName = T.name;
963 for(var i = 0; i < AggregateHistorySize; ++i)
964 {
965 nNumBars++;
966 var A = FD[Property];
967 var Time = A[i];
968 BarTimes.push(Time);
969 BarColors.push(T.color);
970 }
971 }
972
973
974 if(!nNumBars)
975 {
976 ProfileLeave();
977 return;
978 }
979
980 var h = View.h;
981 var w = View.w;
982 var MsTextExtraSpace = Math.cos(3.14/4.0) * (ViewBarMaxMsTextLength);
983 var DrawXLeft = Settings.ViewCompressed ? 3 : 15;
984 DrawXLeft = Math.max(DrawXLeft, MsTextExtraSpace);
985 var DrawXRight = Settings.ViewCompressed ? 3: 10;
986 var DrawY = 35 * 2;
987 if(Settings.ViewCompressed)
988 {
989 DrawY = (MsTextExtraSpace) + 35;
990 }
991 var DrawWidth = w - DrawXLeft - DrawXRight;
992 var DrawHeight = h - DrawY;
993 var SpaceWidth = 5;
994 var BarWidth = (DrawWidth-SpaceWidth*(nNumBars-1))/ nNumBars;
995 for(var x = 0; x < 2; ++x)
996 {
997 if(BarWidth < 14)
998 {
999 SpaceWidth -= 1;
1000 BarWidth = (DrawWidth-SpaceWidth*(nNumBars-1))/ nNumBars;
1001 }
1002 }
1003 if(BarWidth > 50)
1004 BarWidth = 50;
1005 var BarHeight = DrawHeight - 5;
1006
1007 var ReferenceTime = ReferenceBar;
1008
1009 var fHeightScale = h / ReferenceTime;
1010 var MouseDragging = 0;
1011 var fWidth = w / FRAME_COUNT;
1012 var Keys = [];
1013 var X = DrawXLeft;
1014 var offset = 0;
1015 context.textAlign = 'center';
1016 context.fillStyle = '#ffffff';
1017 context.fillText(Title, w / 2.0, FontHeight);
1018 context.textAlign = 'left';
1019 context.fillStyle = 'wheat';
1020 var BaseY = 20;
1021 if(SubIndex == X7BarFirstView)
1022 {
1023 context.fillText(ReferenceTime.toFixed(2) + 'ms', 0, BaseY - 5 + DrawHeight - BarHeight);
1024 }
1025 else if(SubIndex == X7BarLastView)
1026 {
1027 context.textAlign = 'right';
1028 context.fillText(ReferenceTime.toFixed(2) + 'ms', w, BaseY - 5 + DrawHeight - BarHeight);
1029 }
1030 context.textAlign = 'right';
1031 var BarFont = FontLarge;
1032 var DrawNames = true;
1033 if(BarWidth < 14)
1034 {
1035 DrawNames = BarWidth > 4;
1036 var FontXX = 'Bold ' + Math.floor(BarWidth) + 'px Courier New';
1037 BarFont = FontXX;
1038
1039 }
1040 context.font = BarFont;
1041 for(var i = 0; i < BarTimes.length; ++i)
1042 {
1043 var TimeText = FormatTime(Time);
1044 var w = context.measureText(TimeText).width;
1045 ViewBarMaxMsTextLength = Math.max(w, ViewBarMaxMsTextLength);
1046
1047
1048 }
1049 for(var i = 0; i < BarTimes.length; ++i)
1050 {
1051 var Time = BarTimes[i];
1052 var TimeText = FormatTime(Time);
1053 ReferenceBarAutomatic = Math.max(Time, ReferenceBarAutomatic);
1054 var Color = BarColors[i];
1055 var fPrc = Time / ReferenceTime;
1056 if(fPrc > 1.0)
1057 fPrc = 1.0;
1058 var BarH = fPrc * BarHeight;
1059
1060 var X0 = X;
1061 var Y0 = BaseY + DrawHeight - BarH;
1062 context.fillStyle = Color;
1063 context.fillRect(X0, Y0, BarWidth, BarH);
1064 context.fillStyle = '#ffffff';
1065 var MouseOver = LocalMouseX > X0 && LocalMouseX < X0 + BarWidth;
1066 if(MouseOver || (Settings.ViewCompressed&&DrawNames))
1067 {
1068 context.save();
1069 context.translate(X0 + BarWidth * 0.5, BaseY + DrawHeight - 2);
1070 context.rotate(-3.14/2.0);
1071 context.font = BarFont;
1072 context.textAlign = 'left';
1073 context.textBaseline = 'middle';
1074 var m = context.measureText(BarNames[i]);
1075 context.fillStyle = 'black';
1076 context.fillText(BarNames[i], -1, -1);
1077 context.fillStyle = 'white';
1078 context.fillText(BarNames[i], 0, 0);
1079 context.textAlign = 'right';
1080 context.restore();
1081 }
1082 context.save();
1083 var XText = X+BarWidth;
1084 var YText = BaseY + DrawHeight + FontHeight;
1085 context.translate(XText, YText);
1086 context.rotate(-3.14/4.0);
1087 context.font = BarFont;
1088 context.fillText(TimeText, 0, 0);
1089 context.restore();
1090
1091 X += BarWidth + SpaceWidth;
1092 }
1093 context.font = Font;
1094 ProfileLeave();
1095 }
1096
1097 function SortColumnFromName(Name)
1098 {
1099 //should match switch in drawtableview
1100 if(Name == StrAverage)
1101 {
1102 return 1;
1103 }
1104 else if(Name == StrMax)
1105 {
1106 return 2;
1107 }
1108 else if(Name == StrTotal)
1109 {
1110 return 3;
1111 }
1112 else if(Name == StrMin)
1113 {
1114 return 4;
1115 }
1116 else if(Name == StrSpike)
1117 {
1118 return 5;
1119 }
1120 else if(Name == StrCallAverage)
1121 {
1122 return 6;
1123 }
1124 else if(Name == StrCount)
1125 {
1126 return 7;
1127 }
1128 else if(Name == StrExclAverage)
1129 {
1130 return 8;
1131 }
1132 else if(Name == StrExclMax)
1133 {
1134 return 9;
1135 }
1136 else if(Name == StrGroup)
1137 {
1138 return -1;
1139 }
1140 else if(Name == StrTimer)
1141 {
1142 return -2;
1143 }
1144 return 0;
1145 }
1146
1147 function DrawTableView(View, LocalMouseX, LocalMouseY, SubIndex)
1148 {
1149 ProfileEnter("DrawTableView");
1150 var Canvas = View.Canvas[View.BackBuffer];
1151 var context = Canvas.getContext('2d');
1152 var Height = BoxHeight;
1153 var Width = nWidth;
1154 var Y = Height;
1155 var XBase = 0;
1156 var nColorIndex = 0;
1157 var bMouseIn = 0;
1158 var RcpReferenceTime = 1.0 / Settings.ReferenceTime;
1159 var CountWidth = 12 * FontWidth;
1160 var InnerBoxHeight = BoxHeight-2;
1161 var TimerLen = 8;
1162 var TimerWidth = TimerLen * FontWidth;
1163 var nWidthBars = nBarsWidth+2;
1164 var nWidthMs = TimerWidth+2+10;
1165 var NameWidth = 200;
1166 var R = 0;
1167
1168 var OffsetY = BoxHeight;
1169
1170
1171 context.clearRect(0, 0, View.w, View.h);
1172 context.fillStyle = 'white';
1173 context.font = Font;
1174
1175
1176 function HeaderMouseHandle(XBegin, X, Y, Header)
1177 {
1178 if(Header == null)
1179 debugger;
1180 var bMouseIn = LocalMouseY >= Y && LocalMouseY < BoxHeight+Y && LocalMouseX < X && LocalMouseX > XBegin;
1181 if(bMouseIn)
1182 {
1183 SortColumnMouseOverNext = Header;
1184 }
1185 }
1186 function HeaderString(Header)
1187 {
1188 if(Header == Settings.SortColumnName)
1189 {
1190 return Header + (Settings.SortColumnOrderFlip ? '<' : '>');
1191 }
1192 else
1193 {
1194 return Header;
1195 }
1196
1197 }
1198 function DrawHeaderSplit(Header, Y)
1199 {
1200 if(Settings.BarColumnEnabledTable[R])
1201 {
1202 context.fillStyle = 'white';
1203 context.fillText(HeaderString(Header), X, Y + Height-FontAscent);
1204 var XBegin = X;
1205 X += nWidthBars;
1206 context.fillStyle = nBackColorOffset;
1207 X += ColumnsWidth[R];
1208
1209 if(X >= NameWidth)
1210 {
1211 context.fillRect(X-3, Y, 1, nHeight);
1212 }
1213 HeaderMouseHandle(XBegin, X, Y, Header);
1214 }
1215 R++;
1216 }
1217 function DrawHeaderSplitSingle(Header, Y)
1218 {
1219 if(Settings.BarColumnEnabledTable[R])
1220 {
1221 context.fillStyle = 'white';
1222 context.fillText(HeaderString(Header), X, Y + Height-FontAscent);
1223 var XBegin = X;
1224 X += ColumnsWidth[R];
1225 context.fillStyle = nBackColorOffset;
1226 if(X >= NameWidth)
1227 {
1228 context.fillRect(X-3, Y, 1, nHeight);
1229 }
1230 HeaderMouseHandle(XBegin, X, Y, Header);
1231 }
1232 R++;
1233 }
1234 function DrawHeaderSplitLeftRight(HeaderLeft, HeaderRight, Y, Width)
1235 {
1236 var HeaderLeftS = HeaderString(HeaderLeft);
1237 var HeaderRightS = HeaderString(HeaderRight);
1238 context.textAlign = 'left';
1239 context.fillStyle = 'white';
1240 context.fillText(HeaderLeftS, X, Y + Height-FontAscent);
1241 var wLeft = context.measureText(HeaderLeftS).width;
1242 var XBegin = X;
1243 X += Width;
1244 context.textAlign = 'right';
1245 context.fillText(HeaderRightS, X-5, Y + Height-FontAscent);
1246 context.textAlign = 'left';
1247 context.fillStyle = nBackColorOffset;
1248 if(X >= NameWidth)
1249 {
1250 context.fillRect(X-3, 0, 1, nHeight);
1251 }
1252 HeaderMouseHandle(XBegin, XBegin + wLeft, Y, HeaderLeft);
1253 HeaderMouseHandle(XBegin + wLeft, X, Y, HeaderRight);
1254
1255 }
1256 function DrawTimer(Value, Color)
1257 {
1258 if(Settings.BarColumnEnabledTable[R])
1259 {
1260 if(null == Value)
1261 {
1262 X += nWidthBars + ColumnsWidth[R];
1263 console.log("Should not happen2\n");
1264 debugger;
1265 return;
1266 }
1267 var Prc = Value * RcpReferenceTime;
1268 var YText = Y+Height-FontAscent;
1269 if(Prc > 1)
1270 {
1271 Prc = 1;
1272 }
1273 context.textAlign = 'left';
1274 context.fillStyle = Color;
1275 context.fillRect(X+1, Y+1, Prc * nBarsWidth, InnerBoxHeight);
1276 X += nWidthBars;
1277 context.fillStyle = 'white';
1278 var TimerText = Value.toFixed(2);
1279 var W = context.measureText(TimerText).width + FontWidth;
1280 ColumnsWidth[R] = Math.max(W, ColumnsWidth[R]);
1281 X += ColumnsWidth[R];
1282 context.textAlign = 'right';
1283 context.fillText(TimerText, X - FontWidth, YText);
1284 context.textAlign = 'left';
1285 }
1286 R++;
1287 }
1288 function DrawCount(Str)
1289 {
1290 if(Settings.BarColumnEnabledTable[R])
1291 {
1292 X += ColumnsWidth[R];
1293 context.fillStyle = 'white';
1294 context.textAlign = 'right';
1295 var YText = Y+Height-FontAscent;
1296 context.fillText(Str, X-6, YText);
1297 var W = Math.max(80, context.measureText(Str).width + FontWidth * 2);
1298 ColumnsWidth[R] = Math.max(W, ColumnsWidth[R]);
1299
1300 }
1301 R++;
1302
1303 }
1304 function DrawMeta(Value, Width, Dec, YText)
1305 {
1306 Value = FormatMeta(Value, Dec);
1307 X += (FontWidth*Width);
1308 context.textAlign = 'right';
1309 context.fillText(Value, X-FontWidth, YText);
1310 context.textAlign = 'left';
1311 }
1312
1313 function DrawTimerRow(idx, showgroup)
1314 {
1315 R = 0;
1316 var T = TimerArray[idx];
1317 var key = T.id;
1318 var FD = TimerMap[key];
1319 var AggregateIndex = Settings.AggregateFrames <= 0 ? AggregateHistorySize-1 : AggregateHistorySize-2;
1320
1321 var YText = Y+Height-FontAscent;
1322 X = NameWidth + XBase;
1323
1324 nColorIndex = 1-nColorIndex;
1325 bMouseIn = LocalMouseY >= Y && LocalMouseY < Y + BoxHeight;
1326 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
1327 context.fillRect(0, Y, Width, FontHeight+2);
1328
1329 DrawTimer(T.time, T.color);
1330 DrawTimer(T.excl, T.color);
1331
1332 DrawTimer(T.average, T.color);
1333 DrawTimer(T.max, T.color);
1334 DrawTimer(T.min, T.color);
1335 DrawTimer(T.total, T.color);
1336
1337 DrawTimer(T.exclaverage, T.color);
1338 DrawTimer(T.exclmax, T.color);
1339 DrawTimer(T.excltotal, T.color);
1340
1341 DrawCount((T.spike?T.spike.toFixed(2):"0") + '%');
1342 DrawTimer(T.callaverage, T.color);
1343 DrawTimer(T.callexclaverage, T.color);
1344 DrawCount('' + T.callcount);
1345
1346 context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
1347 context.fillRect(0, Y, NameWidth, Height);
1348 if(T.idtype == TYPE_GROUP)
1349 {
1350 context.textAlign = 'left';
1351 context.fillStyle = T.color;
1352 context.fillText(T.name, 1, YText);
1353 }
1354 else
1355 {
1356 context.textAlign = 'right';
1357 context.fillStyle = T.color;
1358 context.fillText(T.name, NameWidth - 5, YText);
1359 context.textAlign = 'left';
1360 let P = TimerArray[T.parent];
1361 context.fillStyle = P.color;
1362 var ParentName = P.name;
1363 context.fillText(ParentName, 1, YText);
1364 }
1365 }
1366 function FilterMatch(FilterArray, value)
1367 {
1368 if(!FilterArray)
1369 return true;
1370 for(var i = 0; i < FilterArray.length; ++i)
1371 {
1372 var res = value.search(FilterArray[i]);
1373 if(res<0)
1374 return false;
1375 }
1376 return true;
1377 }
1378 var TimerMap = FrameData.TimerMap;
1379 if(!TimerMap)
1380 {
1381 return;
1382 }
1383
1384 var wfirst = 100;
1385 var OrderArray = new Array();
1386 var nTotalRows = 0;
1387 for(var key in TimerMap)
1388 {
1389 var idx = GetTimer(key);
1390 var T = TimerArray[idx];
1391 if(T.e)
1392 {
1393 OrderArray.push(idx);
1394 wfirst = wfirst < T.wtotal ? T.wtotal : wfirst;
1395 nTotalRows++;
1396 }
1397 }
1398 NameWidth = wfirst + 20;
1399
1400
1401 var nTotalRowPixels = nTotalRows * Height;
1402 var nFrameRows = nHeight - HistoryHeight - BoxHeight;
1403 if(nTotalRowPixels > nFrameRows)
1404 {
1405 if(nOffsetBarsY + nFrameRows > nTotalRowPixels)
1406 {
1407 nOffsetBarsY = nTotalRowPixels - nFrameRows;
1408 }
1409 }
1410 else
1411 {
1412 nOffsetBarsY = 0;
1413 }
1414 Y = Y - nOffsetBarsY;
1415 Y += OffsetY;
1416 XBase = XBase - nOffsetBarsX;
1417
1418 if(1)
1419 {
1420 let Flip = Settings.SortColumnOrderFlip == 1 ? -1 : 1;
1421 let StringCompare = function(Key)
1422 {
1423 let F = function(A, B)
1424 {
1425 let s1 = Key(A);
1426 let s2 = Key(B);
1427 return Flip * s2.localeCompare(s1);
1428 };
1429 return F;
1430 };
1431 let NumberCompare = function(Key)
1432 {
1433 let F = function(A, B)
1434 {
1435 let v0 = Key(B);
1436 let v1 = Key(A);
1437 return Flip * (v0 - v1);
1438 //Key(B) - Key(A));
1439 };
1440 return F;
1441 };
1442 let N = Settings.SortColumnName;
1443 if(N == StrTime)
1444 {
1445 let Do = function()
1446 {
1447 for(var i = 0; i < OrderArray.length; ++i)
1448 {
1449 let t = TimerArray[OrderArray[i]];
1450 console.log("", i, OrderArray[i], t.name, t.id, t.time);
1451 };
1452
1453 };
1454 // Do();
1455 OrderArray.sort( NumberCompare( function (a) {
1456 return TimerArray[a].time;
1457 } ) );
1458 // Do();
1459 }
1460 else if(N == StrExclusive)
1461 {
1462 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].excl; } ) );
1463 }
1464 else if(N == StrAverage)
1465 {
1466 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].average; } ) );
1467 }
1468 else if(N == StrMax)
1469 {
1470 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].max; } ) );
1471 }
1472 else if(N == StrTotal)
1473 {
1474 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].total; } ) );
1475 }
1476 else if(N == StrMin)
1477 {
1478 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].min; } ) );
1479 }
1480 else if(N == StrSpike)
1481 {
1482 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].spike; } ) );
1483 }
1484 else if(N == StrCallAverage)
1485 {
1486 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].callaverage; } ) );
1487 }
1488 else if(N == StrCount)
1489 {
1490 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].count; } ) );
1491 }
1492 else if(N == StrExclAverage)
1493 {
1494 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].exclaverage; } ) );
1495 }
1496 else if(N == StrExclMax)
1497 {
1498 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].exclmax; } ) );
1499 }
1500 else if(N == StrExclTotal)
1501 {
1502 OrderArray.sort( NumberCompare( function (a) { return TimerArray[a].excltotal; } ) );
1503 }
1504 else if(N == StrGroup)
1505 {
1506 OrderArray.sort( StringCompare( function (a) { return TimerArray[TimerArray[a].parent].name; } ) );
1507 }
1508 else if(N == StrTimer)
1509 {
1510 OrderArray.sort( StringCompare( function (a) { return TimerArray[a].name; } ) );
1511 }
1512 else
1513 {
1514 if(N != "")
1515 {
1516 console.log("unhandle sortkey", N);
1517 debugger;
1518 }
1519
1520 OrderArray.sort( StringCompare( function (a) { return TimerArray[a].sortkey; } ) );
1521 }
1522 }
1523
1524 let ColorHigh = '#85929e';
1525
1526
1527 for(var i = 0; i < OrderArray.length; ++i)
1528 {
1529 var idx = OrderArray[i];
1530 var T = TimerArray[idx];
1531 if(T.idtype == TYPE_GROUP)
1532 {
1533 DrawTimerRow(idx, 1);
1534 Y += Height;
1535 }
1536 }
1537 let SplitY = Y;
1538
1539 for(var i = 0; i < OrderArray.length; ++i)
1540 {
1541 var idx = OrderArray[i];
1542 var T = TimerArray[idx];
1543 if(T.idtype != TYPE_GROUP)
1544 {
1545 DrawTimerRow(idx, 1);
1546 Y += Height;
1547 }
1548 }
1549
1550 var X = 0;
1551 context.fillStyle = nBackColorOffset;
1552 context.fillRect(0, 0, Width, 2*Height);
1553 context.fillStyle = 'white';
1554 SortColumnMouseOverNext = null;
1555 X = NameWidth + XBase;
1556 R = 0;
1557
1558 let Aggr = Settings.AggregateFrames <= 0 ? AggregateCurrent : Settings.AggregateFrames;
1559 let Headers = ["Per Frame", "Aggregate/" + Aggr + " Frames", "Call/" + Aggr + " Frames"];
1560 let SplitX = [0,0,0];
1561
1562 DrawHeaderSplit(StrTime,OffsetY);
1563 DrawHeaderSplit(StrExclusive, OffsetY);
1564 SplitX[0] = X;
1565
1566 DrawHeaderSplit(StrAverage, OffsetY);
1567 DrawHeaderSplit(StrMax, OffsetY);
1568 DrawHeaderSplit(StrMin, OffsetY);
1569 DrawHeaderSplit(StrTotal, OffsetY);
1570
1571 DrawHeaderSplit(StrExclAverage, OffsetY);
1572 DrawHeaderSplit(StrExclMax, OffsetY);
1573 DrawHeaderSplit(StrExclTotal, OffsetY);
1574
1575 DrawHeaderSplitSingle(StrSpike, OffsetY);
1576 SplitX[1] = X;
1577
1578 DrawHeaderSplit(StrCallAverage, OffsetY);
1579 DrawHeaderSplit(StrCallExclAverage, OffsetY);
1580 DrawHeaderSplitSingle(StrCount, OffsetY);
1581 SplitX[2] = X;
1582
1583 context.fillStyle = 'white';
1584 for(var i = 0; i < SplitX.length; ++i)
1585 {
1586 var X0 = i == 0 ? (NameWidth + XBase) : SplitX[i-1];
1587 var X1 = SplitX[i];
1588 if(X0 != X1)
1589 {
1590 context.fillText(Headers[i], X0 + 1, Height-FontAscent);
1591 }
1592 }
1593
1594
1595 X = 0;
1596 context.fillStyle = nBackColorOffset;
1597 context.fillRect(0, 0, NameWidth, Height * 2);
1598 context.fillStyle = 'white';
1599 DrawHeaderSplitLeftRight(StrGroup, StrTimer, 0, NameWidth);
1600
1601
1602 for(var i = 0; i < SplitX.length; ++i)
1603 {
1604 var X0 = i == 0 ? (NameWidth + XBase) : SplitX[i-1];
1605 var X1 = SplitX[i];
1606 if(X0 != X1)
1607 {
1608 context.fillStyle = ColorHigh;
1609 if(X1 >= NameWidth)
1610 context.fillRect(X1-2.5, 0, 2, nHeight);
1611 if(X0 >= NameWidth)
1612 context.fillRect(X0-2.5, 0, 2, nHeight);
1613 }
1614 }
1615 context.fillStyle = ColorHigh;
1616 context.fillRect(0, 2*Height-1, nWidth, 2);
1617
1618 context.fillStyle = ColorHigh;
1619 context.fillRect(0, SplitY-1, nWidth, 2);
1620
1621
1622 ProfileLeave();
1623 }
1624 function DrawGraphThreadGroup(View, LocalMouseX, LocalMouseY, SubIndex)
1625 {
1626 DrawGraphThreadExclusive(View, LocalMouseX, LocalMouseY, SubIndex);
1627 }
1628 function DrawGraphSplit(View, LocalMouseX, LocalMouseY, SubIndex)
1629 {
1630 DrawGraph(View, LocalMouseX, LocalMouseY, SubIndex, 1);
1631 }
1632
1633 function DrawGraphThreadExclusive(View, LocalMouseX, LocalMouseY, SubIndex, Split)
1634 {
1635 var TimerMap = FrameData.TimerMap;
1636 if(!TimerMap)
1637 return;
1638
1639 ProfileEnter("DrawGraphThreadExclusive");
1640 var Canvas = View.Canvas[View.BackBuffer];
1641 var context = Canvas.getContext('2d');
1642 context.clearRect(0, 0, View.w, View.h);
1643
1644 var h = View.h;
1645 var w = View.w;
1646 var fHeightScale = h / ReferenceGraph;
1647 var MouseDragging = 0;
1648 var fWidth = w / FRAME_COUNT;
1649 var MouseTime = ReferenceGraph * (1-(LocalMouseY / h));
1650 var HighlightKey = 0;
1651 var HighlightFrame = -1;
1652
1653
1654 var NumGraphs = 0;
1655 for(let k in ThreadInfo)
1656 {
1657 NumGraphs++;
1658 }
1659 if(NumGraphs)
1660 {
1661 let hstart = 0;
1662 let gh = h / NumGraphs;
1663 let cidx = 1;
1664 let Count = FRAME_COUNT;
1665 let Last = AllocClearedArray(Count);
1666 let FT = FrameData.Time;
1667 let RcpFT = AllocClearedArray(Count);
1668 if(FT.length != RcpFT.length)
1669 debugger;
1670 for(let k = 0; k < RcpFT.length; ++k)
1671 {
1672 if(FT[k] != 0)
1673 {
1674 RcpFT[k] = 1.0 / FT[k];
1675 }
1676 else
1677 {
1678 RcpFT[k] = 0;
1679 }
1680 }
1681
1682 for(let k in ThreadInfo)
1683 {
1684 for(let j = 0; j < Last.length; ++j)
1685 Last[j] = 0.0;
1686 let TI = ThreadInfo[k];
1687 let X = 0;
1688 let Y = hstart + gh;
1689 var YStart = Y;
1690 if(LocalMouseX >= 0 && LocalMouseY >= hstart && LocalMouseX < w && LocalMouseY <= Y)
1691 {
1692 HighlightKey = k;
1693 HighlightFrame = Math.floor(FRAME_COUNT * LocalMouseX / w);
1694 }
1695
1696
1697 context.globalAlpha = 1;
1698 context.fillStyle = nBackColorsDark[cidx];
1699 cidx = 1-cidx;
1700 context.fillRect(0, hstart, w, gh);
1701 context.strokeStyle = 'white';
1702 context.fillStyle = 'white';
1703 for(let l = 0; l < TI.a.length; ++l)
1704 {
1705 X = 0;
1706 let a = TI.a[l];
1707 if(a.length != Count)
1708 {
1709 console.log("should not happen!\n");
1710 debugger;
1711 }
1712 let idx = GetTimer(TI.ids[l]);
1713 let c = TimerArray[idx].color;
1714 context.strokeStyle = c;
1715 context.fillStyle = c;
1716 context.beginPath();
1717
1718 for(let m = Last.length-1;m >= 0; m--)
1719 {
1720 let XX = X + fWidth * m;
1721 Y = Math.max(YStart - Last[m] * gh, hstart);
1722 if(m == Last.length-1)
1723 {
1724 context.moveTo(XX, Y);
1725 }
1726 else
1727 {
1728 context.lineTo(XX, Y);
1729 }
1730 }
1731
1732 for(let m = 0; m < a.length; ++m)
1733 {
1734
1735 let h = a[m] * RcpFT[m];
1736 if(h > 1.1)
1737 {
1738 console.log("should not happen ", a[m], RcpFT[m], h);
1739 debugger;
1740 h = 1;
1741 //todo...
1742 }
1743 let hm = h + Last[m];
1744 if(hm > 1.1)
1745 {
1746 console.log("should not happen ", hm, h, Last[m]);
1747 debugger;
1748 hm = 1;
1749 //todo...
1750 }
1751 Y = Math.max(YStart - hm * gh, hstart);
1752 context.lineTo(X, Y);
1753 X += fWidth;
1754 Last[m] = hm;
1755 }
1756 context.fill();
1757
1758 }
1759 context.fillStyle = 'wheat';
1760 context.textAlign='right';
1761 context.fillText('100%', nWidth, hstart + FontHeight);
1762 context.textAlign='left';
1763 context.fillText(TI.n, 0, hstart + FontHeight);
1764 hstart += gh;
1765 }
1766 }
1767
1768 if(HighlightKey != 0 && SubMenuActive == -1)
1769 {
1770 ToolTipCallback = function(canvas, x, y)
1771 {
1772 let TI = ThreadInfo[HighlightKey];
1773 let ret = [];
1774 let colors = [];
1775 for(let l = 0; l < TI.a.length; ++l)
1776 {
1777 let a = TI.a[l];
1778 let idx = GetTimer(TI.ids[l]);
1779 let c = TimerArray[idx].color;
1780 colors.push(c);
1781 ret.push(TimerArray[idx].name);
1782 let t = FormatTime(a[HighlightFrame]) + 'ms';
1783 colors.push('white');
1784 ret.push(t);
1785 }
1786 return {c:colors, a:ret};
1787 }
1788 }
1789
1790 ProfileLeave();
1791 }
1792
1793 function DrawGraphPercentile(View, LocalMouseX, LocalMouseY, SubIndex)
1794 {
1795 let TimerMap = FrameData.TimerMap;
1796 if(!TimerMap)
1797 return;
1798
1799 ProfileEnter("DrawGraphPercentile");
1800 let Canvas = View.Canvas[View.BackBuffer];
1801 let context = Canvas.getContext('2d');
1802 context.clearRect(0, 0, View.w, View.h);
1803
1804 let h = View.h;
1805 let w = View.w;
1806 let NumGraphs = 0;
1807 let ToolTips = Array();
1808 for(let key in TimerMap)
1809 {
1810 if(!IsGroup(key))
1811 {
1812 let idx = GetTimer(key);
1813 if(TimerArray[idx].e)
1814 {
1815 NumGraphs++;
1816 }
1817 }
1818 }
1819 if(NumGraphs)
1820 {
1821 let hstart = 0;
1822 let gh = h / NumGraphs;
1823 let Keys = [];
1824 let cidx = 1;
1825
1826 if(LocalMouseX >= 0 && LocalMouseY >= 0 && LocalMouseX < w && LocalMouseY < h && SubMenuActive == -1)
1827 {
1828 ToolTipCallback = function(canvas, x, y)
1829 {
1830 let TimerMap = FrameData.TimerMap;
1831 let context = canvas.getContext('2d');
1832 context.font = Font;
1833 let XPos = x - 20;
1834 for(let key in TimerMap)
1835 {
1836 let idx = GetTimer(key);
1837 let TimerState = TimerMap[key];
1838 let T = TimerArray[idx];
1839 if(!IsGroup(key) && T.e && TimerState.PercentileMax > TimerState.PercentileMin)
1840 {
1841 let HighlightIndex = -1;
1842 let Max = TimerState.PercentileMax;
1843 let Min = TimerState.PercentileMin;
1844 let h = View.h;
1845 let w = View.w;
1846 let tooltipstring = TimerState.tooltipstring;
1847
1848 if(LocalMouseX >= 0 && LocalMouseY >= 0 && LocalMouseX < w && LocalMouseY < h && SubMenuActive == -1 && tooltipstring)
1849 {
1850 if(TimerState.tooltipysoft)
1851 {
1852 let RATE = 0.05;
1853 if(Math.abs(TimerState.tooltipysoft - TimerState.tooltipy) > 6)
1854 {
1855 TimerState.tooltipysoft = TimerState.tooltipy * RATE + TimerState.tooltipysoft * (1-RATE);
1856 }
1857 }
1858 else
1859 {
1860 TimerState.tooltipysoft = TimerState.tooltipy;
1861 }
1862 let Y = TimerState.tooltipysoft;
1863 let wtext = context.measureText(tooltipstring, XPos, Y).width;
1864 let X = Math.max(0, XPos - wtext);
1865 context.fillStyle = 'black';
1866 context.fillRect(X - 1, Y-1 , wtext+2, BoxHeight+2);
1867 context.fillStyle = 'white';
1868 context.textAlign = 'right';
1869 context.fillText(tooltipstring, X + wtext, Y+BoxHeight-2);
1870
1871 }
1872 }
1873 context.textAlign = 'left';
1874 }
1875 }
1876 }
1877
1878
1879 for(let key in TimerMap)
1880 {
1881 let idx = GetTimer(key);
1882 let TimerState = TimerMap[key];
1883 TimerState.tooltipstring = null;
1884 let Valid = TimerState.PercentileMax > TimerState.PercentileMin;
1885 if(!IsGroup(key) && TimerArray[idx].e)
1886 {
1887 let Max = Valid ? TimerState.PercentileMax : 1;
1888 let Min = Valid ? TimerState.PercentileMin : 0;
1889 let SubGraphSettings = GetSubGraphSettings(key);
1890 let Percentile = 0.0;
1891 if(Percentile == null)
1892 Percentile = 0.0;
1893 Percentile = Math.max(0.0, Math.min(99.0, Percentile));
1894 if(!SubGraphSettings.AutomaticReference)
1895 {
1896 Max = SubGraphSettings.ReferenceTime;
1897 }
1898 let Reference = Max;
1899 let PercentileData = TimerState.Percentile;
1900 let PercentileCount = TimerState.PercentileCount;
1901 let BasePrc = 0;
1902 if(PercentileCount > PERCENTILE_SAMPLES)
1903 {
1904 BasePrc = 100 * (1- PERCENTILE_SAMPLES / PercentileCount);
1905 }
1906 let Total = PercentileData.length-1;
1907 let NumElementsOnScreen = Total * (100 - Percentile) / (100);
1908 let WidthPerElement = w / NumElementsOnScreen;
1909 let TotalWidth = Total * WidthPerElement;
1910 let PercentilePrc = Percentile / 100;
1911 let PercentileOffset = PercentilePrc * TotalWidth;
1912 let fHeightScale2 = gh / Max;
1913 let color = TimerArray[idx].color;
1914 let X = 0;
1915 let Y = hstart + gh;
1916 let YStart = Y;
1917 let MouseInside = LocalMouseX >= 0 && LocalMouseY >= 0 && LocalMouseX < w && LocalMouseY < h && SubMenuActive == -1;
1918
1919 context.globalAlpha = 1;
1920 context.fillStyle = nBackColorsDark[cidx];
1921 cidx = 1-cidx;
1922 context.fillRect(0, hstart, w, gh);
1923 context.strokeStyle = color;
1924 context.fillStyle = color;
1925 let PercentileStart = Math.max(0, Math.floor(0.01*Percentile / PercentileData.length));
1926 {
1927 context.beginPath();
1928 context.moveTo(X,Y);
1929 for(let i = PercentileStart; i < PercentileData.length; ++i)
1930 {
1931 X = i * WidthPerElement - PercentileOffset;
1932 Y = Math.max(YStart - PercentileData[i] * fHeightScale2, hstart);
1933 context.lineTo(X, Y);
1934 }
1935 context.stroke();
1936 context.lineTo(X, YStart);
1937 context.globalAlpha = GRAPH_ALPHA;
1938 context.fill();
1939 }
1940 context.globalAlpha = 1;
1941 context.fillStyle = 'wheat';
1942 context.textAlign='right';
1943 context.fillText(FormatTime(Reference) + 'ms', nWidth, hstart + FontHeight);
1944 context.fillText('100%', nWidth, hstart + gh-2);
1945 context.textAlign='centered';
1946 Percentile = BasePrc;
1947 context.fillText( ((Percentile + 100)/2).toFixed(2) + '%', nWidth/2, hstart + gh-2);
1948 context.textAlign='left';
1949 context.fillText(Percentile.toFixed(2) + "% [Samples:" + PercentileCount + "]", 0, hstart + gh-2);
1950 context.fillText(TimerArray[idx].name, 15, hstart + FontHeight);
1951 context.fillText(Percentile + '%', nWidth, hstart + FontHeight);
1952
1953 if(MouseInside)
1954 {
1955 let Element = (PercentileOffset + LocalMouseX) / WidthPerElement;
1956 let Rounded = Math.round(Element);
1957 let HighlightIndex = Math.max(0, Math.min(Rounded, PercentileData.length-1));
1958 X = HighlightIndex * WidthPerElement - PercentileOffset;
1959 let Y = YStart - Math.min(PercentileData[HighlightIndex], Reference) * fHeightScale2;
1960 context.strokeStyle = color;
1961 context.beginPath();
1962 let CrossX = X;
1963 let CrossY = Y;
1964 context.moveTo(CrossX-2, CrossY-2);
1965 context.lineTo(CrossX+2, CrossY+2);
1966 context.moveTo(CrossX+2, CrossY-2);
1967 context.lineTo(CrossX-2, CrossY+2);
1968 context.moveTo(CrossX, hstart);
1969 context.lineTo(CrossX, hstart + gh);
1970 context.stroke();
1971 TimerState.tooltipy = Math.min(YStart - BoxHeight, Y) + View.y;
1972 let Perc = 0;
1973 if(PERCENTILE_SAMPLES < PercentileCount)
1974 {
1975 let Idx = PercentileCount - PERCENTILE_SAMPLES + HighlightIndex;
1976 Perc = 100 * Idx / (PercentileCount-1);
1977 }
1978 else
1979 {
1980 let Idx = HighlightIndex - (PERCENTILE_SAMPLES - PercentileCount);
1981 Idx = Math.max(Idx, 0);
1982 Perc = 100 * (Idx / (PercentileCount-1))
1983 }
1984 TimerState.tooltipstring = FormatTime(Perc) + '% ' + FormatTime(PercentileData[HighlightIndex]) + 'ms';;
1985 }
1986 hstart += gh;
1987 }
1988 }
1989 }
1990 ProfileLeave();
1991 }
1992
1993
1994
1995 function DrawGraph(View, LocalMouseX, LocalMouseY, SubIndex, Split)
1996 {
1997 var TimerMap = FrameData.TimerMap;
1998 if(!TimerMap)
1999 return;
2000
2001 ProfileEnter("DrawGraph");
2002 var Canvas = View.Canvas[View.BackBuffer];
2003 var context = Canvas.getContext('2d');
2004 context.clearRect(0, 0, View.w, View.h);
2005
2006 var h = View.h;
2007 var w = View.w;
2008 var fHeightScale = h / ReferenceGraph;
2009 var MouseDragging = 0;
2010 var fWidth = w / FRAME_COUNT;
2011 var HighlightFrame = -1;
2012 var GraphKey = null;
2013 var GraphBest = 0;
2014 var MouseTime = ReferenceGraph * (1-(LocalMouseY / h));
2015
2016 if(LocalMouseX >= 0 && LocalMouseY >= 0 && LocalMouseX < w && LocalMouseY < h && SubMenuActive == -1)
2017 {
2018 var index = Math.floor(FRAME_COUNT * LocalMouseX / w);
2019 HighlightFrame = index;
2020 for(var key in TimerMap)
2021 {
2022 var idx = GetTimer(key);
2023 var T = TimerArray[idx];
2024 var TimerState = TimerMap[key];
2025 var Time = TimerState.Time;
2026 if(Time[index] >= MouseTime && (GraphBest == 0 || Time[index] <= GraphBest))
2027 {
2028 GraphKey = key;
2029 GraphBest = Time[index];
2030 }
2031 }
2032 ToolTipCallback = function(canvas, x, y)
2033 {
2034 if(Split)
2035 {
2036 var TimerMap = FrameData.TimerMap;
2037 var context = canvas.getContext('2d');
2038 context.font = Font;
2039 var XPos = x - 20;
2040 for(var key in TimerMap)
2041 {
2042 var idx = GetTimer(key);
2043 var T = TimerArray[idx];
2044 var TimerState = TimerMap[key];
2045 var Time = TimerState.Time;
2046 if(TimerState.tooltipysoft)
2047 {
2048 var RATE = 0.05;
2049 if(Math.abs(TimerState.tooltipysoft - TimerState.tooltipy) > 6)
2050 {
2051 TimerState.tooltipysoft = TimerState.tooltipy * RATE + TimerState.tooltipysoft * (1-RATE);
2052 }
2053 }
2054 else
2055 {
2056 TimerState.tooltipysoft = TimerState.tooltipy;
2057 }
2058 var Y = TimerState.tooltipysoft;
2059 var str = '' + FormatTime(Time[index]) + 'ms';
2060 var w = context.measureText(str, XPos, Y).width;
2061 var X = Math.max(0, XPos - w);
2062 context.fillStyle = 'black';
2063 context.fillRect(X - 1, Y-1 , w+2, BoxHeight+2);
2064 context.fillStyle = 'white';
2065 context.textAlign = 'right';
2066 context.fillText(str, X + w, Y+BoxHeight-2);
2067
2068 }
2069 context.textAlign = 'left';
2070 }
2071 else
2072 {
2073 var StringArray = [];
2074 var ColorArray = [];
2075 var TimerMap = FrameData.TimerMap;
2076 for(var key in TimerMap)
2077 {
2078 if(!IsGroup(key))
2079 {
2080 var idx = GetTimer(key);
2081 var T = TimerArray[idx];
2082 var TimerState = TimerMap[key];
2083 var Time = TimerState.Time;
2084 ColorArray.push(TimerArray[idx].color);
2085 StringArray.push('' + T.name);
2086 ColorArray.push('white');
2087 StringArray.push('' + FormatTime(Time[index]) + 'ms') ;
2088 }
2089 }
2090 return {c:ColorArray,a:StringArray};
2091 }
2092 }
2093
2094 }
2095
2096 if(Split)
2097 {
2098 var NumGraphs = 0;
2099 for(var key in TimerMap)
2100 {
2101 if(!IsGroup(key))
2102 {
2103 NumGraphs++;
2104 }
2105 }
2106 if(NumGraphs)
2107 {
2108 var hstart = 0;
2109 var gh = h / NumGraphs;
2110 var Keys = [];
2111 var cidx = 1;
2112 for(var key in TimerMap)
2113 {
2114 var idx = GetTimer(key);
2115 var TimerState = TimerMap[key];
2116 if(!IsGroup(key))
2117 {
2118 let SubGraphSettings = GetSubGraphSettings(key);
2119 var Reference = GetSubGraphReferenceTime(SubGraphSettings, TimerState);
2120 var fHeightScale2 = gh / Reference;
2121
2122 var Time = TimerState.Time;
2123 var color = TimerArray[idx].color;
2124 var X = w - Time.length*fWidth;
2125 var Y = hstart + gh;
2126 var YStart = Y;
2127 context.globalAlpha = 1;
2128 context.fillStyle = nBackColorsDark[cidx];
2129 cidx = 1-cidx;
2130 context.fillRect(0, hstart, w, gh);
2131 context.strokeStyle = color;
2132 context.fillStyle = color;
2133 context.beginPath();
2134 context.moveTo(X,Y);
2135 for(var i = 0; i < Time.length; ++i)
2136 {
2137 Y = Math.max(YStart - Time[i] * fHeightScale2, hstart);
2138 context.lineTo(X, Y);
2139 X += fWidth;
2140
2141 }
2142 context.stroke();
2143 context.lineTo(X, YStart);
2144 context.globalAlpha = GRAPH_ALPHA;
2145 context.fill();
2146
2147
2148 context.globalAlpha = 1;
2149 context.fillStyle = 'wheat';
2150 context.textAlign='right';
2151 context.fillText(FormatTime(Reference) + 'ms', nWidth, hstart + FontHeight);
2152 context.textAlign='left';
2153 context.fillText(TimerArray[idx].name, 15, hstart + FontHeight);
2154
2155 if(HighlightFrame >= 0)
2156 {
2157 var X = w - Time.length * fWidth + fWidth * HighlightFrame;
2158 var Y = YStart - Math.min(Time[HighlightFrame], Reference) * fHeightScale2;
2159 context.strokeStyle = color;
2160 context.beginPath();
2161 var CrossX = X;
2162 var CrossY = Y;
2163 context.moveTo(CrossX-2, CrossY-2);
2164 context.lineTo(CrossX+2, CrossY+2);
2165 context.moveTo(CrossX+2, CrossY-2);
2166 context.lineTo(CrossX-2, CrossY+2);
2167 context.moveTo(CrossX, hstart);
2168 context.lineTo(CrossX, hstart + gh);
2169 context.stroke();
2170 TimerState.tooltipy = Math.min(YStart - BoxHeight, Y) + View.y;
2171 }
2172 hstart += gh;
2173 }
2174 }
2175 }
2176 }
2177 else
2178 {
2179 var Keys = [];
2180 var Prev = Array();
2181 var He = Array();
2182 for(var key in TimerMap)
2183 {
2184 if(!IsGroup(key))
2185 {
2186 var idx = GetTimer(key);
2187 var TimerState = TimerMap[key];
2188 var Time = TimerState.Time;
2189 var color = TimerArray[idx].color;
2190 var X = w - Time.length*fWidth;
2191 var Y = h;
2192 while(Time.length > He.length)
2193 {
2194 He.push(0.0);
2195 }
2196 for(var i = 0; i < Time.length; ++i)
2197 {
2198 He[i] += Time[i];
2199 }
2200 }
2201 }
2202 if(1) // graph with clipping. this code seems way to complicated
2203 {
2204 var NumGraphs = 0;
2205 var Len = 0;
2206 for(let key in TimerMap)
2207 {
2208 if(!IsGroup(key))
2209 {
2210 var idx = GetTimer(key);
2211 var TimerState = TimerMap[key];
2212 var Time = TimerState.Time;
2213 Len = Math.max(Len, Time.length);
2214 NumGraphs++;
2215 }
2216 }
2217 let g = Array(Len);
2218 for(let i = 0; i < g.length; ++i)
2219 g[i] = Array(NumGraphs);
2220 let i = 0;
2221 for(let key in TimerMap)
2222 {
2223 if(!IsGroup(key))
2224 {
2225 var TimerState = TimerMap[key];
2226 var Time = TimerState.Time;
2227 let x = GetTimer(key);
2228 for(let j = 0; j < Time.length; ++j)
2229 {
2230 g[j][i] = {k:key, v: Time[j], x:x, c:TimerArray[x].color,n:TimerArray[x].name};
2231 }
2232 i++;
2233 }
2234 }
2235 for(let i = 0; i < g.length; ++i)
2236 {
2237 let a = g[i];
2238 a.sort( function(l, r){
2239 return l.v-r.v;
2240 });
2241 }
2242 let cvt = function(t){ return h - t * fHeightScale; };
2243 if(1)
2244 {
2245 let Segments = Array();
2246 let MakeSegment = function(b,e)
2247 {
2248 let s = {b:b, e:e, a:[]};
2249 Segments.push(s);
2250 return s;
2251 };
2252 let MakeEntry = function(y0l, y0h, y1l, y1h, c)
2253 {
2254 let e ={y0l:y0l,y0h:y0h,y1h:y1h,y1l:y1l,c:c,t:0};
2255 return e;
2256 };
2257
2258 let X = 0;
2259 for(let i = 1; i < g.length; ++i)
2260 {
2261 let a0 = g[i-1];
2262 let a1 = g[i];
2263 let s = MakeSegment(X, X + fWidth);
2264 if(a0.length != a1.length)
2265 {
2266 console.log("should not happen!!");
2267 debugger;
2268 }
2269 let FailIndex = -1;
2270 for(let j = 0; j < a0.length; ++j)
2271 {
2272 if(a0[j].k != a1[j].k)
2273 {
2274 FailIndex = j;
2275 break;
2276 }
2277
2278 let t0l = j > 0 ? a0[j-1].v : 0;
2279 let t0h = a0[j].v;
2280 let t1l = j > 0 ? a1[j-1].v : 0;
2281 let t1h = a1[j].v;
2282 let c = a1[j].c;
2283 let e = MakeEntry(t0l, t0h, t1l, t1h, c);
2284 s.a.push(e);
2285 }
2286 if(FailIndex >= 0)
2287 {
2288 let l = a0.length;
2289 let ax = Array(l);
2290 if(FailIndex + 1 >= l)
2291 debugger;///no lines, should not happen.
2292 for(let j = FailIndex; j < l; ++j)
2293 {
2294 //find matching
2295 for(let k = FailIndex; k < l; ++k)
2296 {
2297 if(a1[k].k == a0[j].k)
2298 {
2299 if(ax[j])
2300 {
2301 console.log("should never happen");
2302 debugger;//should not happen
2303 }
2304 ax[j] = a1[k];
2305 break;
2306 }
2307 }
2308 }
2309 //find all intersections within [0-1]
2310 let I = [];
2311 I.push(0);
2312 for(let j = FailIndex; j < l; ++j)
2313 {
2314 let ya = a0[j].v;
2315 let yam = ax[j].v;
2316 let ka = yam-ya;
2317 for(let k = j + 1; k < l; ++k)
2318 {
2319 let yb = a0[k].v;
2320 let ybm = ax[k].v;
2321 let kb = ybm-yb;
2322 let num = yb-ya;
2323 let denom = ka-kb;
2324 if(denom>0.00001||denom < -0.00001)
2325 {
2326 let x = num/denom;
2327 if(x>=0 && x <= 1)
2328 {
2329 I.push(x);
2330 }
2331 }
2332 }
2333 }
2334 I.push(1);
2335 if(I.length)
2336 {
2337 I.push(I[0]);
2338 I.push(I[0]);
2339 I.sort();
2340
2341 let i = 0;
2342 let DIST = 0.00001;
2343 while(i+1 < I.length)
2344 {
2345 if(Math.abs(I[i] - I[i+1]) < DIST)
2346 {
2347 I.splice(i, 1);
2348 }
2349 else
2350 {
2351 i++;
2352 }
2353 }
2354 }
2355 for(let i = 0; i < I.length-1; ++i)
2356 {
2357 let x0 = I[i];
2358 let x1 = I[i+1];
2359 let xm = 0.5 * (x0+x1);
2360 let b = X + x0 * fWidth;
2361 let e = X + x1 * fWidth;
2362 let c = X + xm * fWidth;
2363 let s = MakeSegment(b, e);
2364 for(let j = FailIndex; j < l; ++j)
2365 {
2366 let y = a0[j].v;
2367 let yx = ax[j].v;
2368 let yd = yx - y;
2369 let y0 = y + yd * x0;
2370 let y1 = y + yd * x1;
2371 let ym = y + yd * xm;
2372 let e = MakeEntry(ym, y0, ym, y1, a0[j].c);
2373 s.a.push(e);
2374 }
2375 s.a.sort(function(l, r){
2376 return l.y0l-r.y0l;
2377 });
2378 for(let j = 0; j < s.a.length; ++j)
2379 {
2380 if(j == 0)
2381 {
2382 s.a[j].y0l = 0;
2383 s.a[j].y1l = 0;
2384 }
2385 else
2386 {
2387 s.a[j].y0l = s.a[j-1].y0h;
2388 s.a[j].y1l = s.a[j-1].y1h;
2389 }
2390 }
2391 }
2392 }
2393 X += fWidth;
2394 }
2395 for(let i = 0; i < Segments.length; ++i)
2396 {
2397 let s = Segments[i];
2398 let X0 = s.b;
2399 let X1 = s.e;
2400 for(let j = 0; j < s.a.length; ++j)
2401 {
2402 let e = s.a[j];
2403 let xs = [];
2404 let ytop = [];
2405 let ybot = [];
2406 if(!e.t)
2407 {
2408 e.t = 1;
2409 let XB = X0;
2410 let XE = X1;
2411 xs.push(XB);
2412 ytop.push(cvt(e.y0h));
2413 ybot.push(cvt(e.y0l));
2414 let yeh = e.y1h;
2415 let yel = e.y1l;
2416 let k = i + 1;
2417 let Found = true;
2418 while(k < Segments.length && Found)
2419 {
2420 Found = false;
2421 let s = Segments[k];
2422 for(let l = 0; l < s.a.length && !Found; ++l)
2423 {
2424 let e1 = s.a[l];
2425 if(!e1.t && e1.c == e.c && Math.abs(e1.y0l-e.y1l) < 0.0001 && Math.abs(e1.y0h - e.y1h) < 0.0001)
2426 {
2427 e1.t = 1;
2428 xs.push(XE);
2429 ytop.push(cvt(yeh));
2430 ybot.push(cvt(yel));
2431 XE = s.e;
2432 yeh = e1.y1h;
2433 yel = e1.y1l;
2434 Found = true;
2435 e = e1;
2436 }
2437 }
2438 k++;
2439 }
2440 xs.push(XE);
2441 ytop.push(cvt(yeh));
2442 ybot.push(cvt(yel));
2443 }
2444 if(xs.length)
2445 {
2446 context.strokeStyle = e.c;
2447 context.fillStyle = e.c;
2448 context.globalAlpha = GRAPH_ALPHA;
2449 context.beginPath();
2450 context.moveTo(xs[0], ytop[0]);
2451 for(let k = 1; k < xs.length; ++k)
2452 {
2453 context.lineTo(xs[k], ytop[k]);
2454 }
2455 for(let k = xs.length-1; k >= 0; --k)
2456 {
2457 context.lineTo(xs[k], ybot[k]);
2458 }
2459 context.fill();
2460 context.beginPath();
2461 context.moveTo(xs[0], ytop[0]);
2462 for(let k = 1; k < xs.length; ++k)
2463 {
2464 context.lineTo(xs[k], ytop[k]);
2465 }
2466 context.globalAlpha = 1.0;
2467 context.stroke();
2468 }
2469 }
2470 }
2471 }
2472 }
2473 if(0) //old graph code, no clipping
2474 {
2475 for(var key in TimerMap)
2476 {
2477 if(!IsGroup(key))
2478 {
2479 var idx = GetTimer(key);
2480 var TimerState = TimerMap[key];
2481 var Time = TimerState.Time;
2482 var color = TimerArray[idx].color;
2483 var X = w - Time.length*fWidth;
2484 var Y = h;
2485 context.strokeStyle = color;
2486 context.fillStyle = color;
2487
2488 context.beginPath();
2489 context.moveTo(X,Y);
2490 for(var i = 0; i < Time.length; ++i)
2491 {
2492 Y = h - Time[i] * fHeightScale;
2493 context.lineTo(X, Y);
2494 X += fWidth;
2495 }
2496 context.stroke();
2497 context.lineTo(X, h);
2498 context.globalAlpha = GRAPH_ALPHA;
2499 context.fill();
2500 context.globalAlpha = 1;
2501 }
2502 }
2503 }
2504 if(HighlightFrame >= 0)
2505 {
2506 for(var key in TimerMap)
2507 {
2508 if(!IsGroup(key))
2509 {
2510 var idx = GetTimer(key);
2511 var TimerState = TimerMap[key];
2512 var Time = TimerState.Time;
2513 var color = TimerArray[idx].color;
2514 var X = w - Time.length*fWidth + fWidth * HighlightFrame;
2515 var Y = h - Time[HighlightFrame] * fHeightScale;
2516 context.strokeStyle = color;
2517 context.beginPath();
2518 var CrossX = X;
2519 var CrossY = Y;
2520 context.moveTo(CrossX-2, CrossY-2);
2521 context.lineTo(CrossX+2, CrossY+2);
2522 context.moveTo(CrossX+2, CrossY-2);
2523 context.lineTo(CrossX-2, CrossY+2);
2524 context.stroke();
2525 }
2526 }
2527 }
2528 context.fillStyle = 'wheat';
2529 context.textAlign='right';
2530 context.fillText(FormatTime(ReferenceGraph) + 'ms', nWidth, FontHeight);
2531 context.textAlign='left';
2532 }
2533
2534 ProfileLeave();
2535 }
2536
2537 function StringHash(s) //note: matching code in microprofile.cpp: uint32_t MicroProfileStringHash(const char* pString)
2538 {
2539 var h = 0xfeedba3e;
2540 for(var i = 0; i < s.length; ++i)
2541 {
2542 h = s.charCodeAt(i) + ((h << 5) - h);
2543 h = h & h;
2544 }
2545 return Math.abs(h);
2546 }
2547
2548 function StringColorIndex(Name)
2549 {
2550 var h = StringHash(Name);
2551 var cidx = Math.floor(360*(h / (1<<32-1)) );
2552 return cidx;
2553 }
2554
2555 function ColorFromString(Name, S, L)
2556 {
2557 var H = StringColorIndex(Name);
2558 return "hsl(" + H + "," + S + "%, " + L+ "%)";
2559 }
2560
2561 function LerpColor(v)
2562 {
2563 var R_0 = 0;
2564 var G_0 = 1;
2565 var B_0 = 0;
2566
2567 var R_1 = 1;
2568 var G_1 = 0.5;
2569 var B_1 = 0;
2570
2571 var R_2 = 1;
2572 var G_2 = 0;
2573 var B_3 = 0;
2574 var R;
2575 var G;
2576 if(v < 0.5)
2577 {
2578 v *= 2;
2579 var v0 = (1-v);
2580 R = R_0 * v0 + R_1 * v;
2581 G = G_0 * v0 + G_1 * v;
2582
2583 }
2584 else
2585 {
2586 v = (v-0.5) * 2;
2587 var v0 = (1-v);
2588 R = R_1 * v0 + R_2 * v;
2589 G = G_1 * v0 + G_2 * v;
2590 }
2591 R *= 255;
2592 G *= 255;
2593 return "rgb(" + R.toFixed(0) + "," + G.toFixed(0) + ",0)";
2594
2595 }
2596
2597 function DrawRange(context, X, XEnd, Y, YEnd, ColorBack, ColorFront)
2598 {
2599 if(X < XEnd)
2600 {
2601 var W = XEnd - X;
2602 var H = YEnd - Y;
2603 context.globalAlpha = 0.1;
2604 context.fillStyle = ColorBack;
2605 context.fillRect(X, Y, W, H);
2606 context.globalAlpha = 1;
2607 context.strokeStyle = ColorFront;
2608 context.beginPath();
2609 context.moveTo(X, 0);
2610 context.lineTo(X, H);
2611 context.moveTo(X+W, 0);
2612 context.lineTo(X+W, H);
2613 // context.closePath();
2614 context.stroke();
2615 }
2616 }
2617
2618
2619 function DrawHistory(View, LocalMouseX, LocalMouseY)
2620 {
2621 ProfileEnter("DrawHistory");
2622 var Canvas = View.Canvas[View.BackBuffer];
2623 var context = Canvas.getContext('2d');
2624 context.clearRect(0, 0, View.w, View.h);
2625 if(!FrameData.Time)
2626 return;
2627 var fHeight = View.h;
2628 var fWidth = nWidth / FRAME_COUNT;
2629 var fHeightScale = fHeight / ReferenceHistory;
2630 var fX = 0;
2631 var FrameIndex = -1;
2632 var MouseDragging = 0;
2633 var GreenTime = (Settings.TargetTime * 0.9);
2634 var RedBegin = (Settings.TargetTime * 1.1);
2635 var LerpDist = 1.0 / (RedBegin - GreenTime);
2636 var id0 = -1;
2637 var id1 = -1;
2638
2639 if(MouseDragActiveXEnd > MouseDragActiveXStart)
2640 {
2641 var idx0 = Math.ceil(FRAME_COUNT * MouseDragActiveXStart / nWidth);
2642 var idx1 = Math.floor(FRAME_COUNT * MouseDragActiveXEnd / nWidth);
2643 idx0 = Clamp(idx0, 0, FRAME_COUNT-1);
2644 idx1 = Clamp(idx1, 0, FRAME_COUNT-1);
2645 id0 = FrameData.Ids[idx0];
2646 id1 = FrameData.Ids[idx1];
2647 }
2648
2649
2650 var ToolTipFrame = -1;
2651 for(var i = 0; i < FRAME_COUNT; i++)
2652 {
2653 var fMs = FrameData.Time[i];
2654 var fPrc = (fMs - GreenTime) * LerpDist;
2655 fPrc = Clamp(fPrc, 0, 1);
2656 var color = LerpColor(fPrc);
2657 var fid = FrameData.Ids[i];
2658 if(fid >= id0 && fid <= id1)
2659 {
2660 color = 'cyan';
2661 }else if(FrameData.Frozen[i])
2662 {
2663 color = 'purple';
2664 }
2665
2666
2667 var fH = fHeightScale * fMs;
2668 var bMouse = LocalMouseX > fX && LocalMouseX < fX + fWidth+1 && MouseY <= HistoryHeight;
2669 if(bMouse && !MouseDragging)
2670 {
2671 context.fillStyle = FRAME_HISTORY_COLOR_GPU;
2672 ToolTipFrame = i;
2673 }
2674 else
2675 {
2676 context.fillStyle = color;
2677 }
2678 context.fillRect(fX, fHeight - fH, fWidth-1, fH);
2679 fX += fWidth;
2680 }
2681
2682
2683 DrawRange(context, MouseDragActiveXStart, MouseDragActiveXEnd, 0, HistoryHeight, '#59d0ff', '#00ddff');
2684
2685
2686 var fH = fHeight - fHeightScale * Settings.TargetTime;
2687 context.fillStyle = 'wheat';
2688 context.strokeStyle = 'wheat';
2689 context.beginPath();
2690 context.moveTo(0, fH);
2691 context.lineTo(nWidth, fH);
2692 // context.closePath();
2693 context.stroke();
2694 var YText;
2695 if(fH > HistoryHeight * 0.25)
2696 {
2697 YText = fH - FontAscent;
2698 }
2699 else
2700 {
2701 YText = fH + FontHeight;
2702 }
2703
2704 context.fillText(Settings.TargetTime + 'ms', 3, YText);
2705 context.textAlign='right';
2706 context.fillText(FormatTime(ReferenceHistory) + 'ms', nWidth, FontHeight);
2707 context.textAlign='left';
2708
2709
2710
2711 if(ToolTipFrame >= 0)
2712 {
2713 var fMs = FrameData.Time[ToolTipFrame];
2714 var Frozen = FrameData.Frozen[ToolTipFrame];
2715 ToolTipCallback = function()
2716 {
2717 var StringArray = [];
2718 StringArray.push("Frame");
2719 StringArray.push("" + ToolTipFrame);
2720 StringArray.push("Time");
2721 StringArray.push("" + fMs.toFixed(3));
2722 if(Frozen)
2723 {
2724 StringArray.push("Frozen & Unreliable");
2725 StringArray.push("");
2726 }
2727 return StringArray;
2728 }
2729 }
2730
2731
2732 ProfileLeave();
2733
2734 }
2735 function MouseInRect(Rect)
2736 {
2737 return MouseInside(Rect.x, Rect.y, Rect.w, Rect.h);
2738 }
2739 function MouseInside(X, Y, W, H)
2740 {
2741 return MouseX >= X && MouseX <= X + W && MouseY >= Y && MouseY <= Y + H;
2742 }
2743
2744 var MessageText = "";
2745 var MessageTimeout = -1;
2746 var MessageTimeoutLast = new Date();
2747 var MessageShowSpinner = 0;
2748 function SetMessage(text, TimeOut, ShowSpinner)
2749 {
2750 if(TimeOut)
2751 {
2752 MessageTimeout = TimeOut;
2753 }
2754 else
2755 {
2756 MessageTimeout = -1;
2757 }
2758 MessageText = text;
2759 MessageShowSpinner = ShowSpinner;
2760 }
2761 function ClearMessage(Message)
2762 {
2763 if(Message == MessageText)
2764 {
2765 MessageText = "";
2766 MessageTimeout = -1;
2767 }
2768 }
2769
2770 function DrawMessage()
2771 {
2772 var context = CanvasDetailedView.getContext('2d');
2773 var Now = new Date();
2774 var Delta = Now - MessageTimeoutLast;
2775 if(MessageTimeout>0)
2776 {
2777 MessageTimeout -= Delta;
2778 if(MessageTimeout<= 0)
2779 {
2780 MessageText = "";
2781 MessageTimeout = -1;
2782 }
2783
2784 }
2785 MessageTimeoutLast = Now;
2786
2787 var Text = MessageText;
2788 var X = nWidth / 2;
2789
2790 var Y = nHeight / 2;
2791 context.font = FontFlash;
2792 context.textAlign = 'center';
2793 context.fillStyle = 'red';
2794
2795 function MSG(a, Spinner)
2796 {
2797 context.fillText(a, X, Y);
2798 if(Spinner)
2799 {
2800 var w = context.measureText(a).width;
2801 SpinnerDraw(1, context, SpinnerText0, X + 3 + w*0.5, Y - 25, 30, 30);
2802 SpinnerDraw(1, context, SpinnerText1, X - 3 - w*0.5 - 30, Y - 25, 30, 30);
2803 }
2804 Y -= 60;
2805 }
2806 if(!HelpFade)
2807 HelpFade = new Date();
2808 var HelpFadeTime = new Date() - HelpFade;
2809 if(HelpFadeTime < 2000)
2810 {
2811 var Alpha = 1 - (HelpFadeTime/2000);
2812 context.globalAlpha = Alpha;
2813 context.fillText("Press 'h' for help", X, 200);
2814 context.globalAlpha = 1;
2815 }
2816
2817 if(Text != "")
2818 {
2819 MSG(Text);
2820 }
2821 if(IsFrozen)
2822 {
2823 MSG("FROZEN[space]");
2824 }
2825
2826 PresetPending++; //hack: wait 20 frames before showing enable messages to prevent it from showing when loading settings. [[[test]]]
2827 if(WSIsOpen && PresetPending > 20)
2828 {
2829 if(Settings.ViewActive != VIEW_COUNTERS)
2830 {
2831 if(GroupsEnabled == 0)
2832 {
2833 MSG("Paused: Enable groups in 'Control' menu to unpause");
2834 }
2835 if(TimersEnabled == 0 && Settings.ViewActive != VIEW_GRAPH_THREAD_GROUP)
2836 {
2837 MSG("Enable Timers or Functions");
2838 }
2839 }
2840 }
2841 context.textAlign = 'left';
2842 context.font = Font;
2843 }
2844
2845 function DrawGraphSettingsMenu(context, XBase, Y, width, height)
2846 {
2847 if(SubMenuActive != SubMenuGraphSettings)
2848 {
2849 SubMenuGraphSettingsIndex = -1;
2850 SubMenuGraphSettingsKey = "";
2851 }
2852 if(!ShowMenu())
2853 {
2854 return;
2855 }
2856 if(!(Settings.ViewActive == VIEW_GRAPH_SPLIT || Settings.ViewActive == VIEW_GRAPH_PERCENTILE))
2857 {
2858 return;
2859 }
2860 let NumGraphs = 0;
2861 let TimerMap = FrameData.TimerMap;
2862
2863 for(let key in TimerMap)
2864 {
2865 if(!IsGroup(key))
2866 {
2867 let idx = GetTimer(key);
2868 if(TimerArray[idx].e)
2869 {
2870 NumGraphs++;
2871 }
2872 }
2873 }
2874 let h = height;
2875 let w = width;
2876 let hstart = Y;
2877 let gh = h / NumGraphs;
2878 NumGraphs = 0;
2879 for(let key in TimerMap)
2880 {
2881 if(!IsGroup(key))
2882 {
2883 let idx = GetTimer(key);
2884 if(TimerArray[idx].e)
2885 {
2886 let X = XBase+1;
2887 let Y = hstart+1;
2888 let MenuText = ">";
2889 let w2 = 2 + context.measureText(MenuText).width;
2890 let bMouseInside = MouseInside(X, Y, w2, 4 + FontHeight);
2891 context.fillStyle = bMouseInside || (SubMenuGraphSettings == SubMenuActive && SubMenuGraphSettingsIndex == NumGraphs) ? nBackColors[1] : 'black';
2892 context.fillRect(X, Y, w2, 4 + FontHeight);
2893 context.fillStyle = '#ffffff';
2894 context.fillText(MenuText, X, Y + FontHeight);
2895 context.textAlign = 'left';
2896 if(bMouseInside)
2897 {
2898 SubMenuGraphSettingsIndex = NumGraphs;
2899 SubMenuGraphSettingsKey = key;
2900 CaptureButtonX = X + w2 + 2;
2901 CaptureButtonY = Y;
2902 EnableMenu(SubMenuGraphSettings);
2903 }
2904 NumGraphs++;
2905 hstart += gh;
2906
2907
2908 }
2909 }
2910 }
2911 }
2912
2913 function DrawCaptureMenu(context)
2914 {
2915 MouseInCaptureButton = 0;
2916 if(!ShowMenu())
2917 {
2918 return;
2919 }
2920
2921 var CaptureRange = MouseDragActiveXStart < MouseDragActiveXEnd ? "Selection" : (""+Settings.CaptureFrames);
2922 var CaptureText = "Capture[" + CaptureRange + "]";
2923 var w = 10 + context.measureText(CaptureText).width;
2924 var X = nWidth / 2 - w / 2;
2925 var XCenter = nWidth / 2;
2926 var Y = nHeight - 30;
2927 MouseInCaptureButton = MouseInside(X, Y, w, 4 + FontHeight);
2928 context.textAlign = 'center';
2929 context.fillStyle = MouseInCaptureButton ? nBackColors[1] : 'black';
2930 context.fillRect(X, Y, w, 4 + FontHeight);
2931 context.fillStyle = '#ffffff';
2932 context.fillText(CaptureText, XCenter, Y + FontHeight);
2933
2934
2935
2936 X += w + 2;
2937 var MenuText = "^";
2938 var w2 = 10 + context.measureText(MenuText).width;
2939 var bMouseInCaptureMenu = MouseInside(X, Y, w2, 4 + FontHeight);
2940 context.fillStyle = bMouseInCaptureMenu ? nBackColors[1] : 'black';
2941 context.fillRect(X, Y, w2, 4 + FontHeight);
2942
2943 context.fillStyle = '#ffffff';
2944 context.fillText(MenuText, X + w2*0.5, Y + FontHeight);
2945
2946 let X1 = X + w2 + 10;
2947 if(CaptureTriggerDelta)
2948 {
2949 let text = FormatTime(CaptureTriggerDelta);
2950 let w = 10 + context.measureText("text").width;
2951 context.fillStyle = 'black';
2952 context.fillRect(X1, Y, w, 4 + FontHeight);
2953 context.fillStyle = '#ffffff';
2954 context.fillText(text, X1 + w*0.5, Y + FontHeight);
2955 X1 += w;
2956 }
2957
2958 let Pending = (CaptureTriggerTime != null && CaptureTriggerTimeType == 2);
2959 if(AutoCaptureEnabled || Pending)
2960 {
2961 let d = Dots();
2962 let AutoStatus = Pending ? (" pending" + Dots()) : "";
2963 let Source = GetAutoCaptureString();
2964 let Threshold = FormatTime(Settings.AutoCaptureTheshold);
2965 let str = "Autocapture " + AutoStatus + " Source:'" + Source + "' Threshold:" + Threshold + "ms Repeat=" + (Pending?Settings.AutoCaptureRepeat:AutoCaptureEnabled);
2966 let w = 10 + context.measureText(str).width;
2967 context.fillStyle = 'black';
2968 context.fillRect(X1, Y, w, 4 + FontHeight);
2969 context.fillStyle = '#ffffff';
2970 context.fillText(str, X1 + w*0.5, Y + FontHeight);
2971 X1 += w;
2972 }
2973
2974 context.textAlign = 'left';
2975 if(bMouseInCaptureMenu)
2976 {
2977 CaptureButtonX = X + w2;
2978 CaptureButtonY = Y;
2979 EnableMenu(SubMenuCapture);
2980 }
2981 }
2982 function UpdateX7Views()
2983 {
2984 if(Settings.ViewActive == VIEW_BAR_SINGLE || Settings.ViewActive == VIEW_BAR_ALL)
2985 {
2986 var NumSubViews = 0;
2987 var BarColumnEnabled = GetBarColumnEnabled();
2988 X7BarFirstView = -1;
2989 X7BarLastView = -1;
2990 var ViewMask = 0;
2991 for(var i = 0; i < BarColumnEnabled.length; ++i)
2992 {
2993 if(BarColumnEnabled[i])
2994 {
2995 if(X7BarFirstView == -1)
2996 X7BarFirstView = i;
2997 X7BarColumnRemap[NumSubViews++] = i;
2998 ViewMask = ViewMask | (1 << i);
2999 X7BarLastView = i;
3000 }
3001 }
3002 if(ViewMask != X7BarColumnMask)
3003 {
3004 console.log("resizing views");
3005 var w = NumSubViews ? nWidth / NumSubViews : 1;
3006 for(var i = 0; i < X7Views.length; ++i)
3007 {
3008 X7Views[i].visible = i < NumSubViews;
3009 if(i < NumSubViews)
3010 {
3011 var HistoryH = Settings.ViewCompressed ? 0 : HistoryHeight;
3012 ResizeView(X7Views[i], w*i, HistoryH, w, nHeight - HistoryH);
3013 }
3014 }
3015 X7BarColumnMask = ViewMask;
3016 }
3017 X7LegendView.visible = true;
3018 ReferenceBarAutomatic = 0;
3019 }
3020 }
3021 function DrawViews()
3022 {
3023 Plotf("DrawViews");
3024 UpdateX7Views();
3025 ProfileEnter("UpdateViews");
3026 ViewIndex = 0;
3027 for(var i = 0; i < Views.length; ++i)
3028 {
3029 var View = Views[i];
3030 if(View.visible)
3031 {
3032 var LocalMouseX = MouseX - View.x;
3033 var LocalMouseY = MouseY - View.y;
3034 View.DisplayFunc(View, LocalMouseX, LocalMouseY, View.index);
3035 var Canvas = View.Canvas[View.BackBuffer];
3036 var Context = Canvas.getContext('2d');
3037 ViewIndex++;
3038 }
3039 }
3040 ProfileLeave();
3041 var context = CanvasDetailedView.getContext('2d');
3042 context.clearRect(0, 0, nWidth, nHeight);
3043 ProfileEnter("BlitViews");
3044 for(var i = 0; i < Views.length; ++i)
3045 {
3046 var View = Views[i];
3047 if(View.visible)
3048 {
3049 context.drawImage(View.Canvas[View.BackBuffer], Math.floor(View.x), Math.floor(View.y), View.w, View.h);
3050 }
3051 }
3052
3053 DrawCaptureMenu(context);
3054 DrawGraphSettingsMenu(context, MainView.x, MainView.y, MainView.w, MainView.h);
3055
3056 ProfileLeave();
3057
3058 }
3059 var SubMenuGroup = 0;
3060 var SubMenuTimers = 1;
3061 var SubMenuModules = 2;
3062 var SubMenuFunctions = 3;
3063 var SubMenuPatched = 4;
3064 var SubMenuSettings = 5;
3065 var SubMenuViews = 6;
3066 var SubMenuPresets = 7;
3067 var SubMenuColumns = 8;
3068 var SubMenuCapture = 9;
3069 var SubMenuGraphSettings = 10;
3070 var SubMenuGraphSettingsIndex = -1;
3071 var SubMenuGraphSettingsKey = "";
3072
3073 var SubMenuActive = -1;
3074 var SubMenuTimeoutBase = 0.7;
3075 var SubMenuMouseX = 0;
3076 var SubMenuMouseY = 0;
3077 var SubMenuTimeout = new Date();
3078 var MenuItems = [];
3079 var FilterInputTimersValue = '';
3080 var FilterInputGroupsValue = '';
3081 var FilterInputModulesValue = '';
3082 var FilterInputFunctionsValue = '';
3083 var FilterInputPatchedValue = '';
3084
3085
3086 function MakeMenuItem(name, f, visible)
3087 {
3088 var Item = {};
3089 Item.name = name;
3090 Item.f = f;
3091 Item.w = name.length;
3092 Item.x = 0;
3093 Item.y = 0;
3094 Item.visible = visible;
3095 return Item;
3096 }
3097 function EnableMenu(m)
3098 {
3099 if(m != SubMenuActive)
3100 {
3101 if(SubMenuActive == SubMenuTimers)
3102 {
3103 FilterInputTimersValue = FilterInput.value;
3104 }
3105 else if(SubMenuActive == SubMenuGroup)
3106 {
3107 FilterInputGroupsValue = FilterInput.value;
3108 }
3109 else if(SubMenuActive == SubMenuModules)
3110 {
3111 FilterInputModulesValue = FilterInput.value;
3112 }
3113 else if(SubMenuActive == SubMenuFunctions)
3114 {
3115 FilterInputFunctionsValue = FilterInput.value;
3116 }
3117 else if(SubMenuActive == SubMenuPatched)
3118 {
3119 FilterInputPatchedValue = FilterInput.value;
3120 }
3121
3122 SubMenuActive = m;
3123 SubMenuTimeout = new Date();
3124
3125 if(SubMenuActive == SubMenuTimers)
3126 {
3127 FilterInput.value = FilterInputTimersValue;
3128 }
3129 else if(SubMenuActive == SubMenuGroup)
3130 {
3131 FilterInput.value = FilterInputGroupsValue;
3132 }
3133 else if(SubMenuActive == SubMenuModules)
3134 {
3135 FilterInput.value = FilterInputModulesValue;
3136 }
3137 else if(SubMenuActive == SubMenuFunctions)
3138 {
3139 FilterInput.value = FilterInputFunctionsValue;
3140 }
3141 else if(SubMenuActive == SubMenuPatched)
3142 {
3143 FilterInput.value = FilterInputPatchedValue;
3144 }
3145
3146 FilterInputValueLast = FilterInput.value;
3147 }
3148 if(m == -1)
3149 {
3150 SubMenuTimeout = 0;
3151 }
3152
3153 if(SubMenuActive == SubMenuTimers || SubMenuActive == SubMenuGroup || SubMenuActive == SubMenuModules || SubMenuActive == SubMenuFunctions || SubMenuActive == SubMenuPatched)
3154 {
3155 FilterInputDiv.style['display'] = 'inline';
3156 FilterInput.focus();
3157 }
3158 else
3159 {
3160 FilterInputDiv.style['display'] = 'none';
3161 }
3162 }
3163
3164 function Clamp(v, low, high)
3165 {
3166 return v < low ? low : (v > high ? high : v);
3167 }
3168 function TriggerCapture()
3169 {
3170 if(Settings.CaptureDelay <= 0)
3171 {
3172 Capture();
3173 }
3174 else
3175 {
3176 CaptureTriggerTime = new Date();
3177 CaptureTriggerTimeType = 1;
3178 }
3179 }
3180 function CaptureUpdate()
3181 {
3182 if(CaptureTriggerTime)
3183 {
3184 let Time = new Date();
3185 let Delta = Time - CaptureTriggerTime;
3186 CaptureTriggerDelta = Math.max(0.0, (Settings.CaptureDelay * 1000 - Delta) / 1000.0);
3187 if(Delta > Settings.CaptureDelay * 1000)
3188 {
3189 if(CaptureTriggerTimeType == 1)
3190 {
3191 Capture();
3192 }
3193 else if(CaptureTriggerTimeType == 2)
3194 {
3195 AutoCaptureEnabled = Settings.AutoCaptureRepeat > 0 ? Settings.AutoCaptureRepeat : 1;
3196 }
3197 CaptureTriggerTime = null;
3198 CaptureTriggerDelta = 0;
3199 CaptureTriggerTimeType = 0;
3200 }
3201 }
3202
3203 }
3204 function Capture()
3205 {
3206 AutoCaptureCooldown = Settings.CaptureFrames + 5;
3207 var ext = '' + Settings.CaptureFrames;
3208 if(MouseDragActiveXEnd > MouseDragActiveXStart)
3209 {
3210 var idx0 = Math.ceil(FRAME_COUNT * MouseDragActiveXStart / nWidth);
3211 var idx1 = Math.floor(FRAME_COUNT * MouseDragActiveXEnd / nWidth);
3212 idx0 = Clamp(idx0, 0, FRAME_COUNT-1);
3213 idx1 = Clamp(idx1, 0, FRAME_COUNT-1);
3214 var id0 = FrameData.Ids[idx0];
3215 var id1 = FrameData.Ids[idx1];
3216 ext = 'r/'+id0+'/'+id1;
3217 }
3218 var url = 'http://' + WSHost + ':' + WSPort + '/' + ext;
3219 window.open(url);
3220 }
3221 function InitMenu()
3222 {
3223 MenuItems = [];
3224 MenuItems.push(MakeMenuItem("Control", function(){EnableMenu(SubMenuGroup); } ));
3225 MenuItems.push(MakeMenuItem("Timers", function(){EnableMenu(SubMenuTimers); } ));
3226 MenuItems.push(MakeMenuItem("Modules", function(){EnableMenu(SubMenuModules); } ));
3227 MenuItems.push(MakeMenuItem("Functions", function(){EnableMenu(SubMenuFunctions); } ));
3228 MenuItems.push(MakeMenuItem("Patched", function(){EnableMenu(SubMenuPatched); }, function(){ return FunctionsInstrumented.length > 0;} ));
3229 MenuItems.push(MakeMenuItem("Settings", function(){ EnableMenu(SubMenuSettings); } ));
3230 MenuItems.push(MakeMenuItem("Views", function(){ EnableMenu(SubMenuViews); } ));
3231 MenuItems.push(MakeMenuItem("Presets", function(){ EnableMenu(SubMenuPresets); } ));
3232 MenuItems.push(MakeMenuItem("Columns", function(){ EnableMenu(SubMenuColumns); } ));
3233 }
3234 function DrawTopMenu()
3235 {
3236 var context = CanvasDetailedView.getContext('2d');
3237 var X = 2;
3238 var Y = 0;
3239 var MouseInY = MouseY < BoxHeight;
3240 for(var i = 0; i < MenuItems.length; ++i)
3241 {
3242 if(i == SubMenuColumns)
3243 {
3244 if(Settings.ViewActive == VIEW_GRAPH_SPLIT ||
3245 Settings.ViewActive == VIEW_GRAPH_THREAD_GROUP ||
3246 Settings.ViewActive == VIEW_GRAPH_PERCENTILE ||
3247 Settings.ViewActive == VIEW_COUNTERS)
3248 {
3249 continue;
3250 }
3251 }
3252 var Item = MenuItems[i];
3253 if(Item.visible == null || Item.visible())
3254 {
3255 var w = context.measureText(Item.name).width + 4;
3256 var MouseIn = MouseInY && MouseX >= X && MouseX < X + w;
3257 var color = MouseIn ? nBackColors[1] : "black";
3258 Item.x = X;
3259 Item.y = Y + BoxHeight;
3260 if(MouseIn)
3261 {
3262 context.fillStyle = 'white';
3263 context.fillRect(X-2, Y, w+4, BoxHeight);
3264 // Enable
3265 EnableMenu(i);
3266 }
3267 context.fillStyle = color;
3268 context.fillRect(X, Y, w, BoxHeight);
3269 context.fillStyle = "white";
3270 context.fillText(Item.name, X+2, Y+BoxHeight-FontAscent);
3271 if(MouseIn && MouseReleased)
3272 {
3273 Item.f();
3274 }
3275 X += w + 6;
3276 }
3277 }
3278 }
3279
3280 function AggregateMenuSize()
3281 {
3282 var w = 250 + 5 + FontWidth;
3283 return WindowRect(nWidth / 2 - w / 2,HistoryHeight + 50, w, nHeight);
3284 }
3285 function TimerMenuSize()
3286 {
3287 return MenuSize(WidthArray[TYPE_TIMER] + WidthArray[TYPE_GROUP] + 5 + FontWidth);
3288 }
3289
3290 function GroupMenuSize()
3291 {
3292 return MenuSize(WidthTree);
3293 }
3294
3295 function MenuSize(w)
3296 {
3297 return WindowRect(nWidth / 2 - w / 2, HistoryHeight + 50,w, nHeight);
3298 }
3299
3300 function CreateFilter(Filter)
3301 {
3302 if(!Filter || Filter.length == 0)
3303 {
3304 return null;
3305 }
3306 Filter = Filter.split(' ');
3307
3308 var regexp = "";
3309 for(var i = 0; i < Filter.length; ++i)
3310 {
3311 regexp = regexp + ".*" + Filter[i];
3312 }
3313 Filter = new Array();
3314 regexp = regexp + ".*";
3315 Filter.push(new RegExp(regexp, "i"));
3316 return Filter;
3317 }
3318
3319 function FilterMatch(FilterArray, value)
3320 {
3321 if(!FilterArray)
3322 return true;
3323 for(var i = 0; i < FilterArray.length; ++i)
3324 {
3325 var res = value.search(FilterArray[i]);
3326 if(res<0)
3327 return false;
3328 }
3329 return true;
3330 }
3331
3332 function AddPreset(Name)
3333 {
3334 var O = {};
3335 O[Name] = {};
3336 var OO = {};
3337 OO.p = O;
3338 OO.r = {};
3339 AddPresets(OO);
3340 }
3341 function JSONTryParse(str)
3342 {
3343 if(typeof str == 'string')
3344 {
3345 try{
3346 return JSON.parse(str);
3347 }
3348 catch(e){}
3349 }
3350 return {};
3351 }
3352
3353 function ProcessPresets(Data, Names, Cache)
3354 {
3355 for(var idx in Data)
3356 {
3357 if(Names.indexOf(idx) == -1)
3358 {
3359 Names.push(idx);
3360 }
3361 Cache[idx] = JSONTryParse(Data[idx]);
3362 }
3363 }
3364 function AddPresets(Obj)
3365 {
3366 var Names = Obj.p;
3367 var ReadOnlyNames = Obj.r;
3368 ProcessPresets(Obj.p, Presets, PresetsCache);
3369 ProcessPresets(Obj.r, ReadOnlyPresets, ReadOnlyPresetsCache);
3370 }
3371 function GetFullName(T)
3372 {
3373 var parent = T.parent;
3374 var ParentName = "unknown";
3375 var Name = T.name;
3376 if(parent && parent < TimerArray.length)
3377 {
3378 ParentName = TimerArray[parent].name;
3379 }
3380 return ParentName + "/" + Name;
3381 }
3382
3383 function ColorFromFullName(name, type)
3384 {
3385 for(var i = 0; i < TimerArray.length; ++i)
3386 {
3387 var t = TimerArray[i];
3388 if(t.idtype == type && GetFullName(t) == name)
3389 {
3390 return t.color;
3391 }
3392 }
3393 return 'white';
3394
3395 }
3396 function EnableByName(name, type)
3397 {
3398 for(var i = 0; i < TimerArray.length; ++i)
3399 {
3400 var t = TimerArray[i];
3401 if(t.idtype == type && GetFullName(t) == name)
3402 {
3403 WSSendMessage("c" + t.id);
3404 }
3405 }
3406 }
3407
3408
3409 function OnLoadPreset(NewSettings, Apply, RO)
3410 {
3411 if(Apply)
3412 {
3413 WSSendMessage("d");
3414 PresetPending = 0;
3415 }
3416 ActivePreset = NewSettings.PresetName;
3417 ActivePresetRO = RO ? 1 : 0;
3418 console.log('loading preset ' + ActivePresetRO);
3419 var EnableCount = 0;
3420 for(var idx in NewSettings)
3421 {
3422 if(idx == 'Timers')
3423 {
3424 if(Apply)
3425 {
3426 var Timers = NewSettings[idx];
3427 for(var i = 0; i < Timers.length; ++i)
3428 {
3429 var FullName = Timers[i];
3430 EnableCount++;
3431 EnableByName(FullName, TYPE_TIMER);
3432 }
3433 }
3434 }
3435 else if(idx == 'Groups')
3436 {
3437 if(Apply)
3438 {
3439 var Groups = NewSettings[idx];
3440 for(var i = 0; i < Groups.length; ++i)
3441 {
3442 var FullName = Groups[i];
3443 EnableByName(FullName, TYPE_GROUP);
3444
3445 }
3446 }
3447 }
3448 else
3449 {
3450 Settings[idx] = NewSettings[idx];
3451 }
3452 }
3453
3454 if(Settings.FunctionsInstrumented && Apply)
3455 {
3456 if(Settings.FunctionsInstrumented.length == Settings.FunctionsInstrumentedModule.length && Settings.FunctionsInstrumented.length == Settings.FunctionsInstrumentedUnmangled.length)
3457 {
3458 var Msg = "D" + Settings.FunctionsInstrumented.length + " ";
3459 for(var i = 0; i < Settings.FunctionsInstrumented.length; ++i)
3460 {
3461 Msg += Settings.FunctionsInstrumentedModule[i] + "!" + Settings.FunctionsInstrumentedUnmangled[i] + "!";
3462 }
3463 WSSendMessage(Msg);
3464 }
3465 }
3466 if(Settings.ViewActive >= 0)
3467 {
3468 ResizeCanvas();
3469 }
3470 }
3471 function SanitizeString(s)
3472 {
3473 let r = "";
3474 for(let i = 0; i < s.length; ++i)
3475 {
3476 let c = s[i];
3477 if(!((c>='a' && c<='z') || (c >='A' && c <= 'Z') || (c >= '0' && c <= '9')))
3478 {
3479 r += '_';
3480 }
3481 else
3482 {
3483 r += c;
3484 }
3485 }
3486 return r;
3487 }
3488 function LoadPreset(Name, RO)
3489 {
3490 Name = SanitizeString(Name);
3491 WSSendMessage((RO?"m":"l")+Name);
3492 }
3493
3494 function SavePreset(Name)
3495 {
3496 Name = SanitizeString(Name);
3497 AddPreset(Name);
3498 var Timers = [];
3499 var Groups = [];
3500 for(var i = 0; i < TimerArray.length; ++i)
3501 {
3502 var t = TimerArray[i];
3503 var idtype = TimerArray[i].idtype;
3504 if(t.e)
3505 {
3506 if(idtype == TYPE_TIMER)
3507 {
3508 Timers.push(GetFullName(t));
3509 }
3510 else if(idtype == TYPE_GROUP)
3511 {
3512 Groups.push(GetFullName(t));
3513 }
3514 }
3515 }
3516
3517 Settings.Timers = Timers;
3518 Settings.Groups = Groups;
3519 Settings.PresetName = Name;
3520 let Clone = function(A)
3521 {
3522 let N = Array(A.length);
3523 for(var i = 0; i < A.length; ++i)
3524 {
3525 N[i] = A[i];
3526 }
3527 return N;
3528 };
3529 Settings.FunctionsInstrumented = Clone(FunctionsInstrumented);
3530 Settings.FunctionsInstrumentedModule = Clone(FunctionsInstrumentedModule);
3531 Settings.FunctionsInstrumentedUnmangled = Clone(FunctionsInstrumentedUnmangled);
3532
3533 var JsonSettings = JSON.stringify(Settings);
3534 console.log('settings stored ' + JsonSettings);
3535 WSSendMessage("s"+Name+","+JsonSettings);
3536 ActivePreset = Name;
3537 ActivePresetRO = 0;
3538 }
3539 function DrawMenuPresets()
3540 {
3541 var Selection = null;
3542 var SizeInfo = {};
3543 SizeInfo.h = BoxHeight * (Presets.length * 2);
3544 if(ReadOnlyPresets.length)
3545 {
3546 SizeInfo.h += BoxHeight * (Presets.length + 1);
3547 }
3548 var x = MenuItems[SubMenuPresets].x;
3549 var y = MenuItems[SubMenuPresets].y;
3550
3551 var Width = 50;
3552 var WLeft = MeasureArray(0, ["Save ", "Load ", "Save As ..", "Builtin" ]);
3553 Width = MeasureArray(Width, Presets);
3554 var Width = 35 + Width + WLeft;
3555 SizeInfo.w = Width;
3556 SizeInfo.x = x;
3557 SizeInfo.y = y;
3558
3559 var M = CreateMenuState(SizeInfo);
3560 var context = CanvasDetailedView.getContext('2d');
3561
3562 var SettingsCached;
3563 var SettingsCachedY = 0;
3564
3565 for(var i = 0; i < Presets.length; ++i)
3566 {
3567 var Active = (ActivePresetRO == 0 && ActivePreset == Presets[i]) ? 1 : 0;
3568 if(DrawMenuElementMouseIn(M))
3569 {
3570 SettingsCachedY = M.y;
3571 SettingsCached = PresetsCache[Presets[i]];
3572 }
3573
3574 if(DrawMenuElement(M, Active, "Load", Presets[i], 'white', 0))
3575 {
3576 LoadPreset(Presets[i]);
3577 }
3578 }
3579 DrawMenuElement(M, 0, "---", "", 'white', 0);
3580 if(DrawMenuElement(M, 0, "Save As..", "", 'white', 0))
3581 {
3582 var str = ShowPrompt('Enter Preset Name', '');
3583 if(str.length>1)
3584 {
3585 SavePreset(str);
3586 }
3587
3588 }
3589
3590 for(var i = 0; i < Presets.length; ++i)
3591 {
3592 var Active = (ActivePresetRO == 0 && ActivePreset == Presets[i]) ? 1 : 0;
3593 if(DrawMenuElement(M, Active, "Save", Presets[i], 'white', 0))
3594 {
3595 SavePreset(Presets[i]);
3596 }
3597 }
3598 if(ReadOnlyPresets && ReadOnlyPresets.length > 0)
3599 {
3600 DrawMenuElement(M, 0, "---", "", 'white', 0);
3601 for(var i = 0; i < ReadOnlyPresets.length; ++i)
3602 {
3603 var Active = (ActivePresetRO && ActivePreset == ReadOnlyPresets[i]) ? 1 : 0;
3604 if(DrawMenuElementMouseIn(M))
3605 {
3606 SettingsCachedY = M.y;
3607 SettingsCached = ReadOnlyPresetsCache[ReadOnlyPresets[i]];
3608 }
3609 if(DrawMenuElement(M, Active, "Builtin", ReadOnlyPresets[i], 'white', 0))
3610 {
3611 LoadPreset(ReadOnlyPresets[i], 1);
3612 }
3613 }
3614 }
3615 SizeInfo.h = M.y - SizeInfo.y;
3616
3617
3618 if(SettingsCached)
3619 {
3620 var SizeLeft = 10 * FontWidth;
3621 var Timers = SettingsCached.Timers;
3622 var Groups = SettingsCached.Groups;
3623 var Patched = SettingsCached.Patched;
3624 var W = 0;
3625 var H = 0;
3626 if(Timers)
3627 {
3628 W = MeasureArray(W, Timers);
3629 H = 1 + Timers.length;
3630 }
3631 if(Groups)
3632 {
3633 W = MeasureArray(W, Groups);
3634 H = 1 + Groups.length;
3635 }
3636 if(Patched)
3637 {
3638 W = MeasureArray(W, Patched);
3639 H = 1 + Patched.length;
3640 }
3641 W += 40;
3642 H = H * (FontHeight+1);
3643 var M = CreateMenuState(SizeInfo);
3644 M.x += M.w + 5;
3645 M.y = SettingsCachedY;
3646 M.w = W;
3647 M.h = H;
3648
3649 if(Groups && Groups.length)
3650 {
3651 DrawMenuElement(M, 0, "Groups", "", 'white', 0);
3652 for(var i = 0; i < Groups.length; ++i)
3653 {
3654 DrawMenuElement(M, 0, "", Groups[i], 'white', 0);
3655 }
3656 }
3657 if(Timers && Timers.length)
3658 {
3659 DrawMenuElement(M, 0, "Timers", "", 'white', 0);
3660 for(var i = 0; i < Timers.length; ++i)
3661 {
3662 DrawMenuElement(M, 0, "", Timers[i], ColorFromFullName(Timers[i], TYPE_TIMER), 0);
3663 }
3664 }
3665 if(Patched && Patched.length)
3666 {
3667 DrawMenuElement(M, 0, "Patched", "", 'white', 0);
3668 for(var i = 0; i < Patched.length; ++i)
3669 {
3670 DrawMenuElement(M, 0, "", Patched[i], 'white', 0);
3671 }
3672 }
3673
3674
3675 }
3676
3677 return SizeInfo;
3678 }
3679
3680 function DrawMenuColumns()
3681 {
3682 var Selection = null;
3683 var SizeInfo = {};
3684 var BarColumnNames = GetBarColumnNames();
3685 var BarColumnEnabled = GetBarColumnEnabled();
3686 SizeInfo.h = BoxHeight * (BarColumnNames.length);
3687 var x = MenuItems[SubMenuColumns].x;
3688 var y = MenuItems[SubMenuColumns].y;
3689
3690 var Width = MeasureArray(0, BarColumnNames);
3691 SizeInfo.w = Width;
3692 SizeInfo.x = x;
3693 SizeInfo.y = y;
3694
3695 var M = CreateMenuState(SizeInfo);
3696 var context = CanvasDetailedView.getContext('2d');
3697 context.fillRect(M.x, M.y, Width, SizeInfo.h);
3698
3699
3700 for(var i = 0; i < BarColumnNames.length; ++i)
3701 {
3702 var Active = ActivePreset == Presets[i] ? 1 : 0;
3703 if(DrawMenuElement(M, BarColumnEnabled[i], BarColumnNames[i], "", 'white', 0))
3704 {
3705 BarColumnEnabled[i] = !BarColumnEnabled[i];
3706 for(var j = 0; j < ColumnsWidth.length; ++j)
3707 {
3708 ColumnsWidth[i] = 20;
3709 }
3710 }
3711 }
3712
3713 SizeInfo.h = M.y - SizeInfo.y;
3714 return SizeInfo;
3715
3716 }
3717
3718
3719 function ToggleView()
3720 {
3721 Settings.ViewActive = (Settings.ViewActive+1) % VIEW_SIZE;
3722 ActivateView(Settings.ViewActive);
3723 }
3724
3725 function ActivateView(idx)
3726 {
3727 for(var i = 1; i < Views.length; ++i)
3728 {
3729 Views[i].visible = false;
3730 }
3731 if(idx == VIEW_GRAPH_SPLIT)
3732 {
3733 MainView.DisplayFunc = DrawGraphSplit;
3734 MainView.visible = true;
3735 }
3736 else if(idx == VIEW_GRAPH_PERCENTILE)
3737 {
3738 MainView.DisplayFunc = DrawGraphPercentile;
3739 MainView.visible = true;
3740 }
3741 else if(idx == VIEW_GRAPH_THREAD_GROUP)
3742 {
3743 MainView.DisplayFunc = DrawGraphThreadGroup;
3744 MainView.visible = true;
3745 }
3746 else if(idx == VIEW_BAR)
3747 {
3748 MainView.DisplayFunc = DrawTableView;
3749 MainView.visible = true;
3750 }
3751 else if(idx == VIEW_COUNTERS)
3752 {
3753 MainView.DisplayFunc = DrawCounterView;
3754 MainView.visible = true;
3755 }
3756 else if(idx == VIEW_BAR_SINGLE || idx == VIEW_BAR_ALL)
3757 {
3758 for(var i = 0; i < X7Views.length; ++i)
3759 {
3760 X7Views[i].visible = true;
3761 }
3762 SingleTimerBars = idx == VIEW_BAR_SINGLE;
3763 }
3764 Settings.ViewActive = idx;
3765 X7BarColumnMask = -1;
3766 ViewBarMaxMsTextLength = 0;
3767 var hest = 3;
3768 }
3769 function DrawMenuViews()
3770 {
3771 var ViewClick = function(idx, name)
3772 {
3773 ActivateView(idx);
3774 };
3775 var x = MenuItems[SubMenuViews].x;
3776 var y = MenuItems[SubMenuViews].y;
3777 return DrawMenuGeneric(ViewNames, Settings.ViewActive, ViewClick, x, y, ViewNames2);
3778 }
3779
3780 function TweakValue(Value, Tweak, amount, Min, Max)
3781 {
3782 var V = 0.98;
3783 if(Tweak<0)
3784 {
3785 for(var x = 0; x < Math.abs(Tweak); ++x)
3786 {
3787 var newValue = Math.floor(Value*V);
3788 if(newValue == Value)
3789 {
3790 Value--;
3791 }
3792 else
3793 {
3794 Value = newValue;
3795 }
3796 }
3797 }
3798 else
3799 {
3800 var RcpV = 1.0 / V;
3801
3802 for(var x = 0; x < Tweak; ++x)
3803 {
3804 var newValue = Math.ceil(Value*RcpV);
3805 if(newValue == Value)
3806 {
3807 Value++;
3808 }
3809 else
3810 {
3811 Value = newValue;
3812 }
3813 }
3814 }
3815 if(Min!=null && Value < Min)
3816 Value = Min;
3817 if(Max!=null && Value > Max)
3818 Value = Max;
3819 return Value;
3820
3821 }
3822
3823 function NextValue(Presets, Value, Dir)
3824 {
3825 var idx = 0;
3826 if(Dir > 0)
3827 {
3828 for(idx = 0;idx < Presets.length; ++idx)
3829 {
3830 if(Presets[idx] > Value)
3831 {
3832 break;
3833 }
3834 }
3835 }
3836 else
3837 {
3838 for(idx = Presets.length; idx >= 0; idx -= 1)
3839 {
3840 if(Presets[idx] < Value)
3841 {
3842 break;
3843 }
3844 }
3845 }
3846 idx = (idx + Presets.length) % Presets.length;
3847 return Presets[idx];
3848 }
3849 function AutoCaptureRoll(Direction, Tweak, SetDirect)
3850 {
3851 if(SetDirect)
3852 {
3853 Settings.AutoCaptureTheshold = SetDirect;
3854 }
3855 else if(Tweak)
3856 {
3857 Settings.AutoCaptureTheshold = TweakValue(Settings.AutoCaptureTheshold, Tweak, 0.98, 1, 500);
3858 }
3859 else if(Direction)
3860 {
3861 Settings.AutoCaptureTheshold = NextValue(AutoCaptureThesholdPresets, Settings.AutoCaptureTheshold, Direction);
3862 }
3863 }
3864 function AutoCaptureRepeatRoll(Direction, Tweak, SetDirect)
3865 {
3866 if(SetDirect)
3867 {
3868 Settings.AutoCaptureRepeat = SetDirect;
3869 }
3870 else if(Tweak)
3871 {
3872 Settings.AutoCaptureRepeat = TweakValue(Settings.AutoCaptureRepeat, Tweak, 0.98, 1, 500);
3873 }
3874 else if(Direction)
3875 {
3876 Settings.AutoCaptureRepeat = NextValue(AutoCaptureRepeatPresets, Settings.AutoCaptureRepeat, Direction);
3877 }
3878 }
3879 function CaptureRoll(Direction, Tweak, SetDirect)
3880 {
3881 if(SetDirect)
3882 {
3883 Settings.CaptureFrames = SetDirect;
3884 }
3885 else if(Tweak)
3886 {
3887 Settings.CaptureFrames = TweakValue(Settings.CaptureFrames, Tweak, 0.98, 5, 300);
3888
3889 }
3890 else if(Direction)
3891 {
3892 Settings.CaptureFrames = NextValue(CaptureFramesPresets, Settings.CaptureFrames, Direction);
3893 }
3894 }
3895 function CaptureDelayRoll(Direction, Tweak, SetDirect)
3896 {
3897 if(SetDirect)
3898 {
3899 Settings.CaptureDelay = SetDirect;
3900 }
3901 else if(Tweak)
3902 {
3903 Settings.CaptureDelay = TweakValue(Settings.CaptureDelay, Tweak, 0.98, 5, 300);
3904
3905 }
3906 else if(Direction)
3907 {
3908 Settings.CaptureDelay = NextValue(CaptureDelayPresets, Settings.CaptureDelay, Direction);
3909 }
3910 }
3911
3912 function GetAutoCaptureString()
3913 {
3914 if(AutoCaptureSourceIndex >= 0)
3915 {
3916 if(AutoCaptureSourceIndex >= EnabledArray.length)
3917 {
3918 AutoCaptureSourceIndex = -1;
3919 AutoCaptureSourceIndex = -1;
3920 }
3921 else
3922 {
3923 var idx = EnabledArray[AutoCaptureSourceIndex];
3924 return TimerArray[idx].name;
3925 }
3926 }
3927 return "Frame Time";
3928 }
3929
3930 function AutoCaptureSourceRoll(Direction, Tweak, SetDirect)
3931 {
3932 if(SetDirect)
3933 {
3934
3935 }else if(Tweak||Direction)
3936 {
3937 if(!Direction)
3938 Direction = Tweak;
3939 if(Direction<0)
3940 {
3941 AutoCaptureSourceIndex--;
3942 if(AutoCaptureSourceIndex<-1)
3943 {
3944 AutoCaptureSourceIndex = EnabledArray.length-1;
3945 }
3946 }
3947 else
3948 {
3949 AutoCaptureSourceIndex++;
3950 if(AutoCaptureSourceIndex >= EnabledArray.length)
3951 {
3952 AutoCaptureSourceIndex = -1;
3953 }
3954 }
3955
3956 }
3957 }
3958
3959 function ShowPrompt(Title, Value, Type)
3960 {
3961 var v;
3962 if(Type == 'int')
3963 {
3964 var newValue = prompt('' + Title, '' + Value);
3965 v = parseInt(newValue);
3966 }
3967 else if(Type == 'float')
3968 {
3969 var newValue = prompt('' + Title, '' + Value);
3970 v = parseFloat(newValue);
3971 }
3972 else
3973 {
3974 var v = prompt('' + Title, '' + Value);
3975 return v;
3976 }
3977 if(isNaN(v))
3978 {
3979 return Value;
3980 }
3981 else
3982 {
3983 return v;
3984 }
3985
3986 }
3987 function MeasureArray(v, A, f)
3988 {
3989 var context = CanvasDetailedView.getContext('2d');
3990 for(var i = 0; i < A.length; ++i)
3991 {
3992 var s = A[i];
3993 if(f)
3994 s=f(s, i);
3995 var l = context.measureText(s).width;
3996 v = v < l ? l : v;
3997 }
3998 return v;
3999 }
4000
4001 function CreateMenuState(SizeInfo)
4002 {
4003 var MenuState = {};
4004 for(var i in SizeInfo)
4005 {
4006 MenuState[i] = SizeInfo[i];
4007 }
4008 MenuState.cidx = 0;
4009 return MenuState;
4010 }
4011 function DrawMenuElementMouseIn(M)
4012 {
4013 return MouseY >= M.y && MouseY < M.y + BoxHeight;
4014 }
4015 function DrawMenuElement(M, Selected, Name, Value, color)
4016 {
4017 var context = CanvasDetailedView.getContext('2d');
4018
4019 var bMouseIn = DrawMenuElementMouseIn(M);
4020 var YText = M.y + BoxHeight - FontAscent;
4021
4022 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[M.cidx];
4023 context.fillStyle = Selected?'white':bgcolor;
4024 context.fillRect(M.x-2, M.y, M.w + 4, BoxHeight);
4025 context.fillStyle = bgcolor;
4026 context.fillRect(M.x, M.y, M.w, BoxHeight);
4027 context.fillStyle = color;
4028 context.fillText(Name, M.x, YText);
4029 context.textAlign = 'right';
4030 context.fillText('' + Value, M.x + M.w - 2, YText);
4031 context.textAlign = 'left';
4032 M.cidx = 1-M.cidx;
4033 M.y += BoxHeight;
4034 return bMouseIn && MouseReleased;
4035 }
4036 function DrawMenuRoll(M, Name, RollValue, RollExt, RollFunction, Tweak, Type)
4037 {
4038 var context = CanvasDetailedView.getContext('2d');
4039
4040 var YText = M.y + BoxHeight - FontAscent;
4041 var SizeMinus = context.measureText('-').width;
4042 var SizePlus = context.measureText('+').width;
4043
4044 var bMouseIn = MouseY >= M.y && MouseY < M.y + BoxHeight;
4045 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[M.cidx];
4046 context.fillStyle = bgcolor;
4047 context.fillRect(M.x-2, M.y, M.w+4, BoxHeight);
4048 context.fillStyle = 'white';
4049 context.fillText(Name, M.x, YText);
4050 context.textAlign = 'right';
4051 var XTemp = M.x + M.w - 3;
4052
4053 if(KeyShiftDown && bMouseIn)
4054 {
4055 if(Tweak>=0)
4056 {
4057 RollFunction(0, MouseX-Tweak);
4058 }
4059 Tweak = MouseX;
4060 bMouseIn = false;
4061 }
4062 else
4063 {
4064 Tweak = -1;
4065 }
4066
4067 var MouseReleasedUsed = false;
4068 if(bMouseIn && MouseX >= XTemp - SizePlus && MouseX <= XTemp)
4069 {
4070 context.fillStyle = 'red';
4071 if(MouseReleased)
4072 {
4073 RollFunction(1);
4074 MouseReleasedUsed = true;
4075 }
4076 }
4077 else
4078 {
4079 context.fillStyle = 'white';
4080 }
4081 context.fillText('+', XTemp, YText);
4082 XTemp -= SizePlus + 3;
4083
4084
4085
4086 if(bMouseIn && MouseX >= XTemp - SizeMinus && MouseX <= XTemp)
4087 {
4088 context.fillStyle = 'red';
4089 if(MouseReleased)
4090 {
4091 RollFunction(-1);
4092 MouseReleasedUsed = true;
4093 }
4094 }
4095 else
4096 {
4097 context.fillStyle = 'white';
4098 }
4099
4100 context.fillText('-', XTemp, YText);
4101 XTemp -= SizeMinus + 3;
4102 var RollText = ''+RollValue + RollExt;
4103 var RollWidth = context.measureText(RollText).width;
4104 context.fillStyle = 'white';
4105
4106 context.fillText(RollText, XTemp, YText);
4107 XTemp -= RollWidth;
4108
4109 context.textAlign = 'left';
4110
4111 M.cidx = 1-M.cidx;
4112
4113 M.y += BoxHeight;
4114 if(Type && MouseReleased && bMouseIn && !MouseReleasedUsed)
4115 {
4116 var V = ShowPrompt(Name, RollValue, Type);
4117 RollFunction(0,0,V);
4118 }
4119 return Tweak;
4120
4121 }
4122 function CheckPopupAllowed()
4123 {
4124 if(!PopupsAllowed && !PopupTestPending)
4125 {
4126 PopupTestPending = 1;
4127 PopupsAllowed = 0;
4128 PopupsFailed = 0;
4129 let DoPopupTest = function()
4130 {
4131 var W = window.open("about:blank");
4132 var Fail = function()
4133 {
4134 PopupTestPending = 0;
4135 PopupsFailed = 1;
4136 PopupsAllowed = 0;
4137 };
4138 var Check = function()
4139 {
4140 if(!(W.innerHeight>0))
4141 Fail();
4142 else
4143 {
4144 PopupTestPending = 0;
4145 PopupsFailed = 0;
4146 PopupsAllowed = 1;
4147 W.close();
4148 }
4149 };
4150 if(W)
4151 {
4152 if(/chrome/.test(navigator.userAgent.toLowerCase()))
4153 setTimeout(Check, 200);
4154 else
4155 W.onload = Check;
4156 }
4157 else
4158 {
4159 Fail();
4160 }
4161 };
4162 setTimeout(DoPopupTest, 5000);
4163 }
4164 }
4165
4166 function GetSubGraphReferenceTime(SubGraphSettings, TimerState)
4167 {
4168 if(SubGraphSettings.AutomaticReference)
4169 {
4170 return TimerState.historymaxsoft ? TimerState.historymax : TimerState.historymax;
4171 }
4172 else
4173 {
4174 return SubGraphSettings.ReferenceTime;
4175 }
4176 }
4177 function GetSubGraphSettingsKey(key)
4178 {
4179 if(Settings.ViewActive == VIEW_GRAPH_PERCENTILE)
4180 {
4181 return "perc_"+key;
4182 }
4183 else
4184 {
4185 return key;
4186 }
4187 }
4188 function GetSubGraphSettings(key)
4189 {
4190 let k = GetSubGraphSettingsKey(key);
4191 let SubGraphSettings = Settings.SubGraphSettings[k];
4192 if(!SubGraphSettings)
4193 {
4194 SubGraphSettings = {"ReferenceTime":10.0, "TargetTime":-1, "AutomaticReference":1, "Percentile":0.0};
4195 Settings.SubGraphSettings[k] = SubGraphSettings;
4196 }
4197 return SubGraphSettings;
4198 }
4199
4200
4201 function DrawMenuGraphSettings()
4202 {
4203 let Percentile = Settings.ViewActive == VIEW_GRAPH_PERCENTILE;
4204 let Selection = null;
4205 let SizeInfo = {};
4206 SizeInfo.h = (Percentile?3:2) * BoxHeight;
4207 let Strings = ["AutoCapture Enabled", "AutoCapture Threshold", "AutoCapture Source", "Capture Length"];
4208 let wLeft = MeasureArray(0, Strings);
4209 let wRight = 50;
4210 wRight = MeasureArray(wRight, ["Frame Time"]);
4211 wRight = MeasureArray(wRight, EnabledArray, function(a){return TimerArray[a].name; } );
4212 let Width = wLeft + 35 + wRight;
4213 SizeInfo.w = Width;
4214 SizeInfo.x = CaptureButtonX;
4215 SizeInfo.y = CaptureButtonY;
4216
4217 let M = CreateMenuState(SizeInfo);
4218 let context = CanvasDetailedView.getContext('2d');
4219 context.fillRect(M.x, M.y, Width, SizeInfo.h);
4220 let SubGraphSettings = GetSubGraphSettings(SubMenuGraphSettingsKey);
4221
4222
4223 ReferenceTimeTweak = DrawMenuRoll(M, "Reference Time", SubGraphSettings.ReferenceTime, '', ReferenceRollSubGraph, ReferenceTimeTweak, 'int');
4224 if(DrawMenuElement(M, SubGraphSettings.AutomaticReference, "Automatic Reference Time", SubGraphSettings.AutomaticReference, 'white'))
4225 {
4226 SubGraphSettings.AutomaticReference = 1-SubGraphSettings.AutomaticReference;
4227 }
4228 if(Percentile)
4229 {
4230 //PercentileTweak = DrawMenuRoll(M, "Percentile", SubGraphSettings.Percentile, '', PercentileRollSubGraph, PercentileTweak, 'int');
4231 if(DrawMenuElement(M, 0, "Clear Aggregate", "", 'white'))
4232 {
4233 let TimerMap = FrameData.TimerMap;
4234 if(TimerMap)
4235 {
4236 let TimerState = TimerMap[SubMenuGraphSettingsKey];
4237 TimerState.PercentileMax = -1e38;
4238 TimerState.PercentileMin = 1e38;
4239 TimerState.Percentile = new Float32Array(PERCENTILE_SAMPLES);
4240 TimerState.Percentile.fill(0.0);
4241 TimerState.PercentileCount = 0;
4242 }
4243 }
4244 }
4245 SizeInfo.h = M.y - SizeInfo.y;
4246 return SizeInfo;
4247
4248 }
4249
4250 function Dots()
4251 {
4252 let t = new Date().getMilliseconds() / 200;
4253 let dots = [". ",".. ","...",".. "];
4254 let x = Math.floor(t) %4;
4255 return dots[x];
4256 }
4257 function DrawMenuCapture()
4258 {
4259 let Selection = null;
4260 let SizeInfo = {};
4261 SizeInfo.h = 7 * BoxHeight;
4262 let Strings = ["Popups Allowed", "AutoCapture Enabled", "AutoCapture Threshold", "AutoCapture Source", "Capture Length", "Capture Delay"];
4263 let wLeft = MeasureArray(0, Strings);
4264 let wRight = 50;
4265 wRight = MeasureArray(wRight, ["Frame Time"]);
4266 wRight = MeasureArray(wRight, EnabledArray, function(a){return TimerArray[a].name; } );
4267 let Width = wLeft + 35 + wRight;
4268 SizeInfo.w = Width;
4269 SizeInfo.x = CaptureButtonX - SizeInfo.w;
4270 SizeInfo.y = CaptureButtonY - SizeInfo.h;
4271
4272 let M = CreateMenuState(SizeInfo);
4273 let context = CanvasDetailedView.getContext('2d');
4274 context.fillRect(M.x, M.y, Width, SizeInfo.h);
4275 let d = Dots();
4276 let PopupStatus = PopupsAllowed ? "Yes" : (PopupsFailed ? "No" : (PopupTestPending ? ("Testing"+d) : "Untested"));
4277 if(DrawMenuElement(M, 0, "Popups Allowed", PopupStatus, 'white', 0))
4278 {
4279 CheckPopupAllowed();
4280 }
4281 let AutoStatus = AutoCaptureEnabled > 0 ? "on" : "off";
4282 if(CaptureTriggerTime != null && CaptureTriggerTimeType == 2)
4283 {
4284 AutoStatus = "pending"+d;
4285 }
4286 if(DrawMenuElement(M, 0, "AutoCapture Enabled", AutoStatus, 'white', 0))
4287 {
4288 if(!AutoCaptureEnabled && CaptureTriggerTime == null)
4289 {
4290 if(Settings.CaptureDelay <= 0)
4291 {
4292 AutoCaptureEnabled = Settings.AutoCaptureRepeat > 0 ? Settings.AutoCaptureRepeat : 1;
4293 }
4294 else
4295 {
4296 CaptureTriggerTime = new Date();
4297 CaptureTriggerTimeType = 2;
4298 }
4299 }
4300 else
4301 {
4302 AutoCaptureEnabled = 0;
4303 if(CaptureTriggerTimeType == 2)
4304 {
4305 CaptureTriggerTimeType = 0;
4306 CaptureTriggerTime = null;
4307 }
4308 }
4309 }
4310 AutoCaptureSourceTweak = DrawMenuRoll(M, "AutoCapture Source", GetAutoCaptureString(), '', AutoCaptureSourceRoll, AutoCaptureSourceTweak);
4311 AutoCaptureTweak = DrawMenuRoll(M, "AutoCapture Threshold", Settings.AutoCaptureTheshold, 'ms', AutoCaptureRoll, AutoCaptureTweak, 'int');
4312 AutoCaptureRepeatTweak = DrawMenuRoll(M, "AutoCapture Repeat", Settings.AutoCaptureRepeat, '', AutoCaptureRepeatRoll, AutoCaptureRepeatTweak, 'int');
4313 CaptureTweak = DrawMenuRoll(M, "Capture Length", Settings.CaptureFrames, '', CaptureRoll, CaptureTweak, 'int');
4314 CaptureDelayTweak = DrawMenuRoll(M, "Capture Delay", Settings.CaptureDelay, '', CaptureDelayRoll, CaptureDelayTweak, 'int');
4315
4316 SizeInfo.h = M.y - SizeInfo.y;
4317 return SizeInfo;
4318
4319 }
4320 function WindowRect(x,y,w,h)
4321 {
4322 let s = {};
4323 s.x = x;
4324 s.y = y;
4325 s.w = w;
4326 s.h = h;
4327 return s;
4328 }
4329 function GetAggregateString()
4330 {
4331 if(0 == Settings.AggregateFrames)
4332 return 'infinite';
4333 else
4334 return Settings.AggregateFrames + '';
4335 }
4336
4337 function AggregateRoll(Direction, Tweak, SetDirect)
4338 {
4339 if(SetDirect || SetDirect == 0)
4340 {
4341 if(SetDirect <= 0 || SetDirect == 'infinite')
4342 {
4343 Settings.AggregateFrames = 0;
4344 }
4345 else
4346 {
4347 Settings.AggregateFrames = SetDirect;
4348 }
4349 }
4350 else if(Tweak)
4351 {
4352 Settings.AggregateFrames = TweakValue(Settings.AggregateFrames, Tweak, 0.98, 0, 500);
4353
4354 }
4355 else if(Direction)
4356 {
4357 Settings.AggregateFrames = NextValue(AggregatePresets, Settings.AggregateFrames, Direction);
4358 }
4359 }
4360 function ReferenceRoll(Direction, Tweak, SetDirect)
4361 {
4362 if(SetDirect)
4363 {
4364 Settings.ReferenceTime = SetDirect;
4365 }
4366 else if(Tweak)
4367 {
4368 Settings.ReferenceTime = TweakValue(Settings.ReferenceTime, Tweak, 0.98, 5, 1000);
4369
4370 }
4371 else if(Direction)
4372 {
4373 Settings.ReferenceTime = NextValue(ReferencePresets, Settings.ReferenceTime, Direction);
4374 }
4375 }
4376
4377 function ReferenceRollSubGraph(Direction, Tweak, SetDirect)
4378 {
4379 let SubGraphSettings = GetSubGraphSettings(SubMenuGraphSettingsKey);
4380 if(SetDirect)
4381 {
4382 SubGraphSettings.ReferenceTime = SetDirect;
4383 }
4384 else if(Tweak)
4385 {
4386 SubGraphSettings.ReferenceTime = TweakValue(SubGraphSettings.ReferenceTime, Tweak, 0.98, 5, 1000);
4387
4388 }
4389 else if(Direction)
4390 {
4391 SubGraphSettings.ReferenceTime = NextValue(ReferencePresets, SubGraphSettings.ReferenceTime, Direction);
4392 }
4393 }
4394
4395 function PercentileRollSubGraph(Direction, Tweak, SetDirect)
4396 {
4397 let SubGraphSettings = GetSubGraphSettings(SubMenuGraphSettingsKey);
4398 if(SetDirect)
4399 {
4400 SubGraphSettings.Percentile = SetDirect;
4401 }
4402 else if(Tweak)
4403 {
4404 SubGraphSettings.Percentile = TweakValue(SubGraphSettings.Percentile, Tweak, 0.98, 5, 1000);
4405 }
4406 else if(Direction)
4407 {
4408 SubGraphSettings.Percentile = NextValue(PercentilePresets, SubGraphSettings.Percentile, Direction);
4409 }
4410 }
4411
4412
4413 function TargetRoll(Direction, Tweak, SetDirect)
4414 {
4415 if(SetDirect)
4416 {
4417 Settings.TargetTime = SetDirect;
4418 }
4419 else if(Tweak)
4420 {
4421 Settings.TargetTime = TweakValue(Settings.TargetTime, Tweak, 0.98, 5, 1000);
4422
4423 }
4424 else if(Direction)
4425 {
4426 Settings.TargetTime = NextValue(ReferencePresets, Settings.TargetTime, Direction);
4427 }
4428 }
4429 function TargetRollSubGraph(Direction, Tweak, SetDirect)
4430 {
4431 let SubGraphSettings = GetSubGraphSettings(SubMenuGraphSettingsKey);
4432 if(SetDirect)
4433 {
4434 SubGraphSettings.TargetTime = SetDirect;
4435 }
4436 else if(Tweak)
4437 {
4438 SubGraphSettings.TargetTime = TweakValue(SubGraphSettings.TargetTime, Tweak, 0.98, 5, 1000);
4439
4440 }
4441 else if(Direction)
4442 {
4443 SubGraphSettings.TargetTime = NextValue(ReferencePresets, SubGraphSettings.TargetTime, Direction);
4444 }
4445 }
4446 function DrawMenuSettings()
4447 {
4448 var context = CanvasDetailedView.getContext('2d');
4449 var nColorIndex = 0;
4450 var SizeInfo = AggregateMenuSize();
4451 SizeInfo.x = MenuItems[SubMenuSettings].x;
4452 SizeInfo.y = MenuItems[SubMenuSettings].y;
4453
4454 SizeInfo.w = 200;
4455 var M = CreateMenuState(SizeInfo);
4456
4457 AggregateTweak = DrawMenuRoll(M, "Aggregate Frames", GetAggregateString(), '', AggregateRoll, AggregateTweak, 'int');
4458 ReferenceTimeTweak = DrawMenuRoll(M, "Reference Time", Settings.ReferenceTime, '', ReferenceRoll, ReferenceTimeTweak, 'int');
4459 TargetTimeTweak = DrawMenuRoll(M, "Target Time", Settings.TargetTime, '', TargetRoll, TargetTimeTweak, 'int');
4460 if(DrawMenuElement(M, Settings.AutomaticReference, "Automatic Reference Time", Settings.AutomaticReference, 'white'))
4461 {
4462 Settings.AutomaticReference = 1-Settings.AutomaticReference;
4463 }
4464 if(DrawMenuElement(M, Settings.ViewCompressed, "Compressed View", Settings.ViewCompressed, 'white'))
4465 {
4466 Settings.ViewCompressed = 1-Settings.ViewCompressed;
4467 ResizeCanvas();
4468 }
4469
4470 if(Settings.AggregateFrames <= 0)
4471 {
4472 if(DrawMenuElement(M, 0, "Clear Aggregate", "Current[" + AggregateCurrent + "]", 'white'))
4473 {
4474 WSSendMessage("r");
4475 }
4476 }
4477 if(DrawMenuElement(M, 0, "Clear Percentile Aggregate", "", 'white'))
4478 {
4479 let TimerMap = FrameData.TimerMap;
4480 if(TimerMap)
4481 {
4482 for(let key in TimerMap)
4483 {
4484 let idx = GetTimer(key);
4485 let TimerState = TimerMap[key];
4486 if(!IsGroup(key) && TimerState.Percentile)
4487 {
4488 TimerState.PercentileMax = -1e38;
4489 TimerState.PercentileMin = 1e38;
4490 TimerState.Percentile = new Float32Array(PERCENTILE_SAMPLES);
4491 TimerState.Percentile.fill(0.0);
4492 TimerState.PercentileCount = 0;
4493 }
4494 }
4495 }
4496 }
4497
4498
4499 if(DrawMenuElement(M, Settings.AllowHighDPI, "Allow High DPI", Settings.AllowHighDPI, 'white'))
4500 {
4501 Settings.AllowHighDPI = 1 - Settings.AllowHighDPI;
4502 ResizeCanvas();
4503 }
4504 if(DrawMenuElement(M, Cookie.CodeReportMode == 0, "Code Report: Prompt", Cookie.CodeReportMode == 0 ? 1 : 0, 'white'))
4505 {
4506 Cookie.CodeReportMode = 0;
4507 WriteCookie();
4508 }
4509
4510 if(DrawMenuElement(M, Cookie.CodeReportMode == 1, "Code Report: Report Silently", Cookie.CodeReportMode == 1 ? 1 : 0, 'white'))
4511 {
4512 Cookie.CodeReportMode = 1;
4513 WriteCookie();
4514 }
4515 if(DrawMenuElement(M, Cookie.CodeReportMode == 2, "Code Report: Never Report", Cookie.CodeReportMode == 2 ? 1 : 0, 'white'))
4516 {
4517 Cookie.CodeReportMode = 2;
4518 WriteCookie();
4519 }
4520
4521 SizeInfo.h = M.y - SizeInfo.y;
4522 return SizeInfo;
4523 }
4524
4525 function MoveFilterInputDiv(x, y, w)
4526 {
4527 if(FilterInputDivPos.x != x || FilterInputDivPos.y != y || FilterInputDivPos.w != w)
4528 {
4529 FilterInputDivPos.x = x;
4530 FilterInputDivPos.y = y;
4531 FilterInputDivPos.w = w;
4532 FilterInputDiv.style['left'] = x + 'px';
4533 FilterInputDiv.style['top'] = y + 'px';
4534 FilterInput.style['width'] = w + 'px';
4535 }
4536 }
4537
4538 function DrawMenuTimer()
4539 {
4540 if(FilterInputValueLast != FilterInput.value)
4541 {
4542 nOffsetMenuTimers = 0;
4543 }
4544 FilterInputValueLast = FilterInput.value;
4545 var FilterArray = CreateFilter(FilterInput.value);
4546 var context = CanvasDetailedView.getContext('2d');
4547 var nColorIndex = 0;
4548 var SizeInfo = TimerMenuSize();
4549 SizeInfo.x = MenuItems[SubMenuTimers].x;
4550 SizeInfo.y = MenuItems[SubMenuTimers].y;
4551 var Y = SizeInfo.y;
4552 var Width = SizeInfo.w;
4553 var Selection = null;
4554 var X = SizeInfo.x;
4555 MoveFilterInputDiv(SizeInfo.x, SizeInfo.y, SizeInfo.w);
4556 Y += 35;
4557
4558 var bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
4559 var bMouseInClear = MouseY >= Y && MouseY < Y + BoxHeight;
4560 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
4561 var TextY = Y+BoxHeight-FontAscent;
4562 var YClear = Y;
4563 var TextYClear = TextY;
4564 var YStart = Y;
4565
4566 var MouseTaken = bMouseIn;
4567
4568 Y += BoxHeight;
4569 nColorIndex = 1-nColorIndex;
4570
4571 Y -= nOffsetMenuTimers;
4572
4573 for(var i = 0; i < TimerArray.length; ++i)
4574 {
4575 var v = TimerArray[i];
4576 if(v.idtype == TYPE_TIMER
4577 //|| v.idtype == TYPE_GROUP
4578 )
4579 {
4580 var Name = v.name;
4581 var ParentName = TimerArray[v.parent].name;
4582 if(FilterMatch(FilterArray, ParentName + " " + Name) && (0 == TimersActiveOnly || v.e))
4583 {
4584 if(Y > YStart)
4585 {
4586 var ParentColor = TimerArray[v.parent].e ? 'white' : 'grey';
4587 bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight && !MouseTaken;
4588 bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
4589 TextY = Y+BoxHeight-FontAscent;
4590 context.fillStyle = v.e?'white':bgcolor;
4591 context.fillRect(X-2, Y, Width+4, BoxHeight);
4592 context.fillStyle = bgcolor;
4593 context.fillRect(X, Y, Width, BoxHeight);
4594 context.fillStyle = ParentColor;
4595 context.fillText(ParentName, X + 2, TextY);
4596 context.fillStyle = v.color;
4597 context.textAlign = 'right';
4598 context.fillText(Name, X + Width - 2, TextY);
4599 context.textAlign = 'left';
4600 if(bMouseIn)
4601 {
4602 Selection = v.id;
4603 }
4604 }
4605 Y += BoxHeight;
4606 nColorIndex = 1-nColorIndex;
4607 }
4608 }
4609 }
4610
4611 {
4612
4613 var c0 = nBackColorOffset;
4614 var c1 = nBackColors[1];
4615 var W = Width + 4;
4616 var WHalf = W / 2;
4617 var InsideClear = bMouseInClear && MouseX-X< WHalf-1;
4618 var InsideActive = bMouseInClear && MouseX-X > WHalf+1;
4619 context.fillStyle = nBackColors[0];
4620 context.fillRect(X-2, YClear, W, BoxHeight);
4621
4622 context.fillStyle = InsideClear ? c0 :c1;
4623 context.fillRect(X-2, YClear, WHalf-1, BoxHeight);
4624 context.fillStyle = InsideActive ? c0 :c1;
4625 context.fillRect(X-2 + WHalf + 1, YClear, WHalf-1, BoxHeight);
4626
4627
4628 context.fillStyle = 'white';
4629 context.textAlign = 'center';
4630 context.fillText("[clear] ", X + 2 + Width * 0.25, TextYClear);
4631 context.fillStyle = TimersActiveOnly ? 'white' : 'grey';
4632 context.fillText("[active only]", X + 2 + Width * 0.75, TextYClear);
4633 if(MouseReleased)
4634 {
4635 if(InsideActive)
4636 {
4637 TimersActiveOnly = 1-TimersActiveOnly;
4638 }
4639 if(InsideClear)
4640 {
4641 WSSendMessage("x");
4642 }
4643 }
4644 }
4645 context.textAlign = 'left';
4646 if(Selection && MouseReleased && !MouseTaken)
4647 {
4648 WSSendMessage("c" + Selection);
4649 }
4650 SizeInfo.h = Y-SizeInfo.y;
4651 return SizeInfo;
4652 }
4653
4654 var LoadSymbolAnim = -1;
4655 function LoadSymbolAnimRestart()
4656 {
4657 if(LoadSymbolAnim > 0)
4658 {
4659 LoadSymbolAnim += 1;
4660 }
4661 else
4662 {
4663 LoadSymbolAnim = 1;
4664 }
4665 }
4666 function LoadSymbolAnimUpdateAndGet()
4667 {
4668 if(LoadSymbolAnim>=0)
4669 {
4670 LoadSymbolAnim -= 0.03;
4671 if(LoadSymbolAnim < 0)
4672 {
4673 LoadSymbolAnim = -1;
4674 }
4675 else
4676 {
4677 return Math.sin(3.14 * LoadSymbolAnim);
4678 }
4679
4680 }
4681 return -1;
4682 }
4683
4684
4685 var CircleSteps = 30;
4686 var CircleX = Array(CircleSteps);
4687 var CircleY = Array(CircleSteps);
4688 function InitCircle()
4689 {
4690 var twopi = 2 * Math.PI;
4691 for(var i = 0; i < CircleSteps; ++i)
4692 {
4693 var s = (1.0*i) / CircleSteps;
4694
4695 var f = (1.0 * s) * twopi;
4696 CircleX[i] = Math.sin(f);
4697 CircleY[i] = Math.cos(f);
4698 }
4699 }
4700 function SpinnerResize(Spinner, w, h)
4701 {
4702 if(h != Spinner.CanvasH || w != Spinner.CanvasW || DPR != Spinner.CanvasDPR)
4703 {
4704 Spinner.Canvas.style.width = w + 'px';
4705 Spinner.Canvas.style.height = h + 'px';
4706 Spinner.Canvas.width = w * DPR;
4707 Spinner.Canvas.height = h * DPR;
4708 Spinner.Canvas.getContext('2d').scale(DPR, DPR);
4709 Spinner.CanvasBack.style.width = w + 'px';
4710 Spinner.CanvasBack.style.height = h + 'px';
4711 Spinner.CanvasBack.width = w * DPR;
4712 Spinner.CanvasBack.height = h * DPR;
4713
4714 Spinner.CanvasBack.getContext('2d').scale(DPR, DPR);
4715 Spinner.CanvasH = h;
4716 Spinner.CanvasW = w;
4717 Spinner.CanvasDPR = DPR;
4718 }
4719 }
4720 function SpinnerCircle(Phase0, Shift0, Phase1, Shift1, Phase2, Shift2)
4721 {
4722 return {"Phase0" : Phase0, "Shift0": Shift0, "Phase1":Phase1, "Shift1":Shift1, "Phase2": Phase2, "Shift2": Shift2, "Q": 0, "QQ": 0, "A0":0, "A1":0, "A2":0};
4723 }
4724
4725 function SpinnerInit(Blur, Color)
4726 {
4727 var Spinner = {};
4728 Spinner.x = 0;
4729 Spinner.y = 0;
4730 Spinner.Canvas = document.createElement('canvas');
4731 Spinner.CanvasBack = document.createElement('canvas');
4732 Spinner.CanvasOffscreenData;
4733 Spinner.CanvasW = -1;
4734 Spinner.CanvasH = -1;
4735 Spinner.CanvasDPR = -1;
4736 Spinner.Circles = [];
4737 var x = 1 / 4;
4738 var y = 0.07;
4739 Spinner.Circles.push(SpinnerCircle(x, 0, y, 0, 0.0, 0.25));
4740 Spinner.Circles.push(SpinnerCircle(2/4, 0, 0, 0, 0.14, 0.25));
4741 Spinner.Fade = 0;
4742 Spinner.Blur = Blur;
4743 Spinner.Color = Color;
4744 return Spinner;
4745 }
4746
4747 var SpinnerCorner = SpinnerInit(0.8, 'white');
4748 var SpinnerLoadButton = SpinnerInit(0, 'white');
4749 var SpinnerText1 = SpinnerInit(0.0, 'red');
4750 var SpinnerText0 = SpinnerInit(0.0, 'red');
4751
4752
4753 function SpinnerShow()
4754 {
4755 return SymbolState != null && (SymbolState.q == 1 || SymbolState.r != SymbolState.f || FunctionQueryLastRequest != FunctionQueryReceived);
4756 }
4757
4758 function SpinnerDraw(Enable, context, Spinner, X, Y, w, h)
4759 {
4760 SpinnerResize(Spinner, w, h);
4761 var ContextSpinner = Spinner.Canvas.getContext('2d');
4762
4763
4764 var now = Date.now();
4765 if(!ContextSpinner.last)
4766 {
4767 ContextSpinner.last = now;
4768 }
4769 var DT = now - ContextSpinner.last;
4770 ContextSpinner.last = now;
4771 if(Enable)
4772 {
4773 Spinner.Fade += DT / 200;
4774 }
4775 else
4776 {
4777 Spinner.Fade -= DT / 1000;
4778 }
4779 Spinner.Fade = Math.max(0, Spinner.Fade);
4780 Spinner.Fade = Math.min(1, Spinner.Fade);
4781 var F = Spinner.Fade * Spinner.Fade;
4782
4783 if(Spinner.Fade <= 0)
4784 return;
4785 ContextSpinner.clearRect(0, 0, w, h);
4786 if(Spinner.Blur > 0)
4787 {
4788 ContextSpinner.globalAlpha = Spinner.Blur;
4789 ContextSpinner.drawImage(Spinner.CanvasBack, 0, 0, w, h);
4790 ContextSpinner.globalAlpha = 1.0;
4791 }
4792 var twopi = 2 * Math.PI;
4793 for(var jjj = 0; jjj < Spinner.Circles.length; ++jjj)
4794 {
4795 var C = Spinner.Circles[jjj];
4796 InitCircle();
4797 var xs = CircleX;
4798 var ys = CircleY;
4799 var scale = (w-2) / 2;
4800 var offset = (w) / 2;
4801 var SPEED = 100.0;
4802
4803 var angle = (C.Q / SPEED) * twopi;
4804
4805 var QQSPEED = 1000;
4806
4807 C.A0 += (twopi * DT / 1000.0) * C.Phase0;
4808 if(C.A0 > twopi)
4809 C.A0 -= twopi;
4810 C.A1 += (twopi * DT / 1000.0) * C.Phase1;
4811 if(C.A1 > twopi)
4812 C.A1 -= twopi;
4813 C.A2 += (twopi * DT / 1000.0) * C.Phase2;
4814 if(C.A2 > twopi)
4815 C.A2 -= twopi;
4816
4817 var A0 = C.A0 + twopi * C.Shift0;
4818 var A1 = C.A1 + twopi * C.Shift1;
4819 var A2 = C.A2 + twopi * C.Shift2;
4820 var m = Math.cos(A0);
4821 var m0 = Math.sin(A2);
4822 var cs = Math.cos(A1);
4823 var ss = Math.sin(A1);
4824 for(var i = 0; i < xs.length; ++i)
4825 {
4826 var x = xs[i] * m;
4827 var y = ys[i] * m0;
4828 xs[i] = cs * scale * x - ss * scale * y;
4829 ys[i] = ss * scale * x + cs * scale * y;
4830 xs[i] += offset;
4831 ys[i] += offset;
4832 }
4833 ContextSpinner.strokeStyle = Spinner.Color;
4834 ContextSpinner.beginPath();
4835 ContextSpinner.moveTo(xs[0], ys[0]);
4836 for(var i = 1; i < CircleSteps; ++i)
4837 {
4838 ContextSpinner.lineTo(xs[i], ys[i]);
4839 }
4840 ContextSpinner.lineTo(xs[0], ys[0]);
4841 ContextSpinner.stroke();
4842
4843
4844 }
4845 context.globalAlpha = F;
4846 context.drawImage(Spinner.Canvas, X, Y, w, h);
4847 context.globalAlpha = 1;
4848 var tmp = Spinner.CanvasBack;
4849 Spinner.CanvasBack = Spinner.Canvas;
4850 Spinner.Canvas = tmp;
4851 }
4852
4853
4854 function DrawMenuPatched()
4855 {
4856 if(FilterInputValueLast != FilterInput.value)
4857 {
4858 nOffsetMenuPatched = 0;
4859 }
4860
4861 var FilterArray = CreateFilter(FilterInput.value);
4862 var context = CanvasDetailedView.getContext('2d');
4863 var nColorIndex = 0;
4864 var SizeInfo = TimerMenuSize();
4865 SizeInfo.x = MenuItems[SubMenuPatched].x;
4866 SizeInfo.y = MenuItems[SubMenuPatched].y;
4867 var Y = SizeInfo.y;
4868 var Width = SizeInfo.w;
4869 Width = Math.max(300, Width);
4870 Width = 10+ MeasureArray(Width, FunctionsInstrumented, function(s, i){return s + " " + FunctionsInstrumentedModule[i];} );
4871
4872 if(Width + SizeInfo.x + 50 > nWidth)
4873 {
4874 Width = nWidth - (SizeInfo.x+50);
4875 }
4876 SizeInfo.w = Width;
4877 var MaxStringLength = Math.floor(Width/(FontWidth));
4878
4879 var Selection = null;
4880 var X = SizeInfo.x;
4881 context.fillStyle = nBackColors[0];
4882 TextY = Y+BoxHeight-FontAscent;
4883 context.fillRect(X, Y, Width, BoxHeight);
4884
4885 var bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight && MouseX-X < 100;
4886 context.fillRect(X, Y, 99, BoxHeight);
4887 context.textAlign = 'center';
4888 context.fillStyle = 'white';
4889 context.fillText("Patched functions", X + Width/2, TextY);
4890
4891 Y += BoxHeight;
4892 MoveFilterInputDiv(SizeInfo.x, Y, SizeInfo.w-6);
4893 Y += 45;
4894
4895 bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
4896 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
4897 var TextY = Y+BoxHeight-FontAscent;
4898 var YClear = Y;
4899 var TextYClear = TextY;
4900 var bgcolorClear = bgcolor;
4901 var YStart = Y-BoxHeight*2;
4902
4903 nColorIndex = 1-nColorIndex;
4904
4905 Y -= nOffsetMenuFunctions + 10;
4906 var Selection = -1;
4907
4908 var StringColor = function(Name)
4909 {
4910 var h = StringHash(Name);
4911 var cidx = h % 360;
4912 return cidx;
4913 };
4914
4915 var GetColor = function(Str)
4916 {
4917 var cidx = StringColor(Str);
4918 return "hsl(" + cidx + ",50%, 70%)";
4919 };
4920 for(var i = 0; i < FunctionsInstrumented.length; ++i)
4921 {
4922 var Name = FunctionsInstrumented[i];
4923 var ModuleName = FunctionsInstrumentedModule[i];
4924 if(FilterMatch(FilterArray, ModuleName + " " + Name))
4925 {
4926
4927 var Color = GetColor(Name);
4928 var ColorModule = GetColor(Name);
4929 if(Y >= YStart)
4930 {
4931 bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
4932 bgcolor = bMouseIn && MouseX > X ? nBackColorOffset : nBackColors[nColorIndex];
4933 TextY = Y+BoxHeight-FontAscent;
4934
4935 context.fillStyle = bgcolor;
4936 context.fillRect(X, Y, Width, BoxHeight);
4937 context.fillStyle = Color;
4938 context.textAlign = 'right';
4939 context.fillText(Name, X + Width - 2, TextY);
4940 context.textAlign = 'left';
4941 context.fillStyle = ColorModule;
4942 context.fillText(ModuleName, X, TextY);
4943 }
4944 Y += BoxHeight;
4945 nColorIndex = 1-nColorIndex;
4946 }
4947 }
4948 context.textAlign = 'left';
4949 SizeInfo.h = Y-SizeInfo.y;
4950 return SizeInfo;
4951 }
4952
4953
4954 function DrawMenuModules()
4955 {
4956 if(FilterInputValueLast != FilterInput.value)
4957 {
4958 nOffsetMenuModules = 0;
4959 }
4960 FilterInputValueLast = FilterInput.value;
4961 var M = ModuleState;
4962 var FilterArray = CreateFilter(FilterInput.value);
4963 var context = CanvasDetailedView.getContext('2d');
4964 var nColorIndex = 0;
4965 var SizeInfo = TimerMenuSize(); //broken, fix!
4966
4967 SizeInfo.x = MenuItems[SubMenuModules].x;
4968 SizeInfo.y = MenuItems[SubMenuModules].y;
4969 var Y = SizeInfo.y;
4970 var Width = SizeInfo.w;
4971 Width = Math.max(300, Width);
4972 Width = 10+ MeasureArray(Width, M, function(s){return s.n + " " + s.s;} );
4973
4974 if(Width + SizeInfo.x + 50 > nWidth)
4975 {
4976 Width = nWidth - (SizeInfo.x+50);
4977 }
4978 SizeInfo.w = Width;
4979
4980
4981 var MaxStringLength = Math.floor(Width/(FontWidth));
4982
4983
4984 var X = SizeInfo.x;
4985 DrawSymbolHeaderMenu(context, X, Y, Width);
4986
4987 Y += BoxHeight;
4988 MoveFilterInputDiv(SizeInfo.x, Y, SizeInfo.w-6);
4989 Y += 45;
4990
4991 let bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
4992 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
4993 var TextY = Y+BoxHeight-FontAscent;
4994 var YClear = Y;
4995 var TextYClear = TextY;
4996 var bgcolorClear = bgcolor;
4997 var YStart = Y-BoxHeight*2;
4998
4999 nColorIndex = 1-nColorIndex;
5000
5001 Y -= nOffsetMenuModules + 10;
5002 var Selection = -1;
5003
5004 var StringColor = function(Name)
5005 {
5006 var h = StringHash(Name);
5007 var cidx = h % 360;
5008 return cidx;
5009 };
5010
5011 for(var i = 0; i < M.length; ++i)
5012 {
5013 var Name = M[i].n;
5014 var Count = M[i].s;
5015 var Prc = M[i].p;
5016 if(Prc<0||Prc>1)
5017 Prc = 0;
5018 let cidx = StringColor(Name);
5019 let Color = "hsl(" + cidx + ",50%, 70%)";
5020 let C1 = "hsl(" + cidx + ",30%, 40%)";
5021 var N = Name;
5022 if(N.length > MaxStringLength)
5023 {
5024 N = N.substring(N.length - MaxStringLength);
5025 }
5026 if(FilterMatch(FilterArray, Name))
5027 {
5028
5029 if(Y >= YStart)
5030 {
5031 bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
5032 bgcolor = bMouseIn && MouseX > X ? nBackColorOffset : nBackColors[nColorIndex];
5033 TextY = Y+BoxHeight-FontAscent;
5034
5035 context.fillStyle = bgcolor;
5036 context.fillRect(X, Y, Width, BoxHeight);
5037 if(Prc>0 && Prc <= 1)
5038 {
5039 context.fillStyle = C1;
5040 context.fillRect(X, Y, Prc*Width, BoxHeight);
5041 }
5042 context.fillStyle = 'white';
5043 context.textAlign = 'right';
5044 context.fillText(Count + '', X + Width - 2, TextY);
5045 context.textAlign = 'left';
5046 context.fillStyle = Color;
5047 context.fillText(N, X, TextY);
5048 if(bMouseIn)
5049 {
5050 Selection = i;
5051 }
5052 }
5053 Y += BoxHeight;
5054 nColorIndex = 1-nColorIndex;
5055 }
5056 }
5057 context.textAlign = 'left';
5058 if(Selection != -1 && MouseReleased)
5059 {
5060 WSSendMessage("L" + M[Selection].n);
5061 }
5062 SizeInfo.h = Y-SizeInfo.y;
5063 return SizeInfo;
5064 }
5065 function DrawSymbolHeaderMenu(context, X, Y, Width)
5066 {
5067 context.fillStyle = nBackColors[0];
5068 let TextY = Y+BoxHeight-FontAscent;
5069 context.fillRect(X+100, Y, Width-100, BoxHeight);
5070 let bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight && MouseX-X < 100;
5071 if(bMouseIn)
5072 {
5073 context.fillStyle = nBackColorOffset;
5074 }
5075
5076 context.fillRect(X, Y, 99, BoxHeight);
5077
5078
5079 let NumSymbols = 0;
5080 let SymbolStateString = "Load all";
5081 let SymbolButtonActive = 1;
5082 let SymbolSpinnerActive = 0;
5083 let FinishedSymbols = 0;
5084 if(SymbolState)
5085 {
5086 FinishedSymbols = SymbolState.f;
5087 var s = SymbolState.s;
5088 NumSymbols = SymbolState.l;
5089 SymbolButtonActive = 1;
5090 if(SymbolState.q == 1 || FunctionQueryLastRequest != FunctionQueryReceived)
5091 {
5092 SymbolStateString = "Querying";
5093 SymbolButtonActive = 0;
5094 SymbolSpinnerActive = 1;
5095 }
5096 else if(SymbolState.f != SymbolState.r)
5097 {
5098 SymbolButtonActive = 0;
5099 SymbolSpinnerActive = 1;
5100 SymbolStateString = "Loading";
5101 }
5102 else if(SymbolState.f == ModuleState.length)
5103 {
5104 SymbolButtonActive = 0;
5105 SymbolStateString = "Loaded";
5106 }
5107 }
5108 let LoadButtonAnimation = LoadSymbolAnimUpdateAndGet();
5109
5110 context.textAlign = 'right';
5111 context.fillStyle = 'white';
5112 context.fillText(NumSymbols + " Symbols " + FinishedSymbols + "/" + ModuleState.length + " Modules", X+Width-2, TextY);
5113 context.textAlign = 'center';
5114
5115 if(LoadButtonAnimation>0)
5116 {
5117 var c = "hsl(0,0%," + (LoadButtonAnimation * 100)+"%)";
5118 context.fillStyle = c;
5119 }
5120 if(SymbolButtonActive)
5121 {
5122 if(bMouseIn && MouseReleased)
5123 {
5124 WSSendMessage("S"); //load symbols
5125 }
5126 context.fillText(SymbolStateString, X + 50, TextY);
5127 }
5128 else
5129 {
5130 context.fillStyle = 'grey';
5131 context.fillText(SymbolStateString, X + 50, TextY);
5132 }
5133 SpinnerDraw(SymbolSpinnerActive, context, SpinnerLoadButton, X+2, Y, FontHeight, FontHeight );
5134
5135
5136 }
5137
5138 function DrawMenuFunctions()
5139 {
5140 if(FilterInputValueLast != FilterInput.value)
5141 {
5142 nOffsetMenuFunctions = 0;
5143 var m = FilterInput.value.trim();
5144 if(m != "")
5145 {
5146 if(SymbolState && SymbolState.r == SymbolState.f)
5147 {
5148 var Req = ++FunctionQueryLastRequest;
5149 var Q = "q" + Req + "x" + m;
5150 WSSendMessage(Q);
5151 FunctionQueryPending = null;
5152 }
5153 else
5154 {
5155 FunctionQueryPending = m;
5156 if(SymbolState) //wtf?
5157 {
5158 LoadSymbolAnimRestart();
5159 }
5160 }
5161 }
5162 }
5163
5164 FilterInputValueLast = FilterInput.value;
5165 var FF = FunctionQueryArray;
5166 var FilterArray = CreateFilter(FilterInput.value);
5167 var context = CanvasDetailedView.getContext('2d');
5168 var nColorIndex = 0;
5169 var SizeInfo = TimerMenuSize(); //broken, fix
5170 SizeInfo.x = MenuItems[SubMenuFunctions].x;
5171 SizeInfo.y = MenuItems[SubMenuFunctions].y;
5172 var Y = SizeInfo.y;
5173 var Width = SizeInfo.w;
5174 Width = Math.max(300, Width);
5175 Width = 10+ MeasureArray(Width, FF, function(s){return s.n + " " + s.m;} );
5176
5177 if(Width + SizeInfo.x + 50 > nWidth)
5178 {
5179 Width = nWidth - (SizeInfo.x+50);
5180 }
5181 SizeInfo.w = Width;
5182 var MaxStringLength = Math.floor(Width/(FontWidth));
5183
5184 var Selection = null;
5185 var X = SizeInfo.x;
5186
5187 {
5188 DrawSymbolHeaderMenu(context, X, Y, Width);
5189 }
5190
5191
5192 Y += BoxHeight;
5193 MoveFilterInputDiv(SizeInfo.x, Y, SizeInfo.w-6);
5194 Y += 45;
5195
5196 let bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
5197 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5198 var TextY = Y+BoxHeight-FontAscent;
5199 var YClear = Y;
5200 var TextYClear = TextY;
5201 var bgcolorClear = bgcolor;
5202 var YStart = Y-BoxHeight*2;
5203
5204 nColorIndex = 1-nColorIndex;
5205
5206 Y -= nOffsetMenuFunctions + 10;
5207 var Selection = -1;
5208
5209 var StringColor = function(Name)
5210 {
5211 var h = StringHash(Name);
5212 var cidx = h % 360;
5213 return cidx;
5214 };
5215
5216 for(var i = 0; i < FF.length; ++i)
5217 {
5218 if(true)
5219 {
5220 var Name = FF[i].n;
5221 var ShortName = FF[i].sn;
5222 var Color = FF[i].c;
5223 var ColorModule = FF[i].cm;
5224 var ModuleName = FF[i].m;
5225 if(!Color || !ColorModule)
5226 {
5227 var cidx = StringColor(ShortName);
5228 FF[i].c = "hsl(" + cidx + ",50%, 70%)";
5229 FF[i].rgb = ConvertHslToRGB(cidx/ 360, 0.5, 0.7);
5230 var cidxModule = StringColor(ModuleName);
5231 FF[i].cm = "hsl(" + cidxModule + ",50%, 70%)";
5232 FF[i].rgbm = ConvertHslToRGB(cidxModule/ 360, 0.5, 0.7);
5233 Color = FF[i].c;
5234 ColorModule = FF[i].cm;
5235 }
5236 var UseAlt = 0;
5237 var N = UseAlt ? Name : ShortName;
5238 if(N.length > MaxStringLength)
5239 {
5240 N = N.substring(N.length - MaxStringLength);
5241 }
5242 var E = false;
5243 if(true)
5244 {
5245
5246 if(Y >= YStart)
5247 {
5248 bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
5249 bgcolor = bMouseIn && MouseX > X ? nBackColorOffset : nBackColors[nColorIndex];
5250 TextY = Y+BoxHeight-FontAscent;
5251
5252 context.fillStyle = bgcolor;
5253 context.fillRect(X, Y, Width, BoxHeight);
5254 context.fillStyle = Color;
5255 context.textAlign = 'right';
5256 context.fillText(N, X + Width - 2, TextY);
5257 context.textAlign = 'left';
5258 context.fillStyle = ColorModule;
5259 context.fillText(ModuleName, X, TextY);
5260 if(bMouseIn)
5261 {
5262 context.fillStyle = Color;
5263 var bgcolorin = bMouseIn && MouseX < X ? nBackColorOffset : nBackColors[nColorIndex];
5264
5265 Selection = i;
5266 var W = context.measureText('>>').width;
5267 W = Math.max(W, BoxHeight) + 2;
5268 var Corner = X - W - 1;
5269 if(Corner < SizeInfo.x)
5270 {
5271 SizeInfo.w += SizeInfo.x - Corner;
5272 SizeInfo.x = Corner;
5273 }
5274 context.fillStyle = bgcolorin;
5275 context.fillRect(Corner, Y, W, BoxHeight);
5276 context.fillStyle = Color;
5277 context.textAlign = 'center';
5278 context.fillText(">>", Corner + Math.floor(W / 2), TextY);
5279
5280 context.textAlign = 'left';
5281 }
5282 }
5283 Y += BoxHeight;
5284 nColorIndex = 1-nColorIndex;
5285 }
5286 }
5287 }
5288
5289 context.textAlign = 'left';
5290 if(Selection != -1 && MouseReleased)
5291 {
5292 if(KeyShiftDown || MouseX < X)
5293 {
5294 WSSendMessage("I" + FF[Selection].a + ' ' + FF[Selection].rgb + ' ' + FF[Selection].m + '!' + FF[Selection].n);
5295 }
5296 else
5297 {
5298 WSSendMessage("i" + FF[Selection].a + ' ' + FF[Selection].rgb + ' ' + FF[Selection].m + '!' + FF[Selection].n);
5299 }
5300 }
5301 SizeInfo.h = Y-SizeInfo.y;
5302 return SizeInfo;
5303 }
5304
5305 function DrawMenuGeneric(Elements, Active, OnClick, x, y, Elements2)
5306 {
5307 var context = CanvasDetailedView.getContext('2d');
5308 var nColorIndex = 0;
5309 if(Elements2.length != Elements.length)
5310 {
5311 Elements2 = null;
5312 }
5313
5314 var h = FontHeight * Elements.length;
5315 var w = 20;
5316 var w2 = 0;
5317 for(var i = 0; i < Elements.length; ++i)
5318 {
5319 var m = context.measureText(Elements[i]).width;
5320 w = w > m ? w : m;
5321 if(Elements2)
5322 {
5323 m = context.measureText(Elements2[i]).width;
5324 w2 = w2 > m ? w2 : m;
5325 }
5326 }
5327 w += 10 + w2;
5328 var SizeInfo = MenuSize(w);
5329 SizeInfo.x = x;
5330 SizeInfo.y = y;
5331 var X = x;
5332 var Y = y;
5333
5334
5335 for(var i = 0; i < Elements.length; ++i)
5336 {
5337 var Selected = Active == i;
5338 var Name = Elements[i];
5339 var bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
5340 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5341 var TextY = Y+BoxHeight-FontAscent;
5342 context.fillStyle = Selected?'white':bgcolor;
5343 context.fillRect(X-2, Y, w+4, BoxHeight);
5344 context.fillStyle = bgcolor;
5345 context.fillRect(X, Y, w, BoxHeight);
5346 context.fillStyle = 'white';
5347 context.fillText(Name, X + 2, TextY);
5348 if(Elements2)
5349 {
5350 context.textAlign = "right";
5351 context.fillText(Elements2[i], X + w , TextY);
5352 context.textAlign = "left";
5353 }
5354 context.fillText(Name, X + 2, TextY);
5355 if(bMouseIn && MouseReleased)
5356 {
5357 OnClick(i, Name);
5358 }
5359 Y += BoxHeight;
5360 nColorIndex = 1-nColorIndex;
5361 }
5362 SizeInfo.h = Y - SizeInfo.y;
5363 return SizeInfo;
5364 }
5365
5366 function DrawMenuGroup()
5367 {
5368 if(FilterInputValueLast != FilterInput.value)
5369 {
5370 nOffsetMenuGroup = 0;
5371 }
5372 FilterInputValueLast = FilterInput.value;
5373
5374 var context = CanvasDetailedView.getContext('2d');
5375 var nColorIndex = 0;
5376 var Selection = null;
5377 var SizeInfo = GroupMenuSize();
5378 SizeInfo.x = MenuItems[SubMenuGroup].x;
5379 SizeInfo.y = MenuItems[SubMenuGroup].y;
5380 var Y = SizeInfo.y;
5381 var X = SizeInfo.x;
5382 var Width = SizeInfo.w;
5383 var FilterArray = CreateFilter(FilterInput.value);
5384 MoveFilterInputDiv(SizeInfo.x-2, SizeInfo.y, SizeInfo.w-1);
5385 var YStart = Y+20;
5386 Y += 35;
5387 Y -= nOffsetMenuGroup;
5388
5389
5390 function DrawMenuElement(Selected, Name, color, Indent)
5391 {
5392 var bMouseIn = MouseY >= Y && MouseY < Y + BoxHeight;
5393 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
5394 context.fillStyle = Selected?'white':bgcolor;
5395 context.fillRect(X-2, Y, Width+4, BoxHeight);
5396 context.fillStyle = bgcolor;
5397 context.fillRect(X, Y, Width, BoxHeight);
5398 context.fillStyle = color;
5399 if(!Indent) Indent = 0;
5400 context.fillText(Name, X + Indent*FontWidth, Y+BoxHeight-FontAscent);
5401 nColorIndex = 1-nColorIndex;
5402 Y += BoxHeight;
5403 return bMouseIn;
5404 }
5405 function DrawMenuRecursive(Index, Indent, categorymatch)
5406 {
5407 ProfileEnter("DrawMenuRecursive");
5408 var v = TimerArray[Index];
5409 if(v.idtype == TYPE_TIMER || v.idtype == TYPE_COUNTER)
5410 {
5411 return;
5412 }
5413 if(v.idtype == TYPE_GROUP && !categorymatch)
5414 {
5415 if(!FilterMatch(FilterArray, v.name))
5416 {
5417 return;
5418 }
5419 }
5420 var catmatch = 0;
5421 if(v.idtype == TYPE_CATEGORY)
5422 {
5423 if(FilterMatch(FilterArray, v.name))
5424 {
5425 catmatch = 1;
5426 }
5427 }
5428 var Closed = 0;
5429 if(Index > 0)
5430 {
5431 if(Y > YStart)
5432 {
5433 if(DrawMenuElement(v.e, v.name, v.color, Indent))
5434 {
5435 Selection = v.id;
5436 }
5437 }
5438 else
5439 {
5440 Y += BoxHeight;
5441 }
5442 }
5443
5444 if(!Closed)
5445 {
5446 var ChildIndex = v.firstchild;
5447 while(ChildIndex != -1)
5448 {
5449 DrawMenuRecursive(ChildIndex, Indent + 1, catmatch);
5450 ChildIndex = TimerArray[ChildIndex].sibling;
5451 }
5452 }
5453 ProfileLeave();
5454 }
5455 DrawMenuRecursive(0, -1);
5456 if(Selection && MouseReleased)
5457 {
5458 WSSendMessage("c" + Selection);
5459 }
5460 SizeInfo.h = Y - SizeInfo.y;
5461 return SizeInfo;
5462 }
5463
5464 function ShowMenu()
5465 {
5466 if(!Settings.ViewCompressed)
5467 return true;
5468 else
5469 {
5470 var Time = new Date();
5471 var Delta = Time - MouseMoveTime;
5472 console.log('delta time is ' + Delta);
5473 return Delta < 2000;
5474 }
5475 }
5476
5477 function DrawMenu()
5478 {
5479 if(WSConnected && WS && WS.readyState == 1)
5480 {
5481 var context = CanvasDetailedView.getContext('2d');
5482 var nColorIndex = 0;
5483 var Y = 50;
5484 var Width = 300;
5485 var Selection = null;
5486 if(!ShowMenu())
5487 {
5488 return;
5489 }
5490 ProfileEnter("DrawMenu");
5491 DrawTopMenu();
5492 var MenuRect = WindowRect(0,0,nWidth,nHeight);
5493 if(SubMenuActive != -1)
5494 {
5495 MouseMoveTime = new Date();
5496 }
5497 if(SubMenuActive == SubMenuGroup)
5498 {
5499 MenuRect = DrawMenuGroup();
5500 }
5501 else if(SubMenuActive == SubMenuTimers)
5502 {
5503 MenuRect = DrawMenuTimer();
5504 }
5505 else if(SubMenuActive == SubMenuModules)
5506 {
5507 MenuRect = DrawMenuModules();
5508 }
5509 else if(SubMenuActive == SubMenuFunctions)
5510 {
5511 MenuRect = DrawMenuFunctions();
5512 }
5513 else if(SubMenuActive == SubMenuPatched)
5514 {
5515 MenuRect = DrawMenuPatched();
5516 }
5517 else if(SubMenuActive == SubMenuSettings)
5518 {
5519 MenuRect = DrawMenuSettings();
5520 }
5521 else if(SubMenuActive == SubMenuViews)
5522 {
5523 MenuRect = DrawMenuViews();
5524 }
5525 else if(SubMenuActive == SubMenuPresets)
5526 {
5527 MenuRect = DrawMenuPresets();
5528 }
5529 else if(SubMenuActive == SubMenuColumns)
5530 {
5531 MenuRect = DrawMenuColumns();
5532 }
5533 else if(SubMenuActive == SubMenuCapture)
5534 {
5535 MenuRect = DrawMenuCapture();
5536 }
5537 else if(SubMenuActive == SubMenuGraphSettings)
5538 {
5539 MenuRect = DrawMenuGraphSettings();
5540 }
5541 var Grow = 10;
5542 MenuRect.x -= Grow;
5543 MenuRect.y -= Grow;
5544 MenuRect.h += 2*Grow;
5545 MenuRect.w += 2*Grow;
5546 var MouseMoved = MouseX != SubMenuMouseX || MouseY != SubMenuMouseY;
5547
5548 if(MouseInRect(MenuRect) || !MouseMoved)
5549 {
5550 SubMenuTimeout = new Date();
5551 SubMenuMouseX = MouseX;
5552 SubMenuMouseY = MouseY;
5553 }
5554 else
5555 {
5556 var Time = new Date() - SubMenuTimeout;
5557 var Dest = SubMenuTimeoutBase * 1000;
5558 if(Time > Dest)
5559 {
5560 EnableMenu(-1);
5561 }
5562 }
5563 if(0)//debugging of menu extents. dont delete
5564 {
5565 context.strokeStyle = 'red';
5566 context.beginPath();
5567 context.moveTo(MenuRect.x,MenuRect.y);
5568 context.lineTo(MenuRect.x + MenuRect.w,MenuRect.y);
5569 context.lineTo(MenuRect.x + MenuRect.w,MenuRect.y+MenuRect.h);
5570 context.lineTo(MenuRect.x,MenuRect.y+MenuRect.h);
5571 context.lineTo(MenuRect.x,MenuRect.y);
5572 context.stroke();
5573 }
5574 SpinnerDraw(SpinnerShow(), context, SpinnerCorner, 0, nHeight-20, 20, 20);
5575 ProfileLeave();
5576 }
5577 }
5578
5579 function DrawConnectionStatus()
5580 {
5581 if(WSConnected && WS && WS.readyState == 1)
5582 {
5583 if(!ProfileMode)
5584 return;
5585 }
5586 var Strings = new Array();
5587 Strings.push("Status");
5588 if(WSConnected && WS && WS.readyState == 1)
5589 {
5590 Strings.push("[X]");
5591 }
5592 else
5593 {
5594 ConnectionIdx = (ConnectionIdx + 1 ) % ConnectionStr.length;
5595 Strings.push("[" + ConnectionStr[ConnectionIdx]+"]");
5596 }
5597 Strings.push("Port");
5598 Strings.push("" + WSPort);
5599 Strings.push("Path");
5600 Strings.push("" + WSPath);
5601 Strings.push("Sends");
5602 Strings.push("" + WSSend);
5603 Strings.push("Receives");
5604 Strings.push("" + WSReceive);
5605 Strings.push("SendBytes");
5606 Strings.push("" + WSSendBytes);
5607 Strings.push("ReceiveBytes");
5608 Strings.push("" + WSReceiveBytes);
5609 Strings.push("Seconds");
5610 Strings.push("" + WSSeconds);
5611 DrawToolTip(Strings, CanvasDetailedView, 50000, 0);
5612 }
5613 function DrawActiveToolTip()
5614 {
5615 if(SubMenuActive == -1)
5616 {
5617 if(ToolTipCallback && SubMenuActive == -1)
5618 {
5619 var Strings = ToolTipCallback(CanvasDetailedView, MouseX, MouseY);
5620 if(Strings)
5621 {
5622 DrawToolTip(Strings, CanvasDetailedView, MouseX, MouseY);
5623 }
5624 }
5625 }
5626 ToolTipCallback = null;
5627 }
5628 function UpdateSettings()
5629 {
5630 if(Settings.AutomaticReference)
5631 {
5632 if( Math.abs(ReferenceGraph - ReferenceGraphAutomatic) > 0.02 ||
5633 Math.abs(ReferenceHistory - ReferenceHistoryAutomatic) > 0.02)
5634 {
5635 RequestDraw();
5636 }
5637 ReferenceGraph = 0.9 * ReferenceGraph + 0.1 * ReferenceGraphAutomatic;
5638 ReferenceHistory = 0.9 * ReferenceHistory + 0.1 * ReferenceHistoryAutomatic;
5639 ReferenceBar = 0.9 * ReferenceBar + 0.1 * ReferenceBarAutomatic;
5640 var TimerMap = FrameData.TimerMap;
5641 if(!TimerMap)
5642 return;
5643
5644
5645 for(var key in TimerMap)
5646 {
5647 var TimerState = TimerMap[key];
5648 if(!TimerState.historymaxsoft)
5649 {
5650 TimerState.historymaxsoft = TimerState.historymax;
5651 }
5652 else
5653 {
5654 TimerState.historymaxsoft = 0.9 * TimerState.historymaxsoft + 0.1 * TimerState.historymax;
5655 }
5656 }
5657
5658 }
5659 else
5660 {
5661 ReferenceGraph = Settings.ReferenceTime;
5662 ReferenceHistory = Settings.ReferenceTime;
5663 ReferenceBar = Settings.ReferenceTime;
5664 }
5665 if(Settings.AggregateFrames != AggregateFrames)
5666 {
5667 WSSendMessage("a" + Settings.AggregateFrames);
5668 AggregateFrames = Settings.AggregateFrames;
5669 }
5670 }
5671
5672 var PendingDraw = 0;
5673
5674 function Draw()
5675 {
5676 CaptureUpdate();
5677 PendingDraw = 0;
5678 ProfileEnter("Total");
5679
5680 UpdateSettings();
5681
5682 if(WSConnected && WS && WS.readyState == 1)
5683 {
5684 DrawViews();
5685 DrawMessage();
5686 DrawMenu();
5687 }
5688 else
5689 {
5690 var context = CanvasDetailedView.getContext('2d');
5691 context.clearRect(0, 0, nWidth, nHeight);
5692 DrawMessage();
5693 }
5694
5695 DrawConnectionStatus();
5696 DrawPlotf(CanvasDetailedView);
5697 DrawActiveToolTip();
5698
5699
5700 ProfileLeave();
5701 ProfileModeDraw(CanvasDetailedView);
5702 ProfileModeClear();
5703
5704
5705 PlotfClear();
5706
5707 MouseReleased = false;
5708 }
5709 function RequestDraw()
5710 {
5711 if(!PendingDraw)
5712 {
5713 PendingDraw = 1;
5714 requestAnimationFrame(Draw);
5715 }
5716 }
5717
5718
5719
5720
5721 function WSOpen(event)
5722 {
5723 SetMessage("Connected!", 1000);
5724 WSSend = 0;
5725 WSReceive = 0;
5726 WSSendBytes = 0;
5727 WSReceiveBytes = 0;
5728 WSIsOpen = 1;
5729
5730 Empty = {"id":0, "w":0, "depth":0, "sibling":-1,"parent":-1,"firstchild":-1};
5731 TimerArray = [];
5732 TimerArray.push(Empty);
5733 WidthArray = [];
5734 CounterArray = [];
5735 WidthArray[TYPE_NONE] = 0;
5736 WidthArray[TYPE_TIMER] = 0;
5737 WidthArray[TYPE_GROUP] = 0;
5738 WidthArray[TYPE_CATEGORY] = 0;
5739 WidthTree = FontWidth;
5740 SymbolState = null;
5741 FunctionQueryPending = 0;
5742 FunctionQueryReceived = 0;
5743 FunctionQueryLastRequest = 0;
5744 FunctionsInstrumented = [];
5745 FunctionsInstrumentedModule = [];
5746 FunctionsInstrumentedUnmangled = [];
5747
5748 FilterInputTimersValue = "";
5749 FilterInputGroupsValue = "";
5750 FilterInputFunctionsValue = "";
5751 FilterInput.value = "";
5752 FunctionQueryArray = [];
5753 ModuleState = [];
5754
5755 ResetFrameData();
5756 window.document.title = "MP:" + WSHost;
5757
5758 if(PresetToLoad && PresetToLoad != "")
5759 {
5760 LoadPreset(PresetToLoad, PresetToLoadRO);
5761 }
5762 }
5763
5764 function SplitIdTop(v)
5765 {
5766 return v >> 24; // todo: verify
5767 }
5768
5769 function SplitIdBottom(v)
5770 {
5771 return v & 0xffffff; // todo: verify
5772 }
5773
5774 function GetTimer(id)
5775 {
5776 for(var i = 0; i < TimerArray.length; ++i)
5777 {
5778 if(TimerArray[i].id == id)
5779 {
5780 return i;
5781 }
5782 }
5783 return null;
5784 }
5785 function IsGroup(id)
5786 {
5787 var idx = GetTimer(id);
5788 return TimerArray[idx].idtype == TYPE_GROUP;
5789 }
5790
5791 function UpdateActive()
5792 {
5793 GroupsEnabled = 0;
5794 TimersEnabled = 0;
5795 for(var i = 0; i < TimerArray.length; ++i)
5796 {
5797 var T = TimerArray[i];
5798 if(T.e)
5799 {
5800 switch(T.idtype)
5801 {
5802 case TYPE_GROUP:
5803 GroupsEnabled++;
5804 break;
5805 case TYPE_TIMER:
5806 TimersEnabled++;
5807 break;
5808 }
5809 }
5810 }
5811 }
5812 function UpdateEnabledTimer(idx)
5813 {
5814 UpdateActive();
5815 var type = TimerArray[idx].idtype;
5816 var enabled = TimerArray[idx].e;
5817 if(TimerArray[idx].idtype != TYPE_TIMER)
5818 {
5819 return;
5820 }
5821 var AutoCaptureSourceValue = null;
5822 if(AutoCaptureSourceIndex >= 0 && AutoCaptureSourceIndex < EnabledArray.length)
5823 {
5824 AutoCaptureSourceValue = EnabledArray[AutoCaptureSourceIndex];
5825 }
5826
5827 var i = EnabledArray.indexOf(idx);
5828 if(enabled)
5829 {
5830 if(i == -1)
5831 {
5832 EnabledArray.unshift(idx);
5833 }
5834 }
5835 else
5836 {
5837 if(i != -1)
5838 {
5839 EnabledArray.splice(i, 1);
5840 }
5841 }
5842 var NewIndex = AutoCaptureSourceValue != null ? EnabledArray.indexOf(AutoCaptureSourceValue) : -1;
5843 AutoCaptureSourceIndex = NewIndex;
5844 }
5845
5846
5847 function EnableTimer(T)
5848 {
5849 var idx = GetTimer(T.id);
5850 if(idx != null && idx>=0)
5851 {
5852 TimerArray[idx].e = T.e;
5853 UpdateEnabledTimer(idx);
5854 }
5855 else
5856 {
5857 console.log('unknown enable message');
5858 }
5859 }
5860 function MeasureWidth(str)
5861 {
5862 var context = CanvasDetailedView.getContext('2d');
5863 return context.measureText(str).width;
5864 }
5865 function AddTimer(T)
5866 {
5867 if(!T.color || T.color == "")
5868 {
5869 T.color = ColorFromString(T.name, 40, 50);
5870 }
5871 console.log("Added timer", T.name);
5872 var idx = TimerArray.length;
5873 var existing = GetTimer(T.id);
5874 if(existing)
5875 {
5876 idx = existing;
5877 }
5878 else
5879 {
5880 TimerArray[idx] = T;
5881 }
5882 TimerArray[idx].time = 0;
5883 TimerArray[idx].excl = 0;
5884 TimerArray[idx].average = 0;
5885 TimerArray[idx].max = 0;
5886 TimerArray[idx].min = 0;
5887 TimerArray[idx].total = 0;
5888 TimerArray[idx].exclaverage = 0;
5889 TimerArray[idx].exclmax = 0;
5890 TimerArray[idx].excltotal = 0;
5891 TimerArray[idx].spike = 0;
5892 TimerArray[idx].callaverage = 0;
5893 TimerArray[idx].callexclaverage = 0;
5894 TimerArray[idx].callcount = 0;
5895 var w = MeasureWidth(T.name);
5896 var idtype = SplitIdTop(T.id);
5897 var idelement = SplitIdBottom(T.id);
5898 TimerArray[idx].idtype = idtype;
5899 TimerArray[idx].idelement = idelement;
5900 TimerArray[idx].w = w;
5901 TimerArray[idx].wtree = w;
5902 if(!existing)
5903 {
5904 TimerArray[idx].sibling = -1;
5905 TimerArray[idx].parent = -1;
5906 TimerArray[idx].firstchild = -1;
5907 }
5908 if(w > WidthArray[idtype])
5909 {
5910 WidthArray[idtype] = w;
5911 }
5912 UpdateEnabledTimer(idx);
5913 var wparent = 0;
5914 var pidx = GetTimer(T.pid);
5915 if(pidx >= 0 && !existing)
5916 {
5917 TimerArray[idx].parent = pidx;
5918 var Parent = TimerArray[pidx];
5919 var Sibling = Parent.firstchild;
5920 wparent = MeasureWidth(Parent.name);
5921 Parent.firstchild = idx;
5922 if(Sibling != -1)
5923 {
5924 if(TimerArray[Sibling].sibling == idx)
5925 {
5926 debugger;
5927 }
5928 }
5929 TimerArray[idx].sibling = Sibling;
5930 TimerArray[idx].wtree += Parent.depth * FontWidth;
5931 TimerArray[idx].depth = Parent.depth + 1;
5932 if(TimerArray[idx].wtree > WidthTree)
5933 {
5934 WidthTree = TimerArray[idx].wtree;
5935 }
5936 TimerArray[idx].sortkey = Parent.name + " __ " + T.name;
5937 }
5938 else
5939 {
5940 TimerArray[idx].sortkey = T.name;
5941 }
5942 TimerArray[idx].wparent = wparent;
5943 TimerArray[idx].wtotal = wparent + w;
5944
5945 if(idtype == TYPE_COUNTER)
5946 {
5947 if(idelement != CounterArray.length)
5948 {
5949 debugger;
5950 }
5951 CounterArray.push(idx);
5952 TimerArray[idx].formattedlimit = FormatCounter(TimerArray[idx].format, TimerArray[idx].limit);
5953 CounterLimitWidth = Math.max(CounterLimitWidth, TimerArray[idx].formattedlimit.length * (FontWidth+1));
5954 CounterNameWidth = Math.max(CounterNameWidth, (TimerArray[idx].name.length + 1 + TimerArray[idx].depth) * (FontWidth+1));
5955 TimerArray[idx].counterhistory = {};
5956 TimerArray[idx].counterhistory.history = AllocClearedArray(120);
5957 TimerArray[idx].counterhistory.prc = AllocClearedArray(120);
5958 }
5959 if(idtype == TYPE_TIMER)
5960 {
5961 if(T.color == "#000000")
5962 {
5963 T.color = ColorFromString(T.name + "x" + Parent.name, 40, 50);
5964 }
5965
5966 }
5967 RequestDraw();
5968 }
5969
5970 function AllocClearedArray(Size)
5971 {
5972 var A = new Array(Size);
5973 for(var i = 0; i < Size; ++i)
5974 {
5975 A[i] = 0;
5976 }
5977 return A;
5978 }
5979 function PushIntoArray(A, v)
5980 {
5981 A.shift();
5982 A.push(v);
5983 }
5984 function ResetFrameData()
5985 {
5986 FrameData = {};
5987 FrameData.TimerMap = {};
5988 FrameData.Time = AllocClearedArray(FRAME_COUNT);
5989 FrameData.Ids = AllocClearedArray(FRAME_COUNT);
5990 FrameData.Frozen = AllocClearedArray(FRAME_COUNT);
5991 FrameData.ThreadTime = {};
5992 }
5993 function GetFrameData(id)
5994 {
5995 if(FrameData.TimerMap[id])
5996 {
5997 return FrameData.TimerMap[id];
5998 }
5999 else
6000 {
6001 var FD = {};
6002 FD.Count = AllocClearedArray(FRAME_COUNT);
6003 FD.Time = AllocClearedArray(FRAME_COUNT);
6004 FD.TimeExcl = AllocClearedArray(FRAME_COUNT);
6005 FD.TimeMax = AllocClearedArray(AggregateHistorySize);
6006 FD.TimeMin = AllocClearedArray(AggregateHistorySize);
6007 FD.TimeAvg = AllocClearedArray(AggregateHistorySize);
6008 FD.TimeExclMax = AllocClearedArray(AggregateHistorySize);
6009 FD.TimeExclMin = AllocClearedArray(AggregateHistorySize);
6010 FD.TimeExclAvg = AllocClearedArray(AggregateHistorySize);
6011 FD.TimeCallAvg = AllocClearedArray(AggregateHistorySize);
6012 FD.TimeCallExclAvg = AllocClearedArray(AggregateHistorySize);
6013 FD.TimeTotal = AllocClearedArray(AggregateHistorySize);
6014 FD.TimeExclTotal = AllocClearedArray(AggregateHistorySize);
6015 FD.CallCount = AllocClearedArray(AggregateHistorySize);
6016 FD.Percentile = new Float32Array(PERCENTILE_SAMPLES);
6017 FD.Percentile.fill(0.0);
6018 FD.PercentileMax = -1e38;
6019 FD.PercentileMin = 1e38;
6020 FD.PercentileCount = 0;
6021 FD.EmptyFrames = 0;
6022
6023
6024 FD.AggregateFrames = 0;
6025 FD.FrameTime = 0.0;
6026 FD.Aggregate = 0;
6027 FD.AggregateTime = 0.0;
6028 FD.AggregateSum = 0;
6029 FD.AggregateMax = 0;
6030 FD.AggregateMin = C_HUGE;
6031 FD.AggregateExclSum = 0;
6032 FD.AggregateExclMax = 0;
6033 FD.AggregateCount = 0;
6034 FD.AggregateExclMin = C_HUGE;
6035
6036
6037
6038 FrameData.TimerMap[id] = FD;
6039 return FD;
6040 }
6041 }
6042
6043 function ProcessCounters(C)
6044 {
6045 for(var i = 0; i < CounterArray.length; ++i)
6046 {
6047 if(i > C.length)
6048 {
6049 debugger;
6050 }
6051 var idx = CounterArray[i];
6052 var value = C[i];
6053 var T = TimerArray[idx];
6054 T.value = value;
6055 if(T.minvalue == undefined)
6056 T.minvalue = value;
6057 else
6058 T.minvalue = Math.min(T.minvalue, value);
6059 if(T.maxvalue == undefined)
6060 T.maxvalue = value;
6061 else
6062 T.maxvalue = Math.max(T.maxvalue, value);
6063 T.formatted = FormatCounter(T.format, value);
6064 var boxprc = 1.0;
6065 var counterprc = 0;
6066 if(T.limit)
6067 {
6068 counterprc = value / T.limit;
6069 if(counterprc > 1.0)
6070 {
6071 boxprc = 1.0 / counterprc;
6072 counterprc = 1.0;
6073 }
6074 counterprc = Math.max(counterprc, 0.0);
6075
6076 }
6077 T.boxprc = boxprc;
6078 T.counterprc = counterprc;
6079 PushIntoArray(T.counterhistory.history, value);
6080 var prc = T.maxvalue > T.minvalue ? (value - T.minvalue) / (T.maxvalue - T.minvalue) : 0.0;
6081 PushIntoArray(T.counterhistory.prc, prc);
6082 CounterValueWidth = Math.max(CounterValueWidth, T.formatted.length * (FontWidth+1));
6083 }
6084
6085 }
6086
6087
6088 function ProcessFrame(F, Inactive)
6089 {
6090 ProfileEnter("ProcessFrame");
6091 if(F.s)
6092 {
6093 if(F.s.l == F.s.r)
6094 {
6095 if(FunctionQueryPending)
6096 {
6097 var Req = ++FunctionQueryLastRequest;
6098 var Q = "q" + Req + "x" + FunctionQueryPending;
6099 WSSendMessage(Q);
6100 FunctionQueryPending = null;
6101 }
6102 }
6103 SymbolState = F.s;
6104 if(F.M)
6105 {
6106 ModuleState = F.M;
6107 }
6108 MenuItems[SubMenuFunctions].visible = function(){return true;};
6109 MenuItems[SubMenuModules].visible = function(){return true;};
6110 }
6111 else
6112 {
6113 MenuItems[SubMenuFunctions].visible = function(){return false;};
6114 MenuItems[SubMenuModules].visible = function(){return false;};
6115 }
6116 if(F.fr)
6117 {
6118 IsFrozen = 10;//allow it to stabilize after freezing
6119 ProfileLeave();
6120 return;
6121 }
6122 if(IsFrozen)
6123 {
6124 IsFrozen--;
6125 }
6126 if(!Inactive)
6127 {
6128 var TriggerAutoCapture = 0;
6129 PushIntoArray(FrameData.Time, F.t);
6130 PushIntoArray(FrameData.Ids, F.f);
6131 PushIntoArray(FrameData.Frozen, IsFrozen ? 1 : 0);
6132 var CaptureId = null;
6133 var AutoCapture = AutoCaptureEnabled && !IsFrozen;
6134 AggregateCurrent = F.a;
6135 if(F.m != Settings.ViewActive)
6136 {
6137 WSSendMessage("v" + Settings.ViewActive);
6138 }
6139 if(AutoCapture > 0 && null == CaptureTriggerTime && AutoCaptureCooldown < 0)
6140 {
6141 if(AutoCaptureSourceIndex == -1 && F.t > Settings.AutoCaptureTheshold)
6142 {
6143 AutoCaptureEnabled -= 1;
6144 TriggerAutoCapture = 1;
6145 }
6146 else if(AutoCaptureSourceIndex >= 0 && AutoCaptureSourceIndex < EnabledArray.length)
6147 {
6148 var id = TimerArray[EnabledArray[AutoCaptureSourceIndex]].id;
6149 var Data = F.x[id];
6150 if(Data && Data[0])
6151 {
6152 if(Data[0] > Settings.AutoCaptureTheshold)
6153 {
6154 TriggerAutoCapture = 1;
6155 AutoCaptureEnabled -= 1;
6156 console.log('trigger capture! ', Data[0], ' ', Settings.AutoCaptureTheshold);
6157 }
6158 }
6159 }
6160 }
6161 AutoCaptureCooldown = AutoCaptureCooldown - 1;
6162
6163 var GraphTimeMax = 0;
6164 var GraphTimeGroupMax = 0;
6165 var HistoryTimeMax = 0;
6166
6167 for(var i = 0; i < FrameData.Time.length; ++i)
6168 {
6169 if(0 == FrameData.Frozen[i])
6170 {
6171 HistoryTimeMax = HistoryTimeMax > FrameData.Time[i] ? HistoryTimeMax : FrameData.Time[i];
6172 }
6173 }
6174 var FindMaxTime = function(A, bIsGroup)
6175 {
6176 var MaxTime = 0;
6177 for(var i = 0; i < A.length; ++i)
6178 {
6179 if(0 == FrameData.Frozen[i])
6180 {
6181 MaxTime = MaxTime > A[i] ? MaxTime : A[i];
6182 }
6183 }
6184 if(bIsGroup)
6185 GraphTimeGroupMax = MaxTime > GraphTimeGroupMax ? MaxTime : GraphTimeGroupMax;
6186 else
6187 GraphTimeMax = MaxTime > GraphTimeMax ? MaxTime : GraphTimeMax;
6188 return MaxTime;
6189 };
6190 function SetAggregateTimersInArray(FD, id)
6191 {
6192 var idx = GetTimer(id);
6193 var Pos = AggregateHistorySize-1;
6194 var T = TimerArray[idx];
6195
6196 T.max = FD.TimeMax[Pos];
6197 T.total = FD.TimeTotal[Pos];
6198 T.excltotal = FD.TimeExclTotal[Pos];
6199 T.min = FD.TimeMin[Pos];
6200 T.spike = (T.average == 0 || T.max == 0) ? 0 : (100*T.max/T.average);
6201 T.callaverage = FD.TimeCallAvg[Pos];
6202 T.callcount = FD.CallCount[Pos];
6203 T.callexclaverage = FD.TimeCallExclAvg[Pos];
6204 T.exclaverage = FD.TimeExclAvg[Pos];
6205 T.exclmax = FD.TimeExclMax[Pos];
6206 T.exclmin = FD.TimeExclMin[Pos];
6207 T.average = FD.TimeAvg[Pos];
6208 };
6209 function SetTimersInArray(FD, id)
6210 {
6211 var idx = GetTimer(id);
6212 var Pos = FD.Time.length-1;
6213 var T = TimerArray[idx];
6214 T.time = FD.Time[Pos];
6215 T.excl = FD.TimeExcl[Pos];
6216 T.count = FD.Count[Pos];
6217
6218 };
6219
6220 let UpdateFrameDataInternal = function(id, Time, TimeExcl, Count, bIsGroup)
6221 {
6222
6223 let FD = GetFrameData(id);
6224 if(!IsFrozen)
6225 {
6226 ProfileEnter("PercentileAccum");
6227 FD.PercentileMax = Math.max(FD.PercentileMax, Time);
6228 FD.PercentileMin = Math.min(FD.PercentileMin, Time);
6229 FD.PercentileCount += 1;
6230 if(Time > FD.Percentile[0])
6231 {
6232 FD.Percentile[0] = Time;
6233 FD.Percentile.sort( function(a,b){return a - b;} );
6234 }
6235 ProfileLeave();
6236 }
6237 PushIntoArray(FD.Time, Time);
6238 PushIntoArray(FD.TimeExcl, TimeExcl);
6239 PushIntoArray(FD.Count, Count);
6240 FD.historymax = FindMaxTime(FD.Time, bIsGroup);
6241
6242 if((FD.Aggregate > Settings.AggregateFrames && Settings.AggregateFrames > 0) || AggregateCurrent == 0)
6243 {
6244 SetAggregateTimersInArray(FD, id);
6245 FD.Aggregate = 0;
6246 FD.AggregateSum = 0;
6247 FD.AggregateMax = 0;
6248 FD.AggregateMin = C_HUGE;
6249 FD.AggregateExclSum = 0;
6250 FD.AggregateExclMax = 0;
6251 FD.AggregateExclMin = C_HUGE;
6252 FD.AggregateCount = 0;
6253
6254 FD.TimeMax.shift();
6255 FD.TimeMax.push(0);
6256
6257 FD.TimeMin.shift();
6258 FD.TimeMin.push(0);
6259
6260 FD.TimeAvg.shift();
6261 FD.TimeAvg.push(0);
6262
6263 FD.TimeCallAvg.shift();
6264 FD.TimeCallAvg.push(0);
6265
6266 FD.TimeCallExclAvg.shift();
6267 FD.TimeCallExclAvg.push(0);
6268
6269 FD.CallCount.shift();
6270 FD.CallCount.push(0);
6271
6272 FD.TimeTotal.shift();
6273 FD.TimeTotal.push(0);
6274
6275 FD.TimeExclTotal.shift();
6276 FD.TimeExclTotal.push(0);
6277
6278 FD.TimeExclMax.shift();
6279 FD.TimeExclMax.push(0);
6280
6281 FD.TimeExclMin.shift();
6282 FD.TimeExclMin.push(0);
6283
6284 FD.TimeExclAvg.shift();
6285 FD.TimeExclAvg.push(0);
6286 }
6287
6288 FD.Aggregate += 1;
6289 FD.AggregateSum += Time;
6290 FD.AggregateMax = FD.AggregateMax > Time ? FD.AggregateMax : Time;
6291 FD.AggregateMin = FD.AggregateMin < Time ? FD.AggregateMin : Time;
6292 FD.AggregateExclSum += TimeExcl;
6293 FD.AggregateExclMax = FD.AggregateExclMax > TimeExcl ? FD.AggregateExclMax : TimeExcl;
6294 FD.AggregateExclMin = FD.AggregateExclMin < TimeExcl ? FD.AggregateExclMin : TimeExcl;
6295 FD.AggregateCount += Count;
6296 var UpdatePos = AggregateHistorySize-1;
6297 if(UpdatePos != FD.TimeMax.length - 1)
6298 {
6299 debugger;
6300 }
6301
6302 FD.TimeMax[UpdatePos] = FD.AggregateMax;
6303 FD.TimeMin[UpdatePos] = FD.AggregateMin;
6304 FD.TimeAvg[UpdatePos] = FD.AggregateSum / FD.Aggregate;
6305 FD.TimeCallAvg[UpdatePos] = FD.AggregateCount ? FD.AggregateSum / FD.AggregateCount : 0;
6306 FD.TimeCallExclAvg[UpdatePos] = FD.AggregateCount ? FD.AggregateExclSum / FD.AggregateCount : 0;
6307 FD.TimeTotal[UpdatePos] = FD.AggregateSum;
6308 FD.TimeExclTotal[UpdatePos] = FD.AggregateExclSum;
6309 FD.CallCount[UpdatePos] = FD.AggregateCount;
6310 FD.TimeExclAvg[UpdatePos] = FD.Aggregate ? FD.AggregateExclSum / FD.Aggregate : 0;
6311 FD.TimeExclMax[UpdatePos] = FD.AggregateExclMax;
6312 FD.TimeExclMin[UpdatePos] = FD.AggregateExclMin;
6313
6314 if(Settings.AggregateFrames <= 0)
6315 {
6316 SetAggregateTimersInArray(FD, id);
6317 }
6318 SetTimersInArray(FD, id);
6319 };
6320
6321 for(var id in F.x)
6322 {
6323 var Data = F.x[id];
6324 var Time = Data[0];
6325 var TimeExcl = Data[1];
6326 var Count = Data[2];
6327 UpdateFrameDataInternal(id, Data[0], Data[1], Data[2]);
6328 }
6329
6330 var groups = {};
6331 for(var i = 0; i < F.g.length; ++i)
6332 {
6333 var id = F.gi[i];
6334 groups[id] = 1;
6335 var t = F.g[i];
6336 UpdateFrameDataInternal(id, t[0], t[1], t[2], 1);
6337 }
6338
6339 let UpdateThreadInfo = function(o)
6340 {
6341 let sn = SanitizeString(o.n);
6342 let TI = ThreadInfo[sn];
6343 if(!TI)
6344 {
6345 TI = { ids:o.gi, a:[], n:o.n, sn:sn };
6346 for(let i = 0; i < TI.ids.length; ++i)
6347 {
6348 TI.a.push(AllocClearedArray(FRAME_COUNT));
6349 }
6350 ThreadInfo[sn] = TI;
6351 }
6352 for(let i = 0; i < o.gi.length; ++i)
6353 {
6354 let id = o.gi[i];
6355 let t = o.g[i][1];
6356 let te = FrameData.Time[FrameData.Time.length-1];
6357 if(t > te)
6358 {
6359 console.log("fail!");
6360 // debugger;
6361 }
6362 let idx = TI.ids.indexOf(id);
6363 if(-1 == idx)
6364 {
6365 TI.ids.push(id);
6366 let a = AllocClearedArray(FRAME_COUNT);
6367 a[a.length-1] = o.g[i][1];
6368 TI.a.push(a);
6369 }
6370 else
6371 {
6372 let l = TI.a[idx].length;
6373 TI.a[idx][l-1] = o.g[i][1];
6374 }
6375 }
6376 };
6377 if(F.gt && F.gt.length)
6378 {
6379 for(let key in ThreadInfo)
6380 {
6381 let TI = ThreadInfo[key];
6382 for(let i = 0; i < TI.a.length; ++i)
6383 {
6384 PushIntoArray(TI.a[i], 0);
6385 }
6386 }
6387
6388
6389 for(let i = 0; i < F.gt.length; ++i)
6390 {
6391 let o = F.gt[i];
6392 UpdateThreadInfo(o);
6393 }
6394 }
6395
6396
6397
6398 var ToDelete = new Array();
6399 for(var id in FrameData.TimerMap)
6400 {
6401 let FD = FrameData.TimerMap[id];
6402 if(!F.x[id] && !groups[id])
6403 {
6404 PushIntoArray(FD.Time,0.0);
6405 PushIntoArray(FD.TimeExcl, 0.0);
6406 PushIntoArray(FD.Count, 0);
6407 FindMaxTime(FD.Time);
6408 FD.EmptyFrames++;
6409 }
6410 else
6411 {
6412 FD.EmptyFrames = 0;
6413 }
6414 FD.FrameTime = FD.Time[FD.Time.length-1]; //Fix her..?
6415 FD.AggregateTime = FD.Time[FD.Time.length-1];
6416
6417 if(FD.EmptyFrames == FD.Time.length)
6418 {
6419 ToDelete.push(id);
6420 }
6421 }
6422 for(var i = 0; i < ToDelete.length; ++i)
6423 {
6424 delete FrameData.TimerMap[ToDelete[i]];
6425 }
6426 FramePending++;
6427
6428
6429 if(TriggerAutoCapture)
6430 {
6431 Capture();
6432 }
6433 ReferenceGraphAutomaticGroup = 1.05 * GraphTimeGroupMax;
6434 ReferenceGraphAutomatic = 1.05 * GraphTimeMax;
6435 ReferenceHistoryAutomatic = 1.05 * HistoryTimeMax;
6436 }
6437 RequestDraw();
6438 ProfileLeave();
6439 }
6440
6441 function WSMessage(event)
6442 {
6443 // console.log(event.data);
6444 var Obj = JSON.parse(event.data);
6445 WSReceive++;
6446 WSReceiveBytes += event.data.length;
6447 var k = Obj.k;
6448 if(k == MSG_TIMER_TREE)
6449 {
6450 AddTimer(Obj.v);
6451 }
6452 else if(k == MSG_ENABLED)
6453 {
6454 EnableTimer(Obj.v);
6455 }
6456 else if(k == MSG_FRAME)
6457 {
6458 ProcessFrame(Obj.v);
6459 }
6460 else if(k == MSG_LOADSETTINGS)
6461 {
6462 OnLoadPreset(Obj.v, 1, Obj.ro);
6463 }
6464 else if(k == MSG_CURRENTSETTINGS)
6465 {
6466 OnLoadPreset(Obj.v, 0, Obj.ro);
6467 }
6468 else if(k == MSG_PRESETS)
6469 {
6470 AddPresets(Obj.v);
6471 }
6472 else if(k == MSG_COUNTERS)
6473 {
6474 ProcessCounters(Obj.v);
6475 }
6476 else if(k == MSG_FUNCTION_RESULTS)
6477 {
6478 FunctionQueryPending = null;
6479 if(FunctionQueryReceived< Obj.q)
6480 {
6481 FunctionQueryArray = Obj.v;
6482 FunctionQueryReceived = Obj.q;
6483 console.log('got result from query ' + Obj.q);
6484 }
6485 else
6486 {
6487 console.log('ignored result from query ' + Obj.q);
6488 }
6489
6490
6491 }
6492 else if(k == MSG_INACTIVE_FRAME)
6493 {
6494 ProcessFrame(Obj.v, 1);
6495 }
6496 else if(k == MSG_FUNCTION_NAMES)
6497 {
6498 for(var i = 0; i < Obj.v.length; ++i)
6499 {
6500 FunctionsInstrumented.push(Obj.v[i][0]);
6501 FunctionsInstrumentedModule.push(Obj.v[i][1]);
6502 FunctionsInstrumentedUnmangled.push(Obj.v[i][2]);
6503
6504 }
6505 }
6506 else if(k == MSG_INSTRUMENT_ERROR)
6507 {
6508 var D = Obj.v.data;
6509 var F = Obj.v.functions;
6510 var ASM_SERVER = "http://microprofileasm.zapto.org";
6511 var url = ASM_SERVER + "/add/" + Obj.v.version + "/";
6512 console.log(JSON.stringify(D));
6513 console.log(JSON.stringify(F));
6514 for(var i = 0; i < D.length; ++i)
6515 {
6516 url = url + D[i].code + "/";
6517 }
6518 var s = "Failed to instrument the following functions:\n";
6519
6520 for(var i = 0; i < F.length; ++i)
6521 {
6522 s = s + F[i] + "\n";
6523 }
6524 s = s + "\n\nPlease click \"OK\"to report the failed code segments\n"
6525 s = s + "this will open the following url in a hidden frame\n"
6526 s = s + url;
6527 s = s + "\n-No additional data will be sent\n-No symbol names will be sent";
6528 s = s + "\n[this popup can be auto-denied or auto-accepted from the settings menu]";
6529 if(Cookie.CodeReportMode != 2)
6530 {
6531 if(Cookie.CodeReportMode == 1 || confirm(s))
6532 {
6533 var iframe = document.createElement("iframe");
6534 iframe.onload = function(){document.body.removeChild(iframe); console.log("removed iframe");};
6535 console.log("opening url " + url);
6536 iframe.setAttribute("src", url);
6537 iframe.style.width = "100x";
6538 iframe.style.height = "100px";
6539 document.body.appendChild(iframe);
6540 }
6541 }
6542 console.log("got error "+ JSON.stringify(Obj.v));
6543 }
6544 // else if(k == MSG_MODULE_NAME)
6545 // {
6546 // console.log("MODULENAME..\n");
6547 // console.log(JSON.stringify(Obj.v));
6548 // ModuleState = Obj.v;
6549
6550 // }
6551 else
6552 {
6553 console.log('hest!');
6554 }
6555
6556 }
6557 function WSError(event)
6558 {
6559 console.log('WSError');
6560 }
6561 function WSClose(event)
6562 {
6563 console.log('WSClose');
6564 WSIsOpen = 0;
6565 window.document.title = "MicroProfile Live";
6566 FilterInputDiv.style['display'] = 'none';
6567 }
6568 function WSSendMessage(msgid)
6569 {
6570 if(WSIsOpen)
6571 {
6572 var str = '' + msgid;
6573 WSSend++;
6574 WSSendBytes += str.length;
6575 WS.send(str);
6576 }
6577 else
6578 {
6579 if(msgid[0] == 'c')
6580 {
6581 console.log('failing to send ' + msgid);
6582 }
6583 }
6584 }
6585
6586
6587 function Connect()
6588 {
6589 if(WS && (WS.readyState == 1 || WS.readyState == 0))
6590 {
6591 WSConnected = WS.readyState == 1;
6592 WSFail = 0;
6593 WSSeconds = 0;
6594 }
6595 else
6596 {
6597 WSConnected = 0;
6598 WSSeconds = (new Date() - WSOpenTime);
6599 if(!WS || WSSeconds > 2000)
6600 {
6601 if(WS)
6602 {
6603 WS.close();
6604 WS = null;
6605 }
6606 WSOpenTime = new Date();
6607 WSPath = "ws://" + WSHost + ":" + WSPort + "/ws";
6608 SetMessage('Connecting to ' + WSPath,5 * 1000, 1);
6609 WS = new WebSocket(WSPath);
6610 WS.onopen = WSOpen;
6611 WS.onmessage = WSMessage;
6612 WS.onerror = WSError;
6613 WS.onclose = WSClose;
6614 WSFail = 0;
6615 }
6616 else
6617 {
6618 WSFail++;
6619 }
6620 }
6621 RequestDraw();
6622 }
6623
6624
6625 function MouseDragPan()
6626 {
6627 return MouseDragButton == 1 || MouseDragKeyShift;
6628 }
6629 function MouseDragSelectRange()
6630 {
6631 return MouseDragState == MouseDragMove && (MouseDragButton == 3 || (MouseDragKeyShift&&MouseDragKeyCtrl));
6632 }
6633
6634 function MouseHandleDrag()
6635 {
6636 if(MouseDragTarget == CanvasDetailedView)
6637 {
6638 if(SubMenuActive == -1)
6639 {
6640 if(MouseDragSelectRange() && SubMenuActive == -1)
6641 {
6642 var xStart = MouseDragXStart;
6643 var xEnd = MouseDragX;
6644 if(xStart > xEnd)
6645 {
6646 var Temp = xStart;
6647 xStart = xEnd;
6648 xEnd = Temp;
6649 }
6650 if(xEnd - xStart > 1)
6651 {
6652 MouseDragActiveXStart = xStart;
6653 MouseDragActiveXEnd = xEnd;
6654 }
6655 }
6656 else if(MouseDragPan())
6657 {
6658 var X = MouseDragX - MouseDragXLast;
6659 var Y = MouseDragY - MouseDragYLast;
6660 if(X && MouseDragActiveXStart < MouseDragActiveXEnd)
6661 {
6662 MouseDragActiveXStart += X;
6663 MouseDragActiveXEnd += X;
6664 }
6665 }
6666 if(Settings.ViewActive == VIEW_BAR)
6667 {
6668 if(MouseDragKeyShift || MouseDragButton == 1)
6669 {
6670 var X = MouseDragX - MouseDragXLast;
6671 var Y = MouseDragY - MouseDragYLast;
6672 nOffsetBarsY -= Y;
6673 nOffsetBarsX -= X;
6674 if(nOffsetBarsY < 0)
6675 {
6676 nOffsetBarsY = 0;
6677 }
6678 if(nOffsetBarsX < 0)
6679 {
6680 nOffsetBarsX = 0;
6681 }
6682 }
6683 }
6684 if(Settings.ViewActive == VIEW_COUNTERS)
6685 {
6686 if(MouseDragKeyShift || MouseDragButton == 1)
6687 {
6688 var Y = MouseDragY - MouseDragYLast;
6689 nOffsetCountersY -= Y;
6690 if(nOffsetCountersY < 0)
6691 {
6692 nOffsetCountersY = 0;
6693 }
6694 }
6695 }
6696 }
6697 else if(SubMenuActive == SubMenuTimers || SubMenuActive == SubMenuGroup || SubMenuActive == SubMenuFunctions)
6698 {
6699 if(MouseDragKeyShift || MouseDragButton == 1)
6700 {
6701 var Y = MouseDragY - MouseDragYLast;
6702 if(SubMenuActive == SubMenuTimers)
6703 {
6704 nOffsetMenuTimers -= Y;
6705 if(nOffsetMenuTimers < 0)
6706 {
6707 nOffsetMenuTimers = 0;
6708 }
6709 }
6710 else if(SubMenuActive == SubMenuFunctions)
6711 {
6712 nOffsetMenuFunctions -= Y;
6713 if(nOffsetMenuFunctions < 0)
6714 {
6715 nOffsetMenuFunctions = 0;
6716 }
6717 }
6718 else
6719 {
6720 nOffsetMenuGroup -= Y;
6721 if(nOffsetMenuGroup < 0)
6722 {
6723 nOffsetMenuGroup = 0;
6724 }
6725 }
6726 }
6727 }
6728 }
6729 MouseDragXLast = MouseDragX;
6730 MouseDragYLast = MouseDragY;
6731 }
6732 function MouseHandleDragEnd()
6733 {
6734 if(MouseDragTarget == CanvasDetailedView)
6735 {
6736
6737 }
6738 }
6739
6740 function MouseHandleDragClick()
6741 {
6742 if(SubMenuActive == -1)
6743 {
6744 if(nHoverCounter != -1)
6745 {
6746 if(TimerArray[nHoverCounter].firstchild != -1)
6747 {
6748 TimerArray[nHoverCounter].closed = !TimerArray[nHoverCounter].closed;
6749 }
6750 else
6751 {
6752 TimerArray[nHoverCounter].Expanded = !TimerArray[nHoverCounter].Expanded;
6753 }
6754 Draw(1);
6755 }
6756 }
6757 if(MouseInCaptureButton)
6758 {
6759 TriggerCapture();
6760 }
6761 }
6762
6763 function MapMouseButton(event)
6764 {
6765 if(event.button == 1 || event.which == 1)
6766 {
6767 return 1;
6768 }
6769 else if(event.button == 3 || event.which == 3)
6770 {
6771 return 3;
6772 }
6773 else
6774 {
6775 return 0;
6776 }
6777 }
6778
6779 function MouseDragReset()
6780 {
6781 MouseDragState = MouseDragOff;
6782 MouseDragTarget = 0;
6783 MouseDragKeyShift = 0;
6784 MouseDragKeyCtrl = 0;
6785 MouseDragButton = 0;
6786 }
6787 function MouseDragKeyUp()
6788 {
6789 if((MouseDragKeyShift && !KeyShiftDown) || (MouseDragKeyCtrl && !KeyCtrlDown))
6790 {
6791 MouseHandleDragEnd();
6792 MouseDragReset();
6793 }
6794 }
6795 function MouseDrag(Source, Event)
6796 {
6797 if(Source == MouseDragOff || (MouseDragTarget && MouseDragTarget != Event.target))
6798 {
6799 MouseDragReset();
6800 return;
6801 }
6802
6803 var LocalRect = Event.target.getBoundingClientRect();
6804 MouseDragX = Event.clientX - LocalRect.left;
6805 MouseDragY = Event.clientY - LocalRect.top;
6806 if(MouseDragState == MouseDragMove)
6807 {
6808 var dx = Math.abs(MouseDragX - MouseDragXStart);
6809 var dy = Math.abs(MouseDragY - MouseDragYStart);
6810 if((Source == MouseDragUp && MapMouseButton(Event) == MouseDragButton) ||
6811 (MouseDragKeyCtrl && !KeyCtrlDown) ||
6812 (MouseDragKeyShift && !KeyShiftDown))
6813 {
6814 MouseHandleDragEnd();
6815 MouseDragReset();
6816 return;
6817 }
6818 else
6819 {
6820 MouseHandleDrag();
6821 }
6822 }
6823 else if(MouseDragState == MouseDragOff)
6824 {
6825 if(Source == MouseDragDown || KeyShiftDown || KeyCtrlDown)
6826 {
6827 MouseDragTarget = Event.target;
6828 MouseDragButton = MapMouseButton(Event);
6829 MouseDragState = MouseDragDown;
6830 MouseDragXStart = MouseDragX;
6831 MouseDragYStart = MouseDragY;
6832 MouseDragKeyCtrl = 0;
6833 MouseDragKeyShift = 0;
6834
6835 if(KeyShiftDown || KeyCtrlDown)
6836 {
6837 MouseDragKeyShift = KeyShiftDown;
6838 MouseDragKeyCtrl = KeyCtrlDown;
6839 MouseDragState = MouseDragMove;
6840 }
6841 }
6842 }
6843 else if(MouseDragState == MouseDragDown)
6844 {
6845 if(Source == MouseDragUp)
6846 {
6847 MouseHandleDragClick();
6848 MouseDragReset();
6849 }
6850 else if(Source == MouseDragMove)
6851 {
6852 var dx = Math.abs(MouseDragX - MouseDragXStart);
6853 var dy = Math.abs(MouseDragY - MouseDragYStart);
6854 if(dx+dy>1)
6855 {
6856 MouseDragState = MouseDragMove;
6857 }
6858 }
6859 }
6860 MouseDragXLast = MouseDragX;
6861 MouseDragYLast = MouseDragY;
6862 }
6863
6864
6865 function MouseMove(evt)
6866 {
6867 evt.preventDefault();
6868 var rect = evt.target.getBoundingClientRect();
6869 var x = evt.clientX - rect.left;
6870 var y = evt.clientY - rect.top;
6871 MouseX = x;
6872 MouseY = y;
6873 MouseMoveTime = new Date();
6874 MouseDrag(MouseDragMove, evt);
6875 RequestDraw();
6876 }
6877
6878
6879 function MouseSortClick()
6880 {
6881 if(SubMenuActive == -1)
6882 {
6883 if(SortColumnMouseOverNext)
6884 {
6885 if(SortColumnMouseOverNext == Settings.SortColumnName)
6886 {
6887 Settings.SortColumnOrderFlip = 1 - Settings.SortColumnOrderFlip;
6888 }
6889 else
6890 {
6891 Settings.SortColumnOrderFlip = 0;
6892 }
6893
6894 Settings.SortColumnName = SortColumnMouseOverNext;
6895 SortColumnMouseOverNext = null;
6896 }
6897 }
6898 }
6899
6900
6901 function MouseButton(bPressed, evt)
6902 {
6903 evt.preventDefault();
6904 MouseReleased = !bPressed;
6905 MouseDrag(bPressed ? MouseDragDown : MouseDragUp, evt);
6906 if(!bPressed)
6907 MouseSortClick();
6908 RequestDraw();
6909 }
6910
6911 function MouseOut(evt)
6912 {
6913 MouseDrag(MouseDragOff, evt);
6914 KeyCtrlDown = 0;
6915 KeyShiftDown = 0;
6916 // MouseDragButton = 0;
6917 // nHoverToken = -1;
6918 // RangeCpu = RangeInit();
6919 }
6920
6921 function MouseWheel(e)
6922 {
6923 // var e = window.event || e;
6924 // var delta = (e.wheelDelta || e.detail * (-120));
6925 // ZoomGraph((-4 * delta / 120.0) | 0);
6926 // Draw(1);
6927 }
6928
6929 function KeyUp(evt)
6930 {
6931 var k = evt.keyCode;
6932 var InputActive = SubMenuActive == SubMenuTimers || SubMenuActive == SubMenuGroup || SubMenuActive == SubMenuFunctions || SubMenuActive == SubMenuPatched || SubMenuActive == SubMenuModules;
6933 if(!InputActive)
6934 {
6935 if(k == 220)
6936 {
6937 ProfileMode = !ProfileMode;
6938 }
6939 if(k == 191)
6940 {
6941 WSPort++;
6942 if(WSPort > 1338+2)
6943 {
6944 WSPort = 1338;
6945 }
6946 if(WS)
6947 {
6948 WS.close();
6949 WS = null;
6950 }
6951 }
6952 if(k == 32)
6953 {
6954 if(0) //for debugging.
6955 {
6956 console.log("FrameData =");
6957 console.log(JSON.stringify(FrameData));
6958 console.log("TimerArray =");
6959 console.log(JSON.stringify(TimerArray));
6960 }
6961 WSSendMessage("f");
6962 }
6963 if(k == 88)
6964 {
6965 ToggleView();
6966 }
6967 if(k == 13)
6968 {
6969 TriggerCapture();
6970 }
6971 if(k == 72)
6972 {
6973 ShowHelp(0, 1);
6974 }
6975
6976
6977 }
6978 if(k == 27)
6979 {
6980 if(FilterInput.value.trim() != "")
6981 {
6982 FilterInput.value = "";
6983 }
6984 else
6985 {
6986 EnableMenu(-1);
6987 }
6988
6989 MouseDragActiveXStart = MouseDragActiveXEnd = -1;
6990 Settings.SortColumnName = "";
6991 ShowHelp(0);
6992 }
6993 if(k == 192)
6994 {
6995 Settings.ViewCompressed = Settings.ViewCompressed ? 0 : 1;
6996 ResizeCanvas();
6997 }
6998
6999 if(evt.keyCode == 17)
7000 {
7001 KeyCtrlDown = 0;
7002 MouseDragKeyUp();
7003 }
7004 if(evt.keyCode == 16)
7005 {
7006 KeyShiftDown = 0;
7007 MouseDragKeyUp();
7008 }
7009 }
7010
7011 function KeyDown(evt)
7012 {
7013 // console.log("keydow ", k);
7014 if(evt.keyCode == 17)
7015 {
7016 KeyCtrlDown = 1;
7017 MouseDragKeyUp();
7018 }
7019 if(evt.keyCode == 16)
7020 {
7021 KeyShiftDown = 1;
7022 MouseDragKeyUp();
7023 }
7024 }
7025
7026
7027 function SetupEvents()
7028 {
7029 var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel"; //FF doesn't recognize mousewheel as of
7030 CanvasDetailedView.addEventListener('mousemove', MouseMove, false);
7031 CanvasDetailedView.addEventListener('mousedown', function(evt) { MouseButton(true, evt); });
7032 CanvasDetailedView.addEventListener('mouseup', function(evt) { MouseButton(false, evt); } );
7033 CanvasDetailedView.addEventListener('mouseout', MouseOut);
7034 CanvasDetailedView.addEventListener("contextmenu", function (e) { e.preventDefault(); }, false);
7035 CanvasDetailedView.addEventListener(mousewheelevt, MouseWheel, false);
7036 window.addEventListener('keydown', KeyDown);
7037 window.addEventListener('keyup', KeyUp);
7038 window.addEventListener('resize', ResizeCanvas, false);
7039 }
7040
7041 function DrawToolTip(StringArray, Canvas, x, y)
7042 {
7043 if(!ShowMenu())
7044 {
7045 return;
7046 }
7047 let colors;
7048 let a = StringArray;
7049 if(StringArray.c)
7050 {
7051 a = StringArray.a;
7052 colors = StringArray.c;
7053 }
7054 var context = Canvas.getContext('2d');
7055 context.font = Font;
7056 var WidthArray = Array(a.length);
7057 var nMaxWidth = 0;
7058 var nHeight = 0;
7059 for(var i = 0; i < a.length; i += 2)
7060 {
7061 var nWidth0 = context.measureText(a[i]).width;
7062 var nWidth1 = context.measureText(a[i+1]).width;
7063 var nSum = nWidth0 + nWidth1;
7064 WidthArray[i] = nWidth0;
7065 WidthArray[i+1] = nWidth1;
7066 if(nSum > nMaxWidth)
7067 {
7068 nMaxWidth = nSum;
7069 }
7070 nHeight += BoxHeight;
7071 }
7072 nMaxWidth += 15;
7073 //bounds check.
7074 x = Math.max(0, x - 10 - nMaxWidth);
7075 var CanvasRect = Canvas.getBoundingClientRect();
7076 if(y + nHeight > CanvasRect.height)
7077 {
7078 y = CanvasRect.height - nHeight;
7079 x += 20;
7080 }
7081 if(x + nMaxWidth > CanvasRect.width)
7082 {
7083 x = CanvasRect.width - nMaxWidth;
7084 }
7085
7086 context.fillStyle = 'black';
7087 context.fillRect(x-1, y, nMaxWidth+2, nHeight);
7088 context.fillStyle = 'white';
7089
7090 var XPos = x;
7091 var XPosRight = x + nMaxWidth;
7092 var YPos = y + BoxHeight-2;
7093 context.fillStyle = 'white';
7094 for(i = 0; i < a.length; i += 2)
7095 {
7096 if(colors)
7097 context.fillStyle = colors[i];
7098 context.fillText(a[i], XPos, YPos);
7099 if(colors)
7100 context.fillStyle = colors[i+1];
7101 context.fillText(a[i+1], XPosRight - WidthArray[i+1], YPos);
7102 YPos += BoxHeight;
7103 }
7104 context.fillStyle = 'white';
7105 }
7106
7107 function DrawPlotf(Canvas)
7108 {
7109 return;
7110 var context = Canvas.getContext('2d');
7111 context.font = Font;
7112 var WidthArray = Array(PlotfArray.length);
7113 var nMaxWidth = 0;
7114 var nHeight = 0;
7115
7116 context.font = Font;
7117 for(i = 0; i < PlotfArray.length; i++)
7118 {
7119 var nWidth = context.measureText(PlotfArray[i]).width;
7120 WidthArray[i] = nWidth;
7121 if(nWidth > nMaxWidth)
7122 {
7123 nMaxWidth = nWidth;
7124 }
7125 nHeight += BoxHeight;
7126 }
7127 nMaxWidth += 15;
7128 var x = 0;
7129 var y = 0;
7130
7131 context.fillStyle = 'black';
7132 context.fillRect(x-1, y, nMaxWidth+2, nHeight);
7133 context.fillStyle = 'white';
7134
7135 var XPos = x;
7136 var XPosRight = x + nMaxWidth;
7137 var YPos = y + BoxHeight-2;
7138 for(i = 0; i < PlotfArray.length; i++)
7139 {
7140 context.fillText(PlotfArray[i], XPos, YPos);
7141 YPos += BoxHeight;
7142 }
7143 }
7144
7145
7146 function ShiftRight10(v)
7147 {
7148 if(v > 1024)
7149 {
7150 return v / 1024.0;
7151 }
7152 else
7153 {
7154 return v >> 10;
7155 }
7156 }
7157
7158 function FormatCounter(Format, Counter)
7159 {
7160 if(!Counter)
7161 {
7162 return '0';
7163 }
7164 var Negative = 0;
7165 if(Counter < 0)
7166 {
7167 Counter = -Counter;
7168 Negative = 1;
7169 if(Counter < 0) // handle INT_MIN
7170 {
7171 Counter = -(Counter+1);
7172 if(Counter < 0)
7173 {
7174 return '?';
7175 }
7176 }
7177 }
7178 var str = Negative ? '-' :'' ;
7179 if(Format == FormatCounterDefault)
7180 {
7181 var Seperate = 0;
7182 var result = '';
7183 while (Counter)
7184 {
7185 if (Seperate)
7186 {
7187 result += '.';
7188 }
7189 Seperate = 1;
7190 for (var i = 0; Counter && i < 3; ++i)
7191 {
7192 var Digit = Math.floor(Counter % 10);
7193 Counter = Math.floor(Counter / 10);
7194 result += '' + Digit;
7195 }
7196 }
7197
7198 for(var i = 0; i < result.length; ++i)
7199 {
7200 str += result[result.length-1-i];
7201 }
7202 return str;
7203 }
7204 else if(Format == FormatCounterBytes)
7205 {
7206 var Shift = 0;
7207 var Divisor = 1;
7208 var CountShifted = ShiftRight10(Counter);
7209 while(CountShifted)
7210 {
7211 Divisor <<= 10;
7212 CountShifted = ShiftRight10(CountShifted);
7213 Shift++;
7214 }
7215 if(Shift)
7216 {
7217 return str + (Counter / Divisor).toFixed(2) + '' + FormatCounterBytesExt[Shift];
7218 }
7219 else
7220 {
7221 return str + Counter.toFixed(2) + '' + FormatCounterBytesExt[0];
7222 }
7223 }
7224 return '?';
7225 }
7226 function DrawCounterView(View, LocalMouseX, LocalMouseY, SubIndex)
7227 {
7228 var TimerMap = FrameData.TimerMap;
7229 if(!TimerMap)
7230 return;
7231
7232
7233 ProfileEnter("DrawCounterView");
7234
7235 var Canvas = View.Canvas[View.BackBuffer];
7236 var context = Canvas.getContext('2d');
7237 context.clearRect(0, 0, View.w, View.h);
7238
7239
7240
7241 var Height = BoxHeight;
7242 var Width = nWidth;
7243 var nTotalRows = CounterArray.length;
7244 var nTotalRowPixels = nTotalRows * Height;
7245 var nFrameRows = nHeight - BoxHeight;
7246 if(nOffsetCountersY + nFrameRows > nTotalRowPixels && nTotalRowPixels > nFrameRows)
7247 {
7248 nOffsetCountersY = nTotalRowPixels - nFrameRows;
7249 }
7250 var CounterWidth = 150;
7251 var Y = -nOffsetCountersY + BoxHeight;
7252 var X = 0;
7253 var nColorIndex = 0;
7254 context.fillStyle = 'white';
7255 context.font = Font;
7256 var bMouseIn = 0;
7257 function DrawHeaderSplitSingle(Header, Width)
7258 {
7259 context.fillStyle = 'white';
7260 context.fillText(Header, X, Height-FontAscent);
7261 X += Width;
7262 context.fillStyle = nBackColorOffset;
7263 context.fillRect(X-3, 0, 1, nHeight);
7264 }
7265 function DrawHeaderSplitSingleRight(Header, Width)
7266 {
7267 X += Width;
7268 context.fillStyle = 'white';
7269 context.textAlign = 'right';
7270 context.fillText(Header, X - FontWidth, Height-FontAscent);
7271 context.fillStyle = nBackColorOffset;
7272 context.fillRect(X, 0, 1, nHeight);
7273 context.textAlign = 'left';
7274 }
7275 var TimerLen = 6;
7276 var TimerWidth = TimerLen * FontWidth;
7277 nHoverCounter = -1;
7278 function CounterIndent(Level)
7279 {
7280 return Level * 4 * FontWidth;
7281 }
7282 function Max(a, b)
7283 {
7284 return a > b ? a : b;
7285 }
7286
7287 function DrawCounterRecursive(Index)
7288 {
7289 var Counter = TimerArray[Index];
7290 if(Counter.idtype == TYPE_COUNTER)
7291 {
7292 var Indent = CounterIndent(Counter.depth-1);
7293 var X = 0;
7294 nColorIndex = 1-nColorIndex;
7295 var HeightExpanded = Counter.Expanded ? Height * 5 : Height;
7296
7297 bMouseIn = LocalMouseY >= Y && LocalMouseY < Y + HeightExpanded;
7298 if(bMouseIn)
7299 {
7300 nHoverCounter = Index;
7301 }
7302 var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];
7303 context.fillStyle = bgcolor;
7304 context.fillRect(0, Y, Width, HeightExpanded);
7305 context.fillStyle = 'white';
7306 var c = Counter.closed ? '*' : ' ';
7307 context.fillText(c + Counter.name, Indent, Y+Height-FontAscent);
7308 X += CounterNameWidth;
7309 X += CounterValueWidth - FontWidth;
7310 context.textAlign = 'right';
7311 context.fillText(Counter.formatted, X, Y+Height-FontAscent);
7312 context.textAlign = 'left';
7313 X += FontWidth * 4;
7314 var Y0 = Y + 1;
7315 if(Counter.limit != 0)
7316 {
7317 context.fillText(Counter.formattedlimit, X, Y+Height-FontAscent);
7318 X += CounterLimitWidth;
7319 var X0 = X + 1;
7320 context.fillStyle = 'white';
7321 context.fillRect(X0, Y0, Counter.boxprc * (CounterWidth-2), Height-2);
7322 context.fillStyle = bgcolor;
7323 context.fillRect(X0+1, Y0+1, Counter.boxprc * (CounterWidth-4), Height-4);
7324 context.fillStyle = 'cyan';
7325 context.fillRect(X0+1, Y0+1, Counter.counterprc * (CounterWidth-4), Height-4);
7326 X += CounterWidth + 10;
7327 }
7328 else
7329 {
7330 X += CounterLimitWidth;
7331 X += CounterWidth + 10;
7332 }
7333
7334 if(Counter.minvalue != Counter.maxvalue)
7335 {
7336 var CounterHistory = Counter.counterhistory;
7337 var Prc = CounterHistory.prc;
7338 context.fillStyle = 'cyan';
7339 context.strokeStyle = 'cyan';
7340 context.globalAlpha = 0.5;
7341 context.beginPath();
7342 var x = X;
7343 var YBase = Y0 + HeightExpanded-1;
7344 var YOffset = -(HeightExpanded-2);
7345
7346 context.moveTo(X, Y0);
7347 for(var i = 0; i < Prc.length; ++i)
7348 {
7349 context.moveTo(x, YBase);
7350 context.lineTo(x, YBase + Prc[i] * YOffset);
7351 x += 1;
7352 }
7353 context.stroke();
7354
7355 x = X;
7356 context.globalAlpha = 1.0;
7357 context.beginPath();
7358 context.moveTo(X, YBase);
7359
7360 for(var i = 0; i < Prc.length; ++i)
7361 {
7362 context.lineTo(x, YBase + Prc[i] * YOffset);
7363 x += 1;
7364 }
7365 context.stroke();
7366 if(bMouseIn)
7367 {
7368 var MouseGraphX = Math.floor(LocalMouseX - X);
7369 if(MouseGraphX >= 0 && MouseGraphX < CounterHistory.history.length)
7370 {
7371 context.fillStyle = 'white';
7372 var Formatted = FormatCounter(Counter.format, CounterHistory.history[MouseGraphX]);
7373 context.fillText(Formatted, X, Y+Height-FontAscent);
7374 }
7375 context.strokeStyle = 'orange';
7376 context.beginPath();
7377 var CrossX = X + MouseGraphX;
7378 var CrossY = YBase + Prc[MouseGraphX] * YOffset;
7379 context.moveTo(CrossX-2, CrossY-2);
7380 context.lineTo(CrossX+2, CrossY+2);
7381 context.moveTo(CrossX+2, CrossY-2);
7382 context.lineTo(CrossX-2, CrossY+2);
7383 context.stroke();
7384
7385 }
7386 X += Prc.length + 5;
7387 context.fillStyle = 'white';
7388 context.fillText( FormatCounter(Counter.format, Counter.minvalue), X, Y + Height - FontAscent);
7389 X += CounterWidth + 5;
7390 context.fillText( FormatCounter(Counter.format, Counter.maxvalue), X, Y + Height - FontAscent);
7391 X += CounterWidth + 5;
7392 }
7393 Y += HeightExpanded;
7394 }
7395
7396 if(Index == 0 || (!Counter.closed && Counter.idtype == TYPE_COUNTER))
7397 {
7398 var ChildIndex = Counter.firstchild;
7399 while(ChildIndex != -1)
7400 {
7401 DrawCounterRecursive(ChildIndex);
7402 ChildIndex = TimerArray[ChildIndex].sibling;
7403 }
7404 }
7405 }
7406
7407 DrawCounterRecursive(0);
7408
7409 X = 0;
7410 context.fillStyle = nBackColorOffset;
7411 context.fillRect(0, 0, Width, Height);
7412 context.fillStyle = 'white';
7413 DrawHeaderSplitSingle('Name', CounterNameWidth);
7414 DrawHeaderSplitSingleRight('Value', CounterValueWidth + (FontWidth+1));
7415 DrawHeaderSplitSingle('Limit', CounterLimitWidth + CounterWidth + 3 * (FontWidth+1));
7416 ProfileLeave();
7417 }
7418
7419 function ShowHelp(Show, Toggle)
7420 {
7421 var HelpWindow = document.getElementById('helpwindow');
7422 if(Toggle)
7423 {
7424 if(HelpWindow.style['display'] == 'block')
7425 {
7426 HelpWindow.style['display'] = 'none';
7427 }
7428 else
7429 {
7430 HelpWindow.style['display'] = 'block';
7431 }
7432 }
7433 else
7434 {
7435 if(Show)
7436 {
7437 HelpWindow.style['display'] = 'block';
7438 }
7439 else
7440 {
7441 HelpWindow.style['display'] = 'none';
7442 }
7443 }
7444 }
7445
7446 function ParseUrl()
7447 {
7448 var path = window.location.pathname;
7449 var idx = path.indexOf('/');
7450 if(idx < 0)
7451 return;
7452 var StrCommand = path.substring(idx+1);
7453 idx = StrCommand.indexOf('/');
7454 if(idx < 0)
7455 return;
7456 var StrSettings = StrCommand.substring(idx+1);
7457 PresetToLoad = StrSettings;
7458 PresetToLoadRO = StrCommand[0] == 'b';
7459 }
7460
7461
7462 function GetCookie()
7463 {
7464 var result = document.cookie.match(/fisk=([^;]+)/);
7465 if(result && result.length > 0)
7466 {
7467 var Obj = JSON.parse(result[1]);
7468 if(!Obj.offline)
7469 {
7470 var C = {};
7471 C.offline = Obj;
7472 Obj = C;
7473 }
7474 return Obj;
7475 }
7476 else
7477 {
7478 return {offline:{},live:{}};
7479 }
7480 }
7481
7482 function ReadCookie()
7483 {
7484 var C = GetCookie().live;
7485 for(var i in C)
7486 {
7487 Cookie[i] = C[i];
7488 }
7489 }
7490 function WriteCookie()
7491 {
7492 var C = GetCookie();
7493 C.live = {};
7494 for(var i in Cookie)
7495 {
7496 C.live[i] = Cookie[i];
7497 }
7498
7499 var date = new Date();
7500 date.setFullYear(2099);
7501 var cookie = 'fisk=' + JSON.stringify(C) + ';expires=' + date;
7502 document.cookie = cookie;
7503 }
7504
7505 let CSVSets = {};
7506 let CSVIndex = 0;
7507 function CreateCSVSetFile(Set, Filename)
7508 {
7509 let File = {};
7510 File.Name = Filename;
7511 File.DataSorted = [];
7512 File.Data = [];
7513 File.ColumnToIndex = {};
7514 File.ColumnsSorted = {};
7515 File.Columns = {};
7516 return File;
7517
7518 }
7519 function CreateCSVSet()
7520 {
7521 let Index = ++CSVIndex;
7522 let Name = "Drop_" + Index;
7523 let Set = {};
7524 Set.Name = Name;
7525 Set.Files = {};
7526 Set.Columns = {};
7527 Set.ColumnNames = {};
7528 Set.ColumnIndex = 0;
7529 Set.PendingCount = 0;
7530 Set.FinishedCount = 0;
7531 return Set;
7532 }
7533 function ParseCSVCheckFinished(Name)
7534 {
7535 let Set = CSVSets[Name];
7536 console.log("Finished parsing ", Set.FinishedCount, ":", Set.PendingCount);
7537 if(Set.FinishedCount == Set.PendingCount)
7538 {
7539 if(Set.FinishedCount == 0)
7540 {
7541 console.error("No CSV files were parsable");
7542 CSVSets[Name] = null;
7543 }
7544 else
7545 {
7546 for(let CName in Set.ColumnNames)
7547 {
7548 let aggr = {};
7549 let MaxCount = 0;
7550 console.log("aggr for ", CName);
7551 for(let F in Set.Files)
7552 {
7553 let File = Set.Files[F];
7554 if(File.Columns[CName])
7555 MaxCount = Math.max(MaxCount, File.Columns[CName].length);
7556 }
7557 let count = new Array(MaxCount);
7558 let sum = new Array(MaxCount);
7559 let min = new Array(MaxCount);
7560 let max = new Array(MaxCount);
7561 let avg = new Array(MaxCount);
7562 for(let i = 0; i < MaxCount; ++i)
7563 {
7564 count[i] = 0;
7565 sum[i] = 0;
7566 min[i] = 1e28;
7567 max[i] = -1e28;
7568 }
7569 for(let F in Set.Files)
7570 {
7571 let File = Set.Files[F];
7572 if(File.Columns[CName])
7573 {
7574 let c = File.Columns[CName];
7575 for(let i = 0; i < c.length; ++i)
7576 {
7577 count[i]++;
7578 sum[i] += c[i];
7579 min[i] = Math.min(c[i], min[i]);
7580 max[i] = Math.max(c[i], max[i]);
7581
7582 }
7583 }
7584 }
7585 for(let i = 0; i < MaxCount; ++i)
7586 {
7587 if(count[i])
7588 {
7589 avg[i] = sum[i] / count[i];
7590 console.log(".. ", avg[i], " min ", min[i]);
7591 }
7592 else
7593 {
7594 min[i] = 0;
7595 max[i] = 0;
7596 }
7597 }
7598 }
7599 }
7600 }
7601 }
7602 function ParseCSVLine(Line)
7603 {
7604 let Pos = 0;
7605 let Start = 0;
7606 let Len = Line.length;
7607 let InBrackets = 0;
7608 let Out = new Array();
7609 let BracketStart = -1;
7610 let BracketEnd = -1;
7611 let push = function()
7612 {
7613 if(BracketStart >= 0)
7614 {
7615 console.assert(BracketEnd >= 0);
7616 Out.push(Line.slice(BracketStart+1, BracketEnd));
7617 }
7618 else
7619 {
7620 Out.push(Line.slice(Start, Pos).trim());
7621
7622 }
7623 Start = Pos+1;
7624 InBrackets = 0;
7625 BracketStart = -1;
7626 BracketEnd = -1;
7627 };
7628 while(Pos != Len)
7629 {
7630 let Char = Line[Pos];
7631 if(InBrackets)
7632 {
7633 if(Char == "\"")
7634 {
7635 BracketEnd = Pos;
7636 InBrackets = 0;
7637 }
7638 }
7639 else
7640 {
7641 if(Char == "\"")
7642 {
7643 BracketStart = Pos;
7644 InBrackets = 1;
7645 }
7646 else if(Char == ",")
7647 {
7648 push();
7649 }
7650 }
7651 Pos++;
7652 }
7653 push();
7654 return Out;
7655
7656 }
7657
7658 function ParseCSVFile(Set, Result, Name)
7659 {
7660 let File = CreateCSVSetFile(Set, Name);
7661 let Lines = Result.split(/\r?\n/);
7662 let Headers, Data, DataSorted;
7663 let Columns = 0;
7664 for(let i = 0; i < Lines.length; ++i)
7665 {
7666 let LineData = ParseCSVLine(Lines[i]);
7667 if(i == 0)
7668 {
7669 Headers = LineData;
7670 Columns = Headers.length;
7671
7672 Data = new Array(Columns);
7673 DataSorted = new Array(Columns);
7674 File.Data = Data;
7675 File.DataSorted = DataSorted;
7676 for(let j = 0; j < Columns; ++j)
7677 {
7678 Data[j] = new Array();
7679 DataSorted[j] = new Array();
7680
7681 let ColumnName = Headers[j];
7682 File.ColumnToIndex[Headers[j]] = j;
7683 File.Columns[ColumnName] = Data[j];
7684 File.ColumnsSorted[ColumnName] = DataSorted[j];
7685 Set.ColumnNames[ColumnName] = 1;
7686 }
7687 }
7688 else
7689 {
7690 if(LineData.length != Columns)
7691 {
7692 console.error("Failed to parse csv file ", Name);
7693 Set.PendingCount--;
7694 Set.FinishedCount--;
7695 ParseCSVCheckFinished(Set.Name);
7696 debugger;
7697
7698 }
7699 for(let j = 0; j < Columns; ++j)
7700 {
7701 Data[j].push(parseFloat(LineData[j]));
7702 DataSorted[j].push(parseFloat(LineData[j]));
7703 }
7704 }
7705 }
7706 for(let j = 0; j < Columns; ++j)
7707 {
7708 DataSorted[j].sort();
7709
7710 }
7711 Set.Files[Name] = File;
7712 Set.FinishedCount++;
7713 ParseCSVCheckFinished(Set.Name);
7714
7715 }
7716
7717 function ReadCSVFile(Set, File)
7718 {
7719 if(!File)
7720 return;
7721 let Reader = new FileReader();
7722 Reader.onload = function(e) {
7723 ParseCSVFile(Set, e.target.result, File.name);
7724 };
7725 Reader.onprogress = function(e)
7726 {
7727 var m = e.loaded + ":" + e.total + " :: " + e.lengthComputable;
7728 console.log(m);
7729 };
7730 Set.PendingCount++;
7731 Reader.readAsText(File);
7732
7733 }
7734
7735 // magic from stack-overflow somewhere..
7736 function WindowDragEnter(e)
7737 {
7738 LastDropTarget = e.target;
7739 document.querySelector(".dropzone").style.visibility = "";
7740 document.querySelector(".dropzone").style.opacity = 1;
7741 };
7742
7743 function WindowDragLeave(e)
7744 {
7745 if(e.target === LastDropTarget || e.target === document)
7746 {
7747 document.querySelector(".dropzone").style.visibility = "hidden";
7748 document.querySelector(".dropzone").style.opacity = 0;
7749 }
7750 };
7751 function DropHandler(ev)
7752 {
7753 document.querySelector(".dropzone").style.visibility = "hidden";
7754 document.querySelector(".dropzone").style.opacity = 0;
7755 LastDropTarget = null;
7756
7757 let Set = CreateCSVSet();
7758 Set.PendingCount++;
7759 CSVSets[Set.Name] = Set;
7760 for(let i = 0; i < ev.dataTransfer.files.length; ++i)
7761 {
7762 let File = ev.dataTransfer.files[i];
7763 let Name = File.name;
7764 let ExtMatch = Name.match(/\.[0-9a-zA-Z]+$/);
7765 let Ext = ExtMatch ? ExtMatch[0] : "";
7766 if(Ext.toLowerCase() == ".csv")
7767 {
7768 ReadCSVFile(Set, File);
7769 }
7770 else
7771 {
7772 console.log("Not a .csv file!\n" + Name);
7773 }
7774 }
7775 if(0 == Set.PendingCount)
7776 {
7777 window.alert("No dropped CSV files. Please drop one or more csv files to use csv viewer");
7778 }
7779 Set.FinishedCount++;
7780 ParseCSVCheckFinished(Set.Name);
7781 ev.preventDefault();
7782 }
7783
7784 function DragOverHandler(ev)
7785 {
7786 ev.preventDefault();
7787 }
7788
7789
7790
7791 ReadCookie();
7792 ParseUrl();
7793 ResizeCanvas();
7794 SetupEvents();
7795 InitMenu();
7796 window.addEventListener("dragenter", WindowDragEnter);
7797 window.addEventListener("dragleave", WindowDragLeave);
7798 setInterval(Connect, 100);
7799 RequestDraw();
7800
7801
7802 </script>
7803 </body>
7804 </html>