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

Unified Diff: base/debug/proc_maps_linux.cc

Issue 18661009: Update ReadProcMaps() to reflect lack of atomicity when reading /proc/self/maps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use std::string::resize() Created 7 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/proc_maps_linux.cc
diff --git a/base/debug/proc_maps_linux.cc b/base/debug/proc_maps_linux.cc
index 9557feb025994b1e88763b3c52f855127eaeda81..562189ff72b9c90470a343d06b4626bda1476a30 100644
--- a/base/debug/proc_maps_linux.cc
+++ b/base/debug/proc_maps_linux.cc
@@ -22,7 +22,20 @@
namespace base {
namespace debug {
+// Local testing revealed that the size of /proc/<pid>/maps for an official
+// release build of chrome hovered around the ~45 KB mark with some processes
+// hitting 80-90 KB. We'll play it safe and use 256 KB.
+enum { kLargeProcMapsSize = 256 * 1024 };
Mark Mentovai 2013/07/11 03:47:50 Why an enum? Why not a const? And why is it out h
+
bool ReadProcMaps(std::string* proc_maps) {
+ // It's possible for /proc/self/maps to change during reading (e.g., when
+ // running under ThreadSanitizer). Resize |proc_maps| to be large enough
+ // to read without causing a reallocation.
+ //
+ // Refer to http://crbug.com/258451 for details.
+ proc_maps->clear();
+ proc_maps->reserve(kLargeProcMapsSize);
Mark Mentovai 2013/07/11 03:47:50 How is this supposed to help…?
+
FilePath proc_maps_path("/proc/self/maps");
return file_util::ReadFileToString(proc_maps_path, proc_maps);
Mark Mentovai 2013/07/11 03:47:50 …file_util::ReadFileToString still reads chunks of
Alexander Potapenko 2013/07/11 10:28:54 Maybe base::MemoryMappedFile could be used instead
Mark Mentovai 2013/07/11 14:20:40 Alexander Potapenko wrote:
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698