Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / power_profiler / power_data_provider_ia_win.cc
blob597e3bd73ac53730372ab386ee9e3e6db6ede4c3
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"
9 namespace content {
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()
20 : sockets_number_(0),
21 is_open_(false) {
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())
33 return events;
35 PowerEvent event;
36 double package_power = 0.0;
37 double power[3];
38 int data_count;
40 for (int i = 0; i < sockets_number_; i++) {
41 if (power_msr_ids_[PowerEvent::SOC_PACKAGE] == -1)
42 break;
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);
54 return events;
57 bool PowerDataProviderIA::Initialize() {
58 if (is_open_)
59 return true;
61 if (!energy_lib_.IntelEnergyLibInitialize()) {
62 LOG(ERROR) << "Power Data Provider initialize failed!";
63 return false;
66 energy_lib_.GetNumNodes(&sockets_number_);
68 const std::wstring package_msr_name = L"Processor";
70 int msr_number;
71 energy_lib_.GetNumMsrs(&msr_number);
73 int func_id;
74 wchar_t name[32];
75 for(int i = 0; i < msr_number; i++) {
76 energy_lib_.GetMsrFunc(i, &func_id);
77 energy_lib_.GetMsrName(i, name);
79 if (func_id != 1)
80 continue;
82 if (package_msr_name.compare(name) == 0)
83 power_msr_ids_[PowerEvent::SOC_PACKAGE] = i;
86 is_open_ = true;
87 return true;
90 } // namespace content