OLD | NEW |
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 "gpu/config/gpu_info_collector.h" | 5 #include "gpu/config/gpu_info_collector.h" |
6 | 6 |
7 // This has to be included before windows.h. | 7 // This has to be included before windows.h. |
8 #include "third_party/re2/re2/re2.h" | 8 #include "third_party/re2/re2/re2.h" |
9 | 9 |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (!reader->ReadElementContent(&score_string)) | 56 if (!reader->ReadElementContent(&score_string)) |
57 return 0.0; | 57 return 0.0; |
58 | 58 |
59 double score; | 59 double score; |
60 if (!base::StringToDouble(score_string, &score)) | 60 if (!base::StringToDouble(score_string, &score)) |
61 return 0.0; | 61 return 0.0; |
62 | 62 |
63 return static_cast<float>(score); | 63 return static_cast<float>(score); |
64 } | 64 } |
65 | 65 |
66 GpuPerformanceStats RetrieveGpuPerformanceStats() { | |
67 TRACE_EVENT0("gpu", "RetrieveGpuPerformanceStats"); | |
68 | |
69 // If the user re-runs the assessment without restarting, the COM API | |
70 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. Because of that and | |
71 // http://crbug.com/124325, read the assessment result files directly. | |
72 GpuPerformanceStats stats; | |
73 | |
74 // Get path to WinSAT results files. | |
75 wchar_t winsat_results_path[MAX_PATH]; | |
76 DWORD size = ExpandEnvironmentStrings( | |
77 L"%WinDir%\\Performance\\WinSAT\\DataStore\\", | |
78 winsat_results_path, MAX_PATH); | |
79 if (size == 0 || size > MAX_PATH) { | |
80 LOG(ERROR) << "The path to the WinSAT results is too long: " | |
81 << size << " chars."; | |
82 return stats; | |
83 } | |
84 | |
85 // Find most recent formal assessment results. | |
86 base::FileEnumerator file_enumerator( | |
87 base::FilePath(winsat_results_path), | |
88 false, // not recursive | |
89 base::FileEnumerator::FILES, | |
90 FILE_PATH_LITERAL("* * Formal.Assessment (*).WinSAT.xml")); | |
91 | |
92 base::FilePath current_results; | |
93 for (base::FilePath results = file_enumerator.Next(); !results.empty(); | |
94 results = file_enumerator.Next()) { | |
95 // The filenames start with the date and time as yyyy-mm-dd hh.mm.ss.xxx, | |
96 // so the greatest file lexicographically is also the most recent file. | |
97 if (base::FilePath::CompareLessIgnoreCase(current_results.value(), | |
98 results.value())) | |
99 current_results = results; | |
100 } | |
101 | |
102 std::string current_results_string = current_results.MaybeAsASCII(); | |
103 if (current_results_string.empty()) | |
104 return stats; | |
105 | |
106 // Get relevant scores from results file. XML schema at: | |
107 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa969210.aspx | |
108 XmlReader reader; | |
109 if (!reader.LoadFile(current_results_string)) { | |
110 LOG(ERROR) << "Could not open WinSAT results file."; | |
111 return stats; | |
112 } | |
113 // Descend into <WinSAT> root element. | |
114 if (!reader.SkipToElement() || !reader.Read()) { | |
115 LOG(ERROR) << "Could not read WinSAT results file."; | |
116 return stats; | |
117 } | |
118 | |
119 // Search for <WinSPR> element containing the results. | |
120 do { | |
121 if (reader.NodeName() == "WinSPR") | |
122 break; | |
123 } while (reader.Next()); | |
124 // Descend into <WinSPR> element. | |
125 if (!reader.Read()) { | |
126 LOG(ERROR) << "Could not find WinSPR element in results file."; | |
127 return stats; | |
128 } | |
129 | |
130 // Read scores. | |
131 for (int depth = reader.Depth(); reader.Depth() == depth; reader.Next()) { | |
132 std::string node_name = reader.NodeName(); | |
133 if (node_name == "SystemScore") | |
134 stats.overall = ReadXMLFloatValue(&reader); | |
135 else if (node_name == "GraphicsScore") | |
136 stats.graphics = ReadXMLFloatValue(&reader); | |
137 else if (node_name == "GamingScore") | |
138 stats.gaming = ReadXMLFloatValue(&reader); | |
139 } | |
140 | |
141 if (stats.overall == 0.0) | |
142 LOG(ERROR) << "Could not read overall score from assessment results."; | |
143 if (stats.graphics == 0.0) | |
144 LOG(ERROR) << "Could not read graphics score from assessment results."; | |
145 if (stats.gaming == 0.0) | |
146 LOG(ERROR) << "Could not read gaming score from assessment results."; | |
147 | |
148 return stats; | |
149 } | |
150 | |
151 GpuPerformanceStats RetrieveGpuPerformanceStatsWithHistograms() { | |
152 base::TimeTicks start_time = base::TimeTicks::Now(); | |
153 | |
154 GpuPerformanceStats stats = RetrieveGpuPerformanceStats(); | |
155 | |
156 UMA_HISTOGRAM_TIMES("GPU.WinSAT.ReadResultsFileTime", | |
157 base::TimeTicks::Now() - start_time); | |
158 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
159 "GPU.WinSAT.OverallScore2", | |
160 static_cast<base::HistogramBase::Sample>(stats.overall * 10), 10, 200, | |
161 50); | |
162 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
163 "GPU.WinSAT.GraphicsScore2", | |
164 static_cast<base::HistogramBase::Sample>(stats.graphics * 10), 10, 200, | |
165 50); | |
166 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
167 "GPU.WinSAT.GamingScore2", | |
168 static_cast<base::HistogramBase::Sample>(stats.gaming * 10), 10, 200, 50); | |
169 UMA_HISTOGRAM_BOOLEAN( | |
170 "GPU.WinSAT.HasResults", | |
171 stats.overall != 0.0 && stats.graphics != 0.0 && stats.gaming != 0.0); | |
172 | |
173 return stats; | |
174 } | |
175 | |
176 // Returns the display link driver version or an invalid version if it is | 66 // Returns the display link driver version or an invalid version if it is |
177 // not installed. | 67 // not installed. |
178 Version DisplayLinkVersion() { | 68 Version DisplayLinkVersion() { |
179 base::win::RegKey key; | 69 base::win::RegKey key; |
180 | 70 |
181 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY)) | 71 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY)) |
182 return Version(); | 72 return Version(); |
183 | 73 |
184 if (key.OpenKey(L"DisplayLink", KEY_READ | KEY_WOW64_64KEY)) | 74 if (key.OpenKey(L"DisplayLink", KEY_READ | KEY_WOW64_64KEY)) |
185 return Version(); | 75 return Version(); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 return kCollectInfoSuccess; | 388 return kCollectInfoSuccess; |
499 } | 389 } |
500 return kCollectInfoNonFatalFailure; | 390 return kCollectInfoNonFatalFailure; |
501 } | 391 } |
502 | 392 |
503 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { | 393 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { |
504 TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo"); | 394 TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo"); |
505 | 395 |
506 DCHECK(gpu_info); | 396 DCHECK(gpu_info); |
507 | 397 |
508 gpu_info->performance_stats = RetrieveGpuPerformanceStatsWithHistograms(); | |
509 | |
510 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled. | 398 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled. |
511 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll"); | 399 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll"); |
512 gpu_info->optimus = nvd3d9wrap != NULL; | 400 gpu_info->optimus = nvd3d9wrap != NULL; |
513 | 401 |
514 gpu_info->lenovo_dcute = IsLenovoDCuteInstalled(); | 402 gpu_info->lenovo_dcute = IsLenovoDCuteInstalled(); |
515 | 403 |
516 gpu_info->display_link_version = DisplayLinkVersion(); | 404 gpu_info->display_link_version = DisplayLinkVersion(); |
517 | 405 |
518 if (!gpu_info->display_link_version .IsValid()) { | 406 if (!gpu_info->display_link_version .IsValid()) { |
519 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus", | 407 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus", |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 shader_model, | 503 shader_model, |
616 NUM_SHADER_MODELS); | 504 NUM_SHADER_MODELS); |
617 } | 505 } |
618 | 506 |
619 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); | 507 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); |
620 | 508 |
621 basic_gpu_info->dx_diagnostics = context_gpu_info.dx_diagnostics; | 509 basic_gpu_info->dx_diagnostics = context_gpu_info.dx_diagnostics; |
622 } | 510 } |
623 | 511 |
624 } // namespace gpu | 512 } // namespace gpu |
OLD | NEW |