[fuchsia] Get histograms from child processes.
Collects histograms from child processes (GPU, renderer, etc.) before
sending metrics over the fuchsia.legacymetrics.MetricsRecorder
interface.
Implement upload batching, to break up large report calls into
smaller chunks that fit within the FIDL message limit.
Make the AdditionalMetricsCallback interface asynchronous, so that
async data collection may take place.
Bug: 1060768
Change-Id: I4d4ae5f168ecbeb65a8d9745e940fb05f68e2399
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147683
Commit-Queue: Kevin Marshall <[email protected]>
Reviewed-by: Sergey Ulanov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#759033}
diff --git a/fuchsia/base/legacymetrics_client.h b/fuchsia/base/legacymetrics_client.h
index 1d0dc332..98576a1 100644
--- a/fuchsia/base/legacymetrics_client.h
+++ b/fuchsia/base/legacymetrics_client.h
@@ -25,11 +25,14 @@
// Must be constructed, used, and destroyed on the same sequence.
class LegacyMetricsClient {
public:
+ // Maximum number of Events to send to Record() at a time, so as to not exceed
+ // the 64KB FIDL maximum message size.
+ static constexpr size_t kMaxBatchSize = 50;
+
using ReportAdditionalMetricsCallback = base::RepeatingCallback<void(
- std::vector<fuchsia::legacymetrics::Event>*)>;
+ base::OnceCallback<void(std::vector<fuchsia::legacymetrics::Event>)>)>;
LegacyMetricsClient();
-
~LegacyMetricsClient();
explicit LegacyMetricsClient(const LegacyMetricsClient&) = delete;
@@ -39,17 +42,24 @@
// |report_interval|.
void Start(base::TimeDelta report_interval);
- // Sets a |callback| to be invoked just prior to reporting, allowing users to
- // report additional custom metrics.
- // Must be called before Start().
+ // Sets an asynchronous |callback| to be invoked just prior to reporting,
+ // allowing users to asynchronously gather and provide additional custom
+ // metrics. |callback| will receive the list of metrics when they are ready.
+ // Reporting is paused until |callback| is fulfilled.
+ // If used, then this method must be called before calling Start().
void SetReportAdditionalMetricsCallback(
ReportAdditionalMetricsCallback callback);
private:
void ScheduleNextReport();
- void Report();
+ void StartReport();
+ void Report(std::vector<fuchsia::legacymetrics::Event> additional_metrics);
void OnMetricsRecorderDisconnected(zx_status_t status);
+ // Incrementally sends the contents of |buffer| to |metrics_recorder|, and
+ // invokes |done_cb| when finished.
+ void DrainBuffer(std::vector<fuchsia::legacymetrics::Event> buffer);
+
base::TimeDelta report_interval_;
ReportAdditionalMetricsCallback report_additional_callback_;
std::unique_ptr<LegacyMetricsUserActionRecorder> user_events_recorder_;
@@ -57,6 +67,10 @@
fuchsia::legacymetrics::MetricsRecorderPtr metrics_recorder_;
base::RetainingOneShotTimer timer_;
SEQUENCE_CHECKER(sequence_checker_);
+
+ // Prevents use-after-free if |report_additional_callback_| is invoked after
+ // |this| is destroyed.
+ base::WeakPtrFactory<LegacyMetricsClient> weak_factory_{this};
};
} // namespace cr_fuchsia