-
Notifications
You must be signed in to change notification settings - Fork 900
/
Copy pathbrave_histogram_rewrite.cc
99 lines (83 loc) · 2.59 KB
/
brave_histogram_rewrite.cc
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
/* Copyright 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/components/p3a/brave_histogram_rewrite.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/statistics_recorder.h"
namespace brave {
namespace {
// Please keep this list sorted and synced with |DoHistogramBravezation|.
constexpr const char* kBravezationHistograms[] = {
"Bookmarks.Count.OnProfileLoad",
"Extensions.LoadExtension",
"Tabs.TabCount",
"Tabs.WindowCount",
};
// Records the given sample using the proper Brave way.
void DoHistogramBravezation(base::StringPiece histogram_name,
base::HistogramBase::Sample sample) {
if ("Bookmarks.Count.OnProfileLoad" == histogram_name) {
int answer = 0;
if (0 <= sample && sample < 5)
answer = 0;
if (5 <= sample && sample < 20)
answer = 1;
if (20 <= sample && sample < 100)
answer = 2;
if (sample >= 100)
answer = 3;
UMA_HISTOGRAM_EXACT_LINEAR("Brave.Core.BookmarksCountOnProfileLoad", answer,
3);
return;
}
if ("Extensions.LoadExtension" == histogram_name) {
int answer = 0;
if (sample == 1)
answer = 1;
else if (2 <= sample && sample <= 4)
answer = 2;
else if (sample >= 5)
answer = 3;
UMA_HISTOGRAM_EXACT_LINEAR("Brave.Core.NumberOfExtensions", answer, 3);
return;
}
if ("Tabs.TabCount" == histogram_name) {
int answer = 0;
if (0 <= sample && sample <= 1) {
answer = 0;
} else if (2 <= sample && sample <= 5) {
answer = 1;
} else if (6 <= sample && sample <= 10) {
answer = 2;
} else if (11 <= sample && sample <= 50) {
answer = 3;
} else {
answer = 4;
}
UMA_HISTOGRAM_EXACT_LINEAR("Brave.Core.TabCount", answer, 4);
return;
}
if ("Tabs.WindowCount" == histogram_name) {
int answer = 0;
if (0 <= sample && sample <= 1) {
answer = 0;
} else if (2 <= sample && sample <= 5) {
answer = 1;
} else {
answer = 2;
}
UMA_HISTOGRAM_EXACT_LINEAR("Brave.Core.WindowCount", answer, 2);
return;
}
}
} // namespace
void SetupHistogramsBraveization() {
for (const char* histogram_name : kBravezationHistograms) {
base::StatisticsRecorder::SetCallback(
histogram_name,
base::BindRepeating(&DoHistogramBravezation, histogram_name));
}
}
} // namespace brave