1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/extension_registry.html">
9<link rel="import" href="/tracing/model/event.html">
10<link rel="import" href="/tracing/value/unit.html">
11
12<script>
13'use strict';
14
15tr.exportTo('tr.model', function() {
16  /**
17   * A snapshot of an object instance, at a given moment in time.
18   *
19   * Initialization of snapshots and instances is three phased:
20   *
21   * 1. Instances and snapshots are constructed. This happens during event
22   *    importing. Little should be done here, because the object's data
23   *    are still being used by the importer to reconstruct object references.
24   *
25   * 2. Instances and snapshtos are preinitialized. This happens after implicit
26   *    objects have been found, but before any references have been found and
27   *    switched to direct references. Thus, every snapshot stands on its own.
28   *    This is a good time to do global field renaming and type conversion,
29   *    e.g. recognizing domain-specific types and converting from C++ naming
30   *    convention to JS.
31   *
32   * 3. Instances and snapshtos are initialized. At this point, {id_ref:
33   *    '0x1000'} fields have been converted to snapshot references. This is a
34   *    good time to generic initialization steps and argument verification.
35   *
36   * @constructor
37   */
38  function ObjectSnapshot(objectInstance, ts, args) {
39    tr.model.Event.call(this);
40    this.objectInstance = objectInstance;
41    this.ts = ts;
42    this.args = args;
43  }
44
45  ObjectSnapshot.prototype = {
46    __proto__: tr.model.Event.prototype,
47
48    /**
49     * See ObjectSnapshot constructor notes on object initialization.
50     */
51    preInitialize: function() {
52    },
53
54    /**
55     * See ObjectSnapshot constructor notes on object initialization.
56     */
57    initialize: function() {
58    },
59
60    addBoundsToRange: function(range) {
61      range.addValue(this.ts);
62    },
63
64    get userFriendlyName() {
65      return 'Snapshot of ' +
66             this.objectInstance.typeName + ' ' +
67             this.objectInstance.id + ' @ ' +
68             tr.v.Unit.byName.timeStampInMs.format(this.ts);
69    }
70  };
71
72  tr.model.EventRegistry.register(
73      ObjectSnapshot,
74      {
75        name: 'objectSnapshot',
76        pluralName: 'objectSnapshots',
77        singleViewElementName: 'tr-ui-a-single-object-snapshot-sub-view',
78        multiViewElementName: 'tr-ui-a-multi-object-sub-view'
79      });
80
81  var options = new tr.b.ExtensionRegistryOptions(
82      tr.b.TYPE_BASED_REGISTRY_MODE);
83  options.mandatoryBaseClass = ObjectSnapshot;
84  options.defaultConstructor = ObjectSnapshot;
85  tr.b.decorateExtensionRegistry(ObjectSnapshot, options);
86
87  return {
88    ObjectSnapshot: ObjectSnapshot
89  };
90});
91</script>
92