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
VMRegion()19 ProcessMemoryMaps::VMRegion::VMRegion()
20 : start_address(0),
21 size_in_bytes(0),
22 protection_flags(0),
23 byte_stats_private_dirty_resident(0),
24 byte_stats_private_clean_resident(0),
25 byte_stats_shared_dirty_resident(0),
26 byte_stats_shared_clean_resident(0),
27 byte_stats_swapped(0),
28 byte_stats_proportional_resident(0) {
29 }
30
ProcessMemoryMaps()31 ProcessMemoryMaps::ProcessMemoryMaps() {
32 }
33
~ProcessMemoryMaps()34 ProcessMemoryMaps::~ProcessMemoryMaps() {
35 }
36
AsValueInto(TracedValue * value) const37 void ProcessMemoryMaps::AsValueInto(TracedValue* value) const {
38 static const char kHexFmt[] = "%" PRIx64;
39
40 // Refer to the design doc goo.gl/sxfFY8 for the semantic of these fields.
41 value->BeginArray("vm_regions");
42 for (const auto& region : vm_regions_) {
43 value->BeginDictionary();
44
45 value->SetString("sa", StringPrintf(kHexFmt, region.start_address));
46 value->SetString("sz", StringPrintf(kHexFmt, region.size_in_bytes));
47 value->SetInteger("pf", region.protection_flags);
48 value->SetString("mf", region.mapped_file);
49
50 value->BeginDictionary("bs"); // byte stats
51 value->SetString(
52 "pss", StringPrintf(kHexFmt, region.byte_stats_proportional_resident));
53 value->SetString(
54 "pd", StringPrintf(kHexFmt, region.byte_stats_private_dirty_resident));
55 value->SetString(
56 "pc", StringPrintf(kHexFmt, region.byte_stats_private_clean_resident));
57 value->SetString(
58 "sd", StringPrintf(kHexFmt, region.byte_stats_shared_dirty_resident));
59 value->SetString(
60 "sc", StringPrintf(kHexFmt, region.byte_stats_shared_clean_resident));
61 value->SetString("sw", StringPrintf(kHexFmt, region.byte_stats_swapped));
62 value->EndDictionary();
63
64 value->EndDictionary();
65 }
66 value->EndArray();
67 }
68
Clear()69 void ProcessMemoryMaps::Clear() {
70 vm_regions_.clear();
71 }
72
73 } // namespace trace_event
74 } // namespace base
75