1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 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/model/timed_event.html"> 9 10<script> 11'use strict'; 12 13/** 14 * @fileoverview Provides the ContainerMemoryDump class. 15 */ 16tr.exportTo('tr.model', function() { 17 /** 18 * The ContainerMemoryDump represents an abstract container memory dump. 19 * @constructor 20 */ 21 function ContainerMemoryDump(start) { 22 tr.model.TimedEvent.call(this, start); 23 24 // 'light' or 'detailed' memory dump. See 25 // base::trace_event::MemoryDumpLevelOfDetail in the Chromium 26 // repository. 27 this.levelOfDetail = undefined; 28 29 this.memoryAllocatorDumps_ = undefined; 30 this.memoryAllocatorDumpsByFullName_ = undefined; 31 }; 32 33 ContainerMemoryDump.prototype = { 34 __proto__: tr.model.TimedEvent.prototype, 35 36 shiftTimestampsForward: function(amount) { 37 this.start += amount; 38 }, 39 40 get memoryAllocatorDumps() { 41 return this.memoryAllocatorDumps_; 42 }, 43 44 set memoryAllocatorDumps(memoryAllocatorDumps) { 45 this.memoryAllocatorDumps_ = memoryAllocatorDumps; 46 this.forceRebuildingMemoryAllocatorDumpByFullNameIndex(); 47 }, 48 49 getMemoryAllocatorDumpByFullName: function(fullName) { 50 if (this.memoryAllocatorDumps_ === undefined) 51 return undefined; 52 53 // Lazily generate the index if necessary. 54 if (this.memoryAllocatorDumpsByFullName_ === undefined) { 55 var index = {}; 56 function addDumpsToIndex(dumps) { 57 dumps.forEach(function(dump) { 58 index[dump.fullName] = dump; 59 addDumpsToIndex(dump.children); 60 }); 61 }; 62 addDumpsToIndex(this.memoryAllocatorDumps_); 63 this.memoryAllocatorDumpsByFullName_ = index; 64 } 65 66 return this.memoryAllocatorDumpsByFullName_[fullName]; 67 }, 68 69 forceRebuildingMemoryAllocatorDumpByFullNameIndex: function() { 70 // Clear the index and generate it lazily. 71 this.memoryAllocatorDumpsByFullName_ = undefined; 72 }, 73 74 iterateRootAllocatorDumps: function(fn, opt_this) { 75 if (this.memoryAllocatorDumps === undefined) 76 return; 77 this.memoryAllocatorDumps.forEach(fn, opt_this || this); 78 } 79 }; 80 81 return { 82 ContainerMemoryDump: ContainerMemoryDump 83 }; 84}); 85</script> 86