| Index: chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
|
| diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
|
| index 74b71637d8a60295d80222e4c7d0d87c6777912f..4b09dd14d3fc03aae2d5dda20a5ac69743a2b706 100644
|
| --- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
|
| +++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_linux.cc
|
| @@ -4,11 +4,50 @@
|
|
|
| #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
|
|
|
| +#include <cstdio>
|
| +#include <iostream>
|
| +
|
| +#include "base/file_util.h"
|
| +#include "base/format_macros.h"
|
| +
|
| namespace extensions {
|
|
|
| +namespace {
|
| +
|
| +const char kProcStat[] = "/proc/stat";
|
| +
|
| +} // namespace
|
| +
|
| bool CpuInfoProvider::QueryCpuTimePerProcessor(std::vector<CpuTime>* times) {
|
| - // TODO(hongbo): Query the cpu time from /proc/stat.
|
| - return false;
|
| + DCHECK(times);
|
| +
|
| + std::string contents;
|
| + if (!file_util::ReadFileToString(FilePath(kProcStat), &contents))
|
| + return false;
|
| +
|
| + std::istringstream iss(contents);
|
| + uint64 user = 0, nice = 0, sys = 0, idle = 0;
|
| + std::string line;
|
| +
|
| + // Skip the first line because it is just an aggregated number of
|
| + // all cpuN lines.
|
| + std::getline(iss, line);
|
| + std::vector<CpuTime> results;
|
| + while (std::getline(iss, line)) {
|
| + if (line.compare(0, 3, "cpu") != 0)
|
| + continue;
|
| +
|
| + sscanf(line.c_str(), "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
|
| + &user, &nice, &sys, &idle);
|
| +
|
| + CpuTime time;
|
| + time.kernel = sys;
|
| + time.user = user + nice;
|
| + time.idle = idle;
|
| + results.push_back(time);
|
| + }
|
| + times->swap(results);
|
| + return true;
|
| }
|
|
|
| } // namespace extensions
|
|
|