mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-30 10:30:22 +00:00
feat: Dump metric values after test run
This commit is contained in:
@@ -134,7 +134,7 @@ runEscrowWasm(
|
||||
|
||||
hfs.executionTimeEvent("runEscrowWasm")
|
||||
.notify(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - start));
|
||||
|
||||
if (!ret)
|
||||
@@ -169,7 +169,7 @@ preflightEscrowWasm(
|
||||
|
||||
hfs.executionTimeEvent("preflightEscrowWasm")
|
||||
.notify(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - start));
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -13,27 +13,66 @@
|
||||
|
||||
#include <boost/algorithm/hex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
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<value_type> 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<double>(total.count()) / static_cast<double>(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<std::size_t>((p / 100.0) * static_cast<double>(sorted.size()));
|
||||
if (rank >= sorted.size())
|
||||
{
|
||||
rank = sorted.size() - 1;
|
||||
}
|
||||
return sorted[rank];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user