Commit 18d336c2 authored by Mehrdad Hessar's avatar Mehrdad Hessar Committed by Commit Bot

This CL adds histogram for experiment time measurement to TFLite Experiment Observer.

Bug: 1116210
Change-Id: I09a3ddbea5756cc569d38805b5c11e4f06ecee6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2357679
Commit-Queue: Mehrdad Hessar <mehrdadh@google.com>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799436}
parent 9de9aa01
...@@ -75,6 +75,8 @@ class TFLiteExperimentKeyedServiceDisabledBrowserTest ...@@ -75,6 +75,8 @@ class TFLiteExperimentKeyedServiceDisabledBrowserTest
0); 0);
} }
const base::HistogramTester* histogram_tester() { return &histogram_tester_; }
private: private:
base::HistogramTester histogram_tester_; base::HistogramTester histogram_tester_;
}; };
...@@ -93,6 +95,8 @@ IN_PROC_BROWSER_TEST_F( ...@@ -93,6 +95,8 @@ IN_PROC_BROWSER_TEST_F(
GURL navigation_url(kNavigationURL); GURL navigation_url(kNavigationURL);
ui_test_utils::NavigateToURL(browser(), navigation_url); ui_test_utils::NavigateToURL(browser(), navigation_url);
WaitForTFLiteObserverToCallNullTFLitePredictor(); WaitForTFLiteObserverToCallNullTFLitePredictor();
histogram_tester()->ExpectUniqueSample(
"TFLiteExperiment.Observer.TFLitePredictor.Null", true, 1);
} }
class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest { class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest {
...@@ -138,6 +142,8 @@ class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest { ...@@ -138,6 +142,8 @@ class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest {
0); 0);
} }
const base::HistogramTester* histogram_tester() { return &histogram_tester_; }
private: private:
base::HistogramTester histogram_tester_; base::HistogramTester histogram_tester_;
}; };
...@@ -174,6 +180,20 @@ IN_PROC_BROWSER_TEST_F(TFLiteExperimentKeyedServiceBrowserTest, ...@@ -174,6 +180,20 @@ IN_PROC_BROWSER_TEST_F(TFLiteExperimentKeyedServiceBrowserTest,
base::ReadFileToString(GetTFLiteExperimentLogPath(), &data); base::ReadFileToString(GetTFLiteExperimentLogPath(), &data);
base::Optional<base::Value> root = base::JSONReader::Read(data); base::Optional<base::Value> root = base::JSONReader::Read(data);
EXPECT_TRUE(root); EXPECT_TRUE(root);
EXPECT_TRUE(*root->FindIntKey("input_set_time")); EXPECT_TRUE(root->FindIntKey("input_set_time_ms"));
EXPECT_TRUE(*root->FindIntKey("evaluation_time")); EXPECT_TRUE(root->FindIntKey("evaluation_time_ms"));
}
IN_PROC_BROWSER_TEST_F(TFLiteExperimentKeyedServiceBrowserTest,
TFLiteExperimentHistogram) {
GURL navigation_url(kNavigationURL);
ui_test_utils::NavigateToURL(browser(), navigation_url);
WaitForObserverToFinish();
histogram_tester()->ExpectTotalCount(
"TFLiteExperiment.Observer.TFLitePredictor.InputSetTime", 1);
histogram_tester()->ExpectTotalCount(
"TFLiteExperiment.Observer.TFLitePredictor.EvaluationTime", 1);
histogram_tester()->ExpectUniqueSample("TFLiteExperiment.Observer.Finish",
true, 1);
} }
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
constexpr int32_t kTFLitePredictorEvaluationLoop = 10; constexpr int kHistogramBucketSize = 1001;
namespace { namespace {
...@@ -66,18 +66,32 @@ void TFLiteExperimentObserver::DidFinishNavigation( ...@@ -66,18 +66,32 @@ void TFLiteExperimentObserver::DidFinishNavigation(
if (is_tflite_evaluated_) if (is_tflite_evaluated_)
return; return;
base::TimeTicks t1 = base::TimeTicks::Now(); auto create_predictor_input_start_time(base::TimeTicks::Now());
CreatePredictorInputForTesting(); CreatePredictorInputForTesting();
base::TimeTicks t2 = base::TimeTicks::Now(); auto create_predictor_input_end_time(base::TimeTicks::Now());
// Run evaluation for |kTFLitePredictorEvaluationLoop| times and report
// average time. LOCAL_HISTOGRAM_CUSTOM_TIMES(
for (int i = 0; i < kTFLitePredictorEvaluationLoop; i++) "TFLiteExperiment.Observer.TFLitePredictor.InputSetTime",
tflite_predictor_->Evaluate(); create_predictor_input_end_time - create_predictor_input_start_time,
base::TimeTicks t3 = base::TimeTicks::Now(); base::TimeDelta::FromMilliseconds(0), base::TimeDelta::FromSeconds(1),
kHistogramBucketSize);
log_dict_.SetIntKey("input_set_time", (t2 - t1).InMicroseconds());
log_dict_.SetIntKey("evaluation_time", (t3 - t2).InMilliseconds() / // Run evaluation report histogram and log time.
kTFLitePredictorEvaluationLoop); auto predictor_eval_start_time(base::TimeTicks::Now());
tflite_predictor_->Evaluate();
auto predictor_eval_end_time(base::TimeTicks::Now());
const base::TimeDelta evaluation_time =
predictor_eval_end_time - predictor_eval_start_time;
LOCAL_HISTOGRAM_CUSTOM_TIMES(
"TFLiteExperiment.Observer.TFLitePredictor.EvaluationTime",
evaluation_time, base::TimeDelta::FromMilliseconds(0),
base::TimeDelta::FromSeconds(1), kHistogramBucketSize);
// Record timing in TFLite experiment log file in addition to histogram.
log_dict_.SetIntKey("input_set_time_ms", (create_predictor_input_end_time -
create_predictor_input_start_time)
.InMilliseconds());
log_dict_.SetIntKey("evaluation_time_ms", evaluation_time.InMilliseconds());
is_tflite_evaluated_ = true; is_tflite_evaluated_ = true;
LOCAL_HISTOGRAM_BOOLEAN( LOCAL_HISTOGRAM_BOOLEAN(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment