Add --header to benchmark overhead + storage (#12204)

* Add header to 'overhead' command

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add header to 'storage' command

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update READMEs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <info@kchr.de>

* .as_ref() and fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Oliver Tale-Yazdi
2022-09-07 23:16:54 +02:00
committed by GitHub
parent 99d8111c67
commit 09ec484139
9 changed files with 41 additions and 39 deletions
@@ -126,6 +126,7 @@ Minimizing this is important to have a large transaction throughput.
- [`--add`](../shared/README.md#arguments)
- [`--metric`](../shared/README.md#arguments)
- [`--weight-path`](../shared/README.md#arguments)
- [`--header`](../shared/README.md#arguments)
License: Apache-2.0
@@ -28,7 +28,7 @@ use sp_runtime::{traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
use clap::{Args, Parser};
use log::info;
use serde::Serialize;
use std::{fmt::Debug, sync::Arc};
use std::{fmt::Debug, path::PathBuf, sync::Arc};
use crate::{
extrinsic::{
@@ -69,6 +69,12 @@ pub struct OverheadParams {
#[allow(missing_docs)]
#[clap(flatten)]
pub hostinfo: HostInfoParams,
/// Add a header to the generated weight output file.
///
/// Good for adding LICENSE headers.
#[clap(long, value_name = "PATH")]
pub header: Option<PathBuf>,
}
/// Type of a benchmark.
@@ -51,6 +51,8 @@ pub(crate) struct TemplateData {
hostname: String,
/// CPU name of the machine that executed the benchmarks.
cpuname: String,
/// Header for the generated file.
header: String,
/// Command line arguments that were passed to the CLI.
args: Vec<String>,
/// Params of the executed command.
@@ -70,6 +72,12 @@ impl TemplateData {
stats: &Stats,
) -> Result<Self> {
let weight = params.weight.calc_weight(stats)?;
let header = params
.header
.as_ref()
.map(|p| std::fs::read_to_string(p))
.transpose()?
.unwrap_or_default();
Ok(TemplateData {
short_name: t.short_name().into(),
@@ -79,6 +87,7 @@ impl TemplateData {
date: chrono::Utc::now().format("%Y-%m-%d (Y/M/D)").to_string(),
hostname: params.hostinfo.hostname(),
cpuname: params.hostinfo.cpuname(),
header,
args: env::args().collect::<Vec<String>>(),
params: params.clone(),
stats: stats.clone(),
@@ -1,20 +1,4 @@
// This file is part of Substrate.
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{{header}}
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`