Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
motion_cost.hpp
Go to the documentation of this file.
1#pragma once
2
20
21#include <pulp/view/motion.hpp>
22
23#include <cstdint>
24#include <functional>
25#include <memory>
26#include <string>
27#include <vector>
28
29namespace pulp::view::motion {
30
31// ── CostSample ───────────────────────────────────────────────────────
32
33constexpr int kCostSchemaVersion = 1;
34
39struct CostSample {
40 std::uint64_t frame = 0;
41 double t_seconds = 0.0;
42
48
51 double dirty_rect_area_px = 0.0;
52
56
59 std::vector<int> active_trace_ids;
60
64 std::vector<Provenance> active_provenance;
65};
66
67// ── CostProbe ────────────────────────────────────────────────────────
68
77
78using CostProbe = std::function<RenderCostSnapshot()>;
79
80// ── CostAttributor ───────────────────────────────────────────────────
81
92class CostAttributor {
93public:
94 using CostSink = std::function<void(const CostSample&)>;
95
96 static CostAttributor& instance();
97
99 void set_enabled(bool on);
100 bool enabled() const noexcept;
101
104 void set_probe(CostProbe probe);
105
109 void remove_sink(int sink_id);
111
114 void reset();
115
118 std::size_t emitted_sample_count() const noexcept;
119
120private:
121 CostAttributor();
122 ~CostAttributor();
123 CostAttributor(const CostAttributor&) = delete;
124 CostAttributor& operator=(const CostAttributor&) = delete;
125
126 friend class Coordinator;
127
131 void note_tick_begin(std::uint64_t frame, double t_seconds);
132 void note_trace_activity(int trace_id);
133 void note_provenance(int trace_id, const Provenance& prov);
134 void emit_frame();
135
136 struct State;
137 std::unique_ptr<State> state_;
138};
139
140// ── JSONL cost sink ──────────────────────────────────────────────────
141
147
152
156
160std::vector<CostSample> load_cost_stream(const std::string& path);
161
162} // namespace pulp::view::motion
Process-wide cost attribution stream.
Definition motion_cost.hpp:92
void set_enabled(bool on)
Enable / disable cost emission. Off by default.
int add_sink(CostSink sink)
Add a sink that receives one CostSample per frame while enabled.
void reset()
Reset all state (sinks, probe, enabled flag, frame counter).
void set_probe(CostProbe probe)
Replace the active render-cost probe.
std::function< void(const CostSample &)> CostSink
Definition motion_cost.hpp:94
bool enabled() const noexcept
friend class Coordinator
Definition motion_cost.hpp:126
std::size_t emitted_sample_count() const noexcept
Cumulative count of CostSamples emitted since reset().
static CostAttributor & instance()
Agent-first motion observability: sample view geometry, scroll state, and arbitrary scalar values at ...
Definition motion.hpp:26
CostAttributor::CostSink make_cost_buffer_sink(std::vector< CostSample > *buffer)
Sink that appends each CostSample to a caller-owned buffer.
std::string serialize_cost_sample(const CostSample &s)
Serialize one CostSample as a single JSON line (without trailing newline).
std::vector< CostSample > load_cost_stream(const std::string &path)
Parse a JSONL CostSample stream from path.
CostAttributor::CostSink make_cost_sink(std::string path)
Sink that appends each CostSample as a JSONL line to path.
constexpr int kCostSchemaVersion
Definition motion_cost.hpp:33
std::function< RenderCostSnapshot()> CostProbe
Definition motion_cost.hpp:78
@ path
Definition anchor_strategy.hpp:42
@ s
Definition input_events.hpp:41
@ on
Definition accessibility.hpp:132
STL namespace.
Per-frame cost attribution sample.
Definition motion_cost.hpp:39
double t_seconds
Definition motion_cost.hpp:41
double dirty_rect_area_px
Total area (in pixels^2) of all dirty rectangles snapshotted from DirtyTracker::dirty_rects().
Definition motion_cost.hpp:51
std::uint64_t frame
Definition motion_cost.hpp:40
std::vector< Provenance > active_provenance
Provenance envelopes for each entry in active_trace_ids, in the same order.
Definition motion_cost.hpp:64
std::vector< int > active_trace_ids
Trace ids that emitted at least one SampleEvent on this frame.
Definition motion_cost.hpp:59
double render_pass_duration_ms
Wall time spent in the most recently completed render pass.
Definition motion_cost.hpp:47
int dirty_rect_count
Number of dirty rectangles snapshotted this frame.
Definition motion_cost.hpp:55
Definition motion.hpp:77
Snapshot of render-layer cost for the current frame.
Definition motion_cost.hpp:72
double render_pass_duration_ms
Definition motion_cost.hpp:73
int dirty_rect_count
Definition motion_cost.hpp:75
double dirty_rect_area_px
Definition motion_cost.hpp:74