Support running the pallet benchmarks analysis without running the benchmarks (#12361)

* Support running the pallet benchmarks analysis without running the benchmarks

* Rename `override-results` to `json-input` and update the help comment

* ".git/.scripts/fmt.sh" 1

Co-authored-by: command-bot <>
This commit is contained in:
Koute
2022-09-29 04:38:12 +09:00
committed by GitHub
parent 8227950ed5
commit 8d81065a54
3 changed files with 82 additions and 15 deletions
+14 -6
View File
@@ -23,14 +23,14 @@ use frame_support::{
traits::StorageInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;
use serde::{Deserialize, Serialize};
use sp_io::hashing::blake2_256;
use sp_runtime::traits::TrailingZeroInput;
use sp_std::{prelude::Box, vec::Vec};
use sp_storage::TrackedStorageKey;
/// An alphabet of possible parameters to use for benchmarking.
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Clone, Copy, PartialEq, Debug)]
#[allow(missing_docs)]
#[allow(non_camel_case_types)]
@@ -71,7 +71,7 @@ impl std::fmt::Display for BenchmarkParameter {
}
/// The results of a single of benchmark.
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Clone, PartialEq, Debug)]
pub struct BenchmarkBatch {
/// The pallet containing this benchmark.
@@ -89,7 +89,7 @@ pub struct BenchmarkBatch {
// TODO: could probably make API cleaner here.
/// The results of a single of benchmark, where time and db results are separated.
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Clone, PartialEq, Debug)]
pub struct BenchmarkBatchSplitResults {
/// The pallet containing this benchmark.
@@ -110,7 +110,7 @@ pub struct BenchmarkBatchSplitResults {
/// Result from running benchmarks on a FRAME pallet.
/// Contains duration of the function call in nanoseconds along with the benchmark parameters
/// used for that benchmark result.
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Default, Clone, PartialEq, Debug)]
pub struct BenchmarkResult {
pub components: Vec<(BenchmarkParameter, u32)>,
@@ -121,7 +121,7 @@ pub struct BenchmarkResult {
pub writes: u32,
pub repeat_writes: u32,
pub proof_size: u32,
#[cfg_attr(feature = "std", serde(skip_serializing))]
#[cfg_attr(feature = "std", serde(skip))]
pub keys: Vec<(Vec<u8>, u32, u32, bool)>,
}
@@ -141,6 +141,14 @@ mod serde_as_str {
let s = std::str::from_utf8(value).map_err(serde::ser::Error::custom)?;
serializer.collect_str(s)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
D: serde::de::Deserializer<'de>,
{
let s: &str = serde::de::Deserialize::deserialize(deserializer)?;
Ok(s.into())
}
}
/// Possible errors returned from the benchmarking pipeline.