Lines Matching full:this

2 // Use of this source code is governed by a BSD-style license that can be
21 // This is the only true formatting, why? For an international audience the
65 this.isEval = false;
68 this.firstEventTimestamp = -1;
69 this.firstParseEventTimestamp = -1;
70 this.firstCompileEventTimestamp = -1;
71 this.lastParseEventTimestamp = -1;
72 this.lastEventTimestamp = -1;
73 this.deserializationTimestamp = -1;
75 this.preparseTimestamp = -1;
76 this.parseTimestamp = -1;
77 this.parse2Timestamp = -1;
78 this.resolutionTimestamp = -1;
79 this.compileTimestamp = -1;
80 this.lazyCompileTimestamp = -1;
81 this.executionTimestamp = -1;
82 this.optimizationTimestamp = -1;
84 this.deserializationDuration = -0.0;
85 this.preparseDuration = -0.0;
86 this.parseDuration = -0.0;
87 this.parse2Duration = -0.0;
88 this.resolutionDuration = -0.0;
89 this.scopeResolutionDuration = -0.0;
90 this.lazyCompileDuration = -0.0;
91 this.compileDuration = -0.0;
92 this.optimizeDuration = -0.0;
94 this.ownBytes = -1;
95 this.compilationCacheHits = [];
99 this.firstEventTimestamp = this.timestampMin(
100 this.deserializationTimestamp, this.parseTimestamp,
101 this.preparseTimestamp, this.resolutionTimestamp,
102 this.executionTimestamp);
104 this.firstParseEventTimestamp = this.timestampMin(
105 this.deserializationTimestamp, this.parseTimestamp,
106 this.preparseTimestamp, this.resolutionTimestamp);
108 this.firstCompileEventTimestamp = this.rawTimestampMin(
109 this.deserializationTimestamp, this.compileTimestamp,
110 this.lazyCompileTimestamp);
112 if (this.hasBeenExecuted() &&
113 (this.firstCompileEventTimestamp <= 0 ||
114 this.executionTimestamp < this.firstCompileTimestamp)) {
115 console.error('Compile < execution timestamp', this);
118 if (this.ownBytes < 0) console.error(this, 'Own bytes must be positive');
122 return this.executionTimestamp > 0;
126 this.compilationCacheHits.push(timestamp);
139 let result = this.rawTimestampMin(...timestamps);
142 'Invalid timestamp min:', {result, timestamps, script: this});
153 'Invalid timestamp max:', {result, timestamps, script: this});
167 this.file = '';
168 this.id = id;
170 this.isNative = false;
171 this.isBackgroundCompiled = false;
172 this.isStreamingCompiled = false;
174 this.funktions = [];
175 this.metrics = new Map();
176 this.maxNestingLevel = 0;
178 this.width = 0;
179 this.bytesTotal = -1;
180 this.finalized = false;
181 this.summary = '';
182 this.source = '';
186 this.file = name;
187 this.isNative = name.startsWith('native ');
191 return this.funktions.length === 0;
195 if (!this.isEval && start === 0) {
198 if (this.finalized) {
199 return this.funktions.find(funktion => funktion.start == start);
201 return this.funktions[start];
206 if (!this.finalized) throw 'Incomplete script';
207 for (let i = this.funktions.length - 1; i >= 0; i--) {
208 let funktion = this.funktions[i];
215 if (this.finalized) throw 'script is finalized!';
217 if (this.funktions[fn.start] === void 0) {
218 this.addFunktion(fn);
224 if (this.finalized) throw 'script is finalized!';
226 if (this.funktions[fn.start] !== void 0) {
230 this.funktions[fn.start] = fn;
234 this.finalized = true;
236 this.funktions = this.funktions.filter(each => true);
240 this.funktions.forEach(fn => {
241 fn.isEval = this.isEval;
261 this.funktions.forEach(fn => {
264 funktionFirstParseEventTimestamp = this.timestampMin(
267 this.lastParseEventTimestamp = this.timestampMax(
268 this.lastParseEventTimestamp, fn.lastParseEventTimestamp);
270 this.lastEventTimestamp =
271 this.timestampMax(this.lastEventTimestamp, fn.lastEventTimestamp);
273 this.maxNestingLevel = maxNesting;
276 if (!this.ownBytes === -1) throw 'Invalid state';
277 if (this.funktions.length == 0) {
278 this.bytesTotal = this.ownBytes = 0;
281 let toplevelFunktionBytes = this.funktions.reduce(
283 if (this.isDeserialized || this.isEval || this.isStreamingCompiled) {
284 if (this.getBytes() === -1) {
285 this.bytesTotal = toplevelFunktionBytes;
288 this.ownBytes = this.bytesTotal - toplevelFunktionBytes;
292 if (funktionFirstParseEventTimestamp < this.firstParseEventTimestamp) {
294 'invalid firstCompileEventTimestamp', this,
295 funktionFirstParseEventTimestamp, this.firstParseEventTimestamp);
300 console.log(this.toString());
304 let str = `SCRIPT id=${this.id} file=${this.file}\n` +
305 `functions[${this.funktions.length}]:`;
306 this.funktions.forEach(fn => str += fn.toString());
311 return this.bytesTotal;
315 return this.ownBytes;
320 if (name == 'lazyCompileTimestamp') return this.getOwnBytes();
321 return this.getOwnBytes();
325 return this[name];
329 fn(this);
330 this.funktions.forEach(fn);
335 return [this];
339 let log = (str) => this.summary += str + '\n';
340 log("SCRIPT: " + this.id);
341 let all = this.funktions;
354 BYTES(ownBytes, this.bytesTotal).padStart(10);
356 this.metrics.set(name + "-bytes", ownBytes);
357 this.metrics.set(name + "-count", funktions.length);
358 this.metrics.set(name + "-count-percent", nofPercent);
359 this.metrics.set(name + "-bytes-percent",
360 Math.round(ownBytes / this.bytesTotal * 100));
363 log(" - file: " + this.file);
365 'isEval=' + this.isEval + ' deserialized=' + this.isDeserialized +
366 ' streamed=' + this.isStreamingCompiled);
367 info("scripts", this.getScripts());
382 parsingCost.setMetrics(this.metrics);
387 preParsingCost.setMetrics(this.metrics);
392 resolutionCost.setMetrics(this.metrics);
396 nesting.setMetrics(this.metrics);
399 if (printSummary) console.log(this.summary);
413 // To reduce the time spent iterating over the funktions of this script
437 this.forEach(funktionOrScript => {
507 return this.funktions.filter(
517 this.scripts = [];
522 // Funktion one by one to keep this.funktions packed.
523 script.funktions.forEach(fn => this.funktions.push(fn));
524 this.scripts.push(script);
525 this.bytesTotal += script.bytesTotal;
530 this.scripts.forEach(script => script.forEach(fn));
534 return this.scripts;
544 this.accumulator = [0, 0, 0, 0, 0];
546 this.max = 0;
548 this.avg = 0;
549 this.totalBytes = 0;
551 funktions.forEach(each => each.accumulateNestingLevel(this.accumulator));
552 this.max = this.accumulator.reduce((max, each) => Math.max(max, each), 0);
553 this.totalBytes = this.accumulator.reduce((sum, each) => sum + each, 0);
554 for (let i = 0; i < this.accumulator.length; i++) {
555 this.avg += this.accumulator[i] * i;
557 this.avg /= this.totalBytes;
561 console.log(this.toString())
566 let accString = this.accumulator.reduce((str, each) => {
567 let index = Math.round(each / this.max * (ticks.length - 1));
570 let percent0 = this.accumulator[0]
571 let percent1 = this.accumulator[1];
572 let percent2plus = this.accumulator.slice(2)
575 ' avg=' + formatNumber(this.avg) +
576 ' l0=' + PERCENT(percent0, this.totalBytes) +
577 ' l1=' + PERCENT(percent1, this.totalBytes) +
578 ' l2+=' + PERCENT(percent2plus, this.totalBytes) +
588 this.prefix = prefix;
590 this.executedCost = 0
592 this.nonExecutedCost = 0;
594 this.executedCost = funktions.reduce((sum, each) => {
597 this.nonExecutedCost = funktions.reduce((sum, each) => {
604 console.log(this.toString())
608 return (' - ' + this.prefix + '-time:').padEnd(24) +
609 (" executed=" + formatNumber(this.executedCost) + 'ms').padEnd(20) +
610 " non-executed=" + formatNumber(this.nonExecutedCost) + 'ms';
614 dict.set('parseMetric', this.executionCost);
615 dict.set('parseMetricNegative', this.nonExecutionCost);
632 this.name = name;
633 this.start = start;
634 this.end = end;
635 this.script = script;
636 this.parent = null;
637 this.nested = [];
638 this.nestingLevel = 0;
640 if (script) this.script.addFunktion(this);
644 this.lastParseEventTimestamp = Math.max(
645 this.preparseTimestamp + this.preparseDuration,
646 this.parseTimestamp + this.parseDuration,
647 this.resolutionTimestamp + this.resolutionDuration);
648 if (!(this.lastParseEventTimestamp > 0)) this.lastParseEventTimestamp = 0;
650 this.lastEventTimestamp =
651 Math.max(this.lastParseEventTimestamp, this.executionTimestamp);
652 if (!(this.lastEventTimestamp > 0)) this.lastEventTimestamp = 0;
654 this.ownBytes = this.nested.reduce(
655 (bytes, each) => bytes - each.getBytes(), this.getBytes());
661 if (name == 'lazyCompileTimestamp') return this.getOwnBytes();
662 return this.getOwnBytes();
667 return this[name];
671 if (this.script != funktion.script) throw "Incompatible script";
672 return funktion.start < this.start && this.end <= funktion.end;
676 return this.parent === null;
680 return this.start <= position && position <= this.end;
684 let value = accumulator[this.nestingLevel] || 0;
685 accumulator[this.nestingLevel] = value + this.getOwnBytes();
689 if (this.script != child.script) throw "Incompatible script";
691 this.nested.push(child);
692 if (this.nested.length > 1) {
695 let last = this.nested[this.nested.length - 2];
701 child.nestingLevel = this.nestingLevel + 1;
706 return this.end - this.start;
710 return this.ownBytes;
714 let value = this[name + 'Timestamp'];
719 console.log(this.toString());
723 let result = 'function' + (this.name ? ' ' + this.name : '') +
724 `() range=${this.start}-${this.end}`;
725 if (details) result += ` script=${this.script ? this.script.id : 'X'}`;
750 this.dispatchTable_ = {
751 // Avoid accidental leaking of __proto__ properties and force this object
762 processor: this.processFunctionEvent
769 processor: this.processCompilationCacheEvent
773 processor: this.processScriptEvent
778 processor: this.processScriptDetails
782 processor: this.processScriptSource
785 this.functionEventDispatchTable_ = {
786 // Avoid accidental leaking of __proto__ properties and force this object
789 'full-parse': this.processFull.bind(this),
790 'parse-function': this.processParseFunction.bind(this),
793 'parse': this.processParseFunction.bind(this),
794 'parse-script': this.processParseScript.bind(this),
795 'parse-eval': this.processParseEval.bind(this),
796 'preparse-no-resolution': this.processPreparseNoResolution.bind(this),
797 'preparse-resolution': this.processPreparseResolution.bind(this),
798 'first-execution': this.processFirstExecution.bind(this),
799 'compile-lazy': this.processCompileLazy.bind(this),
800 'compile': this.processCompile.bind(this),
801 'compile-eval': this.processCompileEval.bind(this),
802 'optimize-lazy': this.processOptimizeLazy.bind(this),
803 'deserialize': this.processDeserialize.bind(this),
806 this.idToScript = new Map();
807 this.fileToScript = new Map();
808 this.nameToFunction = new Map();
809 this.scripts = [];
810 this.totalScript = new TotalScript();
811 this.firstEventTimestamp = -1;
812 this.lastParseEventTimestamp = -1;
813 this.lastEventTimestamp = -1;
818 this.idToScript.forEach(script => script.print());
834 this.processLogLine(line);
836 this.postProcess();
840 this.collectEntries = true
841 this.lastLogFileName_ = fileName;
844 this.processLogLine(line);
846 this.postProcess();
850 this.scripts = Array.from(this.idToScript.values())
853 this.scripts.forEach(script => {
858 this.scripts.forEach(script => this.totalScript.addAllFunktions(script));
859 this.totalScript.calculateMetrics(true);
861 this.firstEventTimestamp = this.totalScript.timestampMin(
862 this.scripts.map(each => each.firstEventTimestamp));
863 this.lastParseEventTimestamp = this.totalScript.timestampMax(
864 this.scripts.map(each => each.lastParseEventTimestamp));
865 this.lastEventTimestamp = this.totalScript.timestampMax(
866 this.scripts.map(each => each.lastEventTimestamp));
878 this.totalScript.getAccumulatedTimeMetrics(
879 metrics, 0, this.lastEventTimestamp, 10);
885 let handlerFn = this.functionEventDispatchTable_[eventName];
895 this.entries.push(entry);
899 return this.idToScript.get(id);
905 return this.lookupFunktionByRange(startPosition, endPosition);
907 let script = this.lookupScript(scriptId);
918 this.idToScript.forEach(script => {
928 let results = this.lookupFunktionsByRange(start, end);
934 let script = this.idToScript.get(scriptId);
941 this.idToScript.set(scriptId, script);
971 let script = this.lookupScript(scriptId);
976 let script = this.lookupScript(scriptId);
985 let script = this.processParseScript(...arguments);
992 // This should only happen for eval.
993 let script = this.lookupScript(scriptId);
997 let funktion = this.getOrCreateFunction(...arguments);
998 // TODO(cbruni): this should never happen, emit differen event from the
1007 let funktion = this.getOrCreateFunction(...arguments);
1015 let script = this.lookupScript(scriptId);
1024 let funktion = this.getOrCreateFunction(...arguments);
1025 // TODO(cbruni): this should never happen, emit different event from the
1034 let funktion = this.getOrCreateFunction(...arguments);
1041 let script = this.lookupScript(scriptId);
1059 let funktion = this.getOrCreateFunction(...arguments);
1066 let script = this.lookupScript(scriptId);
1075 // This should not happen since any funktion has to be parsed first.
1087 let compilationUnit = this.processCompile(...arguments);
1093 let compilationUnit = this.lookupScript(scriptId);
1098 // This should not happen since any funktion has to be parsed first.
1109 let compilationUnit = this.lookupScript(scriptId);
1113 compilationUnit = this.getOrCreateFunction(...arguments);
1122 let compilationUnit = this.lookupScript(scriptId);