-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add support for analysis mode #152
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
base: main
Are you sure you want to change the base?
Changes from all commits
0ce0cab
5a5d450
97e21d0
8d90e07
435a805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,43 @@ jobs: | |
| mode: walltime | ||
| token: ${{ secrets.CODSPEED_TOKEN }} | ||
|
|
||
|
|
||
| compat-integration-test-memory: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| package: | ||
| - codspeed-divan-compat | ||
| - codspeed-divan-compat-examples | ||
| - codspeed-criterion-compat | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: true | ||
| - uses: moonrepo/setup-rust@v1 | ||
| with: | ||
| cache-target: release | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - run: cargo install --path crates/cargo-codspeed --locked | ||
|
|
||
| - run: | | ||
| # Remove the cargo config else it forces instrumentation mode | ||
| rm -f .cargo/config.toml | ||
| cargo codspeed build -p ${{ matrix.package }} -m instrumentation | ||
|
|
||
| # TODO: Enable once we can upload it | ||
| # - name: Run the benchmarks | ||
| # uses: CodSpeedHQ/action@chore/runner-branch | ||
| # env: | ||
| # MY_ENV_VAR: "YES" | ||
| # with: | ||
| # runner-branch: cod-1670-runner-profile-memory-of-command | ||
| # run: cargo codspeed run | ||
| # mode: memory | ||
| # token: ${{ secrets.CODSPEED_TOKEN }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to remove secrets now with OIDC |
||
|
|
||
| musl-build-check: | ||
| strategy: | ||
| matrix: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,7 +226,9 @@ See `cargo codspeed build --help` for more information."); | |
| ]; | ||
|
|
||
| // Add the codspeed cfg flag if simulation mode is enabled | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update comment, or create a function that takes measurement_mode and outputs a bool, named |
||
| if measurement_mode == MeasurementMode::Simulation { | ||
| if measurement_mode == MeasurementMode::Simulation | ||
| || measurement_mode == MeasurementMode::Analysis | ||
| { | ||
| flags.push("--cfg=codspeed".to_owned()); | ||
| } | ||
|
|
||
|
|
||
| +116 −0 | .github/workflows/ci.yml | |
| +3,249 −2,742 | dist/core.c | |
| +36 −0 | includes/compat.h | |
| +1 −0 | includes/core.h | |
| +4 −0 | scripts/release.py | |
| +3 −1 | src/bincode.zig | |
| +0 −17 | src/c.zig | |
| +6 −0 | src/instruments/analysis.zig | |
| +58 −0 | src/instruments/helper.zig | |
| +3 −155 | src/instruments/perf.zig | |
| +27 −14 | src/instruments/root.zig | |
| +5 −1 | src/instruments/valgrind.zig | |
| +183 −0 | src/runner_fifo.zig | |
| +20 −0 | src/shared.zig | |
| +34 −0 | src/utils.zig |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use crate::measurement; | ||
| use crate::{instrument_hooks::InstrumentHooks, measurement}; | ||
| use colored::Colorize; | ||
| use std::ffi::CString; | ||
|
|
||
|
|
@@ -19,7 +19,8 @@ pub struct CodSpeed { | |
|
|
||
| impl CodSpeed { | ||
| pub fn new() -> Self { | ||
| let is_instrumented = measurement::is_instrumented(); | ||
| let ih = InstrumentHooks::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a fan of abbreviations overall, but here it does not bring that much, how about |
||
| let is_instrumented = ih.is_instrumented(); | ||
| if !is_instrumented { | ||
| println!( | ||
| "{} codspeed is enabled, but no performance measurement will be made since it's running in an unknown environment.", | ||
|
|
@@ -46,12 +47,16 @@ impl CodSpeed { | |
| #[inline(always)] | ||
| pub fn start_benchmark(&mut self, name: &str) { | ||
| self.current_benchmark = CString::new(name).expect("CString::new failed"); | ||
| let _ = InstrumentHooks::instance().start_benchmark(); | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| measurement::start(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will that not confuse valgrind to keep both this and the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be the time to say goodbye to the inline assembly and make a major out of this |
||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn end_benchmark(&mut self) { | ||
| measurement::stop(&self.current_benchmark); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same remark here |
||
| let _ = InstrumentHooks::instance().stop_benchmark(); | ||
| let _ = InstrumentHooks::instance() | ||
| .set_executed_benchmark(&self.current_benchmark.to_string_lossy()); | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.benchmarked | ||
| .push(self.current_benchmark.to_str().unwrap().to_string()); | ||
| let action_str = if self.is_instrumented { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,3 +44,7 @@ harness = false | |
| [[bench]] | ||
| name = "counters" | ||
| harness = false | ||
|
|
||
| [[bench]] | ||
| name = "alloc" | ||
| harness = false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use std::{ | ||
| alloc::Layout, | ||
| collections::{HashMap, HashSet}, | ||
| }; | ||
|
|
||
| #[divan::bench] | ||
| fn allocate() { | ||
| println!("Hello, world!"); | ||
|
|
||
| let vec = vec![1, 2, 3]; | ||
| println!("{vec:?}"); | ||
|
|
||
| let mut map = HashMap::new(); | ||
| map.insert("key", "value"); | ||
| println!("{map:?}"); | ||
|
|
||
| let mut set = HashSet::new(); | ||
| set.insert("apple"); | ||
| set.insert("banana"); | ||
| println!("{set:?}"); | ||
|
|
||
| std::thread::sleep(std::time::Duration::from_secs(1)); | ||
|
|
||
| let mut bytes_vec = vec![0u8; 0x100]; | ||
| println!("{:?}", bytes_vec.len()); | ||
|
|
||
| bytes_vec.extend(&vec![0u8; 0x1000]); | ||
|
|
||
| // Alloc 42 bytes of memory per iteration (4200 bytes total) | ||
| for _ in 0..100 { | ||
| let layout = Layout::new::<[u8; 42]>(); | ||
| let memory = unsafe { std::alloc::alloc(layout) }; | ||
| core::hint::black_box(memory); | ||
| unsafe { std::alloc::dealloc(memory, layout) }; | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| divan::main(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have multi-dimensional matrices, as well as some dimensions precising two things
We could combine everything in one big matrix, one dimension being the library we are testing, the other one the mode and the runner it runs on like here https://github.com/CodSpeedHQ/codspeed-cpp/blob/f23b68b27f8543f88f95ff0bdc46785733dee061/.github/workflows/ci.yml#L57-L62
WDYT ?
We could conditionnallly remove the .cargo/config.toml, as well as conditionnally skip the uploading part for memory (for now)