Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Side by Side Diff: extensions/browser/api/system_cpu/cpu_info_provider_linux.cc

Issue 1842953002: [Extensions] Convert APIs to use movable types [13] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "extensions/browser/api/system_cpu/cpu_info_provider.h" 5 #include "extensions/browser/api/system_cpu/cpu_info_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstdio> 9 #include <cstdio>
10 #include <sstream> 10 #include <sstream>
11 11
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/format_macros.h" 13 #include "base/format_macros.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 namespace { 17 namespace {
18 18
19 const char kProcStat[] = "/proc/stat"; 19 const char kProcStat[] = "/proc/stat";
20 20
21 } // namespace 21 } // namespace
22 22
23 bool CpuInfoProvider::QueryCpuTimePerProcessor( 23 bool CpuInfoProvider::QueryCpuTimePerProcessor(
24 std::vector<linked_ptr<api::system_cpu::ProcessorInfo>>* infos) { 24 std::vector<api::system_cpu::ProcessorInfo>* infos) {
25 DCHECK(infos); 25 DCHECK(infos);
26 26
27 // WARNING: this method may return incomplete data because some processors may 27 // WARNING: this method may return incomplete data because some processors may
28 // be brought offline at runtime. /proc/stat does not report statistics of 28 // be brought offline at runtime. /proc/stat does not report statistics of
29 // offline processors. CPU usages of offline processors will be filled with 29 // offline processors. CPU usages of offline processors will be filled with
30 // zeros. 30 // zeros.
31 // 31 //
32 // An example of output of /proc/stat when processor 0 and 3 are online, but 32 // An example of output of /proc/stat when processor 0 and 3 are online, but
33 // processor 1 and 2 are offline: 33 // processor 1 and 2 are offline:
34 // 34 //
(...skipping 22 matching lines...) Expand all
57 &pindex, 57 &pindex,
58 &user, 58 &user,
59 &nice, 59 &nice,
60 &sys, 60 &sys,
61 &idle); 61 &idle);
62 if (vals != 5 || pindex >= infos->size()) { 62 if (vals != 5 || pindex >= infos->size()) {
63 NOTREACHED(); 63 NOTREACHED();
64 return false; 64 return false;
65 } 65 }
66 66
67 infos->at(pindex)->usage.kernel = static_cast<double>(sys); 67 infos->at(pindex).usage.kernel = static_cast<double>(sys);
68 infos->at(pindex)->usage.user = static_cast<double>(user + nice); 68 infos->at(pindex).usage.user = static_cast<double>(user + nice);
69 infos->at(pindex)->usage.idle = static_cast<double>(idle); 69 infos->at(pindex).usage.idle = static_cast<double>(idle);
70 infos->at(pindex)->usage.total = 70 infos->at(pindex).usage.total =
71 static_cast<double>(sys + user + nice + idle); 71 static_cast<double>(sys + user + nice + idle);
72 } 72 }
73 73
74 return true; 74 return true;
75 } 75 }
76 76
77 } // namespace extensions 77 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/system_cpu/cpu_info_provider.cc ('k') | extensions/browser/api/system_cpu/cpu_info_provider_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698