Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
motion_inspector.hpp
Go to the documentation of this file.
1// motion_inspector.hpp — Bridges pulp::view::motion to the inspector
2// protocol. Exposes Motion.startTrace / .stopTrace / .snapshot /
3// .listTraces requests and broadcasts Motion.start / .sample / .end
4// events to inspector clients.
5
6#pragma once
7
11
12#include <cstdint>
13#include <deque>
14#include <functional>
15#include <mutex>
16#include <string>
17#include <string_view>
18#include <unordered_map>
19#include <vector>
20
21namespace pulp::view { class View; }
22
23namespace pulp::inspect {
24
32
34 std::string name;
35 std::string node_id;
36 std::vector<pulp::view::motion::ScrollProperty> properties;
37};
38
40 std::string view_name;
41 int fps = 15;
42 std::vector<MotionGeometryMetric> geometry;
43 std::vector<MotionScrollMetric> scroll_geometry;
44};
45
47 std::int64_t trace_id = 0;
48 std::string error;
49 bool resource_exhausted = false;
50
51 explicit operator bool() const noexcept { return trace_id > 0 && error.empty(); }
52};
53
55public:
60 InspectorEventSink event_sink = {});
62
65
68
70 std::size_t active_trace_count() const;
71
75 std::function<bool()> authority_live,
76 std::function<std::shared_ptr<void>(
77 std::function<void()>)> subscribe_authority_end);
78 bool detach_trace(std::int64_t trace_id, std::string_view owner);
79 bool begin_cost_observation(std::string owner, std::function<bool()> authority_live);
80 bool end_cost_observation(std::string_view owner);
81 std::vector<pulp::view::motion::CostSample>
82 recent_cost_samples(std::size_t maximum_samples, std::string_view owner) const;
83
84private:
85 pulp::view::View* root_ = nullptr;
86 InspectorEventSink event_sink_;
87 int sink_id_ = 0;
88 int cost_sink_id_ = 0;
89
90 mutable std::mutex mtx_;
91 std::unordered_map<std::int64_t, pulp::view::motion::TraceHandle> traces_;
92 struct CanonicalTrace {
94 std::string owner;
95 std::function<bool()> authority_live;
96 std::shared_ptr<void> authority_end_subscription;
97 };
98 std::unordered_map<std::int64_t, CanonicalTrace> canonical_traces_;
99 std::unordered_map<std::int64_t, std::string> cost_trace_owners_;
100 std::deque<pulp::view::motion::CostSample> recent_cost_samples_;
101 std::string cost_owner_;
102 std::function<bool()> cost_authority_live_;
103 bool tracing_was_enabled_ = false;
104 bool canonical_tracing_epoch_active_ = false;
105 bool cost_was_enabled_ = false;
106 std::int64_t next_inspector_id_ = 1;
107
108 InspectorMessage start_trace(const InspectorMessage& req);
109 InspectorMessage stop_trace(const InspectorMessage& req);
110 InspectorMessage snapshot(const InspectorMessage& req);
111 InspectorMessage list_traces(const InspectorMessage& req);
112 InspectorMessage enable_cost(const InspectorMessage& req);
113 InspectorMessage disable_cost(const InspectorMessage& req);
114
115 void broadcast_event(const pulp::view::motion::SampleEvent& e);
116 void broadcast_cost(const pulp::view::motion::CostSample& s);
117 void prune_inactive_traces();
118 void restore_tracing_if_unused_locked();
119};
120
121} // namespace pulp::inspect
std::size_t active_trace_count() const
Number of currently-attached inspector traces.
MotionInspector(pulp::view::View &root, InspectorEventSink event_sink={})
Construct with a root view for node-id lookup and an optional event delivery callback.
InspectorMessage handle(const InspectorMessage &req)
Handle a Motion.* request. Returns response message.
std::vector< pulp::view::motion::CostSample > recent_cost_samples(std::size_t maximum_samples, std::string_view owner) const
MotionTraceAttachResult attach_trace(const MotionTraceSpec &spec, std::string owner, std::function< bool()> authority_live, std::function< std::shared_ptr< void >(std::function< void()>)> subscribe_authority_end)
Transport-independent host operations used by canonical capability executors.
bool end_cost_observation(std::string_view owner)
MotionInspector(const MotionInspector &)=delete
MotionInspector & operator=(const MotionInspector &)=delete
bool detach_trace(std::int64_t trace_id, std::string_view owner)
bool begin_cost_observation(std::string owner, std::function< bool()> authority_live)
Definition view.hpp:73
Definition motion.hpp:491
Agent-first motion observability: sample view geometry, scroll state, and arbitrary scalar values at ...
Motion cost attribution — correlates render-pass cost and dirty area with the motion traces that were...
Definition agent_context.hpp:7
std::function< void(const InspectorMessage &)> InspectorEventSink
Definition inspector_delivery.hpp:30
GeometrySource
Definition motion.hpp:30
@ Layout
Yoga-computed bounds, ignoring paint-time transforms.
Definition motion.hpp:31
GeometrySpace
Definition motion.hpp:35
@ Window
Currently same as ViewGlobal; reserved for window origin.
Definition motion.hpp:38
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ s
Definition input_events.hpp:41
@ e
Definition input_events.hpp:39
A single inspector protocol message (request, response, or event).
Definition protocol.hpp:18
Definition motion_inspector.hpp:25
pulp::view::motion::GeometrySpace space
Definition motion_inspector.hpp:29
pulp::view::motion::GeometrySource source
Definition motion_inspector.hpp:30
std::vector< pulp::view::motion::GeometryProperty > properties
Definition motion_inspector.hpp:28
std::string name
Definition motion_inspector.hpp:26
std::string node_id
Definition motion_inspector.hpp:27
Definition motion_inspector.hpp:33
std::string name
Definition motion_inspector.hpp:34
std::string node_id
Definition motion_inspector.hpp:35
std::vector< pulp::view::motion::ScrollProperty > properties
Definition motion_inspector.hpp:36
Definition motion_inspector.hpp:46
std::string error
Definition motion_inspector.hpp:48
std::int64_t trace_id
Definition motion_inspector.hpp:47
bool resource_exhausted
Definition motion_inspector.hpp:49
Definition motion_inspector.hpp:39
int fps
Definition motion_inspector.hpp:41
std::vector< MotionScrollMetric > scroll_geometry
Definition motion_inspector.hpp:43
std::string view_name
Definition motion_inspector.hpp:40
std::vector< MotionGeometryMetric > geometry
Definition motion_inspector.hpp:42
Per-frame cost attribution sample.
Definition motion_cost.hpp:39
Definition motion.hpp:98