11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ciimport {formatBytes} from '../helper.mjs'; 51cb0ef41Sopenharmony_ciimport {LogEntry} from './log.mjs'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciclass CodeString { 81cb0ef41Sopenharmony_ci constructor(string) { 91cb0ef41Sopenharmony_ci if (typeof string !== 'string') { 101cb0ef41Sopenharmony_ci throw new Error('Expected string'); 111cb0ef41Sopenharmony_ci } 121cb0ef41Sopenharmony_ci this.string = string; 131cb0ef41Sopenharmony_ci } 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci get isCode() { 161cb0ef41Sopenharmony_ci return true; 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci toString() { 201cb0ef41Sopenharmony_ci return this.string; 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciexport class DeoptLogEntry extends LogEntry { 251cb0ef41Sopenharmony_ci constructor( 261cb0ef41Sopenharmony_ci type, time, entry, deoptReason, deoptLocation, scriptOffset, 271cb0ef41Sopenharmony_ci instructionStart, codeSize, inliningId) { 281cb0ef41Sopenharmony_ci super(type, time); 291cb0ef41Sopenharmony_ci this._entry = entry; 301cb0ef41Sopenharmony_ci this._reason = deoptReason; 311cb0ef41Sopenharmony_ci this._location = deoptLocation; 321cb0ef41Sopenharmony_ci this._scriptOffset = scriptOffset; 331cb0ef41Sopenharmony_ci this._instructionStart = instructionStart; 341cb0ef41Sopenharmony_ci this._codeSize = codeSize; 351cb0ef41Sopenharmony_ci this._inliningId = inliningId; 361cb0ef41Sopenharmony_ci this.fileSourcePosition = undefined; 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci get reason() { 401cb0ef41Sopenharmony_ci return this._reason; 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci get location() { 441cb0ef41Sopenharmony_ci return this._location; 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci get entry() { 481cb0ef41Sopenharmony_ci return this._entry; 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci get code() { 521cb0ef41Sopenharmony_ci return this._entry?.logEntry; 531cb0ef41Sopenharmony_ci } 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci get functionName() { 561cb0ef41Sopenharmony_ci return this._entry.functionName; 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci static get propertyNames() { 601cb0ef41Sopenharmony_ci return [ 611cb0ef41Sopenharmony_ci 'type', 'reason', 'functionName', 'sourcePosition', 621cb0ef41Sopenharmony_ci 'functionSourcePosition', 'script', 'code' 631cb0ef41Sopenharmony_ci ]; 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ciclass CodeLikeLogEntry extends LogEntry { 681cb0ef41Sopenharmony_ci constructor(type, time, profilerEntry) { 691cb0ef41Sopenharmony_ci super(type, time); 701cb0ef41Sopenharmony_ci this._entry = profilerEntry; 711cb0ef41Sopenharmony_ci profilerEntry.logEntry = this; 721cb0ef41Sopenharmony_ci this._relatedEntries = []; 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci get entry() { 761cb0ef41Sopenharmony_ci return this._entry; 771cb0ef41Sopenharmony_ci } 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci add(entry) { 801cb0ef41Sopenharmony_ci this._relatedEntries.push(entry); 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci relatedEntries() { 841cb0ef41Sopenharmony_ci return this._relatedEntries; 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci} 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ciexport class CodeLogEntry extends CodeLikeLogEntry { 891cb0ef41Sopenharmony_ci constructor(type, time, kindName, kind, profilerEntry) { 901cb0ef41Sopenharmony_ci super(type, time, profilerEntry); 911cb0ef41Sopenharmony_ci this._kind = kind; 921cb0ef41Sopenharmony_ci this._kindName = kindName; 931cb0ef41Sopenharmony_ci this._feedbackVector = undefined; 941cb0ef41Sopenharmony_ci } 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci get kind() { 971cb0ef41Sopenharmony_ci return this._kind; 981cb0ef41Sopenharmony_ci } 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci get isBuiltinKind() { 1011cb0ef41Sopenharmony_ci return this._kindName === 'Builtin'; 1021cb0ef41Sopenharmony_ci } 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci get isBytecodeKind() { 1051cb0ef41Sopenharmony_ci return this._kindName === 'Unopt'; 1061cb0ef41Sopenharmony_ci } 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci get kindName() { 1091cb0ef41Sopenharmony_ci return this._kindName; 1101cb0ef41Sopenharmony_ci } 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci get functionName() { 1131cb0ef41Sopenharmony_ci return this._entry.functionName ?? this._entry.getRawName(); 1141cb0ef41Sopenharmony_ci } 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_ci get size() { 1171cb0ef41Sopenharmony_ci return this._entry.size; 1181cb0ef41Sopenharmony_ci } 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci get source() { 1211cb0ef41Sopenharmony_ci return this._entry?.getSourceCode() ?? ''; 1221cb0ef41Sopenharmony_ci } 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_ci get code() { 1251cb0ef41Sopenharmony_ci return this._entry?.source?.disassemble; 1261cb0ef41Sopenharmony_ci } 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci get variants() { 1291cb0ef41Sopenharmony_ci const entries = Array.from(this.entry?.func?.codeEntries ?? []); 1301cb0ef41Sopenharmony_ci return entries.map(each => each.logEntry); 1311cb0ef41Sopenharmony_ci } 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci get feedbackVector() { 1341cb0ef41Sopenharmony_ci return this._feedbackVector; 1351cb0ef41Sopenharmony_ci } 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ci setFeedbackVector(fbv) { 1381cb0ef41Sopenharmony_ci if (this._feedbackVector) { 1391cb0ef41Sopenharmony_ci throw new Error('Double setting FeedbackVector'); 1401cb0ef41Sopenharmony_ci } 1411cb0ef41Sopenharmony_ci this._feedbackVector = fbv; 1421cb0ef41Sopenharmony_ci } 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_ci toString() { 1451cb0ef41Sopenharmony_ci return `Code(${this.type})`; 1461cb0ef41Sopenharmony_ci } 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci get toolTipDict() { 1491cb0ef41Sopenharmony_ci const dict = super.toolTipDict; 1501cb0ef41Sopenharmony_ci dict.size = formatBytes(dict.size); 1511cb0ef41Sopenharmony_ci dict.source = new CodeString(dict.source); 1521cb0ef41Sopenharmony_ci dict.code = new CodeString(dict.code); 1531cb0ef41Sopenharmony_ci return dict; 1541cb0ef41Sopenharmony_ci } 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci static get propertyNames() { 1571cb0ef41Sopenharmony_ci return [ 1581cb0ef41Sopenharmony_ci 'functionName', 'sourcePosition', 'kindName', 'size', 'type', 'kind', 1591cb0ef41Sopenharmony_ci 'script', 'source', 'code', 'feedbackVector', 'variants' 1601cb0ef41Sopenharmony_ci ]; 1611cb0ef41Sopenharmony_ci } 1621cb0ef41Sopenharmony_ci} 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_ciexport class FeedbackVectorEntry extends LogEntry { 1651cb0ef41Sopenharmony_ci constructor( 1661cb0ef41Sopenharmony_ci timestamp, codeEntry, fbvAddress, length, optimizationMarker, 1671cb0ef41Sopenharmony_ci optimizationTier, invocationCount, profilerTicks, string) { 1681cb0ef41Sopenharmony_ci super('FeedbackVector', timestamp); 1691cb0ef41Sopenharmony_ci this._length = length; 1701cb0ef41Sopenharmony_ci this._code = codeEntry; 1711cb0ef41Sopenharmony_ci this._string = string; 1721cb0ef41Sopenharmony_ci this._optimizationMarker = optimizationMarker; 1731cb0ef41Sopenharmony_ci this._optimizationTier = optimizationTier; 1741cb0ef41Sopenharmony_ci this._invocationCount = invocationCount; 1751cb0ef41Sopenharmony_ci this._profilerTicks = profilerTicks; 1761cb0ef41Sopenharmony_ci } 1771cb0ef41Sopenharmony_ci 1781cb0ef41Sopenharmony_ci toString() { 1791cb0ef41Sopenharmony_ci return `FeedbackVector(l=${this.length})` 1801cb0ef41Sopenharmony_ci } 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci get length() { 1831cb0ef41Sopenharmony_ci return this._length; 1841cb0ef41Sopenharmony_ci } 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_ci get code() { 1871cb0ef41Sopenharmony_ci return this._code; 1881cb0ef41Sopenharmony_ci } 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci get string() { 1911cb0ef41Sopenharmony_ci return this._string; 1921cb0ef41Sopenharmony_ci } 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci get optimizationMarker() { 1951cb0ef41Sopenharmony_ci return this._optimizationMarker; 1961cb0ef41Sopenharmony_ci } 1971cb0ef41Sopenharmony_ci 1981cb0ef41Sopenharmony_ci get optimizationTier() { 1991cb0ef41Sopenharmony_ci return this._optimizationTier; 2001cb0ef41Sopenharmony_ci } 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci get invocationCount() { 2031cb0ef41Sopenharmony_ci return this._invocationCount; 2041cb0ef41Sopenharmony_ci } 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_ci get profilerTicks() { 2071cb0ef41Sopenharmony_ci return this._profilerTicks; 2081cb0ef41Sopenharmony_ci } 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci static get propertyNames() { 2111cb0ef41Sopenharmony_ci return [ 2121cb0ef41Sopenharmony_ci 'length', 'length', 'code', 'optimizationMarker', 'optimizationTier', 2131cb0ef41Sopenharmony_ci 'invocationCount', 'profilerTicks', 'string' 2141cb0ef41Sopenharmony_ci ]; 2151cb0ef41Sopenharmony_ci } 2161cb0ef41Sopenharmony_ci} 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ciexport class SharedLibLogEntry extends CodeLikeLogEntry { 2191cb0ef41Sopenharmony_ci constructor(profilerEntry) { 2201cb0ef41Sopenharmony_ci super('SHARED_LIB', 0, profilerEntry); 2211cb0ef41Sopenharmony_ci } 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ci get name() { 2241cb0ef41Sopenharmony_ci return this._entry.name; 2251cb0ef41Sopenharmony_ci } 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ci toString() { 2281cb0ef41Sopenharmony_ci return `SharedLib`; 2291cb0ef41Sopenharmony_ci } 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_ci static get propertyNames() { 2321cb0ef41Sopenharmony_ci return ['name']; 2331cb0ef41Sopenharmony_ci } 2341cb0ef41Sopenharmony_ci} 235