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
3 // found in the LICENSE file.
5 #include "base/process/process_metrics.h"
7 #include "base/values.h"
11 SystemMetrics::SystemMetrics() {
12 committed_memory_
= 0;
15 SystemMetrics
SystemMetrics::Sample() {
16 SystemMetrics system_metrics
;
18 system_metrics
.committed_memory_
= GetSystemCommitCharge();
19 #if defined(OS_LINUX) || defined(OS_ANDROID)
20 GetSystemMemoryInfo(&system_metrics
.memory_info_
);
21 GetSystemDiskInfo(&system_metrics
.disk_info_
);
23 #if defined(OS_CHROMEOS)
24 GetSwapInfo(&system_metrics
.swap_info_
);
27 return system_metrics
;
30 scoped_ptr
<Value
> SystemMetrics::ToValue() const {
31 scoped_ptr
<DictionaryValue
> res(new DictionaryValue());
33 res
->SetInteger("committed_memory", static_cast<int>(committed_memory_
));
34 #if defined(OS_LINUX) || defined(OS_ANDROID)
35 res
->Set("meminfo", memory_info_
.ToValue().release());
36 res
->Set("diskinfo", disk_info_
.ToValue().release());
38 #if defined(OS_CHROMEOS)
39 res
->Set("swapinfo", swap_info_
.ToValue().release());
42 return res
.PassAs
<Value
>();