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

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

Issue 1549643002: Switch to standard integer types in extensions/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clean
Patch Set: Created 4 years, 12 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>
8
7 #include <cstdio> 9 #include <cstdio>
8 #include <sstream> 10 #include <sstream>
9 11
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
11 #include "base/format_macros.h" 13 #include "base/format_macros.h"
12 14
13 namespace extensions { 15 namespace extensions {
14 16
15 namespace { 17 namespace {
16 18
(...skipping 23 matching lines...) Expand all
40 std::istringstream iss(contents); 42 std::istringstream iss(contents);
41 std::string line; 43 std::string line;
42 44
43 // Skip the first line because it is just an aggregated number of 45 // Skip the first line because it is just an aggregated number of
44 // all cpuN lines. 46 // all cpuN lines.
45 std::getline(iss, line); 47 std::getline(iss, line);
46 while (std::getline(iss, line)) { 48 while (std::getline(iss, line)) {
47 if (line.compare(0, 3, "cpu") != 0) 49 if (line.compare(0, 3, "cpu") != 0)
48 continue; 50 continue;
49 51
50 uint64 user = 0, nice = 0, sys = 0, idle = 0; 52 uint64_t user = 0, nice = 0, sys = 0, idle = 0;
51 uint32 pindex = 0; 53 uint32_t pindex = 0;
52 int vals = 54 int vals =
53 sscanf(line.c_str(), 55 sscanf(line.c_str(),
54 "cpu%" PRIu32 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, 56 "cpu%" PRIu32 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64,
55 &pindex, 57 &pindex,
56 &user, 58 &user,
57 &nice, 59 &nice,
58 &sys, 60 &sys,
59 &idle); 61 &idle);
60 if (vals != 5 || pindex >= infos->size()) { 62 if (vals != 5 || pindex >= infos->size()) {
61 NOTREACHED(); 63 NOTREACHED();
62 return false; 64 return false;
63 } 65 }
64 66
65 infos->at(pindex)->usage.kernel = static_cast<double>(sys); 67 infos->at(pindex)->usage.kernel = static_cast<double>(sys);
66 infos->at(pindex)->usage.user = static_cast<double>(user + nice); 68 infos->at(pindex)->usage.user = static_cast<double>(user + nice);
67 infos->at(pindex)->usage.idle = static_cast<double>(idle); 69 infos->at(pindex)->usage.idle = static_cast<double>(idle);
68 infos->at(pindex)->usage.total = 70 infos->at(pindex)->usage.total =
69 static_cast<double>(sys + user + nice + idle); 71 static_cast<double>(sys + user + nice + idle);
70 } 72 }
71 73
72 return true; 74 return true;
73 } 75 }
74 76
75 } // namespace extensions 77 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/system_cpu/cpu_info_provider.h ('k') | extensions/browser/api/system_display/display_info_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698