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

feat(l1, l2, levm): make stats #1361

Merged
merged 16 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ TEST_PATTERN ?= /
# For example, to run the rpc-compat suites for eth_chainId & eth_blockNumber you should run:
# `make run-hive SIMULATION=ethereum/rpc-compat TEST_PATTERN="/eth_chainId|eth_blockNumber"`
run-hive: build-image setup-hive ## 🧪 Run Hive testing suite
cd hive && ./hive --sim $(SIMULATION) --client ethrex --sim.limit "$(TEST_PATTERN)"
cd hive && ./hive --client ethrex --sim $(SIMULATION) --sim.limit "$(TEST_PATTERN)"

run-hive-debug: build-image setup-hive ## 🐞 Run Hive testing suite in debug mode
cd hive && ./hive --sim $(SIMULATION) --client ethrex --sim.limit "$(TEST_PATTERN)" --docker.output
Expand All @@ -105,3 +105,25 @@ clean-hive-logs: ## 🧹 Clean Hive logs

loc:
cargo run -p loc

hive-stats:
git clone --quiet --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive || true
Copy link
Collaborator

@mpaulucci mpaulucci Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you add a dependency to setup-hive instead of duplicating code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll refactor it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 763d66d.

cd hive && git checkout --quiet --detach $(HIVE_REVISION) && go build .
if [ "$$(cd hive && git rev-parse HEAD)" != "$(HIVE_REVISION)" ]; then \
cd hive && \
git checkout --quiet master && \
git fetch --quiet --shallow-since=$(HIVE_SHALLOW_SINCE) && \
git checkout --quiet --detach $(HIVE_REVISION) && go build . ;\
fi
rm -rf hive/workspace $(FILE_NAME)_logs
cd hive && ./hive --client ethrex --sim ethereum/rpc-compat --sim.parallelism 4 || exit 0
cd hive && ./hive --client ethrex --sim devp2p --sim.parallelism 4 || exit 0
cd hive && ./hive --client ethrex --sim ethereum/engine --sim.parallelism 4 || exit 0
cd hive && ./hive --client ethrex --sim ethereum/sync --sim.parallelism 4 || exit 0

stats:
cd crates/vm/levm && make download-evm-ef-tests
cargo run --quiet --release -p loc -- --summary && echo
cargo test --quiet -p ef_tests-levm --test ef_tests_levm -- --summary && echo
make hive-stats
cargo run --quiet --release -p hive_report
4 changes: 4 additions & 0 deletions cmd/loc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ edition.workspace = true
tokei = "12.1.2"
serde = "1.0.215"
serde_json = "1.0.133"
clap = { version = "4.3", features = ["derive"] }
clap_complete = "4.5.17"
colored = "2.1.0"
spinoff = "0.8.0"
162 changes: 38 additions & 124 deletions cmd/loc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use serde::{Deserialize, Serialize};
use clap::Parser;
use report::{shell_summary, LinesOfCodeReport, LinesOfCodeReporterOptions};
use spinoff::{spinners::Dots, Color, Spinner};
use std::path::PathBuf;
use tokei::{Config, LanguageType, Languages};

const CARGO_MANIFEST_DIR: &str = std::env!("CARGO_MANIFEST_DIR");
mod report;

#[derive(Default, Serialize, Deserialize, Clone, Copy)]
pub struct LinesOfCodeReport {
ethrex: usize,
ethrex_l1: usize,
ethrex_l2: usize,
levm: usize,
}
const CARGO_MANIFEST_DIR: &str = std::env!("CARGO_MANIFEST_DIR");

