OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/system_cpu/cpu_info_provider.h" | 5 #include "extensions/browser/api/system_cpu/cpu_info_provider.h" |
6 | 6 |
7 #include <cstdio> | 7 #include <cstdio> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char kProcStat[] = "/proc/stat"; | 17 const char kProcStat[] = "/proc/stat"; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 bool CpuInfoProvider::QueryCpuTimePerProcessor( | 21 bool CpuInfoProvider::QueryCpuTimePerProcessor( |
22 std::vector<linked_ptr<api::system_cpu::ProcessorInfo> >* infos) { | 22 std::vector<linked_ptr<core_api::system_cpu::ProcessorInfo> >* infos) { |
23 DCHECK(infos); | 23 DCHECK(infos); |
24 | 24 |
25 std::string contents; | 25 std::string contents; |
26 if (!base::ReadFileToString(base::FilePath(kProcStat), &contents)) | 26 if (!base::ReadFileToString(base::FilePath(kProcStat), &contents)) |
27 return false; | 27 return false; |
28 | 28 |
29 std::istringstream iss(contents); | 29 std::istringstream iss(contents); |
30 std::string line; | 30 std::string line; |
31 | 31 |
32 // Skip the first line because it is just an aggregated number of | 32 // Skip the first line because it is just an aggregated number of |
(...skipping 14 matching lines...) Expand all Loading... |
47 infos->at(i)->usage.user = static_cast<double>(user + nice); | 47 infos->at(i)->usage.user = static_cast<double>(user + nice); |
48 infos->at(i)->usage.idle = static_cast<double>(idle); | 48 infos->at(i)->usage.idle = static_cast<double>(idle); |
49 infos->at(i)->usage.total = static_cast<double>(sys + user + nice + idle); | 49 infos->at(i)->usage.total = static_cast<double>(sys + user + nice + idle); |
50 ++i; | 50 ++i; |
51 } | 51 } |
52 DCHECK_EQ(infos->size(), i); | 52 DCHECK_EQ(infos->size(), i); |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 } // namespace extensions | 56 } // namespace extensions |
OLD | NEW |