Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 0 deletions utils/frame/benchmarking-cli/src/overhead/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion utils/frame/benchmarking-cli/src/overhead/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions utils/frame/benchmarking-cli/src/overhead/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
18 changes: 1 addition & 17 deletions utils/frame/benchmarking-cli/src/overhead/weights.hbs
Original file line number Diff line number Diff line change
@@ -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}}`
Expand Down
1 change: 1 addition & 0 deletions utils/frame/benchmarking-cli/src/shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Contains code that is shared among multiple sub-commands.
- `--db` The database backend to use. This depends on your snapshot.
- `--pruning` Set the pruning mode of the node. Some benchmarks require you to set this to `archive`.
- `--base-path` The location on the disk that should be used for the benchmarks. You can try this on different disks or even on a mounted RAM-disk. It is important to use the same location that will later-on be used to store the chain data to get the correct results.
- `--header` Optional file header which will be prepended to the weight output file. Can be used for adding LICENSE headers.

License: Apache-2.0
1 change: 1 addition & 0 deletions utils/frame/benchmarking-cli/src/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ write: 71_347 * constants::WEIGHT_PER_NANOS,
- [`--weight-path`](../shared/README.md#arguments)
- `--json-read-path` Write the raw 'read' results to this file or directory.
- `--json-write-path` Write the raw 'write' results to this file or directory.
- [`--header`](../shared/README.md#arguments)

License: Apache-2.0

Expand Down
8 changes: 7 additions & 1 deletion utils/frame/benchmarking-cli/src/storage/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ pub struct StorageParams {
#[clap(long)]
pub template_path: Option<PathBuf>,

/// Add a header to the generated weight output file.
///
/// Good for adding LICENSE headers.
#[clap(long, value_name = "PATH")]
pub header: Option<PathBuf>,

/// Path to write the raw 'read' results in JSON format to. Can be a file or directory.
#[clap(long)]
pub json_read_path: Option<PathBuf>,
Expand Down Expand Up @@ -122,7 +128,7 @@ impl StorageCmd {
Block: BlockT<Hash = DbHash>,
C: UsageProvider<Block> + StorageProvider<Block, BA> + HeaderBackend<Block>,
{
let mut template = TemplateData::new(&cfg, &self.params);
let mut template = TemplateData::new(&cfg, &self.params)?;

let block_id = BlockId::<Block>::Number(client.usage_info().chain.best_number);
template.set_block_number(block_id.to_string());
Expand Down
16 changes: 13 additions & 3 deletions utils/frame/benchmarking-cli/src/storage/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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>,
/// Storage params of the executed command.
Expand All @@ -63,18 +65,26 @@ pub(crate) struct TemplateData {

impl TemplateData {
/// Returns a new [`Self`] from the given configuration.
pub fn new(cfg: &Configuration, params: &StorageParams) -> Self {
TemplateData {
pub fn new(cfg: &Configuration, params: &StorageParams) -> Result<Self> {
let header = params
.header
.as_ref()
.map(|p| std::fs::read_to_string(p))
.transpose()?
.unwrap_or_default();

Ok(TemplateData {
db_name: format!("{}", cfg.database),
runtime_name: cfg.chain_spec.name().into(),
version: VERSION.into(),
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(),
..Default::default()
}
})
}

/// Sets the stats and calculates the final weights.
Expand Down
18 changes: 1 addition & 17 deletions utils/frame/benchmarking-cli/src/storage/weights.hbs
Original file line number Diff line number Diff line change
@@ -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}}`
Expand Down