Skip to content

Commit 7f0580c

Browse files
committed
feat: implement debug
1 parent 45023c7 commit 7f0580c

File tree

12 files changed

+247
-34
lines changed

12 files changed

+247
-34
lines changed

iced_examples/counter/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ impl Application for Counter {
6969
)
7070
}
7171

72+
fn name() -> &'static str {
73+
"hello"
74+
}
75+
7276
fn namespace(&self) -> String {
7377
String::from("Counter - Iced")
7478
}

iced_layershell/src/application.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use layershellev::{
3535
};
3636

3737
use futures::{StreamExt, channel::mpsc};
38+
use iced::theme;
39+
use iced_runtime::debug;
3840

3941
use crate::{actions::ActionCallback, event::IcedLayerEvent, proxy::IcedProxy, settings::Settings};
4042

@@ -141,6 +143,8 @@ where
141143

142144
let (message_sender, message_receiver) = std::sync::mpsc::channel::<Action<A::Message>>();
143145

146+
debug::init(A::name());
147+
let boot_span = debug::boot();
144148
let proxy = IcedProxy::new(message_sender);
145149
let mut runtime: SingleRuntime<E, A::Message> = {
146150
let executor = E::new().map_err(Error::ExecutorCreationFailed)?;
@@ -200,6 +204,7 @@ where
200204
));
201205

202206
let mut context = task::Context::from_waker(task::noop_waker_ref());
207+
boot_span.finish();
203208
let mut wl_input_region: Option<WlRegion> = None;
204209

