1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// Copyright 2013 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 "chrome/common/translate/translate_common_metrics.h"
#include "base/basictypes.h"
#include "base/metrics/histogram.h"
namespace {
// Constant string values to indicate UMA names. All entries should have
// a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|.
const char kRenderer4LanguageDetection[] = "Renderer4.LanguageDetection";
const char kTranslateContentLanguage[] = "Translate.ContentLanguage";
const char kTranslateHtmlLang[] = "Translate.HtmlLang";
const char kTranslateLanguageVerification[] = "Translate.LanguageVerification";
const char kTranslateTimeToBeReady[] = "Translate.TimeToBeReady";
const char kTranslateTimeToLoad[] = "Translate.TimeToLoad";
const char kTranslateTimeToTranslate[] = "Translate.TimeToTranslate";
const char kTranslateUserActionDuration[] = "Translate.UserActionDuration";
const char kTranslatePageScheme[] = "Translate.PageScheme";
const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch";
const char kSchemeHttp[] = "http";
const char kSchemeHttps[] = "https";
struct MetricsEntry {
TranslateCommonMetrics::MetricsNameIndex index;
const char* const name;
};
// This entry table should be updated when new UMA items are added.
const MetricsEntry kMetricsEntries[] = {
{ TranslateCommonMetrics::UMA_LANGUAGE_DETECTION,
kRenderer4LanguageDetection },
{ TranslateCommonMetrics::UMA_CONTENT_LANGUAGE,
kTranslateContentLanguage },
{ TranslateCommonMetrics::UMA_HTML_LANG,
kTranslateHtmlLang },
{ TranslateCommonMetrics::UMA_LANGUAGE_VERIFICATION,
kTranslateLanguageVerification },
{ TranslateCommonMetrics::UMA_TIME_TO_BE_READY,
kTranslateTimeToBeReady },
{ TranslateCommonMetrics::UMA_TIME_TO_LOAD,
kTranslateTimeToLoad },
{ TranslateCommonMetrics::UMA_TIME_TO_TRANSLATE,
kTranslateTimeToTranslate },
{ TranslateCommonMetrics::UMA_USER_ACTION_DURATION,
kTranslateUserActionDuration },
{ TranslateCommonMetrics::UMA_PAGE_SCHEME,
kTranslatePageScheme },
{ TranslateCommonMetrics::UMA_SIMILAR_LANGUAGE_MATCH,
kTranslateSimilarLanguageMatch },
};
COMPILE_ASSERT(arraysize(kMetricsEntries) == TranslateCommonMetrics::UMA_MAX,
arraysize_of_kMetricsEntries_should_be_UMA_MAX);
TranslateCommonMetrics::LanguageCheckType GetLanguageCheckMetric(
const std::string& provided_code,
const std::string& revised_code) {
if (provided_code.empty())
return TranslateCommonMetrics::LANGUAGE_NOT_PROVIDED;
else if (provided_code == revised_code)
return TranslateCommonMetrics::LANGUAGE_VALID;
return TranslateCommonMetrics::LANGUAGE_INVALID;
}
} // namespace
namespace TranslateCommonMetrics {
void ReportContentLanguage(const std::string& provided_code,
const std::string& revised_code) {
UMA_HISTOGRAM_ENUMERATION(kTranslateContentLanguage,
GetLanguageCheckMetric(provided_code, revised_code),
TranslateCommonMetrics::LANGUAGE_MAX);
}
void ReportHtmlLang(const std::string& provided_code,
const std::string& revised_code) {
UMA_HISTOGRAM_ENUMERATION(kTranslateHtmlLang,
GetLanguageCheckMetric(provided_code, revised_code),
TranslateCommonMetrics::LANGUAGE_MAX);
}
void ReportLanguageVerification(LanguageVerificationType type) {
UMA_HISTOGRAM_ENUMERATION(kTranslateLanguageVerification,
type,
LANGUAGE_VERIFICATION_MAX);
}
void ReportTimeToBeReady(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToBeReady,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
}
void ReportTimeToLoad(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToLoad,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
}
void ReportTimeToTranslate(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToTranslate,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
}
void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end) {
UMA_HISTOGRAM_LONG_TIMES(kTranslateUserActionDuration, end - begin);
}
void ReportPageScheme(const std::string& scheme) {
SchemeType type = SCHEME_OTHERS;
if (scheme == kSchemeHttp)
type = SCHEME_HTTP;
else if (scheme == kSchemeHttps)
type = SCHEME_HTTPS;
UMA_HISTOGRAM_ENUMERATION(kTranslatePageScheme, type, SCHEME_MAX);
}
#if defined(ENABLE_LANGUAGE_DETECTION)
void ReportLanguageDetectionTime(base::TimeTicks begin, base::TimeTicks end) {
UMA_HISTOGRAM_MEDIUM_TIMES(kRenderer4LanguageDetection, end - begin);
}
#endif // defined(ENABLE_LANGUAGE_DETECTION)
void ReportSimilarLanguageMatch(bool match) {
UMA_HISTOGRAM_BOOLEAN(kTranslateSimilarLanguageMatch, match);
}
const char* GetMetricsName(MetricsNameIndex index) {
for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) {
if (kMetricsEntries[i].index == index)
return kMetricsEntries[i].name;
}
NOTREACHED();
return NULL;
}
} // namespace TranslateCommonMetrics
|