latency_tracker.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2017 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 UI_LATENCY_LATENCY_TRACKER_H_
  5. #define UI_LATENCY_LATENCY_TRACKER_H_
  6. #include "base/time/time.h"
  7. #include "ui/latency/latency_info.h"
  8. namespace ui {
  9. // Utility class for tracking the latency of events. Relies on LatencyInfo
  10. // components logged by content::RenderWidgetHostLatencyTracker.
  11. class LatencyTracker {
  12. public:
  13. LatencyTracker();
  14. LatencyTracker(const LatencyTracker&) = delete;
  15. LatencyTracker& operator=(const LatencyTracker&) = delete;
  16. ~LatencyTracker();
  17. // Terminates latency tracking for events that triggered rendering, also
  18. // performing relevant UMA latency reporting.
  19. // Called when GPU buffers swap completes.
  20. void OnGpuSwapBuffersCompleted(
  21. std::vector<LatencyInfo> latency_info,
  22. bool top_controls_visible_height_changed = false);
  23. private:
  24. enum class InputMetricEvent {
  25. SCROLL_BEGIN_TOUCH = 0,
  26. SCROLL_UPDATE_TOUCH,
  27. SCROLL_BEGIN_WHEEL,
  28. SCROLL_UPDATE_WHEEL,
  29. INPUT_METRIC_EVENT_MAX = SCROLL_UPDATE_WHEEL
  30. };
  31. // Data holder for all intermediate state for jank tracking.
  32. struct JankTrackerState {
  33. int total_update_events_ = 0;
  34. int janky_update_events_ = 0;
  35. bool prev_scroll_update_reported_ = false;
  36. base::TimeDelta prev_duration_;
  37. base::TimeDelta total_update_duration_;
  38. base::TimeDelta janky_update_duration_;
  39. };
  40. JankTrackerState jank_state_;
  41. void ReportUkmScrollLatency(
  42. const InputMetricEvent& metric_event,
  43. base::TimeTicks start_timestamp,
  44. base::TimeTicks time_to_scroll_update_swap_begin_timestamp,
  45. base::TimeTicks time_to_handled_timestamp,
  46. bool is_main_thread,
  47. const ukm::SourceId ukm_source_id);
  48. void ComputeEndToEndLatencyHistograms(
  49. base::TimeTicks gpu_swap_begin_timestamp,
  50. base::TimeTicks gpu_swap_end_timestamp,
  51. const LatencyInfo& latency,
  52. bool top_controls_visible_height_changed);
  53. void ReportJankyFrame(base::TimeTicks gpu_swap_begin_timestamp,
  54. base::TimeTicks gpu_swap_end_timestamp,
  55. const LatencyInfo& latency,
  56. bool first_frame);
  57. };
  58. } // namespace latency
  59. #endif // UI_LATENCY_LATENCY_TRACKER_H_