update event timing dump format

This commit is contained in:
yggverse 2025-03-27 05:37:14 +02:00
parent 8d064308d6
commit a91db1384e

View File

@ -5,10 +5,7 @@ use adw::{
ActionRowExt, ExpanderRowExt, PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt, ActionRowExt, ExpanderRowExt, PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt,
}, },
}; };
use gtk::{ use gtk::{Align, glib::GString};
Align,
glib::{GString, gformat},
};
pub trait Dialog { pub trait Dialog {
fn info(profile: &Profile, info: &Info) -> Self; fn info(profile: &Profile, info: &Info) -> Self;
@ -20,11 +17,12 @@ impl Dialog for PreferencesDialog {
fn row(title: impl Into<GString>, subtitle: impl Into<GString>) -> ActionRow { fn row(title: impl Into<GString>, subtitle: impl Into<GString>) -> ActionRow {
ActionRow::builder() ActionRow::builder()
.css_classes(["property"]) .css_classes(["property"])
.use_markup(true)
.subtitle(subtitle)
.subtitle_selectable(true) .subtitle_selectable(true)
.subtitle(subtitle)
.title_selectable(true) .title_selectable(true)
.title(title) .title(title)
.use_markup(true)
.use_markup(true)
.build() .build()
} }
let d = PreferencesDialog::builder() let d = PreferencesDialog::builder()
@ -255,18 +253,16 @@ impl Dialog for PreferencesDialog {
if is_external { if is_external {
a.add_suffix(&suffix("application-exit-symbolic", "External")) // @TODO links contain ⇖ text label indication a.add_suffix(&suffix("application-exit-symbolic", "External")) // @TODO links contain ⇖ text label indication
} }
// show total redirection time in ms // calculate total redirections time in ms
let c = r.event.last().unwrap().time();
a.set_subtitle(&if i == 0 { a.set_subtitle(&if i == 0 {
t.format_iso8601().unwrap() format!("{} ms", c.difference(t).as_milliseconds())
} else { } else {
gformat!( format!(
"{} ms", "+{} / {} ms",
r.event c.difference(b[i - 1].event.last().unwrap().time())
.last() .as_milliseconds(),
.unwrap() c.difference(t).as_milliseconds()
.time()
.difference(t)
.as_milliseconds()
) )
}); });
a a
@ -291,24 +287,15 @@ impl Dialog for PreferencesDialog {
g.add(&row(n, t.format_iso8601().unwrap())); g.add(&row(n, t.format_iso8601().unwrap()));
for (i, e) in info.event[1..].iter().enumerate() { for (i, e) in info.event[1..].iter().enumerate() {
g.add(&{ g.add(&{
use gtk::{Align, Label}; let c = e.time().difference(info.event[i].time()).as_milliseconds(); // current
let c = e.time().difference(info.event[i].time()).as_milliseconds(); let s = e.time().difference(t).as_milliseconds(); // sum
let a = row( let a = row(
e.name(), e.name(),
gformat!("{} ms", e.time().difference(t).as_milliseconds()), if c == s {
); format!("+{c} ms")
a.add_suffix( } else {
&Label::builder() format!("+{c} / {s} ms")
.css_classes([if c == 0 { "success" } else { "warning" }]) },
.halign(Align::End)
.label(if c > 0 {
format!("+{c} ms")
} else {
c.to_string()
})
.sensitive(false)
.valign(Align::Center)
.build(),
); );
a a
}) })