1// Copyright 2021 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4import {Profile} from '../../profile.mjs' 5 6import {LogEntry} from './log.mjs'; 7 8export class TickLogEntry extends LogEntry { 9 constructor(time, vmState, processedStack) { 10 super(TickLogEntry.extractType(vmState, processedStack), time); 11 this.state = vmState; 12 this.stack = processedStack; 13 this._endTime = time; 14 } 15 16 end(time) { 17 if (this.isInitialized) throw new Error('Invalid timer change'); 18 this._endTime = time; 19 } 20 21 get isInitialized() { 22 return this._endTime !== this._time; 23 } 24 25 get startTime() { 26 return this._time; 27 } 28 29 get endTime() { 30 return this._endTime; 31 } 32 33 get duration() { 34 return this._endTime - this._time; 35 } 36 37 static extractType(vmState, processedStack) { 38 if (processedStack.length == 0 || vmState == Profile.VMState.IDLE) { 39 return 'Idle'; 40 } 41 const topOfStack = processedStack[0]; 42 if (typeof topOfStack === 'number') { 43 // TODO(cbruni): Handle VmStack and native ticks better. 44 return 'Other'; 45 } 46 if (vmState != Profile.VMState.JS) { 47 topOfStack.vmState = vmState; 48 } 49 return this.extractCodeEntryType(topOfStack); 50 } 51 52 static extractCodeEntryType(entry) { 53 if (entry?.state !== undefined) { 54 return 'JS ' + Profile.getKindFromState(entry.state); 55 } 56 if (entry?.vmState) return Profile.vmStateString(entry.vmState); 57 return 'Other'; 58 } 59} 60