throughput_tracker.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 UI_COMPOSITOR_THROUGHPUT_TRACKER_H_
  5. #define UI_COMPOSITOR_THROUGHPUT_TRACKER_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "ui/compositor/compositor_export.h"
  9. #include "ui/compositor/throughput_tracker_host.h"
  10. namespace ui {
  11. class Compositor;
  12. class ThroughputTrackerHost;
  13. // A class to track the throughput of Compositor. The tracking is identified by
  14. // an id. The id is passed into impl side and be used as the sequence id to
  15. // create and stop a kCustom typed cc::FrameSequenceTracker. The class is
  16. // move-only to have only one holder of the id. When ThroughputTracker is
  17. // destroyed with an active tracking, the tracking will be canceled and report
  18. // callback will not be invoked.
  19. class COMPOSITOR_EXPORT ThroughputTracker {
  20. public:
  21. using TrackerId = ThroughputTrackerHost::TrackerId;
  22. // Move only.
  23. ThroughputTracker(ThroughputTracker&& other);
  24. ThroughputTracker& operator=(ThroughputTracker&& other);
  25. ~ThroughputTracker();
  26. // Starts tracking Compositor and provides a callback for reporting. The
  27. // throughput data collection starts after the next commit.
  28. void Start(ThroughputTrackerHost::ReportCallback callback);
  29. // Stops tracking. Returns true when the supplied callback will be invoked
  30. // when the data collection finishes. Returns false when the data collection
  31. // is finished before Stop() is called, e.g. when gpu process crashes.
  32. // Note that no data will be reported if Stop() is not called,
  33. bool Stop();
  34. // Cancels tracking. The supplied callback will not be invoked.
  35. void Cancel();
  36. private:
  37. friend class Compositor;
  38. // Private since it should only be created via Compositor's
  39. // RequestNewThroughputTracker call.
  40. ThroughputTracker(TrackerId id, base::WeakPtr<ThroughputTrackerHost> host);
  41. static const TrackerId kInvalidId = 0u;
  42. TrackerId id_ = kInvalidId;
  43. base::WeakPtr<ThroughputTrackerHost> host_;
  44. bool started_ = false;
  45. };
  46. } // namespace ui
  47. #endif // UI_COMPOSITOR_THROUGHPUT_TRACKER_H_