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

Run diagnostics on live AudioContext #401

Merged
merged 5 commits into from
Nov 25, 2023
Merged

Conversation

orottier
Copy link
Owner

Usage: context.run_diagnostics(|s| println!("Diagnostics:\n{}", s));
It will generate a report on the next render quantum, in a somewhat realtime safe manner.
This will hopefully aid debugging of e.g. #396

@@ -344,6 +344,26 @@ impl AudioContext {
self.base().clear_event_handler(EventType::SinkChange);
}

#[allow(clippy::missing_panics_doc)]
pub fn run_diagnostics<F: Fn(String) + Send + 'static>(&self, callback: F) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Wondering if we should mark this method #[doc(hidden)] because I could imagine we are not keeping the API stable over different versions. Would be interesting to return more structured data in the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup looks reasonable

EventHandler::Once(Box::new(callback)),
);

let buffer = Vec::with_capacity(32 * 1024);
Copy link
Owner Author

Choose a reason for hiding this comment

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

32kB ought to be enough for anybody.

-- Bill Gates

@orottier
Copy link
Owner Author

/bench because we are messing with vtables here in tight loops


/// Return the name of the actual AudioProcessor type
#[doc(hidden)] // not meant to be user facing
fn name(&self) -> &'static str {
Copy link
Owner Author

Choose a reason for hiding this comment

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

This method enables us to ask a Box<dyn AudioProcessor> what its true type is (e.g. ConstantSourceRenderer). This opens the way to mute audio graph legs with no side effects like proposed in #397

Copy link
Collaborator

@b-ma b-ma Nov 25, 2023

Choose a reason for hiding this comment

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

Nice, I'll try to make to list all the cases I can think of about this graph thing next week

Copy link

Benchmark result:


bench_ctor
  Instructions:             4453084 (+0.678351%)
  L1 Accesses:              6767759 (+0.781862%)
  L2 Accesses:                54186 (No change)
  RAM Accesses:               61517 (-0.001626%)
  Estimated Cycles:         9191784 (+0.574102%)

bench_audio_buffer_decode
  Instructions:             7582803 (-0.017352%)
  L1 Accesses:             10484657 (-0.026937%)
  L2 Accesses:                28254 (-0.257705%)
  RAM Accesses:               32046 (-0.009361%)
  Estimated Cycles:        11747537 (-0.028041%)

bench_sine
  Instructions:            69771460 (+0.140086%)
  L1 Accesses:            101435941 (+0.155770%)
  L2 Accesses:               263352 (-0.035681%)
  RAM Accesses:               62386 (No change)
  Estimated Cycles:       104936211 (+0.150117%)

bench_sine_gain
  Instructions:            77404057 (+0.198845%)
  L1 Accesses:            113065164 (+0.225361%)
  L2 Accesses:               294485 (-3.512709%)
  RAM Accesses:               62499 (No change)
  Estimated Cycles:       116725054 (+0.172176%)

bench_sine_gain_delay
  Instructions:           148003203 (+0.167619%)
  L1 Accesses:            207966649 (+0.215112%)
  L2 Accesses:               496555 (-8.262313%)
  RAM Accesses:               64070 (+0.007805%)
  Estimated Cycles:       212691874 (+0.104941%)

bench_buffer_src
  Instructions:            16777507 (+0.577049%)
  L1 Accesses:             24721128 (+0.639127%)
  L2 Accesses:                87986 (-2.504266%)
  RAM Accesses:              100528 (-0.001989%)
  Estimated Cycles:        28679538 (+0.510361%)

bench_buffer_src_delay
  Instructions:            89028739 (+0.222191%)
  L1 Accesses:            122175572 (+0.263065%)
  L2 Accesses:               166259 (-0.475298%)
  RAM Accesses:              100679 (+0.008940%)
  Estimated Cycles:       126530632 (+0.251084%)

bench_buffer_src_iir
  Instructions:            40740537 (+0.301783%)
  L1 Accesses:             59719934 (+0.334554%)
  L2 Accesses:                90252 (-3.276211%)
  RAM Accesses:              100625 (+0.003975%)
  Estimated Cycles:        63693069 (+0.289697%)

bench_buffer_src_biquad
  Instructions:            36054790 (+0.593268%)
  L1 Accesses:             51231572 (+0.669521%)
  L2 Accesses:               128400 (+4.441191%)
  RAM Accesses:              100755 (+0.007941%)
  Estimated Cycles:        55399997 (+0.669260%)

bench_stereo_positional
  Instructions:            40764932 (+1.214180%)
  L1 Accesses:             61547783 (+1.377262%)
  L2 Accesses:               203021 (-18.05806%)
  RAM Accesses:              100825 (-0.007934%)
  Estimated Cycles:        66091763 (+0.934907%)

bench_stereo_panning_automation
  Instructions:            30954145 (+0.469902%)
  L1 Accesses:             46826055 (+0.497590%)
  L2 Accesses:               135541 (+0.918791%)
  RAM Accesses:              100650 (+0.005962%)
  Estimated Cycles:        51026510 (+0.469061%)

bench_analyser_node
  Instructions:            38712265 (+0.316888%)
  L1 Accesses:             54564583 (+0.372676%)
  L2 Accesses:               190183 (-3.540218%)
  RAM Accesses:              101173 (+0.004942%)
  Estimated Cycles:        59056553 (+0.285062%)

bench_hrtf_panners
  Instructions:           329313607 (-0.052586%)
  L1 Accesses:            577528228 (-0.026542%)
  L2 Accesses:             10897259 (+0.167156%)
  RAM Accesses:              120395 (-0.116978%)
  Estimated Cycles:       636228348 (-0.010583%)

bench_sine_gain_with_worklet
  Instructions:            78209726 (+0.187174%)
  L1 Accesses:            114184309 (+0.227486%)
  L2 Accesses:               296797 (-7.235283%)
  RAM Accesses:               62694 (+0.004785%)
  Estimated Cycles:       117862584 (+0.121921%)


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


@b-ma
Copy link
Collaborator

b-ma commented Nov 25, 2023

Looks all good to me!

@orottier orottier merged commit 9273819 into main Nov 25, 2023
3 checks passed
@orottier orottier deleted the feature/print-diagnostics branch November 25, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants