• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/trace_event_argument.h"
10 
11 namespace base {
12 namespace trace_event {
13 
14 // static
15 const uint32_t ProcessMemoryMaps::VMRegion::kProtectionFlagsRead = 4;
16 const uint32_t ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite = 2;
17 const uint32_t ProcessMemoryMaps::VMRegion::kProtectionFlagsExec = 1;
18 const uint32_t ProcessMemoryMaps::VMRegion::kProtectionFlagsMayshare = 128;
19 
VMRegion()20 ProcessMemoryMaps::VMRegion::VMRegion()
21     : start_address(0),
22       size_in_bytes(0),
23       protection_flags(0),
24       byte_stats_private_dirty_resident(0),
25       byte_stats_private_clean_resident(0),
26       byte_stats_shared_dirty_resident(0),
27       byte_stats_shared_clean_resident(0),
28       byte_stats_swapped(0),
29       byte_stats_proportional_resident(0) {
30 }
31 
32 ProcessMemoryMaps::VMRegion::VMRegion(const VMRegion& other) = default;
33 
ProcessMemoryMaps()34 ProcessMemoryMaps::ProcessMemoryMaps() {
35 }
36 
~ProcessMemoryMaps()37 ProcessMemoryMaps::~ProcessMemoryMaps() {
38 }
39 
AsValueInto(TracedValue * value) const40 void ProcessMemoryMaps::AsValueInto(TracedValue* value) const {
41   static const char kHexFmt[] = "%" PRIx64;
42 
43   // Refer to the design doc goo.gl/sxfFY8 for the semantic of these fields.
44   value->BeginArray("vm_regions");
45   for (const auto& region : vm_regions_) {
46     value->BeginDictionary();
47 
48     value->SetString("sa", StringPrintf(kHexFmt, region.start_address));
49     value->SetString("sz", StringPrintf(kHexFmt, region.size_in_bytes));
50     value->SetInteger("pf", region.protection_flags);
51     value->SetString("mf", region.mapped_file);
52 
53     value->BeginDictionary("bs");  // byte stats
54     value->SetString(
55         "pss", StringPrintf(kHexFmt, region.byte_stats_proportional_resident));
56     value->SetString(
57         "pd", StringPrintf(kHexFmt, region.byte_stats_private_dirty_resident));
58     value->SetString(
59         "pc", StringPrintf(kHexFmt, region.byte_stats_private_clean_resident));
60     value->SetString(
61         "sd", StringPrintf(kHexFmt, region.byte_stats_shared_dirty_resident));
62     value->SetString(
63         "sc", StringPrintf(kHexFmt, region.byte_stats_shared_clean_resident));
64     value->SetString("sw", StringPrintf(kHexFmt, region.byte_stats_swapped));
65     value->EndDictionary();
66 
67     value->EndDictionary();
68   }
69   value->EndArray();
70 }
71 
Clear()72 void ProcessMemoryMaps::Clear() {
73   vm_regions_.clear();
74 }
75 
76 }  // namespace trace_event
77 }  // namespace base
78