• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 #ifndef COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_
6 #define COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_
7 
8 #include <string_view>
9 
10 #include "components/prefs/persistent_pref_store.h"
11 
12 namespace metrics::structured {
13 
14 // Whether a single event was recorded correctly, or otherwise what error state
15 // occurred. These values are persisted to logs. Entries should not be
16 // renumbered and numeric values should never be reused.
17 enum class EventRecordingState {
18   kRecorded = 0,
19   kProviderUninitialized = 1,
20   kRecordingDisabled = 2,
21   kProviderMissing = 3,
22   kProjectDisallowed = 4,
23   kLogSizeExceeded = 5,
24   kMaxValue = kLogSizeExceeded,
25 };
26 
27 inline constexpr std::string_view kExternalMetricsProducedHistogramPrefix =
28     "StructuredMetrics.ExternalMetricsProduced2.";
29 
30 inline constexpr std::string_view kExternalMetricsDroppedHistogramPrefix =
31     "StructuredMetrics.ExternalMetricsDropped2.";
32 
33 void LogEventRecordingState(EventRecordingState state);
34 
35 // Log how many structured metrics events were contained in a call to
36 // ProvideCurrentSessionData.
37 void LogNumEventsInUpload(int num_events);
38 
39 // Logs the number of events that were recorded before device and user
40 // cryptographic keys have been loaded to hash events. These events will be kept
41 // in memory.
42 void LogNumEventsRecordedBeforeInit(int num_events);
43 
44 // Logs the number of files processed per external metrics scan.
45 void LogNumFilesPerExternalMetricsScan(int num_files);
46 
47 // Logs the file size of an event.
48 void LogEventFileSizeKB(int64_t file_size_kb);
49 
50 // Logs the serialized size of an event when it is recorded in bytes.
51 void LogEventSerializedSizeBytes(int64_t event_size_bytes);
52 
53 // Logs the StructuredMetrics uploaded size to UMA in bytes.
54 void LogUploadSizeBytes(int64_t upload_size_bytes);
55 
56 // Logs the number of external metrics were scanned for an upload.
57 void LogExternalMetricsScanInUpload(int num_scans);
58 
59 // Logs the number of external metrics that were dropped.
60 void LogDroppedExternalMetrics(int num_dropped);
61 
62 // Logs the number of external metrics that were dropped per-project.
63 void LogDroppedProjectExternalMetrics(std::string_view project_name,
64                                       int num_dropped);
65 
66 // Logs the number of external metrics produced per-project.
67 void LogProducedProjectExternalMetrics(std::string_view project_name,
68                                        int num_produced);
69 
70 // Possible status of the Storage Manager when flushing a buffer to disk. These
71 // values must match the values in
72 // tools/metrics/histograms/metadata/structured_metrics/enums.xml.
73 enum class StorageManagerFlushStatus {
74   kSuccessful = 0,
75   kWriteError = 1,
76   kDiskFull = 2,
77   kEventSerializationError = 3,
78   kQuotaExceeded = 4,
79   kMaxValue = kQuotaExceeded,
80 };
81 
82 // Possible status when an event is recorded to the Storage Manager. These
83 // values must match the values in
84 // tools/metrics/histograms/metadata/structured_metrics/enums.xml.
85 enum class RecordStatus {
86   kOk = 0,
87   kFlushed = 1,
88   kFull = 2,
89   kError = 3,
90   kMaxValue = kError,
91 };
92 
93 // Possible internal errors of the FlushedMap. These should
94 // be looked at in absolute counts. These values must match the values in
95 // tools/metrics/histograms/metadata/structured_metrics/enums.xml.
96 enum class FlushedMapError {
97   kDeletedInvalidKey = 0,
98   kEventSerializationError = 1,
99   kFailedToReadKey = 2,
100   kMaxValue = kFailedToReadKey,
101 };
102 
103 // Logs Storage Managers result when flushing a buffer.
104 void LogStorageManagerFlushStatus(StorageManagerFlushStatus status);
105 
106 // Logs internal errors of the FlushedMap.
107 void LogFlushedMapError(FlushedMapError error);
108 
109 // Logs the number of FlushedKeys that are loaded at boot.
110 void LogFlushedMapLoadedFlushedKeys(int count);
111 
112 // Logs the number of flushed buffers that were deleted when disk quota is
113 // reached.
114 void LogDeletedBuffersWhenOverQuota(int count);
115 
116 // Logs the number of bytes the disk quota has been exceeded. This should be
117 // proportional to the number of buffers deleted.
118 void LogDiskQuotaExceededDelta(int delta_kb);
119 
120 // Logs the number of flushed buffers when an upload occurs.
121 //
122 // With the current implementation, this is implying that this is the number of
123 // buffers read when creating the uploaded log.
124 void LogFlushedBuffersAtUpload(int count);
125 
126 // Logs the number of in-memory events when an upload occurs.
127 void LogInMemoryEventsAtUpload(int count);
128 
129 // Logs the max disk size in kb that the Storage Manager can consume.
130 void LogMaxDiskSizeKb(int size_kb);
131 
132 // Logs the max amount of memory in kb that the in-memory events can consume.
133 void LogMaxMemorySizeKb(int size_kb);
134 
135 // Logs the status of recording an event.
136 void LogStorageManagerRecordStatus(RecordStatus status);
137 
138 }  // namespace metrics::structured
139 
140 #endif  // COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_
141