0

Add a histogram to approximate the amount of content translated

Add Translate.Translation.LanguageDetection.ContentLength to approximate
the amount of content for translation. This histogram records the length
of the page content that was extracted at language identification time
every time a successful translation is finished.

Bug: 1220804
Change-Id: Id474d0ecb782865c8f60c055c241e5af003c3946
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2965863
Reviewed-by: Max Curran <curranmax@chromium.org>
Commit-Queue: Megan Jablonski <megjablon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#894427}
This commit is contained in:
Megan Jablonski
2021-06-21 22:11:35 +00:00
committed by Chromium LUCI CQ
parent 151242065b
commit a82ddb5477
6 changed files with 38 additions and 0 deletions
components/translate
tools/metrics/histograms/histograms_xml/translate

@ -179,6 +179,8 @@ void TranslateAgent::PageCaptured(const std::u16string& contents) {
return;
}
page_contents_length_ = contents.size();
WebLanguageDetectionDetails web_detection_details =
WebLanguageDetectionDetails::CollectLanguageDetectionDetails(document);
std::string content_language = web_detection_details.content_language.Utf8();
@ -491,6 +493,7 @@ void TranslateAgent::CheckTranslateStatus() {
// Check JavaScript performance counters for UMA reports.
ReportTimeToTranslate(
ExecuteScriptAndGetDoubleResult("cr.googleTranslate.translationTime"));
ReportTranslatedLanguageDetectionContentLength(page_contents_length_);
// Notify the browser we are done.
std::move(translate_callback_pending_)
@ -572,6 +575,7 @@ void TranslateAgent::ResetPage() {
receiver_.reset();
translate_callback_pending_.Reset();
CancelPendingTranslation();
page_contents_length_ = 0;
}
void TranslateAgent::OnDestruct() {

@ -175,6 +175,8 @@ class TranslateAgent : public content::RenderFrameObserver,
// The URL scheme for translate extensions.
std::string extension_scheme_;
size_t page_contents_length_;
// The task runner responsible for the translation task, freezing it
// when the frame is backgrounded.
scoped_refptr<base::SingleThreadTaskRunner> translate_task_runner_;

@ -29,6 +29,8 @@ const char kTranslatePageScheme[] = "Translate.PageScheme";
const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch";
const char kTranslateLanguageDeterminedDuration[] =
"Translate.LanguageDeterminedDuration";
const char kTranslatedLanguageDetectionContentLength[] =
"Translate.Translation.LanguageDetection.ContentLength";
} // namespace metrics_internal
@ -82,4 +84,10 @@ void ReportLanguageDeterminedDuration(base::TimeTicks begin,
metrics_internal::kTranslateLanguageDeterminedDuration, end - begin);
}
void ReportTranslatedLanguageDetectionContentLength(size_t content_length) {
base::UmaHistogramCounts100000(
metrics_internal::kTranslatedLanguageDetectionContentLength,
content_length);
}
} // namespace translate

@ -25,6 +25,7 @@ extern const char kTranslatePageScheme[];
extern const char kTranslateSimilarLanguageMatch[];
extern const char kTranslateLanguageDetectionConflict[];
extern const char kTranslateLanguageDeterminedDuration[];
extern const char kTranslatedLanguageDetectionContentLength[];
} // namespace metrics_internal
@ -77,6 +78,9 @@ void ReportSimilarLanguageMatch(bool match);
void ReportLanguageDeterminedDuration(base::TimeTicks begin,
base::TimeTicks end);
// Called after when a translation starts.
void ReportTranslatedLanguageDetectionContentLength(size_t content_length);
} // namespace translate
#endif // COMPONENTS_TRANSLATE_CORE_COMMON_TRANSLATE_METRICS_H_

@ -231,4 +231,13 @@ TEST(TranslateMetricsTest, ReportSimilarLanguageMatch) {
EXPECT_EQ(1, recorder.GetCount(kFalse));
}
TEST(TranslateMetricsTest, ReportTranslatedLanguageDetectionContentLength) {
MetricsRecorder recorder(
translate::metrics_internal::kTranslatedLanguageDetectionContentLength);
recorder.CheckTotalCount(0);
translate::ReportTranslatedLanguageDetectionContentLength(12345);
recorder.CheckValueInLogs(12345);
recorder.CheckTotalCount(1);
}
} // namespace translate

@ -1055,6 +1055,17 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Translate.Translation.LanguageDetection.ContentLength"
units="characters" expires_after="2021-12-12">
<owner>megjablon@chromium.org</owner>
<owner>chrome-language@google.com</owner>
<summary>
The number of characters of page content extracted at language detection
time, recorded when a translation successfully finishes. This can be used as
a rough estimate for the amount of content translated.
</summary>
</histogram>
<histogram name="Translate.Translation.SourceLanguage" enum="CLD3LanguageCode"
expires_after="2021-08-01">
<owner>curranmax@google.com</owner>