205210
let _ = ev.running_with_proxy(message_receiver, move |event, ev, _| {
@@ -507,14 +512,15 @@ async fn run_instance<A, E, C>(
507512
let mut events: Vec<Event> = Vec::new();
508513
let mut custom_actions = Vec::new();
509514

515+
let main_id = IcedCoreWindow::Id::unique();
510516
let mut user_interface = ManuallyDrop::new(build_user_interface(
511517
&application,
512518
cache,
513519
&mut renderer,
514520
state.viewport().logical_size(),
521+
main_id,
515522
));
516523

517-
let main_id = IcedCoreWindow::Id::unique();
518524
let mut p_width: u32 = 0;
519525
let mut p_height: u32 = 0;
520526
let mut p_fractal_scale: f64 = 0.;
@@ -531,12 +537,15 @@ async fn run_instance<A, E, C>(
531537
p_height = height;
532538
p_fractal_scale = fractal_scale;
533539

540+
let layout_span = debug::layout(main_id);
534541
state.update_view_port(width, height, fractal_scale);
535542

536543
user_interface = ManuallyDrop::new(
537544
ManuallyDrop::into_inner(user_interface)
538545
.relayout(state.viewport().logical_size(), &mut renderer),
539546
);
547+
layout_span.finish();
548+
debug::theme_changed(|| theme::Base::palette(&application.theme()));
540549

541550
let physical_size = state.viewport().physical_size();
542551
compositor.configure_surface(
@@ -652,12 +661,14 @@ async fn run_instance<A, E, C>(
652661
&mut clipboard,
653662
&mut custom_actions,
654663
&mut should_exit,
664+
main_id,
655665
);
656666
user_interface = ManuallyDrop::new(build_user_interface(
657667
&application,
658668
cache,
659669
&mut renderer,
660670
state.viewport().logical_size(),
671+
main_id,
661672
));
662673
if should_exit {
663674
break;
@@ -667,13 +678,15 @@ async fn run_instance<A, E, C>(
667678
if events.is_empty() && messages.is_empty() {
668679
continue;
669680
}
681+
let interact_span = debug::interact(main_id);
670682
let (interface_state, statuses) = user_interface.update(
671683
&events,
672684
state.cursor(),
673685
&mut renderer,
674686
&mut clipboard,
675687
&mut messages,
676688
);
689+
interact_span.finish();
677690

678691
for (event, status) in events.drain(..).zip(statuses.into_iter()) {
679692
runtime.broadcast(iced_futures::subscription::Event::Interaction {
@@ -689,11 +702,13 @@ async fn run_instance<A, E, C>(
689702
let cache = ManuallyDrop::into_inner(user_interface).into_cache();
690703
// Update application
691704
update(&mut application, &mut state, &mut runtime, &mut messages);
705+
debug::theme_changed(|| theme::Base::palette(&application.theme()));
692706
user_interface = ManuallyDrop::new(build_user_interface(
693707
&application,
694708
cache,
695709
&mut renderer,
696710
state.viewport().logical_size(),
711+
main_id,
697712
));
698713
}
699714
custom_actions.push(LayerShellAction::RedrawAll);
@@ -715,13 +730,18 @@ pub fn build_user_interface<'a, A: Application>(
715730
cache: user_interface::Cache,
716731
renderer: &mut A::Renderer,
717732
size: Size,
733+
id: IcedCoreWindow::Id,
718734
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
719735
where
720736
A::Theme: DefaultStyle,
721737
{
738+
let view_span = debug::view(id);
722739
let view = application.view();
740+
view_span.finish();
723741

742+
let layout_span = debug::layout(id);
724743
let user_interface = UserInterface::build(view, size, cache, renderer);
744+
layout_span.finish();
725745
user_interface
726746
}
727747

@@ -738,7 +758,10 @@ pub(crate) fn update<A: Application, E: Executor>(
738758
A::Message: 'static,
739759
{
740760
for message in messages.drain(..) {
761+
let update_span = debug::update(&message);
741762
let task = runtime.enter(|| application.update(message));
763+
debug::tasks_spawned(task.units());
764+
update_span.finish();
742765

743766
if let Some(stream) = iced_runtime::task::into_stream(task) {
744767
runtime.run(stream);
@@ -747,9 +770,10 @@ pub(crate) fn update<A: Application, E: Executor>(
747770
state.synchronize(application);
748771

749772
let subscription = runtime.enter(|| application.subscription());
750-
runtime.track(iced_futures::subscription::into_recipes(
751-
subscription.map(Action::Output),
752-
));
773+
let recipes = iced_futures::subscription::into_recipes(subscription.map(Action::Output));
774+
775+
debug::subscriptions_tracked(recipes.len());
776+
runtime.track(recipes);
753777
}
754778

755779
#[allow(clippy::too_many_arguments)]
@@ -764,6 +788,7 @@ pub(crate) fn run_action<A, C>(
764788
clipboard: &mut LayerShellClipboard,
765789
custom_actions: &mut Vec<LayerShellAction>,
766790
should_exit: &mut bool,
791+
id: IcedCoreWindow::Id,
767792
) where
768793
A: Application,
769794
C: Compositor<Renderer = A::Renderer> + 'static,
@@ -800,6 +825,7 @@ pub(crate) fn run_action<A, C>(
800825
current_cache,
801826
renderer,
802827
state.viewport().logical_size(),
828+
id,
803829
);
804830

805831
while let Some(mut operation) = current_operation.take() {

iced_layershell/src/build_pattern/application.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub trait Program: Sized {
5252
"A cool iced application".to_string()
5353
}
5454

55+
fn name() -> &'static str;
56+
5557
/// Handles a __message__ and updates the state of the [`Application`].
5658
///
5759
/// This is where you define your __update logic__. All the __messages__,
@@ -130,6 +132,10 @@ pub trait Program: Sized {
130132
self.program.update(&mut self.state, message)
131133
}
132134

135+
fn name() -> &'static str {
136+
P::name()
137+
}
138+
133139
fn view(&self) -> crate::Element<'_, Self::Message, Self::Theme, Self::Renderer> {
134140
self.program.view(&self.state)
135141
}
@@ -317,6 +323,12 @@ where
317323
type Theme = Theme;
318324
type Executor = iced_futures::backend::default::Executor;
319325

326+
fn name() -> &'static str {
327+
let name = std::any::type_name::<State>();
328+
329+
name.split("::").next().unwrap_or("a_cool_application")
330+
}
331+
320332
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
321333
self.update.update(state, message).into()
322334
}
@@ -366,6 +378,10 @@ pub fn with_executor<P: Program, E: iced_futures::Executor>(
366378
self.program.namespace(state)
367379
}
368380

381+
fn name() -> &'static str {
382+
P::name()
383+
}
384+
369385
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
370386
self.program.update(state, message)
371387
}
@@ -423,6 +439,10 @@ fn with_namespace<P: Program>(
423439
(self.namespace)(state)
424440
}
425441

442+
fn name() -> &'static str {
443+
P::name()
444+
}
445+
426446
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
427447
self.program.update(state, message)
428448
}
@@ -481,6 +501,10 @@ pub fn with_subscription<P: Program>(
481501
self.program.update(state, message)
482502
}
483503

504+
fn name() -> &'static str {
505+
P::name()
506+
}
507+
484508
fn view<'a>(
485509
&self,
486510
state: &'a Self::State,
@@ -534,6 +558,10 @@ pub fn with_theme<P: Program>(
534558
(self.theme)(state)
535559
}
536560

561+
fn name() -> &'static str {
562+
P::name()
563+
}
564+
537565
fn namespace(&self, state: &Self::State) -> String {
538566
self.program.namespace(state)
539567
}
@@ -588,6 +616,10 @@ pub fn with_style<P: Program>(
588616
(self.style)(state, theme)
589617
}
590618

619+
fn name() -> &'static str {
620+
P::name()
621+
}
622+
591623
fn namespace(&self, state: &Self::State) -> String {
592624
self.program.namespace(state)
593625
}
@@ -642,6 +674,10 @@ pub fn with_scale_factor<P: Program>(
642674
self.program.namespace(state)
643675
}
644676

677+
fn name() -> &'static str {
678+
P::name()
679+
}
680+
645681
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
646682
self.program.update(state, message)
647683
}

iced_layershell/src/build_pattern/daemon.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait Program: Sized {
5252
"A cool iced application".to_string()
5353
}
5454

55-
/// Handles a __message__ and updates the state of the [`Application`].
55+
fn name() -> &'static str;
5656
///
5757
/// This is where you define your __update logic__. All the __messages__,
5858
/// produced by either user interactions or commands, will be handled by
@@ -142,6 +142,10 @@ pub trait Program: Sized {
142142
) -> crate::Element<'_, Self::Message, Self::Theme, Self::Renderer> {
143143
self.program.view(&self.state, window)
144144
}
145+
146+
fn name() -> &'static str {
147+
P::name()
148+
}
145149
}
146150

