Skip to content

Commit

Permalink
feat(l1, l2, levm): make stats (#1361)
Browse files Browse the repository at this point in the history
**Motivation**

<!-- Why does this pull request exist? What are its goals? -->

We want to be able to run all the repo statistics locally with one
command (`make stats`).

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

- Updates `loc` bin (lines of code reporter).
- Adds `stats` target to the Makefile that runs:
    - Lines of code report
    - LEVM EF Tests
    - Hive simulation

**Work in progress**

Right now, the hive reporter needs some improvements. If you run the
command `make stats, ` it will run all and print the reports for lines
of code, LEVM EF Tests, and Hive, but the Hive report is off.

**Try it yourself**

```
make stats
```

---------

Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Javier Rodríguez Chatruc <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2024
1 parent f204cd9 commit c4e9f67
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 134 deletions.
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 @@ -87,16 +87,29 @@ HIVE_REVISION := df7d5103d4ddc772307f9947be4ad1f20ce03ed0
# 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 \
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 @@ -106,7 +119,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
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 @@ -116,3 +132,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

0 comments on commit c4e9f67

Please sign in to comment.