timer.mjs 1.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {formatDurationMicros} from '../helper.mjs';

import {LogEntry} from './log.mjs';

export class TimerLogEntry extends LogEntry {
  constructor(type, startTime, endTime = -1) {
    super(type, startTime);
    this._endTime = endTime;
    this.depth = 0;
  }

  end(time) {
    if (this.isInitialized) throw new Error('Invalid timer change');
    this._endTime = time;
  }

  get isInitialized() {
    return this._endTime !== -1;
  }

  get startTime() {
    return this._time;
  }

  get endTime() {
    return this._endTime;
  }

  get duration() {
    return this._endTime - this._time;
  }

  covers(time) {
    return this._time <= time && time <= this._endTime;
  }

  get toolTipDict() {
    const dict = super.toolTipDict;
    dict.startTime = formatDurationMicros(dict.startTime);
    dict.endTime = formatDurationMicros(dict.endTime);
    dict.duration = formatDurationMicros(dict.duration);
    return dict;
  }

  static get propertyNames() {
    return [
      'type',
      'startTime',
      'endTime',
      'duration',
    ];
  }
}