Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/ntp_snippets/content_suggestions_metrics.h" | 5 #include "components/ntp_snippets/content_suggestions_metrics.h" |
| 6 | 6 |
| 7 #include <cmath> | |
| 7 #include <string> | 8 #include <string> |
| 8 #include <type_traits> | 9 #include <type_traits> |
| 9 | 10 |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/histogram_functions.h" | |
| 11 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 14 #include "base/template_util.h" | 16 #include "base/template_util.h" |
| 15 | 17 |
| 16 namespace ntp_snippets { | 18 namespace ntp_snippets { |
| 17 namespace metrics { | 19 namespace metrics { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const int kMaxSuggestionsPerCategory = 10; | 23 const int kMaxSuggestionsPerCategory = 10; |
| 22 const int kMaxSuggestionsTotal = 50; | 24 const int kMaxSuggestionsTotal = 50; |
| 23 | 25 |
| 24 const char kHistogramCountOnNtpOpened[] = | 26 const char kHistogramCountOnNtpOpened[] = |
| 25 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; | 27 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; |
| 26 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; | 28 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; |
| 27 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; | 29 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; |
| 28 const char kHistogramShownScore[] = "NewTabPage.ContentSuggestions.ShownScore"; | 30 const char kHistogramShownScore[] = |
| 31 "NewTabPage.ContentSuggestions.ShownScoreNormalized"; | |
| 29 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; | 32 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; |
| 30 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; | 33 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; |
| 31 const char kHistogramOpenedScore[] = | 34 const char kHistogramOpenedScore[] = |
| 32 "NewTabPage.ContentSuggestions.OpenedScore"; | 35 "NewTabPage.ContentSuggestions.OpenedScoreNormalized"; |
| 33 const char kHistogramOpenDisposition[] = | 36 const char kHistogramOpenDisposition[] = |
| 34 "NewTabPage.ContentSuggestions.OpenDisposition"; | 37 "NewTabPage.ContentSuggestions.OpenDisposition"; |
| 35 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; | 38 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; |
| 36 const char kHistogramMenuOpenedAge[] = | 39 const char kHistogramMenuOpenedAge[] = |
| 37 "NewTabPage.ContentSuggestions.MenuOpenedAge"; | 40 "NewTabPage.ContentSuggestions.MenuOpenedAge"; |
| 38 const char kHistogramMenuOpenedScore[] = | 41 const char kHistogramMenuOpenedScore[] = |
| 39 "NewTabPage.ContentSuggestions.MenuOpenedScore"; | 42 "NewTabPage.ContentSuggestions.MenuOpenedScoreNormalized"; |
| 40 const char kHistogramDismissedUnvisited[] = | 43 const char kHistogramDismissedUnvisited[] = |
| 41 "NewTabPage.ContentSuggestions.DismissedUnvisited"; | 44 "NewTabPage.ContentSuggestions.DismissedUnvisited"; |
| 42 const char kHistogramDismissedVisited[] = | 45 const char kHistogramDismissedVisited[] = |
| 43 "NewTabPage.ContentSuggestions.DismissedVisited"; | 46 "NewTabPage.ContentSuggestions.DismissedVisited"; |
| 44 const char kHistogramArticlesUsageTimeLocal[] = | 47 const char kHistogramArticlesUsageTimeLocal[] = |
| 45 "NewTabPage.ContentSuggestions.UsageTimeLocal"; | 48 "NewTabPage.ContentSuggestions.UsageTimeLocal"; |
| 46 const char kHistogramVisitDuration[] = | 49 const char kHistogramVisitDuration[] = |
| 47 "NewTabPage.ContentSuggestions.VisitDuration"; | 50 "NewTabPage.ContentSuggestions.VisitDuration"; |
| 48 const char kHistogramMoreButtonShown[] = | 51 const char kHistogramMoreButtonShown[] = |
| 49 "NewTabPage.ContentSuggestions.MoreButtonShown"; | 52 "NewTabPage.ContentSuggestions.MoreButtonShown"; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 return std::string(); | 133 return std::string(); |
| 131 } | 134 } |
| 132 | 135 |
| 133 std::string GetCategoryHistogramName(const char* base_name, Category category) { | 136 std::string GetCategoryHistogramName(const char* base_name, Category category) { |
| 134 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, | 137 return base::StringPrintf(kPerCategoryHistogramFormat, base_name, |
| 135 GetCategorySuffix(category).c_str()); | 138 GetCategorySuffix(category).c_str()); |
| 136 } | 139 } |
| 137 | 140 |
| 138 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram | 141 // This corresponds to UMA_HISTOGRAM_ENUMERATION, for use with dynamic histogram |
| 139 // names. | 142 // names. |
| 140 void UmaHistogramEnumeration(const std::string& name, | 143 void UmaHistogramEnumeration(const std::string& name, |
|
Alexei Svitkine (slow)
2017/01/13 18:40:00
Can this be removed too?
tschumann
2017/01/16 11:21:50
yes -- thanks for calling that out! Turned out we
| |
| 141 int value, | 144 int value, |
| 142 int boundary_value) { | 145 int boundary_value) { |
| 143 base::LinearHistogram::FactoryGet( | 146 base::LinearHistogram::FactoryGet( |
| 144 name, 1, boundary_value, boundary_value + 1, | 147 name, 1, boundary_value, boundary_value + 1, |
| 145 base::HistogramBase::kUmaTargetedHistogramFlag) | 148 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 146 ->Add(value); | 149 ->Add(value); |
| 147 } | 150 } |
| 148 | 151 |
| 149 // This corresponds to UMA_HISTOGRAM_LONG_TIMES for use with dynamic histogram | |
| 150 // names. | |
| 151 void UmaHistogramLongTimes(const std::string& name, | |
| 152 const base::TimeDelta& value) { | |
| 153 base::Histogram::FactoryTimeGet( | |
| 154 name, base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromHours(1), | |
| 155 50, base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 156 ->AddTime(value); | |
| 157 } | |
| 158 | |
| 159 // This corresponds to UMA_HISTOGRAM_CUSTOM_TIMES (with min/max appropriate | 152 // This corresponds to UMA_HISTOGRAM_CUSTOM_TIMES (with min/max appropriate |
| 160 // for the age of suggestions) for use with dynamic histogram names. | 153 // for the age of suggestions) for use with dynamic histogram names. |
| 161 void UmaHistogramAge(const std::string& name, const base::TimeDelta& value) { | 154 void UmaHistogramAge(const std::string& name, const base::TimeDelta& value) { |
| 162 base::Histogram::FactoryTimeGet( | 155 base::Histogram::FactoryTimeGet( |
| 163 name, base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 100, | 156 name, base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 100, |
| 164 base::HistogramBase::kUmaTargetedHistogramFlag) | 157 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 165 ->AddTime(value); | 158 ->AddTime(value); |
| 166 } | 159 } |
| 167 | 160 |
| 168 // This corresponds to UMA_HISTOGRAM_CUSTOM_COUNTS (with min/max appropriate | 161 // This corresponds to UMA_HISTOGRAM_CUSTOM_COUNTS (with min/max appropriate |
| 169 // for the score of suggestions) for use with dynamic histogram names. | 162 // for the score of suggestions) for use with dynamic histogram names. |
| 170 void UmaHistogramScore(const std::string& name, float value) { | 163 void UmaHistogramScore(const std::string& name, float value) { |
| 171 base::Histogram::FactoryGet(name, 1, 100000, 50, | 164 // Scores are typically reported in a range of (0,1]. As UMA does not support |
| 172 base::HistogramBase::kUmaTargetedHistogramFlag) | 165 // floats, we put them on a discrete scale of [1,10]. We keep the extra bucket |
| 173 ->Add(value); | 166 // 11 for unexpected over-flows as we want to distinguish them from scores |
| 167 // close to 1. For instance, the discrete value 1 represents score values | |
| 168 // within (0.0, 0.1]. | |
| 169 base::UmaHistogramExactLinear(name, ceil(value * 10), 11); | |
| 174 } | 170 } |
| 175 | 171 |
| 176 void LogCategoryHistogramEnumeration(const char* base_name, | 172 void LogCategoryHistogramEnumeration(const char* base_name, |
| 177 Category category, | 173 Category category, |
| 178 int value, | 174 int value, |
| 179 int boundary_value) { | 175 int boundary_value) { |
| 180 std::string name = GetCategoryHistogramName(base_name, category); | 176 std::string name = GetCategoryHistogramName(base_name, category); |
| 181 // Since the histogram name is dynamic, we can't use the regular macro. | 177 // Since the histogram name is dynamic, we can't use the regular macro. |
| 182 UmaHistogramEnumeration(name, value, boundary_value); | 178 UmaHistogramEnumeration(name, value, boundary_value); |
| 183 } | 179 } |
| 184 | 180 |
| 185 void LogCategoryHistogramLongTimes(const char* base_name, | 181 void LogCategoryHistogramLongTimes(const char* base_name, |
| 186 Category category, | 182 Category category, |
| 187 const base::TimeDelta& value) { | 183 const base::TimeDelta& value) { |
| 188 std::string name = GetCategoryHistogramName(base_name, category); | 184 std::string name = GetCategoryHistogramName(base_name, category); |
| 189 // Since the histogram name is dynamic, we can't use the regular macro. | 185 // Since the histogram name is dynamic, we can't use the regular macro. |
| 190 UmaHistogramLongTimes(name, value); | 186 UmaHistogramLongTimes(name, value); |
|
Alexei Svitkine (slow)
2017/01/13 18:40:00
Prefix this with base:: ?
tschumann
2017/01/16 11:21:50
Done. (ADL at it's best ;-)).
| |
| 191 } | 187 } |
| 192 | 188 |
| 193 void LogCategoryHistogramAge(const char* base_name, | 189 void LogCategoryHistogramAge(const char* base_name, |
| 194 Category category, | 190 Category category, |
| 195 const base::TimeDelta& value) { | 191 const base::TimeDelta& value) { |
| 196 std::string name = GetCategoryHistogramName(base_name, category); | 192 std::string name = GetCategoryHistogramName(base_name, category); |
| 197 // Since the histogram name is dynamic, we can't use the regular macro. | 193 // Since the histogram name is dynamic, we can't use the regular macro. |
| 198 UmaHistogramAge(name, value); | 194 UmaHistogramAge(name, value); |
| 199 } | 195 } |
| 200 | 196 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 } | 359 } |
| 364 | 360 |
| 365 void OnCategoryDismissed(Category category) { | 361 void OnCategoryDismissed(Category category) { |
| 366 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, | 362 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, |
| 367 static_cast<int>(GetHistogramCategory(category)), | 363 static_cast<int>(GetHistogramCategory(category)), |
| 368 static_cast<int>(HistogramCategories::COUNT)); | 364 static_cast<int>(HistogramCategories::COUNT)); |
| 369 } | 365 } |
| 370 | 366 |
| 371 } // namespace metrics | 367 } // namespace metrics |
| 372 } // namespace ntp_snippets | 368 } // namespace ntp_snippets |
| OLD | NEW |