From 3afa31277645e46573ac7b6c5769cefd4069d78f Mon Sep 17 00:00:00 2001 From: "refcell.eth" Date: Mon, 13 Mar 2023 18:12:44 -0400 Subject: [PATCH] feat(flamegraphs): Introduce Flamegraphs (#138) * :fire: flamegraphs * :memo: flamegraph blog post :chain: * client get_fee_history * node get_fee_history * errors: InvalidBaseGaseFee * execution get_fee_history * http rpc get_fee_history * moc rpc get_fee_history and json file * module add get_fee_history * update exec * test feehistory * update execution with logging + better logic * fee history config loader * rust fmt client * rustfmt node * rustfmt error * rustfmt execution * rustfmt http and moc rpc * rustfmt mod.rs * fee history formating * correct typos * use env var * InvalidGasUsedRatio error * check gas used ratio * remove logging * Update execution/src/errors.rs Co-authored-by: refcell.eth * Update execution/src/execution.rs Co-authored-by: refcell.eth * adding block and payload errors * using error * handle error in test * fix: evm panic on slot not found (#208) * fixes, but test fails * fix: cleanup and example (#210) * clean up fee history * bump time dep in chrono, thx dependabot * add benches to pr * sleep * fmt :sparkles: * place benching behind a man flag * cleanup flamegraphs * cleanup --------- Co-authored-by: SFYLL Co-authored-by: SFYLL <39958632+SFYLL@users.noreply.github.com> --- Cargo.toml | 6 + README.md | 3 + benches/README.md | 18 ++ benches/flamegraphs/client.svg | 491 +++++++++++++++++++++++++++++++++ 4 files changed, 518 insertions(+) create mode 100644 benches/README.md create mode 100644 benches/flamegraphs/client.svg diff --git a/Cargo.toml b/Cargo.toml index 2c5b92b..52a2bfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "helios" version = "0.2.0" edition = "2021" autobenches = false +exclude = [ + "benches" +] [workspace] members = [ @@ -15,6 +18,9 @@ members = [ "helios-ts", ] +[profile.bench] +debug = true + [dependencies] client = { path = "./client" } config = { path = "./config" } diff --git a/README.md b/README.md index 2d9e854..8d9d51f 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,9 @@ Benchmarks are defined in the [benches](./benches/) subdirectory. They are built To run all benchmarks, you can use `cargo bench`. To run a specific benchmark, you can use `cargo bench --bench `, where `` is one of the benchmarks defined in the [Cargo.toml](./Cargo.toml) file under a `[[bench]]` section. +To learn more about [helios](https://github.com/a16z/helios) benchmarking and to view benchmark flamegraphs, view the [benchmark readme](./benches/README.md). + + ## Contributing All contributions to Helios are welcome. Before opening a PR, please submit an issue detailing the bug or feature. When opening a PR, please ensure that your contribution builds on the nightly rust toolchain, has been linted with `cargo fmt`, and contains tests when applicable. diff --git a/benches/README.md b/benches/README.md new file mode 100644 index 0000000..0842859 --- /dev/null +++ b/benches/README.md @@ -0,0 +1,18 @@ +# Helios Benchmarking + +Helios performance is measured using [criterion](https://github.com/bheisler/criterion.rs) for comprehensive statistics-driven benchmarking. + +Benchmarks are defined in the [benches](./) subdirectory and can be run using the cargo `bench` subcommand (eg `cargo bench`). To run a specific benchmark, you can use `cargo bench --bench `, where `` is one of the benchmarks defined in the [Cargo.toml](./Cargo.toml) file under a `[[bench]]` section. + + +#### Flamegraphs + +[Flamegraph](https://github.com/brendangregg/FlameGraph) is a powerful rust crate for generating profile visualizations, that is graphing the time a program spends in each function. Functions called during execution are displayed as horizontal rectangles with the width proportional to the time spent in that function. As the call stack grows (think nested function invocations), the rectangles are stacked vertically. This provides a powerful visualization for quickly understanding which parts of a codebase take up disproportionate amounts of time. + +Check out Brendan Gregg's [Flame Graphs](http://www.brendangregg.com/flamegraphs.html) blog post if you're interested in learning more about flamegraphs and performance visualizations in general. + +To generate a flamegraph for helios, you can use the `cargo flamegraph` subcommand. For example, to generate a flamegraph for the [`client`](./examples/client.rs) example, you can run: + +```bash +cargo flamegraph --example client -o ./flamegraphs/client.svg +``` diff --git a/benches/flamegraphs/client.svg b/benches/flamegraphs/client.svg new file mode 100644 index 0000000..6c0776f --- /dev/null +++ b/benches/flamegraphs/client.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch dyld`start (1 samples, 25.00%)dyld`startclient`main (1 samples, 25.00%)client`mainclient`std::rt::lang_start_internal (1 samples, 25.00%)client`std::rt::lang_start_internalclient`std::rt::lang_start::_{{closure}} (1 samples, 25.00%)client`std::rt::lang_start::_{{closure}}client`std::sys_common::backtrace::__rust_begin_short_backtrace (1 samples, 25.00%)client`std::sys_common::backtrace::__rus..client`client::main (1 samples, 25.00%)client`client::mainclient`tokio::runtime::builder::Builder::build (1 samples, 25.00%)client`tokio::runtime::builder::Builder:..client`tokio::runtime::scheduler::multi_thread::worker::Launch::launch (1 samples, 25.00%)client`tokio::runtime::scheduler::multi_..client`tokio::runtime::blocking::pool::spawn_blocking (1 samples, 25.00%)client`tokio::runtime::blocking::pool::s..client`tokio::runtime::blocking::pool::Spawner::spawn_blocking (1 samples, 25.00%)client`tokio::runtime::blocking::pool::S..client`tokio::runtime::blocking::pool::Spawner::spawn_task (1 samples, 25.00%)client`tokio::runtime::blocking::pool::S..client`std::thread::Builder::spawn (1 samples, 25.00%)client`std::thread::Builder::spawnclient`std::sys::unix::thread::Thread::new (1 samples, 25.00%)client`std::sys::unix::thread::Thread::n..libsystem_kernel.dylib`__bsdthread_create (1 samples, 25.00%)libsystem_kernel.dylib`__bsdthread_createclient`__rdl_alloc (1 samples, 25.00%)client`__rdl_alloclibsystem_malloc.dylib`posix_memalign (1 samples, 25.00%)libsystem_malloc.dylib`posix_memalignlibsystem_malloc.dylib`_malloc_zone_memalign (1 samples, 25.00%)libsystem_malloc.dylib`_malloc_zone_mema..libsystem_malloc.dylib`szone_malloc_should_clear (1 samples, 25.00%)libsystem_malloc.dylib`szone_malloc_shou..libsystem_malloc.dylib`small_malloc_should_clear (1 samples, 25.00%)libsystem_malloc.dylib`small_malloc_shou..client`core::ops::function::FnOnce::call_once{{vtable.shim}} (2 samples, 50.00%)client`core::ops::function::FnOnce::call_once{{vtable.shim}}client`std::sys_common::backtrace::__rust_begin_short_backtrace (2 samples, 50.00%)client`std::sys_common::backtrace::__rust_begin_short_backtraceclient`tokio::runtime::blocking::pool::Inner::run (2 samples, 50.00%)client`tokio::runtime::blocking::pool::Inner::runclient`parking_lot::raw_mutex::RawMutex::lock_slow (2 samples, 50.00%)client`parking_lot::raw_mutex::RawMutex::lock_slowclient`std::thread::local::lazy::LazyKeyInner<T>::initialize (2 samples, 50.00%)client`std::thread::local::lazy::LazyKeyInner<T>::initializeclient`parking_lot_core::parking_lot::ThreadData::new (2 samples, 50.00%)client`parking_lot_core::parking_lot::ThreadData::newclient`parking_lot_core::parking_lot::create_hashtable (2 samples, 50.00%)client`parking_lot_core::parking_lot::create_hashtableclient`parking_lot_core::parking_lot::HashTable::new (2 samples, 50.00%)client`parking_lot_core::parking_lot::HashTable::newlibsystem_malloc.dylib`nanov2_allocate_outlined (1 samples, 25.00%)libsystem_malloc.dylib`nanov2_allocate_o..all (4 samples, 100%)libsystem_pthread.dylib`thread_start (3 samples, 75.00%)libsystem_pthread.dylib`thread_startlibsystem_pthread.dylib`_pthread_start (3 samples, 75.00%)libsystem_pthread.dylib`_pthread_startclient`std::sys::unix::thread::Thread::new::thread_start (3 samples, 75.00%)client`std::sys::unix::thread::Thread::new::thread_startclient`std::sys::unix::stack_overflow::imp::make_handler (1 samples, 25.00%)client`std::sys::unix::stack_overflow::i..libsystem_kernel.dylib`__mmap (1 samples, 25.00%)libsystem_kernel.dylib`__mmap \ No newline at end of file