Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/process_memory_maps_dump_provider.h" | 5 #include "base/trace_event/process_memory_maps_dump_provider.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 #include <fstream> | 8 #include <fstream> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 ProcessMemoryMaps::VMRegion::kProtectionFlagsRead; | 53 ProcessMemoryMaps::VMRegion::kProtectionFlagsRead; |
| 54 } | 54 } |
| 55 if (protection_flags[1] == 'w') { | 55 if (protection_flags[1] == 'w') { |
| 56 region->protection_flags |= | 56 region->protection_flags |= |
| 57 ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite; | 57 ProcessMemoryMaps::VMRegion::kProtectionFlagsWrite; |
| 58 } | 58 } |
| 59 if (protection_flags[2] == 'x') { | 59 if (protection_flags[2] == 'x') { |
| 60 region->protection_flags |= | 60 region->protection_flags |= |
| 61 ProcessMemoryMaps::VMRegion::kProtectionFlagsExec; | 61 ProcessMemoryMaps::VMRegion::kProtectionFlagsExec; |
| 62 } | 62 } |
| 63 *smaps >> std::hex >> region->mapped_file_offset; | 63 *smaps >> ignored; // Ignore mapped file offset. |
| 64 *smaps >> ignored; // Ignore device maj-min (fc:01 in the example above). | 64 *smaps >> ignored; // Ignore device maj-min (fc:01 in the example above). |
| 65 *smaps >> ignored; // Ignore inode number (1234 in the example above). | 65 *smaps >> ignored; // Ignore inode number (1234 in the example above). |
| 66 | 66 |
| 67 while (smaps->peek() == ' ') | 67 while (smaps->peek() == ' ') |
| 68 smaps->ignore(1); | 68 smaps->ignore(1); |
| 69 char mapped_file[kMaxLineSize]; | 69 char mapped_file[kMaxLineSize]; |
| 70 smaps->getline(mapped_file, sizeof(mapped_file)); | 70 smaps->getline(mapped_file, sizeof(mapped_file)); |
| 71 region->mapped_file = mapped_file; | 71 region->mapped_file = mapped_file; |
| 72 | 72 |
| 73 return res; | 73 return res; |
| 74 } | 74 } |
| 75 | 75 |
| 76 uint32 ParseSmapsCounter(std::istream* smaps, | 76 uint32 ParseSmapsCounter(std::istream* smaps, |
| 77 ProcessMemoryMaps::VMRegion* region) { | 77 ProcessMemoryMaps::VMRegion* region) { |
| 78 // e.g., "RSS: 0 Kb\n" | 78 // e.g., "RSS: 0 Kb\n" |
| 79 uint32 res = 0; | 79 uint32 res = 0; |
| 80 std::string counter_name; | 80 std::string counter_name; |
| 81 *smaps >> counter_name; | 81 *smaps >> counter_name; |
| 82 uint64 counter_value = 0; | |
| 82 | 83 |
| 83 // TODO(primiano): "Swap" should also be accounted as resident. Check | 84 // TODO(primiano): "Swap" should also be accounted as resident. Check |
| 84 // whether Rss isn't already counting swapped and fix below if that is | 85 // whether Rss isn't already counting swapped and fix below if that is |
| 85 // the case. | 86 // the case. |
| 86 if (counter_name == "Rss:") { | 87 if (counter_name == "Pss:") { |
| 87 *smaps >> std::dec >> region->byte_stats_resident; | 88 *smaps >> std::dec >> counter_value; |
| 88 region->byte_stats_resident *= 1024; | 89 region->byte_stats_proportional_resident = (counter_value * 1024); |
|
petrcermak
2015/03/20 11:23:34
Why do you *assign* to byte_stats_proportional_res
petrcermak
2015/03/20 11:23:34
There seems to be a little bit of code duplication
petrcermak
2015/03/20 11:23:34
No reason for parentheses around 'counter_value *
Primiano Tucci (use gerrit)
2015/03/20 13:59:14
Done.
Primiano Tucci (use gerrit)
2015/03/20 13:59:14
Done.
Primiano Tucci (use gerrit)
2015/03/20 13:59:14
I thought that was clear by the fact that Private/
| |
| 89 res = 1; | 90 res = 1; |
| 90 } else if (counter_name == "Anonymous:") { | 91 } else if (counter_name == "Private_Dirty:" || |
| 91 *smaps >> std::dec >> region->byte_stats_anonymous; | 92 counter_name == "Private_Clean:") { |
| 92 region->byte_stats_anonymous *= 1024; | 93 *smaps >> std::dec >> counter_value; |
| 94 region->byte_stats_private_resident += (counter_value * 1024); | |
| 95 res = 1; | |
| 96 } else if (counter_name == "Shared_Dirty:" || | |
| 97 counter_name == "Shared_Clean:") { | |
| 98 *smaps >> std::dec >> counter_value; | |
| 99 region->byte_stats_shared_resident += (counter_value * 1024); | |
| 93 res = 1; | 100 res = 1; |
| 94 } | 101 } |
| 95 | 102 |
| 96 #ifndef NDEBUG | 103 #ifndef NDEBUG |
| 97 // Paranoid check against changes of the Kernel /proc interface. | 104 // Paranoid check against changes of the Kernel /proc interface. |
| 98 if (res) { | 105 if (res) { |
| 99 std::string unit; | 106 std::string unit; |
| 100 *smaps >> unit; | 107 *smaps >> unit; |
| 101 DCHECK_EQ("kB", unit); | 108 DCHECK_EQ("kB", unit); |
| 102 } | 109 } |
| 103 #endif | 110 #endif |
| 104 | 111 |
| 105 smaps->ignore(kMaxLineSize, '\n'); | 112 smaps->ignore(kMaxLineSize, '\n'); |
| 106 | 113 |
| 107 return res; | 114 return res; |
| 108 } | 115 } |
| 109 | 116 |
| 110 uint32 ReadLinuxProcSmapsFile(std::istream* smaps, ProcessMemoryMaps* pmm) { | 117 uint32 ReadLinuxProcSmapsFile(std::istream* smaps, ProcessMemoryMaps* pmm) { |
| 111 if (!smaps->good()) | 118 if (!smaps->good()) |
| 112 return 0; | 119 return 0; |
| 113 | 120 |
| 114 const uint32 kNumExpectedCountersPerRegion = 2; | 121 const uint32 kNumExpectedCountersPerRegion = 5; |
| 115 uint32 counters_parsed_for_current_region = 0; | 122 uint32 counters_parsed_for_current_region = 0; |
| 116 uint32 num_valid_regions = 0; | 123 uint32 num_valid_regions = 0; |
| 117 ProcessMemoryMaps::VMRegion region; | 124 ProcessMemoryMaps::VMRegion region; |
| 118 bool should_add_current_region = false; | 125 bool should_add_current_region = false; |
| 119 for (;;) { | 126 for (;;) { |
| 120 int next = smaps->peek(); | 127 int next = smaps->peek(); |
| 121 if (next == std::ifstream::traits_type::eof() || next == '\n') | 128 if (next == std::ifstream::traits_type::eof() || next == '\n') |
| 122 break; | 129 break; |
| 123 if (isxdigit(next) && !isupper(next)) { | 130 if (isxdigit(next) && !isupper(next)) { |
| 124 region = {0}; | 131 region = {0}; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 185 |
| 179 return false; | 186 return false; |
| 180 } | 187 } |
| 181 | 188 |
| 182 const char* ProcessMemoryMapsDumpProvider::GetFriendlyName() const { | 189 const char* ProcessMemoryMapsDumpProvider::GetFriendlyName() const { |
| 183 return kDumperFriendlyName; | 190 return kDumperFriendlyName; |
| 184 } | 191 } |
| 185 | 192 |
| 186 } // namespace trace_event | 193 } // namespace trace_event |
| 187 } // namespace base | 194 } // namespace base |
| OLD | NEW |