• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium 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.
4
5'use strict';
6
7base.requireStylesheet('tracing.analysis.default_object_view');
8
9base.require('tracing.analysis.analysis_link');
10base.require('tracing.analysis.object_instance_view');
11base.require('tracing.analysis.object_snapshot_view');
12base.require('tracing.analysis.util');
13base.exportTo('tracing.analysis', function() {
14  var tsRound = tracing.analysis.tsRound;
15
16  /*
17   * Displays an object instance in a human readable form.
18   * @constructor
19   */
20  var DefaultObjectSnapshotView = ui.define(
21      'default-object-snapshot-view',
22      tracing.analysis.ObjectSnapshotView);
23
24  DefaultObjectSnapshotView.prototype = {
25    __proto__: tracing.analysis.ObjectSnapshotView.prototype,
26
27    decorate: function() {
28      tracing.analysis.ObjectSnapshotView.prototype.decorate.apply(this);
29      this.classList.add('default-object-view');
30      this.classList.add('default-object-snapshot-view');
31    },
32
33    updateContents: function() {
34      var snapshot = this.objectSnapshot;
35      if (!snapshot) {
36        this.textContent = '';
37        return;
38      }
39      var instance = snapshot.objectInstance;
40
41      var html = '';
42      html += '<div class="title">Snapshot of <a id="instance-link"></a> @ ' +
43          tsRound(snapshot.ts) + 'ms</div>\n';
44      html += '<table>';
45      html += '<tr>';
46      html += '<tr><td>args:</td><td id="args"></td></tr>\n';
47      html += '</table>';
48      this.innerHTML = html;
49
50      // TODO(nduca): ui.decoreate doesn't work when subclassed. So,
51      // replace the template element.
52      var instanceLinkEl = new tracing.analysis.ObjectInstanceLink();
53      instanceLinkEl.objectInstance = instance;
54      var tmp = this.querySelector('#instance-link');
55      tmp.parentElement.replaceChild(instanceLinkEl, tmp);
56
57      var argsEl = this.querySelector('#args');
58      argsEl.textContent = JSON.stringify(
59          snapshot.args,
60          null,
61          2);
62    }
63  };
64
65  /**
66   * Displays an object instance in a human readable form.
67   * @constructor
68   */
69  var DefaultObjectInstanceView = ui.define(
70      'default-object-instance-view',
71      tracing.analysis.ObjectInstanceView);
72
73  DefaultObjectInstanceView.prototype = {
74    __proto__: tracing.analysis.ObjectInstanceView.prototype,
75
76    decorate: function() {
77      tracing.analysis.ObjectInstanceView.prototype.decorate.apply(this);
78      this.classList.add('default-object-view');
79      this.classList.add('default-object-instance-view');
80    },
81
82    updateContents: function() {
83      var instance = this.objectInstance;
84      if (!instance) {
85        this.textContent = '';
86        return;
87      }
88
89      var html = '';
90      html += '<div class="title">' +
91          instance.typeName + ' ' +
92          instance.id + '</div>\n';
93      html += '<table>';
94      html += '<tr>';
95      html += '<tr><td>creationTs:</td><td>' +
96          instance.creationTs + '</td></tr>\n';
97      if (instance.deletionTs != Number.MAX_VALUE) {
98        html += '<tr><td>deletionTs:</td><td>' +
99            instance.deletionTs + '</td></tr>\n';
100      } else {
101        html += '<tr><td>deletionTs:</td><td>not deleted</td></tr>\n';
102      }
103      html += '<tr><td>snapshots:</td><td id="snapshots"></td></tr>\n';
104      html += '</table>';
105      this.innerHTML = html;
106      var snapshotsEl = this.querySelector('#snapshots');
107      instance.snapshots.forEach(function(snapshot) {
108        var snapshotLink = new tracing.analysis.ObjectSnapshotLink();
109        snapshotLink.objectSnapshot = snapshot;
110        snapshotsEl.appendChild(snapshotLink);
111      });
112    }
113  };
114
115  return {
116    DefaultObjectSnapshotView: DefaultObjectSnapshotView,
117    DefaultObjectInstanceView: DefaultObjectInstanceView
118  };
119});
120