Commit 3603a293 authored by Michael Bai's avatar Michael Bai Committed by Commit Bot

ContentCapture: Add metrics for constant streaming

This patch adds one metrics to record the number of times
the task run for completing a capture.

It also replaces CaptureContentTime to CaptureContentTime2.

Bug: 1137463
Change-Id: I34199438353f14beffa20976ebafb3240fd6566f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515143
Commit-Queue: Michael Bai <michaelbai@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824081}
parent 145840e0
...@@ -103,10 +103,10 @@ bool ContentCaptureTask::CaptureContent() { ...@@ -103,10 +103,10 @@ bool ContentCaptureTask::CaptureContent() {
if (histogram_reporter_) if (histogram_reporter_)
histogram_reporter_->OnCaptureContentStarted(); histogram_reporter_->OnCaptureContentStarted();
bool result = CaptureContent(buffer); bool result = CaptureContent(buffer);
if (histogram_reporter_)
histogram_reporter_->OnCaptureContentEnded(buffer.size());
if (!buffer.IsEmpty()) if (!buffer.IsEmpty())
task_session_->SetCapturedContent(buffer); task_session_->SetCapturedContent(buffer);
if (histogram_reporter_)
histogram_reporter_->OnCaptureContentEnded(buffer.size());
return result; return result;
} }
...@@ -230,9 +230,16 @@ void ContentCaptureTask::Run(TimerBase*) { ...@@ -230,9 +230,16 @@ void ContentCaptureTask::Run(TimerBase*) {
task_delay_->IncreaseDelayExponent(); task_delay_->IncreaseDelayExponent();
if (histogram_reporter_) if (histogram_reporter_)
histogram_reporter_->OnTaskRun(); histogram_reporter_->OnTaskRun();
if (!RunInternal()) { bool completed = RunInternal();
if (!completed) {
ScheduleInternal(ScheduleReason::kRetryTask); ScheduleInternal(ScheduleReason::kRetryTask);
} }
if (histogram_reporter_ &&
(completed || task_state_ == TaskState::kCaptureContent)) {
// The current capture session ends if the task indicates it completed or
// is about to capture the new changes.
histogram_reporter_->OnAllCapturedContentSent();
}
} }
base::TimeDelta ContentCaptureTask::GetAndAdjustDelay(ScheduleReason reason) { base::TimeDelta ContentCaptureTask::GetAndAdjustDelay(ScheduleReason reason) {
......
...@@ -14,6 +14,7 @@ constexpr char ContentCaptureTaskHistogramReporter::kCaptureContentDelayTime[]; ...@@ -14,6 +14,7 @@ constexpr char ContentCaptureTaskHistogramReporter::kCaptureContentDelayTime[];
constexpr char ContentCaptureTaskHistogramReporter::kSendContentTime[]; constexpr char ContentCaptureTaskHistogramReporter::kSendContentTime[];
constexpr char ContentCaptureTaskHistogramReporter::kSentContentCount[]; constexpr char ContentCaptureTaskHistogramReporter::kSentContentCount[];
constexpr char ContentCaptureTaskHistogramReporter::kTaskDelayInMs[]; constexpr char ContentCaptureTaskHistogramReporter::kTaskDelayInMs[];
constexpr char ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture[];
ContentCaptureTaskHistogramReporter::ContentCaptureTaskHistogramReporter() ContentCaptureTaskHistogramReporter::ContentCaptureTaskHistogramReporter()
: capture_content_delay_time_histogram_(kCaptureContentDelayTime, : capture_content_delay_time_histogram_(kCaptureContentDelayTime,
...@@ -23,7 +24,8 @@ ContentCaptureTaskHistogramReporter::ContentCaptureTaskHistogramReporter() ...@@ -23,7 +24,8 @@ ContentCaptureTaskHistogramReporter::ContentCaptureTaskHistogramReporter()
capture_content_time_histogram_(kCaptureContentTime, 0, 50000, 50), capture_content_time_histogram_(kCaptureContentTime, 0, 50000, 50),
send_content_time_histogram_(kSendContentTime, 0, 50000, 50), send_content_time_histogram_(kSendContentTime, 0, 50000, 50),
sent_content_count_histogram_(kSentContentCount, 0, 10000, 50), sent_content_count_histogram_(kSentContentCount, 0, 10000, 50),
task_delay_time_in_ms_histogram_(kTaskDelayInMs, 1, 128000, 100) {} task_delay_time_in_ms_histogram_(kTaskDelayInMs, 1, 128000, 100),
task_runs_per_capture_histogram_(kTaskRunsPerCapture, 0, 100, 50) {}
ContentCaptureTaskHistogramReporter::~ContentCaptureTaskHistogramReporter() = ContentCaptureTaskHistogramReporter::~ContentCaptureTaskHistogramReporter() =
default; default;
...@@ -47,6 +49,7 @@ void ContentCaptureTaskHistogramReporter::OnTaskRun() { ...@@ -47,6 +49,7 @@ void ContentCaptureTaskHistogramReporter::OnTaskRun() {
task_scheduled_time_); task_scheduled_time_);
task_scheduled_time_ = base::TimeTicks(); task_scheduled_time_ = base::TimeTicks();
} }
task_runs_per_capture_++;
} }
void ContentCaptureTaskHistogramReporter::OnCaptureContentStarted() { void ContentCaptureTaskHistogramReporter::OnCaptureContentStarted() {
...@@ -87,6 +90,11 @@ void ContentCaptureTaskHistogramReporter::OnSendContentEnded( ...@@ -87,6 +90,11 @@ void ContentCaptureTaskHistogramReporter::OnSendContentEnded(
send_content_start_time_); send_content_start_time_);
} }
void ContentCaptureTaskHistogramReporter::OnAllCapturedContentSent() {
task_runs_per_capture_histogram_.Count(task_runs_per_capture_);
task_runs_per_capture_ = 0;
}
void ContentCaptureTaskHistogramReporter::RecordsSentContentCountPerDocument( void ContentCaptureTaskHistogramReporter::RecordsSentContentCountPerDocument(
size_t sent_content_count) { size_t sent_content_count) {
sent_content_count_histogram_.Count(sent_content_count); sent_content_count_histogram_.Count(sent_content_count);
......
...@@ -20,24 +20,35 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter ...@@ -20,24 +20,35 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter
static constexpr char kCaptureContentDelayTime[] = static constexpr char kCaptureContentDelayTime[] =
"ContentCapture.CaptureContentDelayTime"; "ContentCapture.CaptureContentDelayTime";
static constexpr char kCaptureContentTime[] = static constexpr char kCaptureContentTime[] =
"ContentCapture.CaptureContentTime"; "ContentCapture.CaptureContentTime2";
static constexpr char kSendContentTime[] = "ContentCapture.SendContentTime"; static constexpr char kSendContentTime[] = "ContentCapture.SendContentTime";
static constexpr char kSentContentCount[] = "ContentCapture.SentContentCount"; static constexpr char kSentContentCount[] = "ContentCapture.SentContentCount";
static constexpr char kTaskDelayInMs[] = "ContentCapture.TaskDelayTimeInMs"; static constexpr char kTaskDelayInMs[] = "ContentCapture.TaskDelayTimeInMs";
static constexpr char kTaskRunsPerCapture[] =
"ContentCapture.TaskRunsPerCapture";
ContentCaptureTaskHistogramReporter(); ContentCaptureTaskHistogramReporter();
~ContentCaptureTaskHistogramReporter(); ~ContentCaptureTaskHistogramReporter();
void OnContentChanged(); void OnContentChanged();
void OnTaskScheduled(bool record_task_delay); void OnTaskScheduled(bool record_task_delay);
// Invoked on every task starts.
void OnTaskRun(); void OnTaskRun();
// Invoked on a capturing session starts, a session begins with
// OnCaptureContentStarted(), ends with OnAllCaptureContentSent().
void OnCaptureContentStarted(); void OnCaptureContentStarted();
// Invoked on the on-screen content captured and ready to be sent out.
void OnCaptureContentEnded(size_t captured_content_count); void OnCaptureContentEnded(size_t captured_content_count);
void OnSendContentStarted(); void OnSendContentStarted();
void OnSendContentEnded(size_t sent_content_count); void OnSendContentEnded(size_t sent_content_count);
// Invoked on a capturing session ends, at that time, all captured changes
// which include the new, changed and removed content has been sent.
void OnAllCapturedContentSent();
void RecordsSentContentCountPerDocument(size_t sent_content_count); void RecordsSentContentCountPerDocument(size_t sent_content_count);
private: private:
void MayRecordTaskRunsPerCapture();
// The time of first content change since the last content captured. // The time of first content change since the last content captured.
base::Optional<base::TimeTicks> content_change_time_; base::Optional<base::TimeTicks> content_change_time_;
// The copy of |content_change_time| after the content has been captured; we // The copy of |content_change_time| after the content has been captured; we
...@@ -51,6 +62,9 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter ...@@ -51,6 +62,9 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter
// The time when the task is scheduled, is valid if kTaskDelayInMs needs to be // The time when the task is scheduled, is valid if kTaskDelayInMs needs to be
// recorded. // recorded.
base::TimeTicks task_scheduled_time_; base::TimeTicks task_scheduled_time_;
// Counts the task run times to complete a capture which includes capturing
// and sending the content.
size_t task_runs_per_capture_ = 0;
// Records time from first content change to content that has been sent, its // Records time from first content change to content that has been sent, its
// range is 500ms from to 30s. // range is 500ms from to 30s.
...@@ -67,6 +81,9 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter ...@@ -67,6 +81,9 @@ class CORE_EXPORT ContentCaptureTaskHistogramReporter
// 1ms to 128s. The time of task that was scheduled for the retry wasn't // 1ms to 128s. The time of task that was scheduled for the retry wasn't
// measured because it is always 500ms. // measured because it is always 500ms.
CustomCountHistogram task_delay_time_in_ms_histogram_; CustomCountHistogram task_delay_time_in_ms_histogram_;
// Records the number of times ContentCapture task run to complete a capture
// which includes capturing and sending the content.
CustomCountHistogram task_runs_per_capture_histogram_;
}; };
} // namespace blink } // namespace blink
......
...@@ -642,7 +642,8 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) { ...@@ -642,7 +642,8 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) {
ContentCaptureTaskHistogramReporter::kCaptureContentDelayTime, 0u); ContentCaptureTaskHistogramReporter::kCaptureContentDelayTime, 0u);
histograms.ExpectTotalCount( histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kSentContentCount, 0u); ContentCaptureTaskHistogramReporter::kSentContentCount, 0u);
histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture, 0u);
histograms.ExpectTotalCount( histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kTaskDelayInMs, 1u); ContentCaptureTaskHistogramReporter::kTaskDelayInMs, 1u);
...@@ -695,6 +696,13 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) { ...@@ -695,6 +696,13 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) {
histograms.ExpectTotalCount( histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kTaskDelayInMs, 1u); ContentCaptureTaskHistogramReporter::kTaskDelayInMs, 1u);
histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture, 1u);
// Verify the task ran 4 times, first run stopped before capturing content
// and 2nd run captured content, 3rd and 4th run sent the content out.
histograms.ExpectBucketCount(
ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture, 4u, 1u);
// Create a node and run task until it stops. // Create a node and run task until it stops.
CreateTextNodeAndNotifyManager(); CreateTextNodeAndNotifyManager();
GetContentCaptureTask()->SetTaskStopState( GetContentCaptureTask()->SetTaskStopState(
...@@ -709,6 +717,13 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) { ...@@ -709,6 +717,13 @@ TEST_P(ContentCaptureTest, TaskHistogramReporter) {
histograms.ExpectTotalCount( histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kSentContentCount, 0u); ContentCaptureTaskHistogramReporter::kSentContentCount, 0u);
histograms.ExpectTotalCount(
ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture, 2u);
// Verify the task ran 1 times for this session because we didn't explicitly
// stop it.
histograms.ExpectBucketCount(
ContentCaptureTaskHistogramReporter::kTaskRunsPerCapture, 1u, 1u);
GetContentCaptureTask()->ClearDocumentSessionsForTesting(); GetContentCaptureTask()->ClearDocumentSessionsForTesting();
ThreadState::Current()->CollectAllGarbageForTesting(); ThreadState::Current()->CollectAllGarbageForTesting();
histograms.ExpectTotalCount( histograms.ExpectTotalCount(
......
...@@ -37,7 +37,11 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -37,7 +37,11 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</histogram> </histogram>
<histogram name="ContentCapture.CaptureContentTime" units="microseconds" <histogram name="ContentCapture.CaptureContentTime" units="microseconds"
expires_after="2021-04-04"> expires_after="M87">
<obsolete>
Replaced by ContentCapture.CaptureContentTime2 since M87, the new histogram
records the grouping time additionally.
</obsolete>
<owner>michaelbai@chromium.org</owner> <owner>michaelbai@chromium.org</owner>
<owner>src/third_party/blink/renderer/core/content_capture/OWNERS</owner> <owner>src/third_party/blink/renderer/core/content_capture/OWNERS</owner>
<summary> <summary>
...@@ -48,6 +52,18 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -48,6 +52,18 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram name="ContentCapture.CaptureContentTime2" units="microseconds"
expires_after="2021-04-04">
<owner>michaelbai@chromium.org</owner>
<owner>src/third_party/blink/renderer/core/content_capture/OWNERS</owner>
<summary>
The time taken to capture the on-screen content and group them by document.
Note that this metrics is only recorded on clients on which a
high-resolution clock is available.
</summary>
</histogram>
<histogram name="ContentCapture.GetBoundingBox" units="microseconds" <histogram name="ContentCapture.GetBoundingBox" units="microseconds"
expires_after="2021-04-04"> expires_after="2021-04-04">
<owner>michaelbai@chromium.org</owner> <owner>michaelbai@chromium.org</owner>
...@@ -91,6 +107,18 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -91,6 +107,18 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram name="ContentCapture.TaskRunsPerCapture" units="runs"
expires_after="2021-04-04">
<owner>michaelbai@chromium.org</owner>
<owner>src/third_party/blink/renderer/core/content_capture/OWNERS</owner>
<summary>
The number of the times the task runs for a content capture session.
A content capture session begins with capturing on-screen content and ends
in sending all changes.
</summary>
</histogram>
<histogram name="ContentIndex.ContentAdded" enum="ContentIndexCategory" <histogram name="ContentIndex.ContentAdded" enum="ContentIndexCategory"
expires_after="M89"> expires_after="M89">
<owner>rayankans@chromium.org</owner> <owner>rayankans@chromium.org</owner>
......
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