| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 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="/base/units/util.html"> |
| <link rel="import" href="/model/attribute.html"> |
| <link rel="import" href="/model/container_memory_dump.html"> |
| <link rel="import" href="/model/memory_allocator_dump.html"> |
| |
| <script> |
| 'use strict'; |
| |
| /** |
| * @fileoverview Provides the ProcessMemoryDump class. |
| */ |
| tr.exportTo('tr.model', function() { |
| |
| function getValidSizeAttributeOrUndefined(memoryAllocatorDump, opt_model) { |
| var sizeAttr = memoryAllocatorDump.attributes['size']; |
| if (sizeAttr === undefined) |
| return undefined; |
| |
| if (!(sizeAttr instanceof tr.model.ScalarAttribute)) { |
| if (opt_model !== undefined) { |
| opt_model.importWarning({ |
| type: 'memory_dump_parse_error', |
| message: '\'size\' attribute of memory allocator dump \'' + |
| memoryAllocatorDump.fullName + '\' is not a scalar.' |
| }); |
| } |
| return undefined; |
| } |
| |
| return sizeAttr; |
| } |
| |
| /** |
| * The ProcessMemoryDump represents a memory dump of a single process. |
| * @constructor |
| */ |
| function ProcessMemoryDump(globalMemoryDump, process, start) { |
| tr.model.ContainerMemoryDump.call(this, start); |
| this.process = process; |
| this.globalMemoryDump = globalMemoryDump; |
| |
| this.totalResidentBytes = undefined; |
| this.vmRegions_ = undefined; |
| |
| this.tracingMemoryDiscounted_ = false; |
| }; |
| |
| ProcessMemoryDump.prototype = { |
| __proto__: tr.model.ContainerMemoryDump.prototype, |
| |
| get userFriendlyName() { |
| return 'Process memory dump at ' + tr.b.units.tsString(this.start); |
| }, |
| |
| get vmRegions() { |
| throw new Error( |
| 'VM regions must be accessed through the mostRecentVmRegions field'); |
| }, |
| |
| set vmRegions(vmRegions) { |
| this.vmRegions_ = vmRegions; |
| }, |
| |
| getMostRecentTotalVmRegionStat: function(statName) { |
| if (this.mostRecentVmRegions === undefined) |
| return undefined; |
| |
| var total = 0; |
| this.mostRecentVmRegions.forEach(function(vmRegion) { |
| var statValue = vmRegion.byteStats[statName]; |
| if (statValue === undefined) |
| return; |
| total += statValue; |
| }); |
| return total; |
| }, |
| |
| discountTracingOverhead: function(opt_model) { |
| // Make sure that calling this method twice won't lead to |
| // 'double-discounting'. |
| if (this.tracingMemoryDiscounted_) |
| return; |
| this.tracingMemoryDiscounted_ = true; |
| |
| var tracingDump = this.getMemoryAllocatorDumpByFullName('tracing'); |
| if (tracingDump === undefined) |
| return; |
| |
| var tracingSizeAttr = getValidSizeAttributeOrUndefined( |
| tracingDump, opt_model); |
| if (tracingSizeAttr === undefined) |
| return; |
| |
| var tracingSize = tracingSizeAttr.value; |
| |
| // Subtract the tracing size from the total. |
| if (this.totalResidentBytes !== undefined) |
| this.totalResidentBytes -= tracingSize; |
| |
| // Subtract the tracing size from VM regions. |
| if (this.vmRegions_ !== undefined) { |
| this.vmRegions_.push(VMRegion.fromDict({ |
| mappedFile: '[discounted tracing overhead]', |
| byteStats: { |
| privateDirtyResident: -tracingSize, |
| proportionalResident: -tracingSize |
| } |
| })); |
| } |
| |
| // Subtract the tracing size from the 'malloc' MemoryAllocatorDump. |
| var mallocDump = this.getMemoryAllocatorDumpByFullName('malloc'); |
| if (mallocDump !== undefined) { |
| var overheadSizeAttribute = new tr.model.ScalarAttribute( |
| 'bytes', -tracingSize); |
| var overheadDump = new tr.model.MemoryAllocatorDump( |
| this, 'malloc/discounted_tracing_overhead'); |
| overheadDump.parent = mallocDump; |
| overheadDump.addAttribute('size', overheadSizeAttribute); |
| mallocDump.children.push(overheadDump); |
| |
| var mallocDumpSizeAttr = getValidSizeAttributeOrUndefined( |
| mallocDump, opt_model); |
| if (mallocDumpSizeAttr !== undefined) |
| mallocDumpSizeAttr.value -= tracingSize; |
| |
| // Force rebuilding the memory allocator dump index (as we've just |
| // added a new memory allocator dump). |
| this.memoryAllocatorDumps = this.memoryAllocatorDumps; |
| } |
| } |
| }; |
| |
| ProcessMemoryDump.hookUpMostRecentVmRegionsLinks = function(processDumps) { |
| var mostRecentVmRegions = undefined; |
| |
| processDumps.forEach(function(processDump) { |
| // Update the most recent VM regions from the current dump. |
| if (processDump.vmRegions_ !== undefined) |
| mostRecentVmRegions = processDump.vmRegions_; |
| |
| // Set the most recent VM regions of the current dump. |
| processDump.mostRecentVmRegions = mostRecentVmRegions; |
| }); |
| }; |
| |
| /** |
| * @constructor |
| */ |
| function VMRegion(startAddress, sizeInBytes, protectionFlags, |
| mappedFile, byteStats) { |
| this.startAddress = startAddress; |
| this.sizeInBytes = sizeInBytes; |
| this.protectionFlags = protectionFlags; |
| this.mappedFile = mappedFile; |
| this.byteStats = byteStats; |
| }; |
| |
| VMRegion.PROTECTION_FLAG_READ = 4; |
| VMRegion.PROTECTION_FLAG_WRITE = 2; |
| VMRegion.PROTECTION_FLAG_EXECUTE = 1; |
| |
| VMRegion.prototype = { |
| get protectionFlagsToString() { |
| if (this.protectionFlags === undefined) |
| return undefined; |
| return ( |
| (this.protectionFlags & VMRegion.PROTECTION_FLAG_READ ? 'r' : '-') + |
| (this.protectionFlags & VMRegion.PROTECTION_FLAG_WRITE ? 'w' : '-') + |
| (this.protectionFlags & VMRegion.PROTECTION_FLAG_EXECUTE ? 'x' : '-') |
| ); |
| } |
| }; |
| |
| VMRegion.fromDict = function(dict) { |
| return new VMRegion( |
| dict.startAddress, |
| dict.sizeInBytes, |
| dict.protectionFlags, |
| dict.mappedFile, |
| VMRegionByteStats.fromDict(dict.byteStats)); |
| }; |
| |
| /** |
| * @constructor |
| */ |
| function VMRegionByteStats(privateCleanResident, privateDirtyResident, |
| sharedCleanResident, sharedDirtyResident, |
| proportionalResident, swapped) { |
| this.privateCleanResident = privateCleanResident; |
| this.privateDirtyResident = privateDirtyResident; |
| this.sharedCleanResident = sharedCleanResident; |
| this.sharedDirtyResident = sharedDirtyResident; |
| this.proportionalResident = proportionalResident; |
| this.swapped = swapped; |
| } |
| |
| VMRegionByteStats.fromDict = function(dict) { |
| return new VMRegionByteStats( |
| dict.privateCleanResident, |
| dict.privateDirtyResident, |
| dict.sharedCleanResident, |
| dict.sharedDirtyResident, |
| dict.proportionalResident, |
| dict.swapped); |
| } |
| |
| tr.model.EventRegistry.register( |
| ProcessMemoryDump, |
| { |
| name: 'processMemoryDump', |
| pluralName: 'processMemoryDumps', |
| singleViewElementName: 'tr-c-a-single-process-memory-dump-sub-view', |
| multiViewElementName: 'tr-c-a-multi-process-memory-dump-sub-view' |
| }); |
| |
| return { |
| ProcessMemoryDump: ProcessMemoryDump, |
| VMRegion: VMRegion, |
| VMRegionByteStats: VMRegionByteStats |
| }; |
| }); |
| </script> |