Skip to content

Commit b90638f

Browse files
committed
Implement basic reporting
1 parent d229f73 commit b90638f

File tree

1 file changed

+67
-2
lines changed
  • mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator

1 file changed

+67
-2
lines changed

mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ use serde::Deserialize;
3333
use slog::Level;
3434
use slog_scope::{debug, info, warn};
3535
use thiserror::Error;
36-
use tokio::{select, task::JoinSet, time::sleep};
36+
use tokio::{
37+
select,
38+
task::JoinSet,
39+
time::{sleep, Instant},
40+
};
3741

3842
macro_rules! spin_while_waiting {
3943
($block:block, $timeout:expr, $wait_message:expr, $timeout_message:expr) => {{
@@ -711,9 +715,59 @@ async fn bootstrap_aggregator(
711715
Ok(aggregator)
712716
}
713717

718+
struct Timing {
719+
phase: String,
720+
duration: Duration,
721+
}
722+
723+
struct Reporter {
724+
number_of_signers: usize,
725+
timings: Vec<Timing>,
726+
current_timing: Option<(String, Instant)>,
727+
}
728+
729+
impl Reporter {
730+
fn new(number_of_signers: usize) -> Self {
731+
Self {
732+
number_of_signers,
733+
timings: vec![],
734+
current_timing: None,
735+
}
736+
}
737+
738+
fn start(&mut self, phase: &str) {
739+
self.current_timing = Some((phase.to_owned(), Instant::now()));
740+
}
741+
742+
fn stop(&mut self) {
743+
match &self.current_timing {
744+
Some((phase, instant)) => {
745+
let timing = Timing {
746+
phase: phase.clone(),
747+
duration: instant.elapsed(),
748+
};
749+
750+
self.timings.push(timing);
751+
self.current_timing = None;
752+
}
753+
None => (),
754+
}
755+
}
756+
757+
fn print_report(&self) {
758+
println!("number_of_signers\t{}", self.number_of_signers);
759+
println!("phase\tduration/ms");
760+
for t in &self.timings {
761+
println!("{}\t{}", t.phase, t.duration.as_millis());
762+
}
763+
}
764+
}
765+
714766
#[tokio::main(flavor = "multi_thread")]
715767
async fn main() -> StdResult<()> {
716768
let opts = MainOpts::parse();
769+
let mut reporter: Reporter = Reporter::new(opts.num_signers);
770+
reporter.start("stress tests bootstrap");
717771
// configure a dummy immutable db
718772
let mut immutable_db = DummyImmutablesDbBuilder::new("load-tester")
719773
.with_immutables(&[1, 2, 3])
@@ -726,6 +780,7 @@ async fn main() -> StdResult<()> {
726780
let protocol_parameters = ProtocolParameters::new(2422, 20973, 0.20);
727781
info!(">> Starting stress test with options: {opts:?}");
728782

783+
reporter.start("stress bootstrap");
729784
info!(">> Creation of the Signer Key Registrations payloads");
730785
let signers_fixture = generate_signer_data(opts.num_signers, protocol_parameters);
731786

@@ -736,16 +791,19 @@ async fn main() -> StdResult<()> {
736791
.await?;
737792

738793
let mut aggregator = bootstrap_aggregator(&args, &signers_fixture, &mut current_epoch).await?;
794+
reporter.stop();
739795

740796
info!(">> Move one epoch forward in order to start creating certificates");
741797
current_epoch += 1;
742798
write_epoch(&args.mock_epoch_file_path(), current_epoch);
743799
wait_for_epoch_settings_at_epoch(&aggregator, Duration::from_secs(10), current_epoch).await?;
744800

745801
info!(">> Send the Signer Key Registrations payloads");
802+
reporter.start("signers registration");
746803
let errors =
747804
register_signers_to_aggregator(&aggregator, &signers_fixture.signers(), current_epoch + 1)
748805
.await?;
806+
reporter.stop();
749807
assert_eq!(0, errors);
750808

751809
info!(">> Wait for pending certificate to be available");
@@ -755,12 +813,14 @@ async fn main() -> StdResult<()> {
755813
">> Send the Signer Signatures payloads for MithrilStakeDistribution({:?})",
756814
current_epoch
757815
);
816+
reporter.start("signatures registration");
758817
let errors = register_signatures_to_aggregator(
759818
&aggregator,
760819
&mithril_stake_distribution_signatures,
761820
SignedEntityType::MithrilStakeDistribution(current_epoch),
762821
)
763822
.await?;
823+
reporter.stop();
764824
assert_eq!(0, errors);
765825

766826
info!(">> Wait for certificates to be available...");
@@ -789,12 +849,14 @@ async fn main() -> StdResult<()> {
789849
">> Send the Signer Signatures payloads for CardanoImmutableFiles({:?})",
790850
current_beacon
791851
);
852+
reporter.start("signatures registration");
792853
let errors = register_signatures_to_aggregator(
793854
&aggregator,
794855
&immutable_files_signatures,
795856
SignedEntityType::CardanoImmutableFilesFull(current_beacon),
796857
)
797858
.await?;
859+
reporter.stop();
798860
assert_eq!(0, errors);
799861

800862
info!(">> Wait for certificates to be available...");
@@ -803,8 +865,11 @@ async fn main() -> StdResult<()> {
803865
info!(">> Wait for artifacts to be available...");
804866
wait_for_immutable_files_artifacts(&aggregator, Duration::from_secs(30)).await?;
805867

806-
info!(">> All steps executed successfully, stopping all tasks...");
868+
info!(">> Display execution timings:");
869+
reporter.print_report();
807870

871+
info!(">> All steps executed successfully, stopping all tasks...");
808872
aggregator.stop().await.unwrap();
873+
809874
Ok(())
810875
}

0 commit comments

Comments
 (0)