Skip to content

Commit 4730b4e

Browse files
committed
More instrumenting - stop enumerating devices on start
1 parent 2235fce commit 4730b4e

File tree

12 files changed

+42
-8
lines changed

12 files changed

+42
-8
lines changed

toybox-audio/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ pub mod prelude {
1414
}
1515

1616

17+
#[instrument(skip_all, name="audio init")]
1718
pub fn init() -> anyhow::Result<System> {
1819
let host = cpal::default_host();
1920

20-
if true {
21+
if false {
22+
let _span = tracing::info_span!("enumerate audio devices").entered();
23+
2124
log::trace!("vvvvvvv Available audio devices vvvvvvvv");
2225

2326
for device in host.output_devices()? {

toybox-cfg/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ edition.workspace = true
1010
dirs = "5.0.1"
1111
toml = "0.8.10"
1212
anyhow.workspace = true
13+
tracing.workspace = true
1314
log.workspace = true

toybox-cfg/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod table;
55
use table::{Table, Value};
66

77
use std::path::{PathBuf};
8+
use tracing::instrument;
89

910

1011
/// Runtime representation of hierarchical key-value storage, intended for settings, command line config, etc.
@@ -27,6 +28,7 @@ pub struct Config {
2728
}
2829

2930
impl Config {
31+
#[instrument(skip_all, name="cfg Config::for_app_name")]
3032
pub fn for_app_name(app_name: &str) -> anyhow::Result<Self> {
3133
let mut config = Self::default();
3234

@@ -47,11 +49,13 @@ impl Config {
4749
Ok(config)
4850
}
4951

52+
#[instrument(skip_all, name="cfg Config::save")]
5053
pub fn save(&self) -> anyhow::Result<()> {
5154
// TODO(pat.m): extra resolve?
5255
self.base.save_to_file(&self.save_path)
5356
}
5457

58+
#[instrument(skip_all, name="cfg Config::commit")]
5559
pub fn commit(&mut self) {
5660
self.base.merge_from(&self.preview);
5761
self.arguments.remove_values_in(&self.preview);
@@ -61,6 +65,7 @@ impl Config {
6165
self.resolved = Table::new();
6266
}
6367

68+
#[instrument(skip_all, name="cfg Config::revert")]
6469
pub fn revert(&mut self) {
6570
self.preview = Table::new();
6671
self.resolved = Table::new();
@@ -96,6 +101,7 @@ impl Config {
96101
}
97102

98103

104+
#[instrument]
99105
pub fn config_path(app_name: &str) -> PathBuf {
100106
let mut dir = dirs::preference_dir()
101107
.expect("Couldn't get preferences dir");

toybox-egui/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct Integration {
3232
}
3333

3434
impl Integration {
35+
#[instrument(skip_all, name="egui Integration::new")]
3536
pub fn new(ctx: egui::Context, window: Rc<Window>, gfx: &mut gfx::System) -> anyhow::Result<Integration> {
3637
let theme = None;
3738
let scale_factor = window.scale_factor() as f32;

toybox-egui/src/renderer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct Renderer {
2424
}
2525

2626
impl Renderer {
27+
#[tracing::instrument(skip_all, name="egui Renderer::new")]
2728
pub fn new(gfx: &mut gfx::System) -> Renderer {
2829
Renderer {
2930
vertex_shader: gfx.resource_manager.request(CompileShaderRequest::vertex("egui vs", VERTEX_SOURCE)),

toybox-egui/src/textures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ManagedImage {
2929

3030

3131
impl TextureManager {
32+
#[tracing::instrument(skip_all, name="egui TextureManager::new")]
3233
pub fn new(gfx: &mut gfx::System) -> TextureManager {
3334
let sampler = gfx.core.create_sampler();
3435
gfx.core.set_sampler_minify_filter(sampler, FilterMode::Linear, None);

toybox-gfx/src/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::prelude::*;
22

33
use toybox_host as host;
44
use host::prelude::*;
5+
use tracing::instrument;
56

67
pub mod capabilities;
78
pub mod fbo;
@@ -55,6 +56,7 @@ pub struct Core {
5556
}
5657

5758
impl Core {
59+
#[instrument(skip_all, name="gfx Core::new")]
5860
pub fn new(gl: gl::Gl) -> Core {
5961
let capabilities = Capabilities::from(&gl);
6062
let global_vao_name = Self::create_and_bind_global_vao(&gl);

toybox-gfx/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl System {
4848
}
4949

5050
impl System {
51+
#[instrument(skip_all, name="gfxsys System::new")]
5152
pub fn new(mut core: core::Core) -> anyhow::Result<System> {
5253
core.register_debug_hook();
5354

toybox-host/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ impl BootstrapState {
263263
}
264264

265265
// Try to create our window and a config that describes a context we can create
266+
let _span = tracing::info_span!("host build display").entered();
267+
266268
let (maybe_window, gl_config) = DisplayBuilder::new()
267269
.with_window_attributes(Some(self.window_attributes.clone()))
268270
.with_preference(ApiPreference::PreferEgl)
@@ -277,13 +279,17 @@ impl BootstrapState {
277279
})
278280
.map_err(|e| anyhow::format_err!("Failed to find suitable surface config: {e}"))?;
279281

282+
_span.exit();
283+
280284
log::info!("Display built with config: {gl_config:?}");
281285

282286
let maybe_raw_window_handle = maybe_window
283287
.as_ref()
284288
.and_then(|window| window.window_handle().ok())
285289
.map(|handle| handle.as_raw());
286290

291+
let _span = tracing::info_span!("host create opengl context").entered();
292+
287293
let gl_context_attributes = self.gl_context_attributes.build(maybe_raw_window_handle);
288294
let gl_display = gl_config.display();
289295

@@ -292,17 +298,23 @@ impl BootstrapState {
292298
gl_display.create_context(&gl_config, &gl_context_attributes)?
293299
};
294300

301+
_span.exit();
302+
295303
log::info!("Context created with {gl_context_attributes:?}");
296304

297305
// Create our window for real if not already
298306
let window = match maybe_window {
299307
Some(window) => window,
300-
None => glutin_winit::finalize_window(event_loop, self.window_attributes.clone(), &gl_config)?,
308+
None => {
309+
let _span = tracing::info_span!("host finalize window").entered();
310+
glutin_winit::finalize_window(event_loop, self.window_attributes.clone(), &gl_config)?
311+
}
301312
};
302313

303314
let window = Rc::new(window);
304315

305316
// Create a surface
317+
let _span = tracing::info_span!("host build surface").entered();
306318
let (width, height): (u32, u32) = window.inner_size().into();
307319
let surface_attributes = glutin::surface::SurfaceAttributesBuilder::<WindowSurface>::new()
308320
.with_srgb(Some(true))
@@ -316,13 +328,15 @@ impl BootstrapState {
316328
gl_display.create_window_surface(&gl_config, &surface_attributes)?
317329
};
318330

331+
_span.exit();
332+
319333
// Finally make our context current
320334
let gl_context = non_current_gl_context.make_current(&gl_surface)?;
321335

322-
let gl = gl::Gl::load_with(|symbol| {
336+
let gl = tracing::info_span!("host load opengl").in_scope(|| gl::Gl::load_with(|symbol| {
323337
let symbol = std::ffi::CString::new(symbol).unwrap();
324338
gl_display.get_proc_address(symbol.as_c_str()).cast()
325-
});
339+
}));
326340

327341
Ok(Host {
328342
context: gl_context,

toybox-input/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ winit.workspace = true
99
egui.workspace = true
1010
common.workspace = true
1111
log.workspace = true
12+
tracing.workspace = true
1213

1314

1415
gilrs = { version = "0.10.2", optional = true }

0 commit comments

Comments
 (0)