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

Side by Side Diff: components/ntp_snippets/content_suggestions_metrics.cc

Issue 2619203007: Log suggestion scores in 10 discrete buckets. (Closed)
Patch Set: fixed float literals Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics.h" 13 #include "base/metrics/user_metrics.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/template_util.h" 15 #include "base/template_util.h"
15 16
16 namespace ntp_snippets { 17 namespace ntp_snippets {
17 namespace metrics { 18 namespace metrics {
18 19
19 namespace { 20 namespace {
20 21
21 const int kMaxSuggestionsPerCategory = 10; 22 const int kMaxSuggestionsPerCategory = 10;
22 const int kMaxSuggestionsTotal = 50; 23 const int kMaxSuggestionsTotal = 50;
23 24
24 const char kHistogramCountOnNtpOpened[] = 25 const char kHistogramCountOnNtpOpened[] =
25 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; 26 "NewTabPage.ContentSuggestions.CountOnNtpOpened";
26 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; 27 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown";
27 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; 28 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge";
28 const char kHistogramShownScore[] = "NewTabPage.ContentSuggestions.ShownScore"; 29 const char kHistogramShownScore[] =
30 "NewTabPage.ContentSuggestions.ShownScoreNormalized";
29 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; 31 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened";
30 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; 32 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge";
31 const char kHistogramOpenedScore[] = 33 const char kHistogramOpenedScore[] =
32 "NewTabPage.ContentSuggestions.OpenedScore"; 34 "NewTabPage.ContentSuggestions.OpenedScoreNormalized";
33 const char kHistogramOpenDisposition[] = 35 const char kHistogramOpenDisposition[] =
34 "NewTabPage.ContentSuggestions.OpenDisposition"; 36 "NewTabPage.ContentSuggestions.OpenDisposition";
35 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; 37 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened";
36 const char kHistogramMenuOpenedAge[] = 38 const char kHistogramMenuOpenedAge[] =
37 "NewTabPage.ContentSuggestions.MenuOpenedAge"; 39 "NewTabPage.ContentSuggestions.MenuOpenedAge";
38 const char kHistogramMenuOpenedScore[] = 40 const char kHistogramMenuOpenedScore[] =
39 "NewTabPage.ContentSuggestions.MenuOpenedScore"; 41 "NewTabPage.ContentSuggestions.MenuOpenedScoreNormalized";
40 const char kHistogramDismissedUnvisited[] = 42 const char kHistogramDismissedUnvisited[] =
41 "NewTabPage.ContentSuggestions.DismissedUnvisited"; 43 "NewTabPage.ContentSuggestions.DismissedUnvisited";
42 const char kHistogramDismissedVisited[] = 44 const char kHistogramDismissedVisited[] =
43 "NewTabPage.ContentSuggestions.DismissedVisited"; 45 "NewTabPage.ContentSuggestions.DismissedVisited";
44 const char kHistogramArticlesUsageTimeLocal[] = 46 const char kHistogramArticlesUsageTimeLocal[] =
45 "NewTabPage.ContentSuggestions.UsageTimeLocal"; 47 "NewTabPage.ContentSuggestions.UsageTimeLocal";
46 const char kHistogramVisitDuration[] = 48 const char kHistogramVisitDuration[] =
47 "NewTabPage.ContentSuggestions.VisitDuration"; 49 "NewTabPage.ContentSuggestions.VisitDuration";
48 const char kHistogramMoreButtonShown[] = 50 const char kHistogramMoreButtonShown[] =
49 "NewTabPage.ContentSuggestions.MoreButtonShown"; 51 "NewTabPage.ContentSuggestions.MoreButtonShown";
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void UmaHistogramAge(const std::string& name, const base::TimeDelta& value) { 163 void UmaHistogramAge(const std::string& name, const base::TimeDelta& value) {
162 base::Histogram::FactoryTimeGet( 164 base::Histogram::FactoryTimeGet(
163 name, base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 100, 165 name, base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 100,
164 base::HistogramBase::kUmaTargetedHistogramFlag) 166 base::HistogramBase::kUmaTargetedHistogramFlag)
165 ->AddTime(value); 167 ->AddTime(value);
166 } 168 }
167 169
168 // This corresponds to UMA_HISTOGRAM_CUSTOM_COUNTS (with min/max appropriate 170 // This corresponds to UMA_HISTOGRAM_CUSTOM_COUNTS (with min/max appropriate
169 // for the score of suggestions) for use with dynamic histogram names. 171 // for the score of suggestions) for use with dynamic histogram names.
170 void UmaHistogramScore(const std::string& name, float value) { 172 void UmaHistogramScore(const std::string& name, float value) {
171 base::Histogram::FactoryGet(name, 1, 100000, 50, 173 // Scores are typically reported in a range of (0,1]. As UMA does not support
172 base::HistogramBase::kUmaTargetedHistogramFlag) 174 // floats, we put them on a discrete scale of [1,10]. We keep the extra bucket
173 ->Add(value); 175 // 11 for unexpected over-flows as we want to distinguish them from scores
176 // close to 1. For instance, the discrete value 1 represents score values
177 // within (0.0, 0.1].
178 base::LinearHistogram::FactoryGet(
179 name, 1, 11, 12, base::HistogramBase::kUmaTargetedHistogramFlag)
180 ->Add(ceil(value * 10));
Alexei Svitkine (slow) 2017/01/12 18:42:04 Can you use UmaHistogramExactLinear() here?
tschumann 2017/01/13 17:57:23 Yes. That's actually nice! Turns out UmaHistogramL
174 } 181 }
175 182
176 void LogCategoryHistogramEnumeration(const char* base_name, 183 void LogCategoryHistogramEnumeration(const char* base_name,
177 Category category, 184 Category category,
178 int value, 185 int value,
179 int boundary_value) { 186 int boundary_value) {
180 std::string name = GetCategoryHistogramName(base_name, category); 187 std::string name = GetCategoryHistogramName(base_name, category);
181 // Since the histogram name is dynamic, we can't use the regular macro. 188 // Since the histogram name is dynamic, we can't use the regular macro.
182 UmaHistogramEnumeration(name, value, boundary_value); 189 UmaHistogramEnumeration(name, value, boundary_value);
183 } 190 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 370 }
364 371
365 void OnCategoryDismissed(Category category) { 372 void OnCategoryDismissed(Category category) {
366 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, 373 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed,
367 static_cast<int>(GetHistogramCategory(category)), 374 static_cast<int>(GetHistogramCategory(category)),
368 static_cast<int>(HistogramCategories::COUNT)); 375 static_cast<int>(HistogramCategories::COUNT));
369 } 376 }
370 377
371 } // namespace metrics 378 } // namespace metrics
372 } // namespace ntp_snippets 379 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698