mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
benchmark pallet: Error if files are overwritten twice (#14352)
* benchmark pallet: Error if files are overwritten twice Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix error message Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
committed by
GitHub
parent
72046c2830
commit
fda776951d
@@ -195,4 +195,10 @@ pub struct PalletCmd {
|
|||||||
/// the analysis is read from this file.
|
/// the analysis is read from this file.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub json_input: Option<PathBuf>,
|
pub json_input: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Allow overwriting a single file with multiple results.
|
||||||
|
///
|
||||||
|
/// This exists only to restore legacy behaviour. It should never actually be needed.
|
||||||
|
#[arg(long)]
|
||||||
|
pub unsafe_overwrite_results: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ fn get_benchmark_data(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create weight file from benchmark data and Handlebars template.
|
/// Create weight file from benchmark data and Handlebars template.
|
||||||
pub(crate) fn write_results(
|
pub(crate) fn write_results(
|
||||||
batches: &[BenchmarkBatchSplitResults],
|
batches: &[BenchmarkBatchSplitResults],
|
||||||
storage_info: &[StorageInfo],
|
storage_info: &[StorageInfo],
|
||||||
@@ -384,7 +384,7 @@ pub(crate) fn write_results(
|
|||||||
default_pov_mode: PovEstimationMode,
|
default_pov_mode: PovEstimationMode,
|
||||||
path: &PathBuf,
|
path: &PathBuf,
|
||||||
cmd: &PalletCmd,
|
cmd: &PalletCmd,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), sc_cli::Error> {
|
||||||
// Use custom template if provided.
|
// Use custom template if provided.
|
||||||
let template: String = match &cmd.template {
|
let template: String = match &cmd.template {
|
||||||
Some(template_file) => fs::read_to_string(template_file)?,
|
Some(template_file) => fs::read_to_string(template_file)?,
|
||||||
@@ -492,10 +492,21 @@ pub(crate) fn write_results(
|
|||||||
created_files.push(file_path);
|
created_files.push(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
for file in created_files.iter().duplicates() {
|
let overwritten_files = created_files.iter().duplicates().collect::<Vec<_>>();
|
||||||
// This can happen when there are multiple instances of a pallet deployed
|
if !overwritten_files.is_empty() {
|
||||||
// and `--output` forces the output of all instances into the same file.
|
let msg = format!(
|
||||||
println!("Multiple benchmarks were written to the same file: {:?}.", file);
|
"Multiple results were written to the same file. This can happen when \
|
||||||
|
there are multiple instances of a pallet deployed and `--output` forces the output of all \
|
||||||
|
instances into the same file. Use `--unsafe-overwrite-results` to ignore this error. The \
|
||||||
|
affected files are: {:?}",
|
||||||
|
overwritten_files
|
||||||
|
);
|
||||||
|
|
||||||
|
if cmd.unsafe_overwrite_results {
|
||||||
|
println!("{msg}");
|
||||||
|
} else {
|
||||||
|
return Err(msg.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user