Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow Skipping Benchmark Errors #9699

Merged
5 commits merged into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/utils/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


//! Metering primitives and globals

use lazy_static::lazy_static;
Expand Down
28 changes: 20 additions & 8 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,11 @@ macro_rules! impl_benchmark_test_suite {
},
$crate::BenchmarkError::Override(_) => {
// This is still considered a success condition.
$crate::log::error!("WARNING: benchmark error overrided");
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
},
$crate::BenchmarkError::Skip => {
// This is considered a success condition.
$crate::log::error!("WARNING: benchmark error skipped")
}
}
},
Expand Down Expand Up @@ -1344,13 +1349,14 @@ macro_rules! add_benchmark {
);

let final_results = match benchmark_result {
Ok(results) => results,
Ok(results) => Some(results),
Err($crate::BenchmarkError::Override(mut result)) => {
// Insert override warning as the first storage key.
$crate::log::error!("WARNING: benchmark error overrided");
result.keys.insert(0,
(b"Benchmark Override".to_vec(), 0, 0, false)
);
$crate::vec![result]
Some($crate::vec![result])
},
Err($crate::BenchmarkError::Stop(e)) => {
$crate::show_benchmark_debug_info(
Expand All @@ -1362,14 +1368,20 @@ macro_rules! add_benchmark {
);
return Err(e.into());
},
Err($crate::BenchmarkError::Skip) => {
$crate::log::error!("WARNING: benchmark error skipped");
None
}
};

$batches.push($crate::BenchmarkBatch {
pallet: name_string.to_vec(),
instance: instance_string.to_vec(),
benchmark: benchmark.clone(),
results: final_results,
});
if let Some(final_results) = final_results {
$batches.push($crate::BenchmarkBatch {
pallet: name_string.to_vec(),
instance: instance_string.to_vec(),
benchmark: benchmark.clone(),
results: final_results,
});
}
}
)
}
Expand Down
11 changes: 7 additions & 4 deletions frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,24 @@ impl BenchmarkResult {
}

/// Possible errors returned from the benchmarking pipeline.
///
/// * Stop: The benchmarking pipeline should stop and return the inner string.
/// * WeightOverride: The benchmarking pipeline is allowed to fail here, and we should use the
/// included weight instead.
#[derive(Clone, PartialEq, Debug)]
pub enum BenchmarkError {
/// The benchmarking pipeline should stop and return the inner string.
Stop(&'static str),
/// The benchmarking pipeline is allowed to fail here, and we should use the
/// included weight instead.
Override(BenchmarkResult),
/// The benchmarking pipeline is allowed to fail here, and we should simply
/// skip processing these results.
Skip,
}

impl From<BenchmarkError> for &'static str {
fn from(e: BenchmarkError) -> Self {
match e {
BenchmarkError::Stop(s) => s,
BenchmarkError::Override(_) => "benchmark override",
BenchmarkError::Skip => "benchmark skip",
}
}
}
Expand Down