mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-13 17:25:49 +00:00
cli: introduce host-perf-check command (#4342)
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use log::info;
|
||||
use polkadot_node_core_pvf::sp_maybe_compressed_blob;
|
||||
use polkadot_performance_test::{
|
||||
measure_erasure_coding, measure_pvf_prepare, PerfCheckError, ERASURE_CODING_N_VALIDATORS,
|
||||
ERASURE_CODING_TIME_LIMIT, PVF_PREPARE_TIME_LIMIT, VALIDATION_CODE_BOMB_LIMIT,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn host_perf_check() -> Result<(), PerfCheckError> {
|
||||
let wasm_code =
|
||||
polkadot_performance_test::WASM_BINARY.ok_or(PerfCheckError::WasmBinaryMissing)?;
|
||||
|
||||
// Decompress the code before running checks.
|
||||
let code = sp_maybe_compressed_blob::decompress(wasm_code, VALIDATION_CODE_BOMB_LIMIT)
|
||||
.or(Err(PerfCheckError::CodeDecompressionFailed))?;
|
||||
|
||||
info!("Running the performance checks...");
|
||||
|
||||
perf_check("PVF-prepare", PVF_PREPARE_TIME_LIMIT, || measure_pvf_prepare(code.as_ref()))?;
|
||||
|
||||
perf_check("Erasure-coding", ERASURE_CODING_TIME_LIMIT, || {
|
||||
measure_erasure_coding(ERASURE_CODING_N_VALIDATORS, code.as_ref())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn green_threshold(duration: Duration) -> Duration {
|
||||
duration * 4 / 5
|
||||
}
|
||||
|
||||
fn perf_check(
|
||||
test_name: &str,
|
||||
time_limit: Duration,
|
||||
test: impl Fn() -> Result<Duration, PerfCheckError>,
|
||||
) -> Result<(), PerfCheckError> {
|
||||
let elapsed = test()?;
|
||||
|
||||
if elapsed < green_threshold(time_limit) {
|
||||
info!("🟢 {} performance check passed, elapsed: {:?}", test_name, elapsed);
|
||||
Ok(())
|
||||
} else if elapsed <= time_limit {
|
||||
info!(
|
||||
"🟡 {} performance check passed, {:?} limit almost exceeded, elapsed: {:?}",
|
||||
test_name, time_limit, elapsed
|
||||
);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(PerfCheckError::TimeOut { elapsed, limit: time_limit })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user