Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LNT report serialization updates #136

Merged
merged 4 commits into from
Jan 30, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! A run of a test with fixed compiler options (mode).
//!

use crate::util::is_zero;
use serde::Deserialize;
use serde::Serialize;

Expand All @@ -11,12 +12,16 @@ use serde::Serialize;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Run {
/// The contract size, `Some` for contracts deploys.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub size: Option<usize>,
/// The number of cycles.
#[serde(default, skip_serializing_if = "is_zero")]
pub cycles: usize,
/// The amount of ergs.
#[serde(default, skip_serializing_if = "is_zero")]
pub ergs: u64,
/// The amount of EVM gas.
#[serde(default, skip_serializing_if = "is_zero")]
pub gas: u64,
}

Expand Down
8 changes: 7 additions & 1 deletion benchmark_analyzer/src/model/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ pub struct Context {
pub machine: String,
/// Target, for example "eravm" or "evm".
pub target: era_compiler_common::Target,
/// Type of `solc`, for example `zksync`
/// Type of `toolchain`, for example `ir-llvm`
pub toolchain: String,
antonbaliasnikov marked this conversation as resolved.
Show resolved Hide resolved
/// Version of the `zksolc` compiler.
pub zksolc_version: String,
/// Version of the LLVM backend.
pub llvm_version: String,
}

///
Expand All @@ -23,6 +27,8 @@ pub fn validate_context(context: &Context) -> anyhow::Result<()> {
machine,
toolchain,
target: _,
zksolc_version: _,
llvm_version: _,
} = context;

if machine.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
///
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Machine {
/// Machine name, for example "LNT-AArch64-A53-O3__clang_DEV__aarch64".
/// Machine name, for example "llvm_eravm_ir-llvm_Y+M3B3".
pub name: String,
/// Target name, for example "eravm" or "solc".
/// Target name, for example "eravm" or "evm".
pub target: era_compiler_common::Target,
/// Optimizations level, for example "+M3B3".
pub optimizations: String,
/// Type of solc, for example, "zksync".
/// Code generation, for example "Y+".
pub codegen: String,
/// Optimization levels, for example "M3B3".
pub optimization: String,
/// Type of toolchain, for example, "ir-llvm".
pub toolchain: String,
}
18 changes: 15 additions & 3 deletions benchmark_analyzer/src/output/format/json/lnt/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ pub mod test_description;

use machine::Machine;
use run_description::RunDescription;
use serde::{Deserialize, Serialize};
sayon marked this conversation as resolved.
Show resolved Hide resolved
use test_description::TestDescription;

use crate::BenchmarkVersion;

///
/// Root benchmark structure describing a single JSON file passed to LNT.
/// One such file is generated for every machine configuration.
Expand All @@ -20,11 +19,24 @@ use crate::BenchmarkVersion;
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct LntBenchmark {
/// Benchmark format version
pub format_version: BenchmarkVersion,
pub format_version: LntReportFormatVersion,
/// Machine description is used as a group identifier
pub machine: Machine,
/// Describes the runtime benchmark characteristics, for example, when it has started and when it has ended
pub run: RunDescription,
/// Tests grouped in this benchmark.
pub tests: Vec<TestDescription>,
}

///
/// Version of the LNT report.
///
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum LntReportFormatVersion {
/// Old deprecated LNT report format.
#[serde(rename = "1")]
antonbaliasnikov marked this conversation as resolved.
Show resolved Hide resolved
V1,
/// New LNT report format.
#[serde(rename = "2")]
V2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
use chrono::DateTime;
use chrono::Utc;

///
/// Run order in the LNT report. Equals to DateTime<Utc> for now.
///
type LLVMProjectRevision = DateTime<Utc>;

///
/// Description of the benchmark run in a JSON file passed to LNT.
///
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RunDescription {
/// LNT run order.
pub llvm_project_revision: LLVMProjectRevision,
/// Time when benchmark run was started.
pub start_time: DateTime<Utc>,
/// Time when benchmark run was finished.
pub end_time: DateTime<Utc>,
/// Version of the `zksolc` compiler.
pub zksolc_version: String,
/// Version of the LLVM backend.
pub llvm_version: String,
}
31 changes: 21 additions & 10 deletions benchmark_analyzer/src/output/format/json/lnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::model::benchmark::test::metadata::Metadata as TestMetadata;
use crate::model::benchmark::test::selector::Selector;
use crate::model::benchmark::test::Test;
use crate::model::benchmark::Benchmark;
use crate::output::format::json::lnt::benchmark::LntReportFormatVersion;
use crate::output::format::json::make_json_file;
use crate::output::IBenchmarkSerializer;
use crate::output::Output;
Expand All @@ -34,12 +35,18 @@ pub struct JsonLNT;
fn test_name(selector: &Selector, version: impl std::fmt::Display) -> String {
fn shorten_file_name(name: &str) -> String {
let path_buf = PathBuf::from(name);
path_buf
.file_name()
.expect("Always valid")
.to_str()
.expect("Always valid")
.to_string()
if let Some(parent) = path_buf.parent() {
if let Some(file_name) = path_buf.file_name() {
if let Some(dir_name) = parent.file_name() {
return format!(
"{}/{}",
dir_name.to_string_lossy(),
file_name.to_string_lossy()
);
}
}
}
path_buf.to_str().expect("Always valid").to_string()
}
let Selector { path, case, input } = selector;
let short_path = shorten_file_name(path);
Expand Down Expand Up @@ -81,28 +88,32 @@ impl IBenchmarkSerializer for JsonLNT {
for (codegen, codegen_group) in codegen_groups {
for (version, versioned_group) in &codegen_group.versioned_groups {
for (
optimizations,
optimization,
crate::Executable {
run: measurements, ..
},
) in &versioned_group.executables
{
let machine_name = format!("{}-{codegen}-{optimizations}", context.machine);
let machine_name = format!("{}-{codegen}{optimization}", context.machine);

let machine = Machine {
name: context.machine.clone(),
target: context.target,
optimizations: optimizations.to_owned(),
codegen: codegen.clone(),
optimization: optimization.clone(),
toolchain: context.toolchain.clone(),
};
let run = RunDescription {
llvm_project_revision: benchmark.metadata.start,
start_time: benchmark.metadata.start,
end_time: benchmark.metadata.end,
zksolc_version: context.zksolc_version.clone(),
llvm_version: context.llvm_version.clone(),
};
files
.entry(machine_name)
.or_insert(LntBenchmark {
format_version: benchmark.metadata.version.clone(),
format_version: LntReportFormatVersion::V2,
machine,
run,
tests: vec![],
Expand Down
8 changes: 8 additions & 0 deletions benchmark_analyzer/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
//!

pub mod btreemap;

///
/// Check if a value is zero.
/// This is a helper function for serialization.
///
pub fn is_zero<T: PartialEq + From<u8>>(value: &T) -> bool {
*value == T::from(0)
}
Loading