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

Side by Side Diff: net/tools/disk_cache_memory_test/disk_cache_memory_test.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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
« no previous file with comments | « net/tools/balsa/string_piece_utils.h ('k') | net/tools/dump_cache/dump_files.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <cstdlib> 5 #include <cstdlib>
6 #include <fstream> 6 #include <fstream>
7 #include <iostream> 7 #include <iostream>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return false; 154 return false;
155 } 155 }
156 156
157 // Parses range property lines from /proc/<PID>/smaps, e.g.: 157 // Parses range property lines from /proc/<PID>/smaps, e.g.:
158 // Private_Dirty: 16 kB 158 // Private_Dirty: 16 kB
159 // 159 //
160 // Returns |false| iff it recognizes a new range line. Outputs non-zero |size| 160 // Returns |false| iff it recognizes a new range line. Outputs non-zero |size|
161 // only if parsing succeeded. 161 // only if parsing succeeded.
162 bool ParseRangeProperty(const std::string& line, 162 bool ParseRangeProperty(const std::string& line,
163 std::vector<std::string>* tokens, 163 std::vector<std::string>* tokens,
164 uint64* size, 164 uint64_t* size,
165 bool* is_private_dirty) { 165 bool* is_private_dirty) {
166 *tokens = base::SplitString(line, base::kWhitespaceASCII, 166 *tokens = base::SplitString(line, base::kWhitespaceASCII,
167 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 167 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
168 168
169 // If the line is long, attempt to parse new range outside of this scope. 169 // If the line is long, attempt to parse new range outside of this scope.
170 if (tokens->size() > 3) 170 if (tokens->size() > 3)
171 return false; 171 return false;
172 172
173 // Skip the line on other parsing error occasions. 173 // Skip the line on other parsing error occasions.
174 if (tokens->size() < 3) 174 if (tokens->size() < 3)
175 return true; 175 return true;
176 const std::string& type = (*tokens)[0]; 176 const std::string& type = (*tokens)[0];
177 if (type != kPrivateDirty) 177 if (type != kPrivateDirty)
178 return true; 178 return true;
179 const std::string& unit = (*tokens)[2]; 179 const std::string& unit = (*tokens)[2];
180 if (unit != kKb) { 180 if (unit != kKb) {
181 LOG(WARNING) << "Discarding value not in kB: " << line; 181 LOG(WARNING) << "Discarding value not in kB: " << line;
182 return true; 182 return true;
183 } 183 }
184 const std::string& size_str = (*tokens)[1]; 184 const std::string& size_str = (*tokens)[1];
185 uint64 map_size = 0; 185 uint64_t map_size = 0;
186 if (!base::StringToUint64(size_str, &map_size)) 186 if (!base::StringToUint64(size_str, &map_size))
187 return true; 187 return true;
188 *is_private_dirty = true; 188 *is_private_dirty = true;
189 *size = map_size; 189 *size = map_size;
190 return true; 190 return true;
191 } 191 }
192 192
193 uint64 GetMemoryConsumption() { 193 uint64_t GetMemoryConsumption() {
194 std::ifstream maps_file( 194 std::ifstream maps_file(
195 base::StringPrintf("/proc/%d/smaps", getpid()).c_str()); 195 base::StringPrintf("/proc/%d/smaps", getpid()).c_str());
196 if (!maps_file.good()) { 196 if (!maps_file.good()) {
197 LOG(ERROR) << "Could not open smaps file."; 197 LOG(ERROR) << "Could not open smaps file.";
198 return false; 198 return false;
199 } 199 }
200 std::string line; 200 std::string line;
201 std::vector<std::string> tokens; 201 std::vector<std::string> tokens;
202 uint64 total_size = 0; 202 uint64_t total_size = 0;
203 if (!std::getline(maps_file, line) || line.empty()) 203 if (!std::getline(maps_file, line) || line.empty())
204 return total_size; 204 return total_size;
205 while (true) { 205 while (true) {
206 bool is_anonymous_read_write = false; 206 bool is_anonymous_read_write = false;
207 if (!ParseRangeLine(line, &tokens, &is_anonymous_read_write)) { 207 if (!ParseRangeLine(line, &tokens, &is_anonymous_read_write)) {
208 LOG(WARNING) << "Parsing smaps - did not expect line: " << line; 208 LOG(WARNING) << "Parsing smaps - did not expect line: " << line;
209 } 209 }
210 if (!std::getline(maps_file, line) || line.empty()) 210 if (!std::getline(maps_file, line) || line.empty())
211 return total_size; 211 return total_size;
212 bool is_private_dirty = false; 212 bool is_private_dirty = false;
213 uint64 size = 0; 213 uint64_t size = 0;
214 while (ParseRangeProperty(line, &tokens, &size, &is_private_dirty)) { 214 while (ParseRangeProperty(line, &tokens, &size, &is_private_dirty)) {
215 if (is_anonymous_read_write && is_private_dirty) { 215 if (is_anonymous_read_write && is_private_dirty) {
216 total_size += size; 216 total_size += size;
217 is_private_dirty = false; 217 is_private_dirty = false;
218 } 218 }
219 if (!std::getline(maps_file, line) || line.empty()) 219 if (!std::getline(maps_file, line) || line.empty())
220 return total_size; 220 return total_size;
221 } 221 }
222 } 222 }
223 return total_size; 223 return total_size;
224 } 224 }
225 225
226 bool CacheMemTest(const std::vector<scoped_ptr<CacheSpec>>& specs) { 226 bool CacheMemTest(const std::vector<scoped_ptr<CacheSpec>>& specs) {
227 std::vector<scoped_ptr<Backend>> backends; 227 std::vector<scoped_ptr<Backend>> backends;
228 for (const auto& it : specs) { 228 for (const auto& it : specs) {
229 scoped_ptr<Backend> backend = CreateAndInitBackend(*it); 229 scoped_ptr<Backend> backend = CreateAndInitBackend(*it);
230 if (!backend) 230 if (!backend)
231 return false; 231 return false;
232 std::cout << "Number of entries in " << it->path.LossyDisplayName() << " : " 232 std::cout << "Number of entries in " << it->path.LossyDisplayName() << " : "
233 << backend->GetEntryCount() << std::endl; 233 << backend->GetEntryCount() << std::endl;
234 backends.push_back(std::move(backend)); 234 backends.push_back(std::move(backend));
235 } 235 }
236 const uint64 memory_consumption = GetMemoryConsumption(); 236 const uint64_t memory_consumption = GetMemoryConsumption();
237 std::cout << "Private dirty memory: " << memory_consumption << " kB" 237 std::cout << "Private dirty memory: " << memory_consumption << " kB"
238 << std::endl; 238 << std::endl;
239 return true; 239 return true;
240 } 240 }
241 241
242 void PrintUsage(std::ostream* stream) { 242 void PrintUsage(std::ostream* stream) {
243 *stream << "Usage: disk_cache_mem_test " 243 *stream << "Usage: disk_cache_mem_test "
244 << "--spec-1=<spec> " 244 << "--spec-1=<spec> "
245 << "[--spec-2=<spec>]" 245 << "[--spec-2=<spec>]"
246 << std::endl 246 << std::endl
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 return CacheMemTest(specs); 292 return CacheMemTest(specs);
293 } 293 }
294 294
295 } // namespace 295 } // namespace
296 } // namespace disk_cache 296 } // namespace disk_cache
297 297
298 int main(int argc, char** argv) { 298 int main(int argc, char** argv) {
299 return !disk_cache::Main(argc, argv); 299 return !disk_cache::Main(argc, argv);
300 } 300 }
OLDNEW
« no previous file with comments | « net/tools/balsa/string_piece_utils.h ('k') | net/tools/dump_cache/dump_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698