File: perf_output.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (88 lines) | stat: -rw-r--r-- 2,752 bytes parent folder | download | duplicates (4)
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
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_METRICS_PERF_PERF_OUTPUT_H_
#define CHROME_BROWSER_METRICS_PERF_PERF_OUTPUT_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "chromeos/dbus/common/dbus_callback.h"
#include "chromeos/dbus/common/pipe_reader.h"

namespace ash {
class DebugDaemonClient;
}

namespace metrics {

// Class for handling getting output from perf over DBus. Manages the
// asynchronous DBus call and retrieving data from quipper over a pipe.
class PerfOutputCall {
 public:
  // Called once GetPerfOutput() is complete, or an error occurred.
  // The callback may delete this object.
  // The argument is one of:
  // - Output from "perf record", in PerfDataProto format, OR
  // - The empty string if there was an error.
  // The output is transferred to |perf_stdout|.
  using DoneCallback = base::OnceCallback<void(std::string perf_stdout)>;

  PerfOutputCall(ash::DebugDaemonClient* debug_daemon_client,
                 const std::vector<std::string>& quipper_args,
                 bool disable_cpu_idle,
                 DoneCallback callback);

  PerfOutputCall(const PerfOutputCall&) = delete;
  PerfOutputCall& operator=(const PerfOutputCall&) = delete;

  virtual ~PerfOutputCall();

  // Stop() is made virtual for mocks in testing.
  virtual void Stop();

 protected:
  // Exposed for mocking in unit test.
  PerfOutputCall();

 private:
  // Internal callbacks.
  void OnIOComplete(std::optional<std::string> data);
  void OnGetPerfOutput(std::optional<uint64_t> result);

  void StopImpl();

  // A non-retaining pointer to the DebugDaemonClient instance.
  raw_ptr<ash::DebugDaemonClient> debug_daemon_client_;

  // Used to capture perf data written to a pipe.
  std::unique_ptr<chromeos::PipeReader> perf_data_pipe_reader_;

  // Saved arguments.
  std::vector<std::string> quipper_args_;
  bool disable_cpu_idle_;
  DoneCallback done_callback_;

  // Whether Stop() is called before OnGetPerfOutput() has returned the session
  // ID. If true (meaning Stop() is called very soon after we request perf
  // output), the stop request will be sent out after we have the session ID to
  // stop the perf session.
  bool pending_stop_;
  std::optional<uint64_t> perf_session_id_;

  SEQUENCE_CHECKER(sequence_checker_);

  // To pass around the "this" pointer across threads safely.
  base::WeakPtrFactory<PerfOutputCall> weak_factory_{this};
};

}  // namespace metrics

#endif  // CHROME_BROWSER_METRICS_PERF_PERF_OUTPUT_H_