| <!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="/core/trace_model/container_memory_dump.html"> |
| <link rel="import" href="/core/analysis/util.html"> |
| |
| <script> |
| 'use strict'; |
| |
| /** |
| * @fileoverview Provides the ProcessMemoryDump class. |
| */ |
| tv.exportTo('tv.c.trace_model', function() { |
| /** |
| * The ProcessMemoryDump represents a memory dump of a single process. |
| * @constructor |
| */ |
| function ProcessMemoryDump(globalMemoryDump, process, start) { |
| tv.c.trace_model.ContainerMemoryDump.call(this, start); |
| this.process = process; |
| this.globalMemoryDump = globalMemoryDump; |
| |
| this.totalResidentBytes = undefined; |
| this.vmRegions_ = undefined; |
| }; |
| |
| ProcessMemoryDump.prototype = { |
| __proto__: tv.c.trace_model.ContainerMemoryDump.prototype, |
| |
| get userFriendlyName() { |
| return 'Process memory dump at ' + tv.c.analysis.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(statGetterFn) { |
| if (this.mostRecentVmRegions === undefined) |
| return undefined; |
| |
| var total = 0; |
| this.mostRecentVmRegions.forEach(function(vmRegion) { |
| total += statGetterFn(vmRegion); |
| }); |
| return total; |
| }, |
| |
| get mostRecentTotalProportionalResidentSizeInBytes() { |
| return this.getMostRecentTotalVmRegionStat_(function(vmRegion) { |
| return vmRegion.byteStats.proportionalResident; |
| }); |
| }, |
| |
| get mostRecentTotalPrivateResidentSizeInBytes() { |
| return this.getMostRecentTotalVmRegionStat_(function(vmRegion) { |
| return vmRegion.byteStats.privateResident; |
| }); |
| }, |
| |
| get mostRecentTotalSharedResidentSizeInBytes() { |
| return this.getMostRecentTotalVmRegionStat_(function(vmRegion) { |
| return vmRegion.byteStats.sharedResident; |
| }); |
| } |
| }; |
| |
| 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(privateResident, sharedResident, |
| proportionalResident) { |
| this.privateResident = privateResident; |
| this.sharedResident = sharedResident; |
| this.proportionalResident = proportionalResident; |
| }; |
| |
| VMRegionByteStats.prototype = { |
| get totalResident() { |
| return this.privateResident + this.sharedResident; |
| } |
| }; |
| |
| VMRegionByteStats.fromDict = function(dict) { |
| return new VMRegionByteStats( |
| dict.privateResident, |
| dict.sharedResident, |
| dict.proportionalResident); |
| }; |
| |
| tv.c.trace_model.EventRegistry.register( |
| ProcessMemoryDump, |
| { |
| name: 'processMemoryDump', |
| pluralName: 'processMemoryDumps', |
| singleViewElementName: 'tv-c-single-process-memory-dump-sub-view', |
| multiViewElementName: 'tv-c-multi-process-memory-dump-sub-view' |
| }); |
| |
| return { |
| ProcessMemoryDump: ProcessMemoryDump, |
| VMRegion: VMRegion, |
| VMRegionByteStats: VMRegionByteStats |
| }; |
| }); |
| </script> |