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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/debug/proc_maps_linux.h" 5 #include "base/debug/proc_maps_linux.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <inttypes.h> 8 #include <inttypes.h>
9 #endif 9 #endif
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 13
14 #if defined(OS_ANDROID) 14 #if defined(OS_ANDROID)
15 // Bionic's inttypes.h defines PRI/SCNxPTR as an unsigned long int, which 15 // Bionic's inttypes.h defines PRI/SCNxPTR as an unsigned long int, which
16 // is incompatible with Bionic's stdint.h defining uintptr_t as a unsigned int: 16 // is incompatible with Bionic's stdint.h defining uintptr_t as a unsigned int:
17 // https://code.google.com/p/android/issues/detail?id=57218 17 // https://code.google.com/p/android/issues/detail?id=57218
18 #undef SCNxPTR 18 #undef SCNxPTR
19 #define SCNxPTR "x" 19 #define SCNxPTR "x"
20 #endif 20 #endif
21 21
22 namespace base { 22 namespace base {
23 namespace debug { 23 namespace debug {
24 24
25 // Local testing revealed that the size of /proc/<pid>/maps for an official
26 // release build of chrome hovered around the ~45 KB mark with some processes
27 // hitting 80-90 KB. We'll play it safe and use 256 KB.
28 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
29
25 bool ReadProcMaps(std::string* proc_maps) { 30 bool ReadProcMaps(std::string* proc_maps) {
31 // It's possible for /proc/self/maps to change during reading (e.g., when
32 // running under ThreadSanitizer). Resize |proc_maps| to be large enough
33 // to read without causing a reallocation.
34 //
35 // Refer to http://crbug.com/258451 for details.
36 proc_maps->clear();
37 proc_maps->reserve(kLargeProcMapsSize);
Mark Mentovai 2013/07/11 03:47:50 How is this supposed to help…?
38
26 FilePath proc_maps_path("/proc/self/maps"); 39 FilePath proc_maps_path("/proc/self/maps");
27 return file_util::ReadFileToString(proc_maps_path, proc_maps); 40 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:
28 } 41 }
29 42
30 bool ParseProcMaps(const std::string& input, 43 bool ParseProcMaps(const std::string& input,
31 std::vector<MappedMemoryRegion>* regions_out) { 44 std::vector<MappedMemoryRegion>* regions_out) {
32 std::vector<MappedMemoryRegion> regions; 45 std::vector<MappedMemoryRegion> regions;
33 46
34 // This isn't async safe nor terribly efficient, but it doesn't need to be at 47 // This isn't async safe nor terribly efficient, but it doesn't need to be at
35 // this point in time. 48 // this point in time.
36 std::vector<std::string> lines; 49 std::vector<std::string> lines;
37 SplitString(input, '\n', &lines); 50 SplitString(input, '\n', &lines);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 regions.push_back(region); 105 regions.push_back(region);
93 regions.back().path.assign(line + path_index); 106 regions.back().path.assign(line + path_index);
94 } 107 }
95 108
96 regions_out->swap(regions); 109 regions_out->swap(regions);
97 return true; 110 return true;
98 } 111 }
99 112
100 } // namespace debug 113 } // namespace debug
101 } // namespace base 114 } // namespace base
OLDNEW
« 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