summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 21:25:20 +0000
committernduca@chromium.org <nduca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 21:25:20 +0000
commitf413478a5a9c008dfab8d760a698a90240c41551 (patch)
tree90ee3e550b528b42526f14e724c3baa724a30d8c
parentab55798cc3509e09d497d4df318f0c4415f6d2c9 (diff)
downloadchromium_src-f413478a5a9c008dfab8d760a698a90240c41551.zip
chromium_src-f413478a5a9c008dfab8d760a698a90240c41551.tar.gz
chromium_src-f413478a5a9c008dfab8d760a698a90240c41551.tar.bz2
Move the SwapData class to base/process (where other system metrics data reside) and rename it to SwapInfo.
This only moves code and adds no new functionality. This uses ScopedAllowIO. Since this is perfmon code to /proc, we have deemed that IO is acceptable. BUG=236763 R=darin@chromium.org, nduca@chromium.org Review URL: https://codereview.chromium.org/22780002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220377 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/process/process_metrics.h23
-rw-r--r--base/process/process_metrics_linux.cc41
-rw-r--r--chrome/browser/memory_details.cc18
-rw-r--r--chrome/browser/memory_details.h20
-rw-r--r--chrome/browser/memory_details_linux.cc37
5 files changed, 75 insertions, 64 deletions
diff --git a/base/process/process_metrics.h b/base/process/process_metrics.h
index 8a7fb13..273c8e0 100644
--- a/base/process/process_metrics.h
+++ b/base/process/process_metrics.h
@@ -263,6 +263,29 @@ struct BASE_EXPORT SystemMemoryInfoKB {
BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo);
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
+#if defined(OS_CHROMEOS)
+// Data from files in directory /sys/block/zram0 about ZRAM usage.
+struct BASE_EXPORT SwapInfo {
+ SwapInfo()
+ : num_reads(0),
+ num_writes(0),
+ compr_data_size(0),
+ orig_data_size(0),
+ mem_used_total(0) {
+ }
+
+ uint64 num_reads;
+ uint64 num_writes;
+ uint64 compr_data_size;
+ uint64 orig_data_size;
+ uint64 mem_used_total;
+};
+
+// In ChromeOS, reads files from /sys/block/zram0 that contain ZRAM usage data.
+// Fills in the provided |swap_data| structure.
+BASE_EXPORT void GetSwapInfo(SwapInfo* swap_info);
+#endif // defined(OS_CHROMEOS)
+
// Collects and holds performance metrics for system memory and disk.
// Provides functionality to retrieve the data on various platforms and
// to serialize the stored data.
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc
index 8d1a57c..c500459 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -30,6 +30,20 @@ enum ParsingState {
KEY_VALUE
};
+#ifdef OS_CHROMEOS
+// Read a file with a single number string and return the number as a uint64.
+static uint64 ReadFileToUint64(const base::FilePath file) {
+ std::string file_as_string;
+ if (!file_util::ReadFileToString(file, &file_as_string))
+ return 0;
+ TrimWhitespaceASCII(file_as_string, TRIM_ALL, &file_as_string);
+ uint64 file_as_uint64 = 0;
+ if (!base::StringToUint64(file_as_string, &file_as_uint64))
+ return 0;
+ return file_as_uint64;
+}
+#endif
+
// Read /proc/<pid>/status and returns the value for |field|, or 0 on failure.
// Only works for fields in the form of "Field: value kB".
size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) {
@@ -513,4 +527,31 @@ bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
return true;
}
+#if defined(OS_CHROMEOS)
+void GetSwapInfo(SwapInfo* swap_info) {
+ // Synchronously reading files in /sys/block/zram0 is safe.
+ ThreadRestrictions::ScopedAllowIO allow_io;
+
+ base::FilePath zram_path("/sys/block/zram0");
+ uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size"));
+ if (orig_data_size <= 4096) {
+ // A single page is compressed at startup, and has a high compression
+ // ratio. We ignore this as it doesn't indicate any real swapping.
+ swap_info->orig_data_size = 0;
+ swap_info->num_reads = 0;
+ swap_info->num_writes = 0;
+ swap_info->compr_data_size = 0;
+ swap_info->mem_used_total = 0;
+ return;
+ }
+ swap_info->orig_data_size = orig_data_size;
+ swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads"));
+ swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes"));
+ swap_info->compr_data_size =
+ ReadFileToUint64(zram_path.Append("compr_data_size"));
+ swap_info->mem_used_total =
+ ReadFileToUint64(zram_path.Append("mem_used_total"));
+}
+#endif // defined(OS_CHROMEOS)
+
} // namespace base
diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc
index c589ef2..643e211 100644
--- a/chrome/browser/memory_details.cc
+++ b/chrome/browser/memory_details.cc
@@ -501,8 +501,8 @@ void MemoryDetails::UpdateHistograms() {
#if defined(OS_CHROMEOS)
void MemoryDetails::UpdateSwapHistograms() {
- UMA_HISTOGRAM_BOOLEAN("Memory.Swap.HaveSwapped", swap_data_.num_writes > 0);
- if (swap_data_.num_writes == 0)
+ UMA_HISTOGRAM_BOOLEAN("Memory.Swap.HaveSwapped", swap_info_.num_writes > 0);
+ if (swap_info_.num_writes == 0)
return;
// Only record swap info when any swaps have happened, to give us more
@@ -575,25 +575,25 @@ void MemoryDetails::UpdateSwapHistograms() {
UMA_HISTOGRAM_MEMORY_MB("Memory.Swap.Total", total_sample);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.CompressedDataSize",
- swap_data_.compr_data_size / (1024 * 1024),
+ swap_info_.compr_data_size / (1024 * 1024),
1, 4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.OriginalDataSize",
- swap_data_.orig_data_size / (1024 * 1024),
+ swap_info_.orig_data_size / (1024 * 1024),
1, 4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.MemUsedTotal",
- swap_data_.mem_used_total / (1024 * 1024),
+ swap_info_.mem_used_total / (1024 * 1024),
1, 4096, 50);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumReads",
- swap_data_.num_reads,
+ swap_info_.num_reads,
1, 100000000, 100);
UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites",
- swap_data_.num_writes,
+ swap_info_.num_writes,
1, 100000000, 100);
- if (swap_data_.orig_data_size > 0 && swap_data_.compr_data_size > 0) {
+ if (swap_info_.orig_data_size > 0 && swap_info_.compr_data_size > 0) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Memory.Swap.CompressionRatio",
- swap_data_.orig_data_size / swap_data_.compr_data_size,
+ swap_info_.orig_data_size / swap_info_.compr_data_size,
1, 20, 20);
}
}
diff --git a/chrome/browser/memory_details.h b/chrome/browser/memory_details.h
index cfbd68e..fb2ebb3 100644
--- a/chrome/browser/memory_details.h
+++ b/chrome/browser/memory_details.h
@@ -87,24 +87,6 @@ struct ProcessData {
class ProcessInfoSnapshot;
#endif
-#if defined(OS_CHROMEOS)
-struct SwapData {
- SwapData()
- : num_reads(0),
- num_writes(0),
- compr_data_size(0),
- orig_data_size(0),
- mem_used_total(0) {
- }
-
- uint64 num_reads;
- uint64 num_writes;
- uint64 compr_data_size;
- uint64 orig_data_size;
- uint64 mem_used_total;
-};
-#endif
-
// MemoryDetails fetches memory details about current running browsers.
// Because this data can only be fetched asynchronously, callers use
// this class via a callback.
@@ -206,7 +188,7 @@ class MemoryDetails : public base::RefCountedThreadSafe<MemoryDetails> {
UserMetricsMode user_metrics_mode_;
#if defined(OS_CHROMEOS)
- SwapData swap_data_;
+ base::SwapInfo swap_info_;
#endif
DISALLOW_COPY_AND_ASSIGN(MemoryDetails);
diff --git a/chrome/browser/memory_details_linux.cc b/chrome/browser/memory_details_linux.cc
index ec149da..03f000e 100644
--- a/chrome/browser/memory_details_linux.cc
+++ b/chrome/browser/memory_details_linux.cc
@@ -163,41 +163,6 @@ static std::vector<pid_t> GetAllChildren(const ProcessMap& processes,
return children;
}
-#if defined(OS_CHROMEOS)
-static uint64 ReadFileToUint64(const base::FilePath file) {
- std::string file_as_string;
- if (!file_util::ReadFileToString(file, &file_as_string))
- return 0;
- TrimWhitespaceASCII(file_as_string, TRIM_ALL, &file_as_string);
- uint64 file_as_uint64 = 0;
- if (!base::StringToUint64(file_as_string, &file_as_uint64))
- return 0;
- return file_as_uint64;
-}
-
-static void GetSwapData(SwapData* swap_data) {
- base::FilePath zram_path("/sys/block/zram0");
- uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size"));
- if (orig_data_size <= 4096) {
- // A single page is compressed at startup, and has a high compression
- // ratio. We ignore this as it doesn't indicate any real swapping.
- swap_data->orig_data_size = 0;
- swap_data->num_reads = 0;
- swap_data->num_writes = 0;
- swap_data->compr_data_size = 0;
- swap_data->mem_used_total = 0;
- return;
- }
- swap_data->orig_data_size = orig_data_size;
- swap_data->num_reads = ReadFileToUint64(zram_path.Append("num_reads"));
- swap_data->num_writes = ReadFileToUint64(zram_path.Append("num_writes"));
- swap_data->compr_data_size =
- ReadFileToUint64(zram_path.Append("compr_data_size"));
- swap_data->mem_used_total =
- ReadFileToUint64(zram_path.Append("mem_used_total"));
-}
-#endif
-
void MemoryDetails::CollectProcessData(
const std::vector<ProcessMemoryInformation>& child_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -269,7 +234,7 @@ void MemoryDetails::CollectProcessData(
}
#if defined(OS_CHROMEOS)
- GetSwapData(&swap_data_);
+ base::GetSwapInfo(&swap_info_);
#endif
// Finally return to the browser thread.