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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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.

54 changes: 47 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,29 @@ HIVE_REVISION := f220e0c55fb222aaaffdf17d66aa0537cd16a67a
# the whole history by making it shallow since a given date (one day before our
# target revision).
HIVE_SHALLOW_SINCE := 2024-09-02
QUIET ?= false
hive:
git clone --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive
cd hive && git checkout --detach $(HIVE_REVISION) && go build .
if [ "$(QUIET)" = "true" ]; then \
git clone --quiet --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive && \
cd hive && git checkout --quiet --detach $(HIVE_REVISION) && go build .; \
else \
git clone --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive && \
cd hive && git checkout --detach $(HIVE_REVISION) && go build .; \
fi

setup-hive: hive ## 🐝 Set up Hive testing framework
if [ "$$(cd hive && git rev-parse HEAD)" != "$(HIVE_REVISION)" ]; then \
cd hive && \
git checkout master && \
git fetch --shallow-since=$(HIVE_SHALLOW_SINCE) && \
git checkout --detach $(HIVE_REVISION) && go build . ;\
if [ "$(QUIET)" = "true" ]; then \
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

    if [ "$(QUIET)" = "true" ]; then
        quiet_opt="--quiet"
    fi
    
    git checkout $quiet_opt master && \
    git fetch $quiet_opt --shallow-since="${HIVE_SHALLOW_SINCE}" && \
    git checkout $quiet_opt --detach "${HIVE_REVISION}" && \

Copy link
Collaborator

Choose a reason for hiding this comment

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

or more succint:

    quiet_opt=$([ "$(QUIET)" = "true" ] && echo "--quiet")
    git checkout $quiet_opt master && \
    git fetch $quiet_opt --shallow-since="${HIVE_SHALLOW_SINCE}" && \
    git checkout $quiet_opt --detach "${HIVE_REVISION}" && \

cd hive && \
git checkout --quiet master && \
git fetch --quiet --shallow-since=$(HIVE_SHALLOW_SINCE) && \
git checkout --quiet --detach $(HIVE_REVISION) && go build .;\
else \
cd hive && \
git checkout master && \
git fetch --shallow-since=$(HIVE_SHALLOW_SINCE) && \
git checkout --detach $(HIVE_REVISION) && go build .;\
fi \
fi

TEST_PATTERN ?= /
Expand All @@ -95,7 +108,10 @@ 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-all: build-image setup-hive ## 🧪 Run all Hive testing suites
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need this, you should be able to just use run-hive

cd hive && ./hive --client ethrex --sim $(SIMULATION) --sim.parallelism 4

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 +121,27 @@ clean-hive-logs: ## 🧹 Clean Hive logs

loc:
cargo run -p loc

loc-stats:
if [ "$(QUIET)" = "true" ]; then \
cargo run --quiet -p loc -- --summary;\
else \
cargo run -p loc -- --summary;\
fi


hive-stats:
make hive QUIET=true
make setup-hive QUIET=true
rm -rf hive/workspace $(FILE_NAME)_logs
make run-hive-all SIMULATION=ethereum/rpc-compat || exit 0
make run-hive-all SIMULATION=devp2p || exit 0
make run-hive-all SIMULATION=ethereum/engine || exit 0
make run-hive-all SIMULATION=ethereum/sync || exit 0

stats:
make loc-stats QUIET=true && echo
cd crates/vm/levm && make download-evm-ef-tests
cd crates/vm/levm && make run-evm-ef-tests QUIET=true && 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!");
}
}
Loading
Loading