This source file includes following definitions.
- ReadFileToUint64
- ReadProcStatusAndGetFieldAsSizeT
- GetProcessCPU
- CreateProcessMetrics
- GetPagefileUsage
- GetPeakPagefileUsage
- GetWorkingSetSize
- GetPeakWorkingSetSize
- GetMemoryBytes
- GetWorkingSetKBytes
- GetCPUUsage
- GetIOCounters
- last_cpu_
- GetWorkingSetKBytesTotmaps
- GetWorkingSetKBytesStatm
- GetSystemCommitCharge
- ParseProcStatCPU
- GetNumberOfThreads
- ToValue
- ParseProcMeminfo
- ParseProcVmstat
- GetSystemMemoryInfo
- ToValue
- IsValidDiskName
- GetSystemDiskInfo
- ToValue
- GetSwapInfo
#include "base/process/process_metrics.h"
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "base/file_util.h"
#include "base/logging.h"
#include "base/process/internal_linux.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/threading/thread_restrictions.h"
namespace base {
namespace {
enum ParsingState {
KEY_NAME,
KEY_VALUE
};
#ifdef OS_CHROMEOS
static uint64 ReadFileToUint64(const base::FilePath file) {
std::string file_as_string;
if (!ReadFileToString(file, &file_as_string))
return 0;
base::TrimWhitespaceASCII(file_as_string, base::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
size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) {
FilePath stat_file = internal::GetProcPidDir(pid).Append("status");
std::string status;
{
ThreadRestrictions::ScopedAllowIO allow_io;
if (!ReadFileToString(stat_file, &status))
return 0;
}
StringTokenizer tokenizer(status, ":\n");
ParsingState state = KEY_NAME;
StringPiece last_key_name;
while (tokenizer.GetNext()) {
switch (state) {
case KEY_NAME:
last_key_name = tokenizer.token_piece();
state = KEY_VALUE;
break;
case KEY_VALUE:
DCHECK(!last_key_name.empty());
if (last_key_name == field) {
std::string value_str;
tokenizer.token_piece().CopyToString(&value_str);
std::string value_str_trimmed;
base::TrimWhitespaceASCII(value_str, base::TRIM_ALL,
&value_str_trimmed);
std::vector<std::string> split_value_str;
SplitString(value_str_trimmed, ' ', &split_value_str);
if (split_value_str.size() != 2 || split_value_str[1] != "kB") {
NOTREACHED();
return 0;
}
size_t value;
if (!StringToSizeT(split_value_str[0], &value)) {
NOTREACHED();
return 0;
}
return value;
}
state = KEY_NAME;
break;
}
}
NOTREACHED();
return 0;
}
int GetProcessCPU(pid_t pid) {
FilePath task_path = internal::GetProcPidDir(pid).Append("task");
DIR* dir = opendir(task_path.value().c_str());
if (!dir) {
DPLOG(ERROR) << "opendir(" << task_path.value() << ")";
return -1;
}
int total_cpu = 0;
while (struct dirent* ent = readdir(dir)) {
pid_t tid = internal::ProcDirSlotToPid(ent->d_name);
if (!tid)
continue;
ThreadRestrictions::ScopedAllowIO allow_io;
std::string stat;
FilePath stat_path =
task_path.Append(ent->d_name).Append(internal::kStatFile);
if (ReadFileToString(stat_path, &stat)) {
int cpu = ParseProcStatCPU(stat);
if (cpu > 0)
total_cpu += cpu;
}
}
closedir(dir);
return total_cpu;
}
}
ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
return new ProcessMetrics(process);
}
size_t ProcessMetrics::GetPagefileUsage() const {
return internal::ReadProcStatsAndGetFieldAsSizeT(process_,
internal::VM_VSIZE);
}
size_t ProcessMetrics::GetPeakPagefileUsage() const {
return ReadProcStatusAndGetFieldAsSizeT(process_, "VmPeak") * 1024;
}
size_t ProcessMetrics::GetWorkingSetSize() const {
return internal::ReadProcStatsAndGetFieldAsSizeT(process_, internal::VM_RSS) *
getpagesize();
}
size_t ProcessMetrics::GetPeakWorkingSetSize() const {
return ReadProcStatusAndGetFieldAsSizeT(process_, "VmHWM") * 1024;
}
bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
size_t* shared_bytes) {
WorkingSetKBytes ws_usage;
if (!GetWorkingSetKBytes(&ws_usage))
return false;
if (private_bytes)
*private_bytes = ws_usage.priv * 1024;
if (shared_bytes)
*shared_bytes = ws_usage.shared * 1024;
return true;
}
bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
#if defined(OS_CHROMEOS)
if (GetWorkingSetKBytesTotmaps(ws_usage))
return true;
#endif
return GetWorkingSetKBytesStatm(ws_usage);
}
double ProcessMetrics::GetCPUUsage() {
struct timeval now;
int retval = gettimeofday(&now, NULL);
if (retval)
return 0;
int64 time = TimeValToMicroseconds(now);
if (last_cpu_time_ == 0) {
last_cpu_time_ = time;
last_cpu_ = GetProcessCPU(process_);
return 0;
}
int64 time_delta = time - last_cpu_time_;
DCHECK_NE(time_delta, 0);
if (time_delta == 0)
return 0;
int cpu = GetProcessCPU(process_);
TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu);
TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_);
int percentage = 100 * (cpu_time - last_cpu_time).InSecondsF() /
TimeDelta::FromMicroseconds(time_delta).InSecondsF();
last_cpu_time_ = time;
last_cpu_ = cpu;
return percentage;
}
bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
ThreadRestrictions::ScopedAllowIO allow_io;
std::string proc_io_contents;
FilePath io_file = internal::GetProcPidDir(process_).Append("io");
if (!ReadFileToString(io_file, &proc_io_contents))
return false;
(*io_counters).OtherOperationCount = 0;
(*io_counters).OtherTransferCount = 0;
StringTokenizer tokenizer(proc_io_contents, ": \n");
ParsingState state = KEY_NAME;
StringPiece last_key_name;
while (tokenizer.GetNext()) {
switch (state) {
case KEY_NAME:
last_key_name = tokenizer.token_piece();
state = KEY_VALUE;
break;
case KEY_VALUE:
DCHECK(!last_key_name.empty());
if (last_key_name == "syscr") {
StringToInt64(tokenizer.token_piece(),
reinterpret_cast<int64*>(&(*io_counters).ReadOperationCount));
} else if (last_key_name == "syscw") {
StringToInt64(tokenizer.token_piece(),
reinterpret_cast<int64*>(&(*io_counters).WriteOperationCount));
} else if (last_key_name == "rchar") {
StringToInt64(tokenizer.token_piece(),
reinterpret_cast<int64*>(&(*io_counters).ReadTransferCount));
} else if (last_key_name == "wchar") {
StringToInt64(tokenizer.token_piece(),
reinterpret_cast<int64*>(&(*io_counters).WriteTransferCount));
}
state = KEY_NAME;
break;
}
}
return true;
}
ProcessMetrics::ProcessMetrics(ProcessHandle process)
: process_(process),
last_cpu_time_(0),
last_system_time_(0),
last_cpu_(0) {
processor_count_ = base::SysInfo::NumberOfProcessors();
}
#if defined(OS_CHROMEOS)
bool ProcessMetrics::GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage)
const {
const size_t kPssIndex = (1 * 3) + 1;
const size_t kPrivate_CleanIndex = (4 * 3) + 1;
const size_t kPrivate_DirtyIndex = (5 * 3) + 1;
const size_t kSwapIndex = (9 * 3) + 1;
std::string totmaps_data;
{
FilePath totmaps_file = internal::GetProcPidDir(process_).Append("totmaps");
ThreadRestrictions::ScopedAllowIO allow_io;
bool ret = ReadFileToString(totmaps_file, &totmaps_data);
if (!ret || totmaps_data.length() == 0)
return false;
}
std::vector<std::string> totmaps_fields;
SplitStringAlongWhitespace(totmaps_data, &totmaps_fields);
DCHECK_EQ("Pss:", totmaps_fields[kPssIndex-1]);
DCHECK_EQ("Private_Clean:", totmaps_fields[kPrivate_CleanIndex - 1]);
DCHECK_EQ("Private_Dirty:", totmaps_fields[kPrivate_DirtyIndex - 1]);
DCHECK_EQ("Swap:", totmaps_fields[kSwapIndex-1]);
int pss = 0;
int private_clean = 0;
int private_dirty = 0;
int swap = 0;
bool ret = true;
ret &= StringToInt(totmaps_fields[kPssIndex], &pss);
ret &= StringToInt(totmaps_fields[kPrivate_CleanIndex], &private_clean);
ret &= StringToInt(totmaps_fields[kPrivate_DirtyIndex], &private_dirty);
ret &= StringToInt(totmaps_fields[kSwapIndex], &swap);
ws_usage->priv = private_clean + private_dirty + swap;
ws_usage->shared = pss + swap;
ws_usage->shareable = 0;
ws_usage->swapped = swap;
return ret;
}
#endif
bool ProcessMetrics::GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage)
const {
const int page_size_kb = getpagesize() / 1024;
if (page_size_kb <= 0)
return false;
std::string statm;
{
FilePath statm_file = internal::GetProcPidDir(process_).Append("statm");
ThreadRestrictions::ScopedAllowIO allow_io;
bool ret = ReadFileToString(statm_file, &statm);
if (!ret || statm.length() == 0)
return false;
}
std::vector<std::string> statm_vec;
SplitString(statm, ' ', &statm_vec);
if (statm_vec.size() != 7)
return false;
int statm_rss, statm_shared;
bool ret = true;
ret &= StringToInt(statm_vec[1], &statm_rss);
ret &= StringToInt(statm_vec[2], &statm_shared);
ws_usage->priv = (statm_rss - statm_shared) * page_size_kb;
ws_usage->shared = statm_shared * page_size_kb;
ws_usage->shareable = 0;
#if defined(OS_CHROMEOS)
ws_usage->swapped = 0;
#endif
return ret;
}
size_t GetSystemCommitCharge() {
SystemMemoryInfoKB meminfo;
if (!GetSystemMemoryInfo(&meminfo))
return 0;
return meminfo.total - meminfo.free - meminfo.buffers - meminfo.cached;
}
int ParseProcStatCPU(const std::string& input) {
std::vector<std::string> proc_stats;
if (!internal::ParseProcStats(input, &proc_stats))
return -1;
if (proc_stats.size() <= internal::VM_STIME)
return -1;
int utime = GetProcStatsFieldAsInt64(proc_stats, internal::VM_UTIME);
int stime = GetProcStatsFieldAsInt64(proc_stats, internal::VM_STIME);
return utime + stime;
}
const char kProcSelfExe[] = "/proc/self/exe";
int GetNumberOfThreads(ProcessHandle process) {
return internal::ReadProcStatsAndGetFieldAsInt64(process,
internal::VM_NUMTHREADS);
}
namespace {
const size_t kDiskDriveName = 2;
const size_t kDiskReads = 3;
const size_t kDiskReadsMerged = 4;
const size_t kDiskSectorsRead = 5;
const size_t kDiskReadTime = 6;
const size_t kDiskWrites = 7;
const size_t kDiskWritesMerged = 8;
const size_t kDiskSectorsWritten = 9;
const size_t kDiskWriteTime = 10;
const size_t kDiskIO = 11;
const size_t kDiskIOTime = 12;
const size_t kDiskWeightedIOTime = 13;
}
SystemMemoryInfoKB::SystemMemoryInfoKB() {
total = 0;
free = 0;
buffers = 0;
cached = 0;
active_anon = 0;
inactive_anon = 0;
active_file = 0;
inactive_file = 0;
swap_total = 0;
swap_free = 0;
dirty = 0;
pswpin = 0;
pswpout = 0;
pgmajfault = 0;
#ifdef OS_CHROMEOS
shmem = 0;
slab = 0;
gem_objects = -1;
gem_size = -1;
#endif
}
scoped_ptr<Value> SystemMemoryInfoKB::ToValue() const {
scoped_ptr<DictionaryValue> res(new base::DictionaryValue());
res->SetInteger("total", total);
res->SetInteger("free", free);
res->SetInteger("buffers", buffers);
res->SetInteger("cached", cached);
res->SetInteger("active_anon", active_anon);
res->SetInteger("inactive_anon", inactive_anon);
res->SetInteger("active_file", active_file);
res->SetInteger("inactive_file", inactive_file);
res->SetInteger("swap_total", swap_total);
res->SetInteger("swap_free", swap_free);
res->SetInteger("swap_used", swap_total - swap_free);
res->SetInteger("dirty", dirty);
res->SetInteger("pswpin", pswpin);
res->SetInteger("pswpout", pswpout);
res->SetInteger("pgmajfault", pgmajfault);
#ifdef OS_CHROMEOS
res->SetInteger("shmem", shmem);
res->SetInteger("slab", slab);
res->SetInteger("gem_objects", gem_objects);
res->SetInteger("gem_size", gem_size);
#endif
return res.PassAs<Value>();
}
bool ParseProcMeminfo(const std::string& meminfo_data,
SystemMemoryInfoKB* meminfo) {
meminfo->total = 0;
std::vector<std::string> meminfo_lines;
Tokenize(meminfo_data, "\n", &meminfo_lines);
for (std::vector<std::string>::iterator it = meminfo_lines.begin();
it != meminfo_lines.end(); ++it) {
std::vector<std::string> tokens;
SplitStringAlongWhitespace(*it, &tokens);
if (tokens.size() > 1) {
if (tokens[0] == "MemTotal:") {
StringToInt(tokens[1], &meminfo->total);
continue;
} if (tokens[0] == "MemFree:") {
StringToInt(tokens[1], &meminfo->free);
continue;
} if (tokens[0] == "Buffers:") {
StringToInt(tokens[1], &meminfo->buffers);
continue;
} if (tokens[0] == "Cached:") {
StringToInt(tokens[1], &meminfo->cached);
continue;
} if (tokens[0] == "Active(anon):") {
StringToInt(tokens[1], &meminfo->active_anon);
continue;
} if (tokens[0] == "Inactive(anon):") {
StringToInt(tokens[1], &meminfo->inactive_anon);
continue;
} if (tokens[0] == "Active(file):") {
StringToInt(tokens[1], &meminfo->active_file);
continue;
} if (tokens[0] == "Inactive(file):") {
StringToInt(tokens[1], &meminfo->inactive_file);
continue;
} if (tokens[0] == "SwapTotal:") {
StringToInt(tokens[1], &meminfo->swap_total);
continue;
} if (tokens[0] == "SwapFree:") {
StringToInt(tokens[1], &meminfo->swap_free);
continue;
} if (tokens[0] == "Dirty:") {
StringToInt(tokens[1], &meminfo->dirty);
continue;
#if defined(OS_CHROMEOS)
} if (tokens[0] == "Shmem:") {
StringToInt(tokens[1], &meminfo->shmem);
continue;
} if (tokens[0] == "Slab:") {
StringToInt(tokens[1], &meminfo->slab);
continue;
#endif
}
} else
DLOG(WARNING) << "meminfo: tokens: " << tokens.size()
<< " malformed line: " << *it;
}
if (!meminfo->total)
return false;
return true;
}
bool ParseProcVmstat(const std::string& vmstat_data,
SystemMemoryInfoKB* meminfo) {
std::vector<std::string> vmstat_lines;
Tokenize(vmstat_data, "\n", &vmstat_lines);
for (std::vector<std::string>::iterator it = vmstat_lines.begin();
it != vmstat_lines.end(); ++it) {
std::vector<std::string> tokens;
SplitString(*it, ' ', &tokens);
if (tokens.size() == 2) {
if (tokens[0] == "pswpin") {
StringToInt(tokens[1], &meminfo->pswpin);
continue;
} if (tokens[0] == "pswpout") {
StringToInt(tokens[1], &meminfo->pswpout);
continue;
} if (tokens[0] == "pgmajfault")
StringToInt(tokens[1], &meminfo->pgmajfault);
}
}
return true;
}
bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
ThreadRestrictions::ScopedAllowIO allow_io;
FilePath meminfo_file("/proc/meminfo");
std::string meminfo_data;
if (!ReadFileToString(meminfo_file, &meminfo_data)) {
DLOG(WARNING) << "Failed to open " << meminfo_file.value();
return false;
}
if (!ParseProcMeminfo(meminfo_data, meminfo)) {
DLOG(WARNING) << "Failed to parse " << meminfo_file.value();
return false;
}
#if defined(OS_CHROMEOS)
#if defined(ARCH_CPU_ARM_FAMILY)
FilePath geminfo_file("/var/run/debugfs_gpu/exynos_gem_objects");
#else
FilePath geminfo_file("/var/run/debugfs_gpu/i915_gem_objects");
#endif
std::string geminfo_data;
meminfo->gem_objects = -1;
meminfo->gem_size = -1;
if (ReadFileToString(geminfo_file, &geminfo_data)) {
int gem_objects = -1;
long long gem_size = -1;
int num_res = sscanf(geminfo_data.c_str(),
"%d objects, %lld bytes",
&gem_objects, &gem_size);
if (num_res == 2) {
meminfo->gem_objects = gem_objects;
meminfo->gem_size = gem_size;
}
}
#if defined(ARCH_CPU_ARM_FAMILY)
FilePath mali_memory_file("/sys/class/misc/mali0/device/memory");
std::string mali_memory_data;
if (ReadFileToString(mali_memory_file, &mali_memory_data)) {
long long mali_size = -1;
int num_res = sscanf(mali_memory_data.c_str(), "%lld bytes", &mali_size);
if (num_res == 1)
meminfo->gem_size += mali_size;
}
#endif
#endif
FilePath vmstat_file("/proc/vmstat");
std::string vmstat_data;
if (!ReadFileToString(vmstat_file, &vmstat_data)) {
DLOG(WARNING) << "Failed to open " << vmstat_file.value();
return false;
}
if (!ParseProcVmstat(vmstat_data, meminfo)) {
DLOG(WARNING) << "Failed to parse " << vmstat_file.value();
return false;
}
return true;
}
SystemDiskInfo::SystemDiskInfo() {
reads = 0;
reads_merged = 0;
sectors_read = 0;
read_time = 0;
writes = 0;
writes_merged = 0;
sectors_written = 0;
write_time = 0;
io = 0;
io_time = 0;
weighted_io_time = 0;
}
scoped_ptr<Value> SystemDiskInfo::ToValue() const {
scoped_ptr<DictionaryValue> res(new base::DictionaryValue());
res->SetDouble("reads", static_cast<double>(reads));
res->SetDouble("reads_merged", static_cast<double>(reads_merged));
res->SetDouble("sectors_read", static_cast<double>(sectors_read));
res->SetDouble("read_time", static_cast<double>(read_time));
res->SetDouble("writes", static_cast<double>(writes));
res->SetDouble("writes_merged", static_cast<double>(writes_merged));
res->SetDouble("sectors_written", static_cast<double>(sectors_written));
res->SetDouble("write_time", static_cast<double>(write_time));
res->SetDouble("io", static_cast<double>(io));
res->SetDouble("io_time", static_cast<double>(io_time));
res->SetDouble("weighted_io_time", static_cast<double>(weighted_io_time));
return res.PassAs<Value>();
}
bool IsValidDiskName(const std::string& candidate) {
if (candidate.length() < 3)
return false;
if (candidate.substr(0,2) == "sd" || candidate.substr(0,2) == "hd") {
for (size_t i = 2; i < candidate.length(); i++) {
if (!islower(candidate[i]))
return false;
}
} else {
if (candidate.length() < 7) {
return false;
}
if (candidate.substr(0,6) == "mmcblk") {
for (size_t i = 6; i < candidate.length(); i++) {
if (!isdigit(candidate[i]))
return false;
}
} else {
return false;
}
}
return true;
}
bool GetSystemDiskInfo(SystemDiskInfo* diskinfo) {
ThreadRestrictions::ScopedAllowIO allow_io;
FilePath diskinfo_file("/proc/diskstats");
std::string diskinfo_data;
if (!ReadFileToString(diskinfo_file, &diskinfo_data)) {
DLOG(WARNING) << "Failed to open " << diskinfo_file.value();
return false;
}
std::vector<std::string> diskinfo_lines;
size_t line_count = Tokenize(diskinfo_data, "\n", &diskinfo_lines);
if (line_count == 0) {
DLOG(WARNING) << "No lines found";
return false;
}
diskinfo->reads = 0;
diskinfo->reads_merged = 0;
diskinfo->sectors_read = 0;
diskinfo->read_time = 0;
diskinfo->writes = 0;
diskinfo->writes_merged = 0;
diskinfo->sectors_written = 0;
diskinfo->write_time = 0;
diskinfo->io = 0;
diskinfo->io_time = 0;
diskinfo->weighted_io_time = 0;
uint64 reads = 0;
uint64 reads_merged = 0;
uint64 sectors_read = 0;
uint64 read_time = 0;
uint64 writes = 0;
uint64 writes_merged = 0;
uint64 sectors_written = 0;
uint64 write_time = 0;
uint64 io = 0;
uint64 io_time = 0;
uint64 weighted_io_time = 0;
for (size_t i = 0; i < line_count; i++) {
std::vector<std::string> disk_fields;
SplitStringAlongWhitespace(diskinfo_lines[i], &disk_fields);
if (IsValidDiskName(disk_fields[kDiskDriveName])) {
StringToUint64(disk_fields[kDiskReads], &reads);
StringToUint64(disk_fields[kDiskReadsMerged], &reads_merged);
StringToUint64(disk_fields[kDiskSectorsRead], §ors_read);
StringToUint64(disk_fields[kDiskReadTime], &read_time);
StringToUint64(disk_fields[kDiskWrites], &writes);
StringToUint64(disk_fields[kDiskWritesMerged], &writes_merged);
StringToUint64(disk_fields[kDiskSectorsWritten], §ors_written);
StringToUint64(disk_fields[kDiskWriteTime], &write_time);
StringToUint64(disk_fields[kDiskIO], &io);
StringToUint64(disk_fields[kDiskIOTime], &io_time);
StringToUint64(disk_fields[kDiskWeightedIOTime], &weighted_io_time);
diskinfo->reads += reads;
diskinfo->reads_merged += reads_merged;
diskinfo->sectors_read += sectors_read;
diskinfo->read_time += read_time;
diskinfo->writes += writes;
diskinfo->writes_merged += writes_merged;
diskinfo->sectors_written += sectors_written;
diskinfo->write_time += write_time;
diskinfo->io += io;
diskinfo->io_time += io_time;
diskinfo->weighted_io_time += weighted_io_time;
}
}
return true;
}
#if defined(OS_CHROMEOS)
scoped_ptr<Value> SwapInfo::ToValue() const {
scoped_ptr<DictionaryValue> res(new DictionaryValue());
res->SetDouble("num_reads", static_cast<double>(num_reads));
res->SetDouble("num_writes", static_cast<double>(num_writes));
res->SetDouble("orig_data_size", static_cast<double>(orig_data_size));
res->SetDouble("compr_data_size", static_cast<double>(compr_data_size));
res->SetDouble("mem_used_total", static_cast<double>(mem_used_total));
if (compr_data_size > 0)
res->SetDouble("compression_ratio", static_cast<double>(orig_data_size) /
static_cast<double>(compr_data_size));
else
res->SetDouble("compression_ratio", 0);
return res.PassAs<Value>();
}
void GetSwapInfo(SwapInfo* swap_info) {
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) {
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
}