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

Side by Side Diff: content/gpu/gpu_info_collector_win.cc

Issue 10128002: Retrieve Windows performance assessment information from results files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/gpu/gpu_info_collector.h" 5 #include "content/gpu/gpu_info_collector.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <d3d9.h> 8 #include <d3d9.h>
9 #include <setupapi.h> 9 #include <setupapi.h>
10 #include <winsatcominterfacei.h> 10 #include <winsatcominterfacei.h>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h"
15 #include "base/libxml_utils.h"
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/scoped_native_library.h" 17 #include "base/scoped_native_library.h"
16 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 19 #include "base/string_util.h"
18 #include "base/win/scoped_com_initializer.h" 20 #include "base/win/scoped_com_initializer.h"
19 #include "base/win/scoped_comptr.h" 21 #include "base/win/scoped_comptr.h"
20 #include "ui/gfx/gl/gl_implementation.h" 22 #include "ui/gfx/gl/gl_implementation.h"
21 #include "ui/gfx/gl/gl_surface_egl.h" 23 #include "ui/gfx/gl/gl_surface_egl.h"
22 24
23 // ANGLE seems to require that main.h be included before any other ANGLE header. 25 // ANGLE seems to require that main.h be included before any other ANGLE header.
(...skipping 16 matching lines...) Expand all
40 base::win::ScopedComPtr<IProvideWinSATAssessmentInfo> subcomponent; 42 base::win::ScopedComPtr<IProvideWinSATAssessmentInfo> subcomponent;
41 if (FAILED(results->GetAssessmentInfo(type, subcomponent.Receive()))) 43 if (FAILED(results->GetAssessmentInfo(type, subcomponent.Receive())))
42 return 0.0; 44 return 0.0;
43 45
44 float score = 0.0; 46 float score = 0.0;
45 if (FAILED(subcomponent->get_Score(&score))) 47 if (FAILED(subcomponent->get_Score(&score)))
46 score = 0.0; 48 score = 0.0;
47 return score; 49 return score;
48 } 50 }
49 51
52 float GetAssessmentScoreFromFile(XmlReader* reader,
53 std::string assessment) {
vangelis 2012/04/24 00:37:30 Watch indentation.
dtu 2012/05/01 00:32:16 Done.
54 do {
55 if (reader->NodeName() == assessment) {
56 std::string score_string;
57 if (!reader->ReadElementContent(&score_string))
58 return 0.0;
59
60 double score;
61 if (!base::StringToDouble(score_string, &score))
62 return 0.0;
63
64 return static_cast<float>(score);
65 }
66 } while (reader->Read());
67
68 return 0.0;
69 }
70
50 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { 71 content::GpuPerformanceStats RetrieveGpuPerformanceStats() {
51 content::GpuPerformanceStats stats; 72 content::GpuPerformanceStats stats;
52 73
53 base::win::ScopedCOMInitializer com_initializer; 74 base::win::ScopedCOMInitializer com_initializer;
54 if (!com_initializer.succeeded()) { 75 if (!com_initializer.succeeded()) {
55 LOG(ERROR) << "CoInitializeEx() failed"; 76 LOG(ERROR) << "CoInitializeEx() failed";
56 return stats; 77 return stats;
57 } 78 }
58 79
59 base::win::ScopedComPtr<IQueryRecentWinSATAssessment> assessment; 80 base::win::ScopedComPtr<IQueryRecentWinSATAssessment> assessment;
(...skipping 13 matching lines...) Expand all
73 94
74 WINSAT_ASSESSMENT_STATE state = WINSAT_ASSESSMENT_STATE_UNKNOWN; 95 WINSAT_ASSESSMENT_STATE state = WINSAT_ASSESSMENT_STATE_UNKNOWN;
75 hr = results->get_AssessmentState(&state); 96 hr = results->get_AssessmentState(&state);
76 if (FAILED(hr)) { 97 if (FAILED(hr)) {
77 LOG(ERROR) << "get_AssessmentState() failed"; 98 LOG(ERROR) << "get_AssessmentState() failed";
78 return stats; 99 return stats;
79 } 100 }
80 101
81 if (state != WINSAT_ASSESSMENT_STATE_VALID && 102 if (state != WINSAT_ASSESSMENT_STATE_VALID &&
82 state != WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE) { 103 state != WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE) {
83 LOG(ERROR) << "Can't retrieve a valid assessment"; 104 // If the user re-runs the assessment without restarting, the COM API
105 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. For that case,
106 // fall back to reading the assessment result files directly.
107 file_util::FileEnumerator file_enumerator(
vangelis 2012/04/24 00:37:30 Given the flakiness of the winsat api, we should a
dtu 2012/05/01 00:32:16 Done.
108 FilePath(FILE_PATH_LITERAL("c:/Windows/Performance/WinSAT/DataStore/")),
vangelis 2012/04/24 00:37:30 You should probably use %windir% instead of hardco
dtu 2012/05/01 00:32:16 Done.
109 false, // not recursive
110 file_util::FileEnumerator::FILES,
111 FILE_PATH_LITERAL("* * Formal.Assessment (*).WinSAT.xml"));
112
113 FilePath current_results;
114 for (FilePath results = file_enumerator.Next(); !results.empty();
115 results = file_enumerator.Next())
116 if (FilePath::CompareLessIgnoreCase(current_results.value(),
117 results.value()))
118 current_results = results;
119
120 if (current_results.empty()) {
121 LOG(ERROR) << "Can't retrieve a valid assessment";
122 return stats;
123 }
124
125 XmlReader reader;
126 reader.LoadFile(current_results);
127
128 stats.overall = GetAssessmentScoreFromFile(&reader, "SystemScore");
vangelis 2012/04/24 00:37:30 The WinSAT xml schema is here: http://msdn.microso
dtu 2012/05/01 00:32:16 Done.
129 if (stats.overall == 0.0)
130 LOG(ERROR) << "Could not read overall score from assessment results.";
131
132 stats.graphics = GetAssessmentScoreFromFile(&reader, "GraphicsScore");
133 if (stats.graphics == 0.0)
134 LOG(ERROR) << "Could not read graphics score from assessment results.";
135
136 stats.gaming = GetAssessmentScoreFromFile(&reader, "GamingScore");
137 if (stats.gaming == 0.0)
138 LOG(ERROR) << "Could not read gaming score from assessment results.";
139
84 return stats; 140 return stats;
85 } 141 }
86 142
87 hr = results->get_SystemRating(&stats.overall); 143 hr = results->get_SystemRating(&stats.overall);
88 if (FAILED(hr)) 144 if (FAILED(hr))
89 LOG(ERROR) << "Get overall score failed"; 145 LOG(ERROR) << "Get overall score failed";
90 146
91 stats.gaming = GetAssessmentScore(results, WINSAT_ASSESSMENT_D3D); 147 stats.gaming = GetAssessmentScore(results, WINSAT_ASSESSMENT_D3D);
92 if (stats.gaming == 0.0) 148 if (stats.gaming == 0.0)
93 LOG(ERROR) << "Get gaming score failed"; 149 LOG(ERROR) << "Get gaming score failed";
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 367
312 size_t pos = gl_version_string.find_last_not_of("0123456789."); 368 size_t pos = gl_version_string.find_last_not_of("0123456789.");
313 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { 369 if (pos != std::string::npos && pos < gl_version_string.length() - 1) {
314 gpu_info->driver_version = gl_version_string.substr(pos + 1); 370 gpu_info->driver_version = gl_version_string.substr(pos + 1);
315 return true; 371 return true;
316 } 372 }
317 return false; 373 return false;
318 } 374 }
319 375
320 } // namespace gpu_info_collector 376 } // namespace gpu_info_collector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698