Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
trace_inspector.hpp
Go to the documentation of this file.
1// trace_inspector.hpp — Bridges the process-global pulp::runtime::Tracing
2// controller to the inspector protocol's Trace.* methods, so the `pulp trace`
3// CLI can start / stop / inspect a Perfetto session over the inspector wire.
4//
5// Session state lives in pulp::runtime::Tracing (a process singleton — a DAW
6// hosts one session per process, not per plugin instance). Each bridge is bound
7// to one exact inspector publication generation so one plugin instance cannot
8// stop a capture owned by another.
9// Query and explain are reserved protocol methods that fail explicitly until
10// an analysis backend exists. Safe to construct and call in any build config:
11// with PULP_TRACING=OFF lifecycle requests return protocol errors.
12#pragma once
13
16
17#include <cstdint>
18#include <memory>
19#include <mutex>
20#include <optional>
21#include <string>
22
23namespace pulp::inspect {
24
26public:
27 virtual ~TraceOwnerLease() = default;
28 virtual InspectorMessage handle(const InspectorMessage& request) = 0;
29};
30
32 std::string session_id;
33 std::string instance_id;
34 std::string publication_id;
35
36 bool complete() const {
37 return !session_id.empty() && !instance_id.empty() &&
38 !publication_id.empty();
39 }
40
42 const TracePublicationOwner&) = default;
43};
44
47public:
48 TraceInspector() = default;
50
55
58 std::unique_ptr<TraceOwnerLease> bind_control_registration(
59 std::string registration_id);
60
63
66 static bool owns_method(const std::string& method);
67
68private:
69 enum class OwnerKind { None, ControlRegistration };
70 class OwnerLease;
71 std::unique_ptr<TraceOwnerLease> bind_owner(OwnerKind kind);
72 void release_owner(const std::shared_ptr<void>& owner_token) noexcept;
73 InspectorMessage handle_with_owner(
74 const InspectorMessage& request,
75 const std::shared_ptr<void>& owner_token);
76
77 std::shared_ptr<void> owner_token_;
78 OwnerKind owner_kind_ = OwnerKind::None;
79 std::optional<pulp::runtime::TraceOwnership> ownership_;
80 std::mutex mutex_;
81
82 // The last .pftrace flushed by stopSession, so snapshot can report it.
83 std::string last_trace_path_;
84
85 InspectorMessage start_session(
86 const InspectorMessage& req,
87 const std::shared_ptr<void>* owner_token);
88 InspectorMessage stop_session(
89 const InspectorMessage& req,
90 const std::shared_ptr<void>* owner_token);
91 InspectorMessage snapshot(const InspectorMessage& req);
92 InspectorMessage query(const InspectorMessage& req);
93 InspectorMessage explain(const InspectorMessage& req);
94};
95
96} // namespace pulp::inspect
TraceInspector(const TraceInspector &)=delete
static bool owns_method(const std::string &method)
Whether this inspector recognizes the method (used by DomainHandler dispatch, mirroring MotionScrubbe...
std::unique_ptr< TraceOwnerLease > bind_control_registration(std::string registration_id)
Bind process-global trace ownership to one authenticated control registration.
InspectorMessage handle(const InspectorMessage &req)
Handle a Trace.* request. Returns a response message.
TraceInspector(TraceInspector &&)=delete
TraceInspector & operator=(TraceInspector &&)=delete
TraceInspector & operator=(const TraceInspector &)=delete
Definition trace_inspector.hpp:25
virtual InspectorMessage handle(const InspectorMessage &request)=0
virtual ~TraceOwnerLease()=default
Definition agent_context.hpp:7
Definition control_identity.hpp:190
A single inspector protocol message (request, response, or event).
Definition protocol.hpp:18
Definition trace_inspector.hpp:31
friend bool operator==(const TracePublicationOwner &, const TracePublicationOwner &)=default
std::string session_id
Definition trace_inspector.hpp:32
std::string instance_id
Definition trace_inspector.hpp:33
std::string publication_id
Definition trace_inspector.hpp:34
bool complete() const
Definition trace_inspector.hpp:36