StatisticsRecorder::SetCallback signature changed.
Chromium change: https://source.chromium.org/chromium/chromium/src/+/b63857b27c74a69b28575c514bac9f5a237caaf1 commit b63857b27c74a69b28575c514bac9f5a237caaf1 Author: nuwanda <nuwanda@google.com> Date: Tue Aug 25 22:48:51 2020 +0000 Add support for logging UMA histogram samples from trace config Now when histogram_samples category is set only the histograms listed in a trace config will be monitored. If there are no histograms in a trace config, the effect of enabling the histogram_samples category will remain the same: all the histograms will be monitored. Monitoring all the histograms results in a significant increase in trace size and processing time, that's why we need a way to monitor only a subset of histograms. Based on the events added to trace when enabling the histogram_samples category TBMv3 UMA metrics will be implemented. Bug: 1119834
This commit is contained in:
@@ -24,9 +24,11 @@ constexpr const char* kBravezationHistograms[] = {
|
||||
|
||||
// TODO(iefremov): Replace a bunch of 'if's with something more elegant.
|
||||
// Records the given sample using the proper Brave way.
|
||||
void DoHistogramBravezation(base::StringPiece histogram_name,
|
||||
void DoHistogramBravezation(const char* histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample sample) {
|
||||
if ("Bookmarks.Count.OnProfileLoad" == histogram_name) {
|
||||
DCHECK(histogram_name);
|
||||
if (strcmp("Bookmarks.Count.OnProfileLoad", histogram_name) == 0) {
|
||||
constexpr int kIntervals[] = {5, 20, 100, 500, 1000, 5000, 10000};
|
||||
const int* it =
|
||||
std::lower_bound(kIntervals, std::end(kIntervals), sample);
|
||||
@@ -36,7 +38,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name,
|
||||
return;
|
||||
}
|
||||
|
||||
if ("DefaultBrowser.State" == histogram_name) {
|
||||
if (strcmp("DefaultBrowser.State", histogram_name) == 0) {
|
||||
int answer = 0;
|
||||
switch (sample) {
|
||||
case 0: // Not default.
|
||||
@@ -55,7 +57,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name,
|
||||
UMA_HISTOGRAM_BOOLEAN("Brave.Core.IsDefault", answer);
|
||||
}
|
||||
|
||||
if ("Extensions.LoadExtension" == histogram_name) {
|
||||
if (strcmp("Extensions.LoadExtension", histogram_name) == 0) {
|
||||
int answer = 0;
|
||||
if (sample == 1)
|
||||
answer = 1;
|
||||
@@ -68,7 +70,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name,
|
||||
return;
|
||||
}
|
||||
|
||||
if ("Tabs.TabCount" == histogram_name) {
|
||||
if (strcmp("Tabs.TabCount", histogram_name) == 0) {
|
||||
int answer = 0;
|
||||
if (0 <= sample && sample <= 1) {
|
||||
answer = 0;
|
||||
@@ -86,7 +88,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name,
|
||||
return;
|
||||
}
|
||||
|
||||
if ("Tabs.WindowCount" == histogram_name) {
|
||||
if (strcmp("Tabs.WindowCount", histogram_name) == 0) {
|
||||
int answer = 0;
|
||||
if (sample <= 0) {
|
||||
answer = 0;
|
||||
@@ -109,7 +111,7 @@ void SetupHistogramsBraveization() {
|
||||
for (const char* histogram_name : kBravezationHistograms) {
|
||||
base::StatisticsRecorder::SetCallback(
|
||||
histogram_name,
|
||||
base::BindRepeating(&DoHistogramBravezation, histogram_name));
|
||||
base::BindRepeating(&DoHistogramBravezation));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,8 +199,7 @@ void BraveP3AService::InitCallbacks() {
|
||||
for (const char* histogram_name : kCollectedHistograms) {
|
||||
base::StatisticsRecorder::SetCallback(
|
||||
histogram_name,
|
||||
base::BindRepeating(&BraveP3AService::OnHistogramChanged, this,
|
||||
histogram_name));
|
||||
base::BindRepeating(&BraveP3AService::OnHistogramChanged, this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +379,8 @@ void BraveP3AService::StartScheduledUpload() {
|
||||
}
|
||||
}
|
||||
|
||||
void BraveP3AService::OnHistogramChanged(base::StringPiece histogram_name,
|
||||
void BraveP3AService::OnHistogramChanged(const char* histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample sample) {
|
||||
std::unique_ptr<base::HistogramSamples> samples =
|
||||
base::StatisticsRecorder::FindHistogram(histogram_name)->SnapshotDelta();
|
||||
@@ -392,7 +392,7 @@ void BraveP3AService::OnHistogramChanged(base::StringPiece histogram_name,
|
||||
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(&BraveP3AService::OnHistogramChangedOnUI,
|
||||
this,
|
||||
histogram_name,
|
||||
base::StringPiece(histogram_name),
|
||||
kSuspendedMetricValue,
|
||||
kSuspendedMetricBucket));
|
||||
return;
|
||||
|
||||
@@ -66,7 +66,8 @@ class BraveP3AService : public base::RefCountedThreadSafe<BraveP3AService>,
|
||||
|
||||
// Invoked by callbacks registered by our service. Since these callbacks
|
||||
// can fire on any thread, this method reposts everything to UI thread.
|
||||
void OnHistogramChanged(base::StringPiece histogram_name,
|
||||
void OnHistogramChanged(const char* histogram_name,
|
||||
uint64_t name_hash,
|
||||
base::HistogramBase::Sample sample);
|
||||
|
||||
void OnHistogramChangedOnUI(base::StringPiece histogram_name,
|
||||
|
||||
Reference in New Issue
Block a user