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/logging.h"
11 scoped_ptr
<PowerDataProvider
> PowerDataProvider::Create() {
12 scoped_ptr
<PowerDataProviderIA
> provider(new PowerDataProviderIA());
13 if (provider
->Initialize())
14 return make_scoped_ptr
<PowerDataProvider
>(provider
.release());
16 return make_scoped_ptr
<PowerDataProvider
>(NULL
);
19 PowerDataProviderIA::PowerDataProviderIA()
22 for (int i
= 0; i
< PowerEvent::ID_COUNT
; i
++ )
23 power_msr_ids_
[i
] = -1;
26 PowerDataProviderIA::~PowerDataProviderIA() {
29 PowerEventVector
PowerDataProviderIA::GetData() {
30 PowerEventVector events
;
32 if (!energy_lib_
.ReadSample())
36 double package_power
= 0.0;
40 for (int i
= 0; i
< sockets_number_
; i
++) {
41 if (power_msr_ids_
[PowerEvent::SOC_PACKAGE
] == -1)
44 energy_lib_
.GetPowerData(i
,
45 power_msr_ids_
[PowerEvent::SOC_PACKAGE
], power
, &data_count
);
46 package_power
+= power
[0];
49 event
.type
= PowerEvent::SOC_PACKAGE
;
50 event
.value
= package_power
;
51 event
.time
= base::TimeTicks::Now();
52 events
.push_back(event
);
57 bool PowerDataProviderIA::Initialize() {
61 if (!energy_lib_
.IntelEnergyLibInitialize()) {
62 LOG(ERROR
) << "Power Data Provider initialize failed!";
66 energy_lib_
.GetNumNodes(&sockets_number_
);
68 const std::wstring package_msr_name
= L
"Processor";
71 energy_lib_
.GetNumMsrs(&msr_number
);
75 for(int i
= 0; i
< msr_number
; i
++) {
76 energy_lib_
.GetMsrFunc(i
, &func_id
);
77 energy_lib_
.GetMsrName(i
, name
);
82 if (package_msr_name
.compare(name
) == 0)
83 power_msr_ids_
[PowerEvent::SOC_PACKAGE
] = i
;
90 } // namespace content