summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/ui/analysis/multi_event_details_table.html
blob: 101137cdcb65d9c8af81bcd2004fe8c16c3f79ad (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<!--
Copyright (c) 2013 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/base.html">
<link rel="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/ui/analysis/generic_object_view.html">
<link rel="import" href="/tracing/ui/analysis/multi_event_summary.html">
<link rel="import" href="/tracing/ui/base/table.html">
<link rel="import" href="/tracing/value/ui/scalar_span.html">
<link rel="import" href="/tracing/value/unit.html">

<polymer-element name='tr-ui-a-multi-event-details-table'>
  <template>
    <style>
    :host {
      display: flex;
      flex-direction: column;
    }
    #table {
      flex: 1 1 auto;
      align-self: stretch;
    }

    #titletable {
      font-weight: bold;
    }

    #title-info {
      font-size: 12px;
    }
    </style>
    <tr-ui-b-table id="titletable">
    </tr-ui-b-table>
    <tr-ui-b-table id="table">
    </tr-ui-b-table>
  </template>

  <script>
  'use strict';

  Polymer({
    created: function() {
      this.selection_ = undefined;
      this.eventsHaveDuration_ = true;
      this.eventsHaveSubRows_ = true;
    },

    ready: function() {
      this.initTitleTable_();
    },

    get eventsHaveDuration() {
      return this.eventsHaveDuration_;
    },

    set eventsHaveDuration(eventsHaveDuration) {
      this.eventsHaveDuration_ = eventsHaveDuration;
      this.updateContents_();
    },

    get eventsHaveSubRows() {
      return this.eventsHaveSubRows_;
    },

    set eventsHaveSubRows(eventsHaveSubRows) {
      this.eventsHaveSubRows_ = eventsHaveSubRows;
      this.updateContents_();
    },

    get selection() {
      return this.selection_;
    },

    set selection(selection) {
      this.selection_ = selection;
      this.updateContents_();
    },

    updateContents_: function() {
      var selection = this.selection_;

      this.updateTitleTable_();

      if (this.selection_ === undefined) {
        this.$.table.tableRows = [];
        this.$.table.tableFooterRows = [];
        this.$.table.rebuild();
        return;
      }

      var summary = new tr.ui.analysis.MultiEventSummary(
          'Totals', this.selection_);
      this.updateColumns_(summary);
      this.updateRows_(summary);
      this.$.table.rebuild();
    },

    initTitleTable_: function() {
      var table = this.$.titletable;

      table.showHeader = false;
      table.tableColumns = [
        {
          title: 'Title',
          value: function(row) { return row.title; },
          width: '350px'
        },
        {
          title: 'Value',
          width: '100%',
          value: function(row) {
            return row.value;
          }
        }
      ];
    },

    getSelectionTitle_: function() {
      if (!this.selection || !this.selection.length)
        return '<No selection>';

      var firstTitle = tr.b.getFirstElement(this.selection).title;
      if (!tr.b.every(this.selection, (event) => event.title === firstTitle))
        return '<Different titles>';

      return firstTitle;
    },

    updateTitleTable_: function() {
      this.$.titletable.tableRows = [{
        title: 'Title',
        value: this.getSelectionTitle_()
      }];
    },

    updateColumns_: function(summary) {
      var hasCpuData;
      if (summary.cpuDuration !== undefined)
        hasCpuData = true;
      if (summary.cpuSelfTime !== undefined)
        hasCpuData = true;

      var colWidthPercentage;
      if (hasCpuData)
        colWidthPercentage = '20%';
      else
        colWidthPercentage = '33.3333%';

      var ownerDocument = this.ownerDocument;
      var columns = [];

      columns.push({
        title: 'Start',
        value: function(row) {
          if (row.__proto__ === tr.ui.analysis.MultiEventSummary.prototype) {
            return row.title;
          }

          var linkEl = document.createElement('tr-ui-a-analysis-link');
          linkEl.setSelectionAndContent(function() {
              return new tr.model.EventSet(row.event);
          });
          linkEl.appendChild(tr.v.ui.createScalarSpan(row.start, {
            unit: tr.v.Unit.byName.timeStampInMs,
            ownerDocument: ownerDocument
          }));
          return linkEl;
        },
        width: '350px',
        cmp: function(rowA, rowB) {
          return rowA.start - rowB.start;
        }
      });

      if (this.eventsHaveDuration_) {
        columns.push({
          title: 'Wall Duration (ms)',
          value: function(row) {
            return tr.v.ui.createScalarSpan(row.duration, {
              unit: tr.v.Unit.byName.timeDurationInMs,
              ownerDocument: ownerDocument
            });
          },
          width: '<upated further down>',
          cmp: function(rowA, rowB) {
            return rowA.duration - rowB.duration;
          }
        });
      }

      if (this.eventsHaveDuration_ && hasCpuData) {
        columns.push({
          title: 'CPU Duration (ms)',
          value: function(row) {
            return tr.v.ui.createScalarSpan(row.cpuDuration, {
              unit: tr.v.Unit.byName.timeDurationInMs,
              ownerDocument: ownerDocument
            });
          },
          width: '<upated further down>',
          cmp: function(rowA, rowB) {
            return rowA.cpuDuration - rowB.cpuDuration;
          }
        });
      }

      if (this.eventsHaveSubRows_ && this.eventsHaveDuration_) {
        columns.push({
          title: 'Self time (ms)',
          value: function(row) {
            return tr.v.ui.createScalarSpan(row.selfTime, {
              unit: tr.v.Unit.byName.timeDurationInMs,
              ownerDocument: ownerDocument
            });
          },
          width: '<upated further down>',
          cmp: function(rowA, rowB) {
            return rowA.selfTime - rowB.selfTime;
          }
        });
      }

      if (this.eventsHaveSubRows_ && this.eventsHaveDuration_ && hasCpuData) {
        columns.push({
          title: 'CPU Self Time (ms)',
          value: function(row) {
            return tr.v.ui.createScalarSpan(row.cpuSelfTime, {
              unit: tr.v.Unit.byName.timeDurationInMs,
              ownerDocument: ownerDocument
            });
          },
          width: '<upated further down>',
          cmp: function(rowA, rowB) {
            return rowA.cpuSelfTime - rowB.cpuSelfTime;
          }
        });
      }

      var argKeys = tr.b.dictionaryKeys(summary.totalledArgs);
      argKeys.sort();

      var otherKeys = summary.untotallableArgs.slice(0);
      otherKeys.sort();

      argKeys.push.apply(argKeys, otherKeys);
      var keysWithColumns = argKeys.slice(0, 4);
      var keysInOtherColumn = argKeys.slice(4);

      keysWithColumns.forEach(function(argKey) {

        var hasTotal = summary.totalledArgs[argKey];
        var colDesc = {
          title: 'Arg: ' + argKey,
          value: function(row) {
            if (row.__proto__ !== tr.ui.analysis.MultiEventSummary.prototype) {
              var argView =
                  document.createElement('tr-ui-a-generic-object-view');
              argView.object = row.args[argKey];
              return argView;
            }
            if (hasTotal)
              return row.totalledArgs[argKey];
            return '';
          },
          width: '<upated further down>'
        };
        if (hasTotal) {
          colDesc.cmp = function(rowA, rowB) {
            return rowA.args[argKey] - rowB.args[argKey];
          };
        }
        columns.push(colDesc);
      });

      if (keysInOtherColumn.length) {
        columns.push({
          title: 'Other Args',
          value: function(row) {
            if (row.__proto__ === tr.ui.analysis.MultiEventSummary.prototype)
              return '';
            var argView =
                document.createElement('tr-ui-a-generic-object-view');
            var obj = {};
            for (var i = 0; i < keysInOtherColumn.length; i++)
              obj[keysInOtherColumn[i]] = row.args[keysInOtherColumn[i]];
            argView.object = obj;
            return argView;
          },
          width: '<upated further down>'
        });
      }

      var colWidthPercentage;
      if (columns.length == 1)
        colWidthPercentage = '100%';
      else
        colWidthPercentage = (100 / (columns.length - 1)).toFixed(3) + '%';

      for (var i = 1; i < columns.length; i++)
        columns[i].width = colWidthPercentage;

      this.$.table.tableColumns = columns;
    },

    updateRows_: function(summary) {
      this.$.table.sortColumnIndex = 0;
      function Row(event) {
        this.event = event;
      }
      Row.prototype = {
        get start() { return this.event.start; },
        get duration() { return this.event.duration; },
        get cpuDuration() { return this.event.cpuDuration; },
        get selfTime() { return this.event.selfTime; },
        get cpuSelfTime() { return this.event.cpuSelfTime; },
        get args() { return this.event.args; }
      };

      this.$.table.tableRows = this.selection_.map(function(event) {
        return new Row(event);
      });
      this.$.table.footerRows = [summary];
    }
  });
</script>
</polymer-element>