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"
12 // Default sampling period, as recommended by Intel Power Gadget.
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()
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())
42 double package_power
= 0.0;
46 for (int i
= 0; i
< sockets_number_
; i
++) {
47 if (power_msr_ids_
[PowerEvent::SOC_PACKAGE
] == -1)
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
);
63 base::TimeDelta
PowerDataProviderIA::GetSamplingRate() {
64 return base::TimeDelta::FromMilliseconds(kDefaultSamplePeriodMs
);
67 PowerDataProvider::AccuracyLevel
PowerDataProviderIA::GetAccuracyLevel() {
71 bool PowerDataProviderIA::Initialize() {
75 if (!energy_lib_
.IntelEnergyLibInitialize()) {
76 LOG(ERROR
) << "Power Data Provider initialize failed!";
80 energy_lib_
.GetNumNodes(&sockets_number_
);
82 const std::wstring package_msr_name
= L
"Processor";
85 energy_lib_
.GetNumMsrs(&msr_number
);
89 for(int i
= 0; i
< msr_number
; i
++) {
90 energy_lib_
.GetMsrFunc(i
, &func_id
);
91 energy_lib_
.GetMsrName(i
, name
);
96 if (package_msr_name
.compare(name
) == 0)
97 power_msr_ids_
[PowerEvent::SOC_PACKAGE
] = i
;
104 } // namespace content