Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3676)

Unified Diff: base/trace_event/process_memory_maps_dump_provider.cc

Issue 951463002: [tracing] Add memory maps dumper impl for Linux/Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mmaps_skeleton
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/trace_event/process_memory_maps_dump_provider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/process_memory_maps_dump_provider.cc
diff --git a/base/trace_event/process_memory_maps_dump_provider.cc b/base/trace_event/process_memory_maps_dump_provider.cc
index e052ecb605755864af3840bd9232ffea3ba7329e..e81501641214c7c8f5a63b5e49adabd5331114d4 100644
--- a/base/trace_event/process_memory_maps_dump_provider.cc
+++ b/base/trace_event/process_memory_maps_dump_provider.cc
@@ -23,8 +23,69 @@ uint32 ReadLinuxProcSmapsFile(std::istream* smaps, ProcessMemoryMaps* pmm) {
LOG(ERROR) << "Could not read smaps file.";
return 0;
}
+ const uint32 kNumExpectedCountersPerRegion = 2;
+ const uint32 kMaxLineSize = 4096;
+ uint32 counters_parsed_for_current_region = 0;
uint32 num_regions_processed = 0;
- // TODO(primiano): in next CLs add the actual code to process the smaps file.
+ ProcessMemoryMaps::VMRegion region;
+ for (;;) {
+ int next = smaps->peek();
+ if (next == std::ifstream::traits_type::eof() || next == '\n')
+ break;
+ if ((next >= '0' && next <= '9') || (next >= 'a' && next <= 'f')) {
dsinclair 2015/02/23 15:37:12 What about A-Z? (There is a isxdigit() in <cctype>
Primiano Tucci (use gerrit) 2015/02/23 16:57:03 ![A-F] is deliberate. The kernel always used (so f
+ // Parse head line: "00400000-00421000 r-xp 00000000 fc:01 1234 /foo.so"
dsinclair 2015/02/23 15:37:12 Add the \n to the end since, it looks like, it wil
Primiano Tucci (use gerrit) 2015/02/23 16:57:03 Done.
+ uint64 end_addr;
+ std::string prot_flags;
+ std::string ignored;
+ region = {0};
+ counters_parsed_for_current_region = 0;
+
+ *smaps >> std::hex >> region.start_address;
+ smaps->ignore(1);
+ *smaps >> std::hex >> end_addr;
+ region.size_in_bytes = end_addr - region.start_address;
+ region.protection_flags = 0;
+ *smaps >> prot_flags;
+ CHECK(4UL == prot_flags.size());
+ if (prot_flags[0] == 'r')
+ region.protection_flags |= ProcessMemoryMaps::VMRegion::kProtRead;
+ if (prot_flags[1] == 'w')
+ region.protection_flags |= ProcessMemoryMaps::VMRegion::kProtWrite;
+ if (prot_flags[2] == 'x')
+ region.protection_flags |= ProcessMemoryMaps::VMRegion::kProtExec;
+ *smaps >> std::hex >> region.mapped_file_offset;
+ *smaps >> ignored; // Ignore device maj-min (fc:01 in the example above).
+ *smaps >> ignored; // Ignore inode number (1234 in the example above).
+
+ while (smaps->peek() == ' ')
+ smaps->ignore(1);
+ char mapped_file[kMaxLineSize];
+ smaps->getline(mapped_file, sizeof(mapped_file));
+ region.mapped_file = mapped_file;
dsinclair 2015/02/23 15:37:12 Can the bodies of the if/else get pulled out into
Primiano Tucci (use gerrit) 2015/02/23 16:57:03 Done.
+ } else {
+ // Parse counter line: "VmRSS: 0 Kb"
dsinclair 2015/02/23 15:37:12 If the \n gets consumed below, add it to the examp
Primiano Tucci (use gerrit) 2015/02/23 16:57:03 Done.
+ std::string counter_name;
+ *smaps >> counter_name;
+ // TODO(primiano): "Swap" should also be accounted as resident. Check
+ // whether Rss isn't already counting swapped and fix below if that is
+ // the case.
+ if (counter_name == "Rss:") {
+ *smaps >> std::dec >> region.bytes_stats_resident;
+ region.bytes_stats_resident *= 1024;
+ ++counters_parsed_for_current_region;
+ } else if (counter_name == "Anonymous:") {
+ *smaps >> std::dec >> region.bytes_stats_anonymous;
+ region.bytes_stats_anonymous *= 1024;
+ ++counters_parsed_for_current_region;
+ }
+ smaps->ignore(kMaxLineSize, '\n');
+ if (counters_parsed_for_current_region == kNumExpectedCountersPerRegion) {
+ pmm->AddVMRegion(region);
+ ++num_regions_processed;
+ counters_parsed_for_current_region = 0;
+ }
+ }
+ }
return num_regions_processed;
}
} // namespace
« no previous file with comments | « no previous file | base/trace_event/process_memory_maps_dump_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698