Benjamin Lerman | 507bb1a | 2015-02-26 13:15:17 +0100 | [diff] [blame] | 1 | // Copyright 2015 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. |
| 4 | |
| 5 | #include "base/trace_event/process_memory_maps.h" |
| 6 | |
Alhaad Gokhale | 4f51307 | 2015-03-24 10:49:34 -0700 | [diff] [blame] | 7 | #include "base/format_macros.h" |
| 8 | #include "base/strings/stringprintf.h" |
Benjamin Lerman | 507bb1a | 2015-02-26 13:15:17 +0100 | [diff] [blame] | 9 | #include "base/trace_event/trace_event_argument.h" |
| 10 | |
| 11 | namespace base { |
| 12 | namespace trace_event { |
| 13 | |
| 14 | // static |
| 15 | const uint32 ProcessMemoryMaps::VMRegion::kProtectionFlagsRead = 4; |
| 16 | const uint32 ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite = 2; |
| 17 | const uint32 ProcessMemoryMaps::VMRegion::kProtectionFlagsExec = 1; |
| 18 | |
| 19 | ProcessMemoryMaps::ProcessMemoryMaps() { |
| 20 | } |
| 21 | |
| 22 | ProcessMemoryMaps::~ProcessMemoryMaps() { |
| 23 | } |
| 24 | |
| 25 | void ProcessMemoryMaps::AsValueInto(TracedValue* value) const { |
Alhaad Gokhale | 4f51307 | 2015-03-24 10:49:34 -0700 | [diff] [blame] | 26 | static const char kHexFmt[] = "%" PRIx64; |
| 27 | |
| 28 | // Refer to the design doc goo.gl/sxfFY8 for the semantic of these fields. |
Benjamin Lerman | 507bb1a | 2015-02-26 13:15:17 +0100 | [diff] [blame] | 29 | value->BeginArray("vm_regions"); |
| 30 | for (const auto& region : vm_regions_) { |
| 31 | value->BeginDictionary(); |
| 32 | |
Alhaad Gokhale | 4f51307 | 2015-03-24 10:49:34 -0700 | [diff] [blame] | 33 | value->SetString("sa", StringPrintf(kHexFmt, region.start_address)); |
| 34 | value->SetString("sz", StringPrintf(kHexFmt, region.size_in_bytes)); |
| 35 | value->SetInteger("pf", region.protection_flags); |
| 36 | value->SetString("mf", region.mapped_file); |
Benjamin Lerman | 507bb1a | 2015-02-26 13:15:17 +0100 | [diff] [blame] | 37 | |
Alhaad Gokhale | 4f51307 | 2015-03-24 10:49:34 -0700 | [diff] [blame] | 38 | value->BeginDictionary("bs"); // byte stats |
| 39 | value->SetString( |
| 40 | "pss", StringPrintf(kHexFmt, region.byte_stats_proportional_resident)); |
| 41 | value->SetString("prv", |
| 42 | StringPrintf(kHexFmt, region.byte_stats_private_resident)); |
| 43 | value->SetString("shr", |
| 44 | StringPrintf(kHexFmt, region.byte_stats_shared_resident)); |
Benjamin Lerman | 507bb1a | 2015-02-26 13:15:17 +0100 | [diff] [blame] | 45 | value->EndDictionary(); |
| 46 | |
| 47 | value->EndDictionary(); |
| 48 | } |
| 49 | value->EndArray(); |
| 50 | } |
| 51 | |
| 52 | } // namespace trace_event |
| 53 | } // namespace base |