summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/model/frame.html
blob: d6bc6195bf2459d387e1cda2ca72270c7cd2124a (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/color_scheme.html">
<link rel="import" href="/tracing/base/statistics.html">
<link rel="import" href="/tracing/model/event.html">
<link rel="import" href="/tracing/model/event_set.html">

<script>
'use strict';

/**
 * @fileoverview Class describing rendered frames.
 *
 * Because a frame is produced by multiple threads, it does not inherit from
 * TimedEvent, and has no duration.
 */
tr.exportTo('tr.model', function() {
  var ColorScheme = tr.b.ColorScheme;
  var Statistics = tr.b.Statistics;

  var FRAME_PERF_CLASS = {
    GOOD: 'good',
    BAD: 'bad',
    TERRIBLE: 'terrible',
    NEUTRAL: 'generic_work'
  };

  /**
   * @constructor
   * @param {Array} associatedEvents Selection of events composing the frame.
   * @param {Array} threadTimeRanges Array of {thread, start, end}
   * for each thread, describing the critical path of the frame.
   */
  function Frame(associatedEvents, threadTimeRanges, opt_args) {
    tr.model.Event.call(this);

    this.threadTimeRanges = threadTimeRanges;
    this.associatedEvents = new tr.model.EventSet(associatedEvents);
    this.args = opt_args || {};

    this.title = 'Frame';
    this.start = Statistics.min(
        threadTimeRanges, function(x) { return x.start; });
    this.end = Statistics.max(
        threadTimeRanges, function(x) { return x.end; });
    this.totalDuration = Statistics.sum(
        threadTimeRanges, function(x) { return x.end - x.start; });

    this.perfClass = FRAME_PERF_CLASS.NEUTRAL;
  };

  Frame.prototype = {
    __proto__: tr.model.Event.prototype,

    set perfClass(perfClass) {
      this.colorId = ColorScheme.getColorIdForReservedName(perfClass);
      this.perfClass_ = perfClass;
    },

    get perfClass() {
      return this.perfClass_;
    },

    shiftTimestampsForward: function(amount) {
      this.start += amount;
      this.end += amount;

      for (var i = 0; i < this.threadTimeRanges.length; i++) {
        this.threadTimeRanges[i].start += amount;
        this.threadTimeRanges[i].end += amount;
      }
    },

    addBoundsToRange: function(range) {
      range.addValue(this.start);
      range.addValue(this.end);
    }
  };

  tr.model.EventRegistry.register(
      Frame,
      {
        name: 'frame',
        pluralName: 'frames',
        singleViewElementName: 'tr-ui-a-single-frame-sub-view',
        multiViewElementName: 'tr-ui-a-multi-frame-sub-view'
      });

  return {
    Frame: Frame,
    FRAME_PERF_CLASS: FRAME_PERF_CLASS
  };
});
</script>