metrics_util.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_PUBLIC_CPP_METRICS_UTIL_H_
  5. #define ASH_PUBLIC_CPP_METRICS_UTIL_H_
  6. #include <vector>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/callback.h"
  9. #include "cc/metrics/frame_sequence_metrics.h"
  10. namespace ash {
  11. namespace metrics_util {
  12. using ReportCallback = base::RepeatingCallback<void(
  13. const cc::FrameSequenceMetrics::CustomReportData&)>;
  14. using SmoothnessCallback = base::RepeatingCallback<void(int smoothness)>;
  15. // Returns a ReportCallback that could be passed to ui::ThroughputTracker
  16. // or ui::AnimationThroughputReporter. The returned callback picks up the
  17. // cc::FrameSequenceMetrics::ThroughputData, calculates the smoothness
  18. // out of it and forward it to the smoothness report callback.
  19. ASH_PUBLIC_EXPORT ReportCallback
  20. ForSmoothness(SmoothnessCallback callback,
  21. bool exclude_from_data_collection = false);
  22. // Starts to collect data reported by all trackers unless they opt out.
  23. // Note this DCHECKs if called again without StopDataCollection().
  24. ASH_PUBLIC_EXPORT void StartDataCollection();
  25. // Stops data collection and returns the data collected since starting.
  26. ASH_PUBLIC_EXPORT std::vector<cc::FrameSequenceMetrics::CustomReportData>
  27. StopDataCollection();
  28. // Returns smoothness calculated from given data.
  29. ASH_PUBLIC_EXPORT int CalculateSmoothness(
  30. const cc::FrameSequenceMetrics::CustomReportData& data);
  31. // Returns jank percentage calculated from given data.
  32. ASH_PUBLIC_EXPORT int CalculateJank(
  33. const cc::FrameSequenceMetrics::CustomReportData& data);
  34. } // namespace metrics_util
  35. } // namespace ash
  36. #endif // ASH_PUBLIC_CPP_METRICS_UTIL_H_