[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / power_profiler / power_data_provider_ia_win.cc
blob2127ae299734b293b6a68b5c08e33b7f77475f00
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
3 // found in the LICENSE file.
5 #include "content/browser/power_profiler/power_data_provider_ia_win.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
10 namespace content {
12 // Default sampling period, as recommended by Intel Power Gadget.
13 // Section 3.1 of
14 // http://software.intel.com/en-us/blogs/2013/10/03/using-the-intel-power-gadget-api-on-windows
15 const int kDefaultSamplePeriodMs = 50;
17 scoped_ptr<PowerDataProvider> PowerDataProvider::Create() {
18 scoped_ptr<PowerDataProviderIA> provider(new PowerDataProviderIA());
19 if (provider->Initialize())
20 return make_scoped_ptr<PowerDataProvider>(provider.release());
22 return make_scoped_ptr<PowerDataProvider>(NULL);
25 PowerDataProviderIA::PowerDataProviderIA()
26 : sockets_number_(0),
27 is_open_(false) {
28 for (int i = 0; i < PowerEvent::ID_COUNT; i++ )
29 power_msr_ids_[i] = -1;
32 PowerDataProviderIA::~PowerDataProviderIA() {
35 PowerEventVector PowerDataProviderIA::GetData() {
36 PowerEventVector events;
38 if (!energy_lib_.ReadSample())
39 return events;
41 PowerEvent event;
42 double package_power = 0.0;
43 double power[3];
44 int data_count;
46 for (int i = 0; i < sockets_number_; i++) {
47 if (power_msr_ids_[PowerEvent::SOC_PACKAGE] == -1)
48 break;
50 energy_lib_.GetPowerData(i,
51 power_msr_ids_[PowerEvent::SOC_PACKAGE], power, &data_count);
52 package_power += power[0];
55 event.type = PowerEvent::SOC_PACKAGE;
56 event.value = package_power;
57 event.time = base::TimeTicks::Now();
58 events.push_back(event);
60 return events;
63 base::TimeDelta PowerDataProviderIA::GetSamplingRate() {
64 return base::TimeDelta::FromMilliseconds(kDefaultSamplePeriodMs);
67 bool PowerDataProviderIA::Initialize() {
68 if (is_open_)
69 return true;
71 if (!energy_lib_.IntelEnergyLibInitialize()) {
72 LOG(ERROR) << "Power Data Provider initialize failed!";
73 return false;
76 energy_lib_.GetNumNodes(&sockets_number_);
78 const std::wstring package_msr_name = L"Processor";
80 int msr_number;
81 energy_lib_.GetNumMsrs(&msr_number);
83 int func_id;
84 wchar_t name[32];
85 for(int i = 0; i < msr_number; i++) {
86 energy_lib_.GetMsrFunc(i, &func_id);
87 energy_lib_.GetMsrName(i, name);
89 if (func_id != 1)
90 continue;
92 if (package_msr_name.compare(name) == 0)
93 power_msr_ids_[PowerEvent::SOC_PACKAGE] = i;
96 is_open_ = true;
97 return true;
100 } // namespace content