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

Side by Side Diff: chrome/test/perf/mem_usage_linux.cc

Issue 371025: More memory stats code cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: multiply uses by 1024 to keep stats consistent with old runs Created 11 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/test/perf/mem_usage.h"
6
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/process_util.h"
10 #include "base/string_util.h"
11
12 namespace {
13
14 // The format of /proc/meminfo is:
15 //
16 // MemTotal: 8235324 kB
17 // MemFree: 1628304 kB
18 // Buffers: 429596 kB
19 // Cached: 4728232 kB
20 // ...
21 const size_t kMemTotalIndex = 1;
22 const size_t kMemFreeIndex = 4;
23 const size_t kMemBuffersIndex = 7;
24 const size_t kMemCacheIndex = 10;
25
26 } // namespace
27
28 size_t GetSystemCommitCharge() {
29 // Used memory is: total - free - buffers - caches
30 FilePath meminfo_file("/proc/meminfo");
31 std::string meminfo_data;
32 if (!file_util::ReadFileToString(meminfo_file, &meminfo_data))
33 return 0;
34 std::vector<std::string> meminfo_fields;
35 SplitStringAlongWhitespace(meminfo_data, &meminfo_fields);
36
37 if (meminfo_fields.size() < kMemCacheIndex) {
38 LOG(ERROR) << "Failed to parse /proc/meminfo. Only found " <<
39 meminfo_fields.size() << " fields.";
40 return 0;
41 }
42
43 DCHECK_EQ(meminfo_fields[kMemTotalIndex-1], "MemTotal:");
44 DCHECK_EQ(meminfo_fields[kMemFreeIndex-1], "MemFree:");
45 DCHECK_EQ(meminfo_fields[kMemBuffersIndex-1], "Buffers:");
46 DCHECK_EQ(meminfo_fields[kMemCacheIndex-1], "Cached:");
47
48 int result_in_kb;
49 result_in_kb = StringToInt(meminfo_fields[kMemTotalIndex]);
50 result_in_kb -= StringToInt(meminfo_fields[kMemFreeIndex]);
51 result_in_kb -= StringToInt(meminfo_fields[kMemBuffersIndex]);
52 result_in_kb -= StringToInt(meminfo_fields[kMemCacheIndex]);
53
54 return result_in_kb * 1024;
55 }
56
57 void PrintChromeMemoryUsageInfo() {
58 NOTIMPLEMENTED();
59 }
60
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698