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 {formatDurationMicros} from '../helper.mjs'; 5 6import {LogEntry} from './log.mjs'; 7 8export class TimerLogEntry extends LogEntry { 9 constructor(type, startTime, endTime = -1) { 10 super(type, startTime); 11 this._endTime = endTime; 12 this.depth = 0; 13 } 14 15 end(time) { 16 if (this.isInitialized) throw new Error('Invalid timer change'); 17 this._endTime = time; 18 } 19 20 get isInitialized() { 21 return this._endTime !== -1; 22 } 23 24 get startTime() { 25 return this._time; 26 } 27 28 get endTime() { 29 return this._endTime; 30 } 31 32 get duration() { 33 return Math.max(0, this._endTime - this._time); 34 } 35 36 covers(time) { 37 return this._time <= time && time <= this._endTime; 38 } 39 40 get toolTipDict() { 41 const dict = super.toolTipDict; 42 dict.startTime = formatDurationMicros(dict.startTime); 43 dict.endTime = formatDurationMicros(dict.endTime); 44 dict.duration = formatDurationMicros(dict.duration); 45 return dict; 46 } 47 48 static get propertyNames() { 49 return [ 50 'type', 51 'startTime', 52 'endTime', 53 'duration', 54 ]; 55 } 56} 57