diff --git a/src/libxrpl/tx/wasm/WasmVM.cpp b/src/libxrpl/tx/wasm/WasmVM.cpp index 2ab277e49b..22cdbfa5af 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -134,7 +134,7 @@ runEscrowWasm( hfs.executionTimeEvent("runEscrowWasm") .notify( - std::chrono::duration_cast( + std::chrono::duration_cast( std::chrono::steady_clock::now() - start)); if (!ret) @@ -169,7 +169,7 @@ preflightEscrowWasm( hfs.executionTimeEvent("preflightEscrowWasm") .notify( - std::chrono::duration_cast( + std::chrono::duration_cast( std::chrono::steady_clock::now() - start)); return ret; diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 80e0abae14..98be91ba67 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -13,27 +13,66 @@ #include +#include +#include #include #include #include #include +#include namespace xrpl::test { /** - * Lets a test assert that the WASM execution-timing path fired (and inspect - * the recorded duration) without needing a StatsD sink or a full Collector. + * Lets a test assert that the WASM execution-timing path fired and inspect the + * recorded durations, without needing a StatsD sink or a full Collector. */ struct RecordingEventImpl : public beast::insight::EventImpl { std::size_t count = 0; value_type last{}; + value_type total{}; + value_type min{value_type::max()}; + value_type max{value_type::min()}; + std::vector samples; + + ~RecordingEventImpl() override + { + std::cout << "Mean (ns): " << meanNs() << "\n"; + } void notify(value_type const& value) override { ++count; last = value; + total += value; + min = std::min(min, value); + max = std::max(max, value); + samples.push_back(value); + } + + [[nodiscard]] double + meanNs() const + { + return count != 0 ? static_cast(total.count()) / static_cast(count) : 0.0; + } + + [[nodiscard]] value_type + percentile(double p) const + { + if (samples.empty()) + { + return value_type{}; + } + auto sorted = samples; + std::ranges::sort(sorted); + auto rank = static_cast((p / 100.0) * static_cast(sorted.size())); + if (rank >= sorted.size()) + { + rank = sorted.size() - 1; + } + return sorted[rank]; } }; diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index e39bb98769..0837eedaad 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -1588,7 +1588,7 @@ struct Wasm_test : public beast::unit_test::Suite auto mock = HostFunctions{env.journal}; auto hfns = TestHostFunctions{env, 0}; - perf(hfns, kRuns, [&] { return !preflightEscrowWasm(wasm, mock, escrowFunctionName); }); + perf(hfns, kRuns, [&] { return !preflightEscrowWasm(wasm, hfns, escrowFunctionName); }); } void