xref: /aosp_15_r20/external/cronet/components/metrics/unsent_log_store_metrics_impl.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/metrics/unsent_log_store_metrics_impl.h"
6 
7 #include "base/metrics/histogram_functions.h"
8 
9 namespace metrics {
10 
RecordCompressionRatio(size_t compressed_size,size_t original_size)11 void UnsentLogStoreMetricsImpl::RecordCompressionRatio(size_t compressed_size,
12                                                        size_t original_size) {
13   base::UmaHistogramPercentageObsoleteDoNotUse(
14       "UMA.ProtoCompressionRatio",
15       static_cast<int>(100 * compressed_size / original_size));
16 }
17 
RecordDroppedLogSize(size_t size)18 void UnsentLogStoreMetricsImpl::RecordDroppedLogSize(size_t size) {
19   base::UmaHistogramCounts1M("UMA.UnsentLogs.DroppedSize",
20                              static_cast<int>(size));
21 }
22 
RecordDroppedLogsNum(int dropped_logs_num)23 void UnsentLogStoreMetricsImpl::RecordDroppedLogsNum(int dropped_logs_num) {
24   base::UmaHistogramCounts1M("UMA.UnsentLogs.Dropped", dropped_logs_num);
25 }
26 
RecordLastUnsentLogMetadataMetrics(int unsent_samples_count,int sent_samples_count,int persisted_size_in_kb)27 void UnsentLogStoreMetricsImpl::RecordLastUnsentLogMetadataMetrics(
28     int unsent_samples_count,
29     int sent_samples_count,
30     int persisted_size_in_kb) {
31   if (!base::FeatureList::IsEnabled(kRecordLastUnsentLogMetadataMetrics))
32     return;
33 
34   if (unsent_samples_count < 0 || sent_samples_count < 0 ||
35       persisted_size_in_kb < 0) {
36     return;
37   }
38 
39   base::UmaHistogramCounts100000("UMA.UnsentLogs.UnsentCount",
40                                  unsent_samples_count);
41   base::UmaHistogramCounts1M("UMA.UnsentLogs.SentCount", sent_samples_count);
42   // Sets 10MB as maximum because the total size of logs in each LogStore is up
43   // to 6MB.
44   base::UmaHistogramCounts10000("UMA.UnsentLogs.PersistedSizeInKB",
45                                 persisted_size_in_kb);
46 
47   if (sent_samples_count == 0 && unsent_samples_count == 0) {
48     base::UmaHistogramPercentageObsoleteDoNotUse(
49         "UMA.UnsentLogs.UnsentPercentage", 0);
50   } else {
51     base::UmaHistogramPercentageObsoleteDoNotUse(
52         "UMA.UnsentLogs.UnsentPercentage",
53         100 * unsent_samples_count /
54             (unsent_samples_count + sent_samples_count));
55   }
56 }
57 
58 }  // namespace metrics
59