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

Unified Diff: ios/chrome/test/base/perf_test_ios.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/test/base/perf_test_ios.h ('k') | ios/chrome/test/earl_grey/Info.plist » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/test/base/perf_test_ios.mm
diff --git a/ios/chrome/test/base/perf_test_ios.mm b/ios/chrome/test/base/perf_test_ios.mm
new file mode 100644
index 0000000000000000000000000000000000000000..e366bde32ab340181ed215ed0cc5ef1529d6977b
--- /dev/null
+++ b/ios/chrome/test/base/perf_test_ios.mm
@@ -0,0 +1,112 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#import "ios/chrome/browser/web/chrome_web_client.h"
+#include "ios/chrome/test/base/perf_test_ios.h"
+
+PerfTest::PerfTest(std::string testGroup)
+ : BlockCleanupTest(),
+ testGroup_(testGroup),
+ firstLabel_("1st"),
+ averageLabel_("2nd+"),
+ isWaterfall_(false),
+ verbose_(true),
+ repeatCount_(10),
+ web_client_(base::MakeUnique<ChromeWebClient>()) {}
+PerfTest::PerfTest(std::string testGroup,
+ std::string firstLabel,
+ std::string averageLabel,
+ bool isWaterfall,
+ bool verbose,
+ int repeat)
+ : BlockCleanupTest(),
+ testGroup_(testGroup),
+ firstLabel_(firstLabel),
+ averageLabel_(averageLabel),
+ isWaterfall_(isWaterfall),
+ verbose_(verbose),
+ repeatCount_(repeat),
+ web_client_(base::MakeUnique<ChromeWebClient>()) {}
+
+PerfTest::~PerfTest() {}
+
+void PerfTest::LogPerfTiming(std::string testName, base::TimeDelta elapsed) {
+ LogPerfValue(testName, elapsed.InMillisecondsF(), "ms");
+}
+
+void PerfTest::LogPerfValue(std::string testName,
+ double value,
+ std::string unit) {
+ NSLog(@"%sRESULT %s: %s= %.3f %s\n", isWaterfall_ ? "*" : "",
+ testGroup_.c_str(), testName.c_str(), value, unit.c_str());
+}
+
+void PerfTest::RepeatTimedRuns(std::string testName,
+ TimedActionBlock timedAction,
+ ProceduralBlock postAction) {
+ RepeatTimedRuns(testName, timedAction, postAction, repeatCount_);
+}
+
+void PerfTest::RepeatTimedRuns(std::string testName,
+ TimedActionBlock timedAction,
+ ProceduralBlock postAction,
+ int repeat) {
+ base::TimeDelta firstElapsed;
+ base::TimeDelta totalElapsed;
+ base::TimeDelta maxElapsed;
+ base::TimeDelta minElapsed = base::TimeDelta::FromSeconds(1000);
+ for (int i = 0; i < repeat + 1; ++i) {
+ base::TimeDelta elapsed = timedAction(i);
+ if (i == 0) {
+ std::string label =
+ firstLabel_.length() ? testName + " " + firstLabel_ : testName;
+ LogPerfTiming(label, elapsed);
+ firstElapsed = elapsed;
+ } else {
+ if (verbose_)
+ NSLog(@"%2d: %.3f ms", i, elapsed.InMillisecondsF());
+ totalElapsed += elapsed;
+ if (elapsed > maxElapsed)
+ maxElapsed = elapsed;
+ if (elapsed < minElapsed)
+ minElapsed = elapsed;
+ }
+ if (postAction)
+ postAction();
+ }
+ if (repeat > 2) {
+ base::TimeDelta average =
+ (totalElapsed - maxElapsed - minElapsed) / (repeat - 2);
+ std::string label =
+ averageLabel_.length() ? testName + " " + averageLabel_ : testName;
+ LogPerfTiming(label, average);
+ }
+}
+
+// TODO(leng): Replace this with RepeatTimedRuns when we have figured out
+// the best way to combine various logging requirements in repeated runs.
+base::TimeDelta PerfTest::CalculateAverage(base::TimeDelta* times,
+ int count,
+ base::TimeDelta* min_time,
+ base::TimeDelta* max_time) {
+ DCHECK(times);
+ base::TimeDelta min = times[0];
+ base::TimeDelta max = times[0];
+ base::TimeDelta sum = times[0];
+
+ for (int i = 1; i < count; i++) {
+ sum += times[i];
+ if (times[i] > max)
+ max = times[i];
+ if (times[i] < min)
+ min = times[i];
+ }
+ if (max_time)
+ *max_time = max;
+ if (min_time)
+ *min_time = min;
+ return sum / count;
+}
« no previous file with comments | « ios/chrome/test/base/perf_test_ios.h ('k') | ios/chrome/test/earl_grey/Info.plist » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698