fn main() {
let opts = LinesOfCodeReporterOptions::parse();

let mut spinner = Spinner::new(Dots, "Counting lines of code...", Color::Cyan);

let ethrex = PathBuf::from(CARGO_MANIFEST_DIR).join("../../");
let levm = PathBuf::from(CARGO_MANIFEST_DIR).join("../../crates/vm");
let ethrex_l2 = PathBuf::from(CARGO_MANIFEST_DIR).join("../../crates/l2");
Expand All @@ -31,128 +31,42 @@ fn main() {
languages.get_statistics(&[ethrex_l2], &["tests"], &config);
let ethrex_l2_loc = &languages.get(&LanguageType::Rust).unwrap();

spinner.success("Lines of code calculated!");

let mut spinner = Spinner::new(Dots, "Generating report...", Color::Cyan);

let new_report = LinesOfCodeReport {
ethrex: ethrex_loc.code,
ethrex_l1: ethrex_loc.code - ethrex_l2_loc.code - levm_loc.code,
ethrex_l2: ethrex_l2_loc.code,
levm: levm_loc.code,
};

std::fs::write(
"loc_report.json",
serde_json::to_string(&new_report).unwrap(),
)
.expect("loc_report.json could not be written");

let old_report: LinesOfCodeReport = std::fs::read_to_string("loc_report.json.old")
.map(|s| serde_json::from_str(&s).unwrap())
.unwrap_or(new_report);

std::fs::write(
"loc_report_slack.txt",
slack_message(old_report, new_report),
)
.unwrap();
std::fs::write(
"loc_report_github.txt",
github_step_summary(old_report, new_report),
)
.unwrap();
}
if opts.summary {
spinner.success("Report generated!");
println!("{}", shell_summary(new_report));
} else {
std::fs::write(
"loc_report.json",
serde_json::to_string(&new_report).unwrap(),
)
.expect("loc_report.json could not be written");

fn slack_message(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"{{
"blocks": [
{{
"type": "header",
"text": {{
"type": "plain_text",
"text": "Daily Lines of Code Report"
}}
}},
{{
"type": "divider"
}},
{{
"type": "section",
"text": {{
"type": "mrkdwn",
"text": "*ethrex L1:* {} {}\n*ethrex L2:* {} {}\n*levm:* {} {}\n*ethrex (total):* {} {}"
}}
}}
]
}}"#,
new_report.ethrex_l1,
match new_report.ethrex_l1.cmp(&old_report.ethrex_l1) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l1_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l1_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex_l2,
match new_report.ethrex_l2.cmp(&old_report.ethrex_l2) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l2_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l2_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.levm,
match new_report.levm.cmp(&old_report.levm) {
std::cmp::Ordering::Greater => format!("(+{levm_diff})"),
std::cmp::Ordering::Less => format!("(-{levm_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex,
match new_report.ethrex.cmp(&old_report.ethrex) {
std::cmp::Ordering::Greater => format!("(+{ethrex_diff_total})"),
std::cmp::Ordering::Less => format!("(-{ethrex_diff_total})"),
std::cmp::Ordering::Equal => "".to_string(),
},
)
}
let old_report: LinesOfCodeReport = std::fs::read_to_string("loc_report.json.old")
.map(|s| serde_json::from_str(&s).unwrap())
.unwrap_or(new_report);

std::fs::write(
"loc_report_slack.txt",
report::slack_message(old_report, new_report),
)
.unwrap();
std::fs::write(
"loc_report_github.txt",
report::github_step_summary(old_report, new_report),
)
.unwrap();

fn github_step_summary(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"```
ethrex loc summary
====================
ethrex L1: {} {}
ethrex L2: {} {}
levm: {} ({})
ethrex (total): {} {}
```"#,
new_report.ethrex_l1,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_l1_diff})")
} else {
format!("(-{ethrex_l1_diff})")
},
new_report.ethrex_l2,
if new_report.ethrex_l2 > old_report.ethrex_l2 {
format!("(+{ethrex_l2_diff})")
} else {
format!("(-{ethrex_l2_diff})")
},
new_report.levm,
if new_report.levm > old_report.levm {
format!("(+{levm_diff})")
} else {
format!("(-{levm_diff})")
},
new_report.ethrex,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_diff_total})")
} else {
format!("(-{ethrex_diff_total})")
},
)
spinner.success("Report generated!");
}
}
130 changes: 130 additions & 0 deletions cmd/loc/src/report.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
use clap::Parser;
use colored::Colorize;
use serde::{Deserialize, Serialize};

#[derive(Parser)]
pub struct LinesOfCodeReporterOptions {
#[arg(short, long, value_name = "SUMMARY", default_value = "false")]
pub summary: bool,
}

#[derive(Default, Serialize, Deserialize, Clone, Copy)]
pub struct LinesOfCodeReport {
pub ethrex: usize,
pub ethrex_l1: usize,
pub ethrex_l2: usize,
pub levm: usize,
}

pub fn slack_message(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"{{
"blocks": [
{{
"type": "header",
"text": {{
"type": "plain_text",
"text": "Daily Lines of Code Report"
}}
}},
{{
"type": "divider"
}},
{{
"type": "section",
"text": {{
"type": "mrkdwn",
"text": "*ethrex L1:* {} {}\n*ethrex L2:* {} {}\n*levm:* {} {}\n*ethrex (total):* {} {}"
}}
}}
]
}}"#,
new_report.ethrex_l1,
match new_report.ethrex_l1.cmp(&old_report.ethrex_l1) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l1_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l1_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex_l2,
match new_report.ethrex_l2.cmp(&old_report.ethrex_l2) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l2_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l2_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.levm,
match new_report.levm.cmp(&old_report.levm) {
std::cmp::Ordering::Greater => format!("(+{levm_diff})"),
std::cmp::Ordering::Less => format!("(-{levm_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex,
match new_report.ethrex.cmp(&old_report.ethrex) {
std::cmp::Ordering::Greater => format!("(+{ethrex_diff_total})"),
std::cmp::Ordering::Less => format!("(-{ethrex_diff_total})"),
std::cmp::Ordering::Equal => "".to_string(),
},
)
}

pub fn github_step_summary(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"```
ethrex loc summary
====================
ethrex L1: {} {}
ethrex L2: {} {}
levm: {} ({})
ethrex (total): {} {}
```"#,
new_report.ethrex_l1,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_l1_diff})")
} else {
format!("(-{ethrex_l1_diff})")
},
new_report.ethrex_l2,
if new_report.ethrex_l2 > old_report.ethrex_l2 {
format!("(+{ethrex_l2_diff})")
} else {
format!("(-{ethrex_l2_diff})")
},
new_report.levm,
if new_report.levm > old_report.levm {
format!("(+{levm_diff})")
} else {
format!("(-{levm_diff})")
},
new_report.ethrex,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_diff_total})")
} else {
format!("(-{ethrex_diff_total})")
},
)
}

pub fn shell_summary(new_report: LinesOfCodeReport) -> String {
format!(
"{}\n{}\n{} {}\n{} {}\n{} {}\n{} {}",
"Lines of Code".bold(),
"=============".bold(),
"ethrex L1:".bold(),
new_report.ethrex_l1,
"ethrex L2:".bold(),
new_report.ethrex_l2,
"levm:".bold(),
new_report.levm,
"ethrex (total):".bold(),
new_report.ethrex,
)
}
Loading