Index: components/metrics/metrics_log.cc |
diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc |
index ac35ce396a32a8f06f1a7a7d913953cbb161e290..a9f2fe6109dac4aa24c288d6536dd055a0e4cb18 100644 |
--- a/components/metrics/metrics_log.cc |
+++ b/components/metrics/metrics_log.cc |
@@ -42,6 +42,12 @@ typedef variations::ActiveGroupId ActiveGroupId; |
namespace metrics { |
+namespace internal { |
+// Maximum number of events before truncation. |
+extern const int kOmniboxEventLimit = 5000; |
+extern const int kUserActionEventLimit = 5000; |
+} |
+ |
namespace { |
// Any id less than 16 bytes is considered to be a testing id. |
@@ -323,6 +329,25 @@ void MetricsLog::CloseLog() { |
closed_ = true; |
} |
+void MetricsLog::TruncateEvents() { |
+ DCHECK(!closed_); |
+ if (uma_proto_.user_action_event_size() > internal::kUserActionEventLimit) { |
+ UMA_HISTOGRAM_COUNTS_100000("UMA.TruncatedEvents.UserAction", |
+ uma_proto_.user_action_event_size()); |
+ uma_proto_.mutable_user_action_event()->DeleteSubrange( |
+ internal::kUserActionEventLimit, |
+ uma_proto_.user_action_event_size() - internal::kUserActionEventLimit); |
+ } |
+ |
+ if (uma_proto_.omnibox_event_size() > internal::kOmniboxEventLimit) { |
+ UMA_HISTOGRAM_COUNTS_100000("UMA.TruncatedEvents.Omnibox", |
+ uma_proto_.omnibox_event_size()); |
+ uma_proto_.mutable_omnibox_event()->DeleteSubrange( |
+ internal::kOmniboxEventLimit, |
+ uma_proto_.omnibox_event_size() - internal::kOmniboxEventLimit); |
+ } |
+} |
+ |
void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
DCHECK(closed_); |
uma_proto_.SerializeToString(encoded_log); |