Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / sysapps / device_capabilities / cpu_info_provider_android.cc
1 // Copyright (c) 2013 Intel Corporation. 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.
4
5 #include "xwalk/sysapps/device_capabilities/cpu_info_provider.h"
6
7 #include <string>
8
9 #include "base/files/file_util.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/sys_info.h"
13
14 namespace {
15
16 const char kProcLoadavg[] = "/proc/loadavg";
17
18 }  // namespace
19
20 namespace xwalk {
21 namespace sysapps {
22
23 double CPUInfoProvider::GetCPULoad() const {
24   // Bionic doesn't have a getloadavg() implementation.
25   const base::FilePath proc_loadavg(kProcLoadavg);
26   std::string buffer;
27
28   base::ReadFileToString(proc_loadavg, &buffer);
29
30   std::vector<std::string> stats;
31   base::SplitString(buffer, ' ', &stats);
32
33   double load;
34   base::StringToDouble(stats[0], &load);
35
36   return std::min(load / number_of_processors_, 1.0);
37 }
38
39 }  // namespace sysapps
40 }  // namespace xwalk