File: compositor_metrics_tracker.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (77 lines) | stat: -rw-r--r-- 2,846 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_COMPOSITOR_COMPOSITOR_METRICS_TRACKER_H_
#define UI_COMPOSITOR_COMPOSITOR_METRICS_TRACKER_H_

#include "base/functional/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "ui/compositor/compositor_export.h"
#include "ui/compositor/compositor_metrics_tracker_host.h"

namespace ui {

class Compositor;

// A class to track custom metrics of Compositor. The tracking is identified by
// an id. The id is passed into impl side and be used as the sequence id to
// create and stop a kCustom typed cc::FrameSequenceTracker. The class is
// move-only to have only one holder of the id. When CompositorMetricsTracker is
// destroyed with an active tracking, the tracking will be canceled and report
// callback will not be invoked.
class COMPOSITOR_EXPORT CompositorMetricsTracker {
 public:
  using TrackerId = CompositorMetricsTrackerHost::TrackerId;

  // Move only.
  CompositorMetricsTracker(CompositorMetricsTracker&& other);
  CompositorMetricsTracker& operator=(CompositorMetricsTracker&& other);

  ~CompositorMetricsTracker();

  // Starts tracking Compositor and provides a callback for reporting. The
  // throughput data collection starts after the next commit.
  void Start(CompositorMetricsTrackerHost::ReportCallback callback);

  // Stops tracking. Returns true when the supplied callback will be invoked
  // when the data collection finishes. Returns false when the data collection
  // is finished before Stop() is called, e.g. when gpu process crashes.
  // Note that no data will be reported if Stop() is not called,
  bool Stop();

  // Cancels tracking. The supplied callback will not be invoked.
  void Cancel();

  // Cancels the pending report after `Stop()` is called. The supplied callback
  // will not be invoked after this. Note do not call this in the supplied
  // callback.
  // TODO(b/345297869): Merge with `Cancel`.
  void CancelReport();

 private:
  friend class Compositor;

  enum class State {
    kNotStarted,     // Tracking is not started.
    kStarted,        // Tracking is started.
    kWaitForReport,  // Tracking is stopped and waits for report.
    kCanceled,       // Tracking is stopped and reporting is canceled.
  };

  // Private since it should only be created via Compositor's
  // RequestNewMetricsTracker call.
  CompositorMetricsTracker(TrackerId id,
                           base::WeakPtr<CompositorMetricsTrackerHost> host);

  static const TrackerId kInvalidId = 0u;
  TrackerId id_ = kInvalidId;
  base::WeakPtr<CompositorMetricsTrackerHost> host_;
  State state_ = State::kNotStarted;
};

using ThroughputTracker = CompositorMetricsTracker;

}  // namespace ui

#endif  // UI_COMPOSITOR_COMPOSITOR_METRICS_TRACKER_H_