#include #include #include #include #include #include #include namespace aethera::mcp::benchmarks { namespace { [[nodiscard]] Plot_Input_Request timestamped_drag_request( Event_Type type = Event_Type::pointer_move) { Plot_Input_Request request; request.plot = "datoviz_point"; request.event.type = type; request.event.time_milliseconds = 1'000.0; request.event.position = {240.0, 180.0}; request.event.global_position = {240.0, 180.0}; request.event.button = Mouse_Button::left; request.event.buttons = 1; return request; } void decode_timestamped_drag(benchmark::State& state) { const auto encoded = encode_protocol_value(timestamped_drag_request()); for ([[maybe_unused]] auto iteration : state) { Plot_Input_Request decoded; decode_protocol_value(decoded, encoded); benchmark::DoNotOptimize(decoded.event.time_milliseconds); benchmark::ClobberMemory(); } state.SetItemsProcessed(state.iterations()); } void decode_timed_render(benchmark::State& state) { const auto encoded = encode_protocol_value( Plot_Render_Request{"datoviz_point", 1'000.0, 720, 420}); for ([[maybe_unused]] auto iteration : state) { Plot_Render_Request decoded; decode_protocol_value(decoded, encoded); benchmark::DoNotOptimize(decoded.time_milliseconds); benchmark::ClobberMemory(); } state.SetItemsProcessed(state.iterations()); } class Control_Path : public benchmark::Fixture { public: void SetUp(const benchmark::State&) override { service = Control_Service::create(); } void TearDown(const benchmark::State&) override { service.reset(); } protected: std::shared_ptr service; }; BENCHMARK_DEFINE_F(Control_Path, Timestamped_Drag_Admission)( benchmark::State& state) { auto request = timestamped_drag_request(Event_Type::pointer_press); auto arguments = encode_protocol_value(request); const auto press = service->call_tool("aethera_plot_input", arguments); if (press.result != Tool_Call_Result::ok) { state.SkipWithError("timestamped pointer press was rejected"); return; } arguments["event"]["type"] = "pointer_move"; double time_milliseconds = request.event.time_milliseconds; for ([[maybe_unused]] auto iteration : state) { time_milliseconds += 1'000.0 / 120.0; arguments["event"]["time_milliseconds"] = time_milliseconds; const auto result = service->call_tool( "aethera_plot_input", arguments); if (result.result != Tool_Call_Result::ok) { state.SkipWithError("timestamped pointer move was rejected"); break; } benchmark::DoNotOptimize(result.result); } state.SetItemsProcessed(state.iterations()); const auto runtime = service->call_tool( "aethera_task_runtime", nlohmann::json::object()); if (runtime.result != Tool_Call_Result::ok) { state.SkipWithError("Taskflow runtime diagnostics were rejected"); return; } const auto milliseconds = [](const nlohmann::json& value, std::string_view key) { return static_cast(value.at(key).get()) / 1'000'000.0; }; state.counters["taskflow_wall_ms"] = milliseconds(runtime.content, "observed_wall_time_ns"); state.counters["worker_busy_ms"] = milliseconds(runtime.content, "worker_busy_time_ns"); state.counters["worker_cpu_ms"] = milliseconds(runtime.content, "worker_cpu_time_ns"); state.counters["worker_utilization_pct"] = runtime.content.at("worker_utilization").get(); state.counters["worker_cpu_utilization_pct"] = runtime.content.at("worker_cpu_utilization").get(); state.counters["active_taskflows"] = static_cast(runtime.content.at("active_taskflows").get()); state.counters["completed_taskflows"] = static_cast(runtime.content.at("completed_taskflows").get()); state.SetLabel(runtime.content.at("longest_task").at("name").get()); } BENCHMARK(decode_timestamped_drag); BENCHMARK(decode_timed_render); BENCHMARK_REGISTER_F(Control_Path, Timestamped_Drag_Admission) ->Iterations(512); } } int main(int argc, char** argv) { aethera::initialize_runtime({}); benchmark::Initialize(&argc, argv); if (benchmark::ReportUnrecognizedArguments(argc, argv)) return 2; benchmark::RunSpecifiedBenchmarks(); benchmark::Shutdown(); return 0; }