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

Unified Diff: chrome/renderer/translate/translate_helper.cc

Issue 387903003: Add metrics for tracking UX impact of non-static CLD data providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use histos instead of actions Created 6 years, 5 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: chrome/renderer/translate/translate_helper.cc
diff --git a/chrome/renderer/translate/translate_helper.cc b/chrome/renderer/translate/translate_helper.cc
index cffcfc55d92e040870ff44f43a00362d74e1cde9..678b0dccd05ea8ad10d8cee0c40adb658a470fa0 100644
--- a/chrome/renderer/translate/translate_helper.cc
+++ b/chrome/renderer/translate/translate_helper.cc
@@ -8,6 +8,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/metrics/histogram.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -17,6 +18,8 @@
#include "components/translate/core/common/translate_metrics.h"
#include "components/translate/core/common/translate_util.h"
#include "components/translate/core/language_detection/language_detection_util.h"
+#include "content/public/common/content_constants.h"
+#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "extensions/common/constants.h"
#include "extensions/renderer/extension_groups.h"
@@ -140,17 +143,25 @@ void TranslateHelper::PageCapturedImpl(int page_seq_no,
if (!main_frame || page_seq_no_ != page_seq_no)
return;
- // TODO(andrewhayden): UMA insertion point here: Track if data is available.
- // TODO(andrewhayden): Retry insertion point here, retry till data available.
if (!cld_data_provider_->IsCldDataAvailable()) {
// We're in dynamic mode and CLD data isn't loaded. Retry when CLD data
// is loaded, if ever.
deferred_page_capture_ = true;
deferred_page_seq_no_ = page_seq_no;
deferred_contents_ = contents;
+ RecordLanguageDetectionTiming(DEFERRED);
return;
}
+ if (deferred_page_seq_no_ == -1) {
jar (doing other things) 2014/07/16 16:44:44 nit: Although I'm not usually a big fan of the ter
andrewhayden 2014/07/17 08:36:19 Ha. OK, will do :)
Andrew Hayden (chromium.org) 2014/07/17 14:00:43 Changed my mind on this one, I like the comments.
+ // CLD data was available before language detection was requested.
+ RecordLanguageDetectionTiming(ON_TIME);
+ } else {
+ // This is a request that was triggered because CLD data is now available
+ // and was previously deferred.
+ RecordLanguageDetectionTiming(RESUMED);
+ }
+
WebDocument document = main_frame->document();
std::string content_language = document.contentLanguage().utf8();
WebElement html_element = document.documentElement();
@@ -608,3 +619,68 @@ void TranslateHelper::OnCldDataAvailable() {
deferred_contents_.clear(); // Clean up for sanity
}
}
+
Takashi Toyoshima 2014/07/17 02:09:31 Having comments on implementation details in sourc
Andrew Hayden (chromium.org) 2014/07/17 14:00:43 I moved it to the header file. I considered kickin
+// Note on metrics:
+//
+// This class provides metrics that allow tracking the user experience impact
+// of non-static CldDataProvider implementations. For background on the data
+// providers, please refer to the following documentation:
+// http://www.chromium.org/developers/how-tos/compact-language-detector-cld-data-source-configuration
+//
+// Available metrics (from the LanguageDetectionTiming enum):
+// 1. ON_TIME
+// Recorded if PageCaptured(...) is invoked after CLD is available. This is
+// the ideal case, indicating that CLD is available before it is needed.
+// 2. DEFERRED
+// Recorded if PageCaptured(...) is invoked before CLD is available.
+// Sub-optimal case indicating that CLD wasn't available when it was needed,
+// so the request for detection has been deferred until CLD is available or
+// until the user navigates to a different page.
+// 3. RESUMED
+// Recorded if CLD becomes available after a language detection request was
+// deferred, but before the user navigated to a different page. Language
+// detection is ultimately completed, it just didn't happen on time.
+//
+// Note that there is NOT a metric that records the number of times that
+// language detection had to be aborted because CLD never became available in
+// time. This is because there is no reasonable way to cover all the cases
+// under which this could occur, particularly the destruction of the renderer
+// for which this object was created. However, this value can be synthetically
+// derived, using the logic below.
+//
+// Every page load that triggers language detection will result in the
+// recording of exactly one of the first two events: ON_TIME or DEFERRED. If
+// CLD is available in time to satisfy the request, the third event (RESUMED)
+// will be recorded; thus, the number of times when language detection
+// ultimately fails because CLD isn't ever available is implied as the number of
+// times that detection is deferred minus the number of times that language
+// detection is late:
+//
+// count(FAILED) ~= count(DEFERRED) - count(RESUMED)
+//
+// Note that this is not 100% accurate: some renderer process are so short-lived
+// that language detection wouldn't have been relevant anyway, and so a failure
+// to detect the language in a timely manner might be completely innocuous. The
+// overall problem with language detection is that it isn't possible to know
+// whether it was required or not until after it has been performed!
+//
+// We use histograms for recording these metrics. On Android, the renderer can
+// be killed without the chance to clean up or transmit these histograms,
+// leading to dropped metrics. To work around this, this method forces an IPC
+// message to be sent to the browser process immediately.
+void TranslateHelper::RecordLanguageDetectionTiming(LanguageDetectionTiming
Alexei Svitkine (slow) 2014/07/16 14:50:40 Nit: Wrap after ( instead and indent next line 4.
andrewhayden 2014/07/17 08:36:19 Will do.
+ timing) {
+ // The following comment is copied from page_load_histograms.cc, and applies
+ // just as equally here:
+ //
+ // Since there are currently no guarantees that renderer histograms will be
+ // sent to the browser, we initiate a PostTask here to be sure that we send
+ // the histograms we generated. Without this call, pages that don't have an
+ // on-close-handler might generate data that is lost when the renderer is
+ // shutdown abruptly (perchance because the user closed the tab).
+ VLOG(1) << "Language detection timing: " << timing;
Alexei Svitkine (slow) 2014/07/16 14:50:40 Do you need the VLOG(1) message or is this left ov
andrewhayden 2014/07/17 08:36:19 I put this here so that I don't have to scan throu
Alexei Svitkine (slow) 2014/07/17 13:20:25 You can filter chrome://histograms/ by substring -
Andrew Hayden (chromium.org) 2014/07/17 14:00:43 DVLOG it is, then.
+ UMA_HISTOGRAM_ENUMERATION("Translate.LanguageDetectionTiming", timing,
+ kLanguageDetectionTimingMax);
+ content::RenderThread::Get()->UpdateHistograms(
jar (doing other things) 2014/07/16 16:44:44 How often (max) could this be called? Is it really
andrewhayden 2014/07/17 08:36:19 As above, in the great majority of cases this shou
Andrew Hayden (chromium.org) 2014/07/17 14:00:43 Performance comments added here.
+ content::kHistogramSynchronizerReservedSequenceNumber);
+}

Powered by Google App Engine
This is Rietveld 408576698