Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: third_party/power_gadget/IntelPowerGadgetLib.cpp

Issue 106223002: chrome power profiler chrome side changes (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright (c) (2013) Intel Corporation All Rights Reserved.
3
4 The source code, information and material ("Material") contained herein is owned by Intel Corporation or its suppliers or licensors, and title to such Material remains with Intel Corporation or its suppliers or licensors. The Material conta ins proprietary information of Intel or its suppliers and licensors. The Materia l is protected by worldwide copyright laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted , transmitted, distributed or disclosed in any way without Intel's prior express written permission. No license under any patent, copyright or other intellectua l property rights in the Material is granted to or conferred upon you, either ex pressly, by implication, inducement, estoppel or otherwise. Any license under su ch intellectual property rights must be express and approved by Intel in writing .
5
6
7 Include any supplier copyright notices as supplier requires Intel to use.
8
9 Include supplier trademarks or logos as supplier requires Intel to use, preceded by an asterisk. An asterisked footnote can be added as follows: *Third Party tr ademarks are the property of their respective owners.
10
11 Unless otherwise agreed by Intel in writing, you may not remove or alter this no tice or any other notice embedded in Materials by Intel or Intel’s suppliers or licensors in any way.
12 */
13
14 #include "IntelPowerGadgetLib.h"
15 #include <Windows.h>
16 #include <string>
17 #include <vector>
18
19 using namespace std;
20
21 wstring g_lastError;
22 HMODULE g_hModule = NULL;
23
24 static bool split(const wstring& s, wstring &path)
25 {
26 bool bResult = false;
27 vector<wstring> output;
28
29 wstring::size_type prev_pos = 0, pos = 0;
30
31 while((pos = s.find(L';', pos)) != wstring::npos)
32 {
33 wstring substring( s.substr(prev_pos, pos-prev_pos) );
34 if (substring.find(L"Power Gadget 2.") != wstring::npos)
35 {
36 path = substring;
37 bResult = true;
38 break;
39 }
40 prev_pos = ++pos;
41 }
42
43 if (!bResult)
44 {
45 wstring substring(s.substr(prev_pos, pos-prev_pos));
46
47 if (substring.find(L"Power Gadget 2.") != wstring::npos)
48 {
49 path = substring;
50 bResult = true;
51 }
52 }
53
54 if (bResult)
55 {
56 basic_string <char>::size_type pos = path.rfind(L" ");
57 wstring version = path.substr(pos+1, path.length());
58 double fVer = _wtof(version.c_str());
59 if (fVer > 2.6)
60 bResult = true;
61 }
62
63 return bResult;
64 }
65
66 static bool GetLibraryLocation(wstring& strLocation)
67 {
68 TCHAR *pszPath = _wgetenv(L"IPG_Dir");
69 if (pszPath == NULL || wcslen(pszPath) == 0)
70 return false;
71
72 TCHAR *pszVersion = _wgetenv(L"IPG_Ver");
73 if (pszVersion == NULL || wcslen(pszVersion) == 0)
74 return false;
75
76 int version = _wtof(pszVersion) * 100;
77 if (version >= 270)
78 {
79 #if _M_X64
80 strLocation = wstring(pszPath) + L"\\EnergyLib64.dll";
81 #else
82 strLocation = wstring(pszPath) + L"\\EnergyLib32.dll";
83 #endif
84 return true;
85 }
86 else
87 return false;
88 }
89
90 CIntelPowerGadgetLib::CIntelPowerGadgetLib(void) :
91 pInitialize(NULL),
92 pGetNumNodes(NULL),
93 pGetMsrName(NULL),
94 pGetMsrFunc(NULL),
95 pGetIAFrequency(NULL),
96 pGetTDP(NULL),
97 pGetMaxTemperature(NULL),
98 pGetTemperature(NULL),
99 pReadSample(NULL),
100 pGetSysTime(NULL),
101 pGetRDTSC(NULL),
102 pGetTimeInterval(NULL),
103 pGetBaseFrequency(NULL),
104 pGetPowerData(NULL),
105 pStartLog(NULL),
106 pStopLog(NULL),
107 pGetNumMsrs(NULL)
108 {
109 wstring strLocation;
110 if (GetLibraryLocation(strLocation) == false)
111 {
112 g_lastError = L"Intel Power Gadget 2.7 or higher not found. If u nsure, check if the path is in the user's path environment variable";
113 return;
114 }
115
116 g_hModule = LoadLibrary(strLocation.c_str());
117 if (g_hModule == NULL)
118 {
119 g_lastError = L"LoadLibrary failed on " + strLocation;
120 return;
121 }
122
123 pInitialize = (IPGInitialize) GetProcAddress(g_hModule, "IntelEnergyLibIniti alize");
124 pGetNumNodes = (IPGGetNumNodes) GetProcAddress(g_hModule, "GetNumNodes");
125 pGetMsrName = (IPGGetMsrName) GetProcAddress(g_hModule, "GetMsrName");
126 pGetMsrFunc = (IPGGetMsrFunc) GetProcAddress(g_hModule, "GetMsrFunc");
127 pGetIAFrequency = (IPGGetIAFrequency) GetProcAddress(g_hModule, "GetIAFreque ncy");
128 pGetTDP = (IPGGetTDP) GetProcAddress(g_hModule, "GetTDP");
129 pGetMaxTemperature = (IPGGetMaxTemperature) GetProcAddress(g_hModule, "GetMa xTemperature");
130 pGetTemperature = (IPGGetTemperature) GetProcAddress(g_hModule, "GetTemperat ure");
131 pReadSample = (IPGReadSample) GetProcAddress(g_hModule, "ReadSample");
132 pGetSysTime = (IPGGetSysTime) GetProcAddress(g_hModule, "GetSysTime");
133 pGetRDTSC = (IPGGetRDTSC) GetProcAddress(g_hModule, "GetRDTSC");
134 pGetTimeInterval = (IPGGetTimeInterval) GetProcAddress(g_hModule, "GetTimeIn terval");
135 pGetBaseFrequency = (IPGGetBaseFrequency) GetProcAddress(g_hModule, "GetBase Frequency");
136 pGetPowerData = (IPGGetPowerData) GetProcAddress(g_hModule, "GetPowerData");
137 pStartLog = (IPGStartLog) GetProcAddress(g_hModule, "StartLog");
138 pStopLog = (IPGStopLog) GetProcAddress(g_hModule, "StopLog");
139 pGetNumMsrs = (IPGGetNumMsrs) GetProcAddress(g_hModule, "GetNumMsrs");
140 }
141
142
143 CIntelPowerGadgetLib::~CIntelPowerGadgetLib(void)
144 {
145 if (g_hModule != NULL)
146 FreeLibrary(g_hModule);
147 }
148
149
150
151 wstring CIntelPowerGadgetLib::GetLastError()
152 {
153 return g_lastError;
154 }
155
156 bool CIntelPowerGadgetLib::IntelEnergyLibInitialize(void)
157 {
158 if (pInitialize == NULL)
159 return false;
160
161 bool bSuccess = pInitialize();
162 if (!bSuccess)
163 {
164 g_lastError = L"Initializing the energy library failed";
165 return false;
166 }
167
168 return true;
169 }
170
171
172 bool CIntelPowerGadgetLib::GetNumNodes(int * nNodes)
173 {
174 return pGetNumNodes(nNodes);
175 }
176
177 bool CIntelPowerGadgetLib::GetNumMsrs(int * nMsrs)
178 {
179 return pGetNumMsrs(nMsrs);
180 }
181
182 bool CIntelPowerGadgetLib::GetMsrName(int iMsr, wchar_t *pszName)
183 {
184 return pGetMsrName(iMsr, pszName);
185 }
186
187 bool CIntelPowerGadgetLib::GetMsrFunc(int iMsr, int *funcID)
188 {
189 return pGetMsrFunc(iMsr, funcID);
190 }
191
192 bool CIntelPowerGadgetLib::GetIAFrequency(int iNode, int *freqInMHz)
193 {
194 return pGetIAFrequency(iNode, freqInMHz);
195 }
196
197 bool CIntelPowerGadgetLib::GetTDP(int iNode, double *TDP)
198 {
199 return pGetTDP(iNode, TDP);
200 }
201
202 bool CIntelPowerGadgetLib::GetMaxTemperature(int iNode, int *degreeC)
203 {
204 return pGetMaxTemperature(iNode, degreeC);
205 }
206
207 bool CIntelPowerGadgetLib::GetTemperature(int iNode, int *degreeC)
208 {
209 return pGetTemperature(iNode, degreeC);
210 }
211
212 bool CIntelPowerGadgetLib::ReadSample()
213 {
214 bool bSuccess = pReadSample();
215 if (bSuccess == false)
216 g_lastError = L"MSR overflowed. You can safely discard this samp le";
217 return bSuccess;
218 }
219
220 bool CIntelPowerGadgetLib::GetSysTime(SYSTEMTIME *sysTime)
221 {
222 return pGetSysTime(sysTime);
223 }
224
225 bool CIntelPowerGadgetLib::GetRDTSC(UINT64 *TSC)
226 {
227 return pGetRDTSC(TSC);
228 }
229
230 bool CIntelPowerGadgetLib::GetTimeInterval(double *offset)
231 {
232 return pGetTimeInterval(offset);
233 }
234
235 bool CIntelPowerGadgetLib::GetBaseFrequency(int iNode, double *baseFrequency)
236 {
237 return pGetBaseFrequency(iNode, baseFrequency);
238 }
239
240 bool CIntelPowerGadgetLib::GetPowerData(int iNode, int iMSR, double *results, in t *nResult)
241 {
242 return pGetPowerData(iNode, iMSR, results, nResult);
243 }
244
245 bool CIntelPowerGadgetLib::StartLog(wchar_t *szFilename)
246 {
247 return pStartLog(szFilename);
248 }
249
250 bool CIntelPowerGadgetLib::StopLog()
251 {
252 return pStopLog();
253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698