-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Oleksandr Zarudnyi <[email protected]>
- Loading branch information
1 parent
2b7bdb1
commit 59ff334
Showing
43 changed files
with
1,071 additions
and
657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//! | ||
//! Serializing benchmark data to CSV. | ||
//! | ||
use std::fmt::Write; | ||
|
||
use super::Benchmark; | ||
use super::IBenchmarkSerializer; | ||
use crate::benchmark::group::element::selector::Selector; | ||
use crate::benchmark::group::element::Element; | ||
use crate::benchmark::metadata::Metadata; | ||
|
||
/// | ||
/// Serialize the benchmark to CSV in the following format: | ||
/// "group_name", "element_name", "size_str", "cycles", "ergs", "gas" | ||
/// | ||
#[derive(Default)] | ||
pub struct Csv; | ||
|
||
impl IBenchmarkSerializer for Csv { | ||
type Err = std::fmt::Error; | ||
|
||
fn serialize_to_string(&self, benchmark: &Benchmark) -> Result<String, Self::Err> { | ||
let mut result = String::with_capacity(estimate_csv_size(benchmark)); | ||
result.push_str( | ||
r#""group", "mode", "version", "path", "case", "input", "size", "cycles", "ergs", "gas""#, | ||
); | ||
result.push('\n'); | ||
for (group_name, group) in &benchmark.groups { | ||
for Element { | ||
metadata: | ||
Metadata { | ||
selector: Selector { path, case, input }, | ||
mode, | ||
version, | ||
group: _, | ||
}, | ||
size, | ||
cycles, | ||
ergs, | ||
gas, | ||
} in group.elements.values() | ||
{ | ||
let size_str = size.map(|s| s.to_string()).unwrap_or_default(); | ||
let mode = mode.as_deref().unwrap_or_default(); | ||
let input = input.clone().map(|s| s.to_string()).unwrap_or_default(); | ||
let case = case.as_deref().unwrap_or_default(); | ||
let version = version.as_deref().unwrap_or_default(); | ||
writeln!( | ||
&mut result, | ||
r#""{group_name}", "{mode}", "{version}", "{path}", "{case}", "{input}", {size_str}, {cycles}, {ergs}, {gas}"#, | ||
)?; | ||
} | ||
} | ||
Ok(result) | ||
} | ||
} | ||
|
||
fn estimate_csv_line_length() -> usize { | ||
let number_fields = 4; | ||
let number_field_estimated_max_length = 15; | ||
let group_name_estimated_max = 10; | ||
let test_name_estimated_max = 300; | ||
group_name_estimated_max | ||
+ test_name_estimated_max | ||
+ number_fields * number_field_estimated_max_length | ||
} | ||
|
||
fn estimate_csv_size(benchmark: &Benchmark) -> usize { | ||
(benchmark.groups.len() + 1) * estimate_csv_line_length() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! | ||
//! Serializing benchmark data to JSON. | ||
//! | ||
use super::Benchmark; | ||
use super::IBenchmarkSerializer; | ||
|
||
/// Serialize the benchmark data to JSON using `serde` library. | ||
#[derive(Default)] | ||
pub struct Json; | ||
|
||
impl IBenchmarkSerializer for Json { | ||
type Err = serde_json::error::Error; | ||
|
||
fn serialize_to_string(&self, benchmark: &Benchmark) -> Result<String, Self::Err> { | ||
serde_json::to_string(benchmark) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! | ||
//! Serialization of benchmark data in different output formats. | ||
//! | ||
pub mod csv; | ||
pub mod json; | ||
|
||
use crate::benchmark::Benchmark; | ||
|
||
/// Serialization format for benchmark data. | ||
pub trait IBenchmarkSerializer { | ||
type Err: std::error::Error; | ||
/// Serialize benchmark data in the selected format. | ||
fn serialize_to_string(&self, benchmark: &Benchmark) -> anyhow::Result<String, Self::Err>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! | ||
//! Identifier for the test input. Describes the input type and position but not the actual contents. | ||
//! | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
/// | ||
/// Identifier for the test input. Describes the input type and position but not the actual contents. | ||
/// | ||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum Input { | ||
/// The contract deploy, regardless of target. | ||
Deployer { | ||
/// Contract identifier, usually file name and contract name separated by a colon. | ||
contract_identifier: String, | ||
}, | ||
/// The contract call. | ||
Runtime { | ||
/// Index in the array of inputs. | ||
input_index: usize, | ||
/// Input name, provided in the test description. | ||
name: String, | ||
}, | ||
/// The storage empty check. | ||
StorageEmpty { | ||
/// Index in the array of inputs. | ||
input_index: usize, | ||
}, | ||
/// Check account balance. | ||
Balance { | ||
/// Index in the array of inputs. | ||
input_index: usize, | ||
}, | ||
} | ||
|
||
impl std::fmt::Display for Input { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Input::Deployer { | ||
contract_identifier, | ||
} => f.write_fmt(format_args!("#deployer:{contract_identifier}")), | ||
Input::Runtime { input_index, name } => { | ||
f.write_fmt(format_args!("{name}:{input_index}")) | ||
} | ||
Input::StorageEmpty { input_index } => { | ||
f.write_fmt(format_args!("#storage_empty_check:{input_index}")) | ||
} | ||
Input::Balance { input_index } => { | ||
f.write_fmt(format_args!("#balance_check:{input_index}")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
benchmark_analyzer/src/benchmark/group/element/selector.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! | ||
//! Test selector, unambiously locating a test suite, or a specific input. | ||
//! | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use crate::benchmark::group::element::input::Input; | ||
|
||
/// | ||
/// Test selector, unambiously locating a test suite, case, or input. | ||
/// | ||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct Selector { | ||
/// Path to the file containing test. | ||
pub path: String, | ||
/// Name of the case, if any. `None` means nameless case. | ||
pub case: Option<String>, | ||
/// Identifier of the specific input. | ||
pub input: Option<Input>, | ||
} | ||
|
||
impl std::fmt::Display for Selector { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let Self { | ||
path: filename, | ||
case: case_name, | ||
input, | ||
} = self; | ||
f.write_fmt(format_args!("{filename}"))?; | ||
if let Some(case_name) = case_name { | ||
f.write_fmt(format_args!("::{case_name}"))?; | ||
} | ||
if let Some(input) = input { | ||
f.write_fmt(format_args!("[{input}]"))?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! | ||
//! Information associated with the benchmark element. | ||
//! | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use crate::benchmark::group::element::selector::Selector; | ||
|
||
/// | ||
/// Encoded compiler mode. In future, it can be expanded into a structured type | ||
/// shared between crates `benchmark_analyzer` and `compiler_tester`. | ||
/// | ||
pub type Mode = String; | ||
|
||
/// | ||
/// Information associated with the benchmark element. | ||
/// | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Metadata { | ||
/// Test selector. | ||
pub selector: Selector, | ||
/// Compiler mode. | ||
pub mode: Option<Mode>, | ||
/// Compiler version, e.g. solc. | ||
pub version: Option<Mode>, | ||
/// Test group | ||
pub group: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.