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.
7 tvcm.require('tracing.trace_model.event');
9 tvcm.exportTo('tracing.trace_model', function() {
11 * A snapshot of an object instance, at a given moment in time.
13 * Initialization of snapshots and instances is three phased:
15 * 1. Instances and snapshots are constructed. This happens during event
16 * importing. Little should be done here, because the object's data
17 * are still being used by the importer to reconstruct object references.
19 * 2. Instances and snapshtos are preinitialized. This happens after implicit
20 * objects have been found, but before any references have been found and
21 * switched to direct references. Thus, every snapshot stands on its own.
22 * This is a good time to do global field renaming and type conversion,
23 * e.g. recognizing domain-specific types and converting from C++ naming
26 * 3. Instances and snapshtos are initialized. At this point, {id_ref:
27 * '0x1000'} fields have been converted to snapshot references. This is a
28 * good time to generic initialization steps and argument verification.
32 function ObjectSnapshot(objectInstance, ts, args) {
33 tracing.trace_model.Event.call(this);
34 this.objectInstance = objectInstance;
39 ObjectSnapshot.prototype = {
40 __proto__: tracing.trace_model.Event.prototype,
43 * See ObjectSnapshot constructor notes on object initialization.
45 preInitialize: function() {
49 * See ObjectSnapshot constructor notes on object initialization.
51 initialize: function() {
54 addBoundsToRange: function(range) {
55 range.addValue(this.ts);
59 ObjectSnapshot.nameToConstructorMap_ = {};
60 ObjectSnapshot.register = function(name, constructor) {
61 if (ObjectSnapshot.nameToConstructorMap_[name])
62 throw new Error('Constructor already registerd for ' + name);
63 ObjectSnapshot.nameToConstructorMap_[name] = constructor;
66 ObjectSnapshot.unregister = function(name) {
67 delete ObjectSnapshot.nameToConstructorMap_[name];
70 ObjectSnapshot.getConstructor = function(name) {
71 if (ObjectSnapshot.nameToConstructorMap_[name])
72 return ObjectSnapshot.nameToConstructorMap_[name];
73 return ObjectSnapshot;
77 ObjectSnapshot: ObjectSnapshot