diff --git a/src/libxrpl/tx/wasm/WasmVM.cpp b/src/libxrpl/tx/wasm/WasmVM.cpp index 2ab277e49b..b1d94953c0 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -132,10 +132,13 @@ runEscrowWasm( auto const ret = vm.run(wasmCode, hfs, gasLimit, funcName, params, createWasmImport(hfs), hfs.getJournal()); + // microseconds is intentional. The resolution of the StatsD is milliseconds, + // but this runs too fast for that. hfs.executionTimeEvent("runEscrowWasm") .notify( - std::chrono::duration_cast( - std::chrono::steady_clock::now() - start)); + std::chrono::milliseconds{std::chrono::duration_cast( + std::chrono::steady_clock::now() - start) + .count()}); if (!ret) { @@ -167,10 +170,13 @@ preflightEscrowWasm( auto const ret = vm.check(wasmCode, hfs, funcName, params, createWasmImport(hfs), hfs.getJournal()); + // microseconds is intentional. The resolution of the StatsD is milliseconds, + // but this runs too fast for that. hfs.executionTimeEvent("preflightEscrowWasm") .notify( - std::chrono::duration_cast( - std::chrono::steady_clock::now() - start)); + std::chrono::milliseconds{std::chrono::duration_cast( + std::chrono::steady_clock::now() - start) + .count()}); return ret; } diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 9bac56e3cc..9623a48eb8 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -35,12 +35,13 @@ struct RecordingEventImpl : public beast::insight::EventImpl value_type min{value_type::max()}; value_type max{value_type::min()}; std::vector samples; + bool printOnDestruction{}; ~RecordingEventImpl() override { - if (count > 0) + if (printOnDestruction && count > 0) { - std::cout << "Mean (ms): " << meanMs() << "\n"; + std::cout << "Mean (us): " << meanUs() << "\n"; } } @@ -56,7 +57,7 @@ struct RecordingEventImpl : public beast::insight::EventImpl } [[nodiscard]] double - meanMs() const + meanUs() const { return count != 0 ? static_cast(total.count()) / static_cast(count) : 0.0; } diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 200e7c212d..8f7762c607 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -1568,6 +1568,7 @@ struct Wasm_test : public beast::unit_test::Suite Env env{*this}; auto hfns = TestHostFunctions{env, 0}; + hfns.execTimeEvent->printOnDestruction = true; perf(hfns, kRuns, [&] { return runEscrowWasm(wasm, hfns, 1'000'000, escrowFunctionName, {}).has_value(); @@ -1586,6 +1587,7 @@ struct Wasm_test : public beast::unit_test::Suite Env env{*this}; auto hfns = TestHostFunctions{env, 0}; + hfns.execTimeEvent->printOnDestruction = true; perf(hfns, kRuns, [&] { return !preflightEscrowWasm(wasm, hfns, escrowFunctionName); }); }