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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/gpu/gpu_info_collector_win.cc
diff --git a/content/gpu/gpu_info_collector_win.cc b/content/gpu/gpu_info_collector_win.cc
index 1533a48291856969387b87418626ecf0a102b624..c4e662ca20fff4e4cb1fda2af08800a650ac1295 100644
--- a/content/gpu/gpu_info_collector_win.cc
+++ b/content/gpu/gpu_info_collector_win.cc
@@ -11,6 +11,8 @@
#include "base/command_line.h"
#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/libxml_utils.h"
#include "base/logging.h"
#include "base/scoped_native_library.h"
#include "base/string_number_conversions.h"
@@ -47,6 +49,25 @@ float GetAssessmentScore(IProvideWinSATResultsInfo* results,
return score;
}
+float GetAssessmentScoreFromFile(XmlReader* reader,
+ std::string assessment) {
vangelis 2012/04/24 00:37:30 Watch indentation.
dtu 2012/05/01 00:32:16 Done.
+ do {
+ if (reader->NodeName() == assessment) {
+ std::string score_string;
+ if (!reader->ReadElementContent(&score_string))
+ return 0.0;
+
+ double score;
+ if (!base::StringToDouble(score_string, &score))
+ return 0.0;
+
+ return static_cast<float>(score);
+ }
+ } while (reader->Read());
+
+ return 0.0;
+}
+
content::GpuPerformanceStats RetrieveGpuPerformanceStats() {
content::GpuPerformanceStats stats;
@@ -80,7 +101,42 @@ content::GpuPerformanceStats RetrieveGpuPerformanceStats() {
if (state != WINSAT_ASSESSMENT_STATE_VALID &&
state != WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE) {
- LOG(ERROR) << "Can't retrieve a valid assessment";
+ // If the user re-runs the assessment without restarting, the COM API
+ // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. For that case,
+ // fall back to reading the assessment result files directly.
+ 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.
+ 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.
+ false, // not recursive
+ file_util::FileEnumerator::FILES,
+ FILE_PATH_LITERAL("* * Formal.Assessment (*).WinSAT.xml"));
+
+ FilePath current_results;
+ for (FilePath results = file_enumerator.Next(); !results.empty();
+ results = file_enumerator.Next())
+ if (FilePath::CompareLessIgnoreCase(current_results.value(),
+ results.value()))
+ current_results = results;
+
+ if (current_results.empty()) {
+ LOG(ERROR) << "Can't retrieve a valid assessment";
+ return stats;
+ }
+
+ XmlReader reader;
+ reader.LoadFile(current_results);
+
+ 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.
+ if (stats.overall == 0.0)
+ LOG(ERROR) << "Could not read overall score from assessment results.";
+
+ stats.graphics = GetAssessmentScoreFromFile(&reader, "GraphicsScore");
+ if (stats.graphics == 0.0)
+ LOG(ERROR) << "Could not read graphics score from assessment results.";
+
+ stats.gaming = GetAssessmentScoreFromFile(&reader, "GamingScore");
+ if (stats.gaming == 0.0)
+ LOG(ERROR) << "Could not read gaming score from assessment results.";
+
return stats;
}

Powered by Google App Engine
This is Rietveld 408576698