147151
impl<P: Program, I: FnOnce() -> (P::State, Task<P::Message>)>
@@ -371,6 +375,12 @@ where
371375
) -> Element<'a, Self::Message, Self::Theme, Self::Renderer> {
372376
self.view.view(state, window).into()
373377
}
378+
379+
fn name() -> &'static str {
380+
let name = std::any::type_name::<State>();
381+
382+
name.split("::").next().unwrap_or("a_cool_application")
383+
}
374384
}
375385
Daemon {
376386
raw: Instance {
@@ -434,6 +444,10 @@ fn with_namespace<P: Program>(
434444
self.program.subscription(state)
435445
}
436446

447+
fn name() -> &'static str {
448+
P::name()
449+
}
450+
437451
fn style(
438452
&self,
439453
state: &Self::State,
@@ -480,6 +494,10 @@ pub fn with_subscription<P: Program>(
480494
self.program.update(state, message)
481495
}
482496

497+
fn name() -> &'static str {
498+
P::name()
499+
}
500+
483501
fn view<'a>(
484502
&self,
485503
state: &'a Self::State,
@@ -544,7 +562,9 @@ pub fn with_theme<P: Program>(
544562
fn namespace(&self, state: &Self::State) -> String {
545563
self.program.namespace(state)
546564
}
547-
565+
fn name() -> &'static str {
566+
P::name()
567+
}
548568
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
549569
self.program.update(state, message)
550570
}
@@ -609,7 +629,9 @@ pub fn with_style<P: Program>(
609629
fn namespace(&self, state: &Self::State) -> String {
610630
self.program.namespace(state)
611631
}
612-
632+
fn name() -> &'static str {
633+
P::name()
634+
}
613635
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
614636
self.program.update(state, message)
615637
}
@@ -668,7 +690,9 @@ pub fn with_scale_factor<P: Program>(
668690
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
669691
self.program.update(state, message)
670692
}
671-
693+
fn name() -> &'static str {
694+
P::name()
695+
}
672696
fn view<'a>(
673697
&self,
674698
state: &'a Self::State,
@@ -728,7 +752,9 @@ pub fn with_executor<P: Program, E: iced_futures::Executor>(
728752
fn namespace(&self, state: &Self::State) -> String {
729753
self.program.namespace(state)
730754
}
731-
755+
fn name() -> &'static str {
756+
P::name()
757+
}
732758
fn update(&self, state: &mut Self::State, message: Self::Message) -> Task<Self::Message> {
733759
self.program.update(state, message)
734760
}

0 commit comments

Comments
 (0)