mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(events): list komorebi's time with its source, and say when it fell back
This commit is contained in:
1 parent
63d3d256aa
commit
333bf2fd03
3 files changed
+73
-4
No files matched your search
@@ -179,6 +179,11 @@ pub struct EventsData {
|
||||
/// The name komorebi knew this recorder by. When komorebi logs at DEBUG it names it for each
|
||||
/// notification pushed, which makes pairing events with handlers exact.
|
||||
pub subscriber: Option<String>,
|
||||
/// Set when some of the returned events show the received time as their `komorebi_time`
|
||||
/// because the log has no `pushed notification` line for them: says so and why. Absent when
|
||||
/// every event has its pushed time.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub komorebi_time_note: Option<String>,
|
||||
}
|
||||
|
||||
/// Which windows, monitors and workspaces a state answer is about.
|
||||
@@ -476,6 +481,7 @@ impl Analysis {
|
||||
.iter()
|
||||
.filter_map(|index| self.event_view(*index))
|
||||
.collect();
|
||||
let komorebi_time_note = super::views::komorebi_time_note(&events);
|
||||
let next_cursor = (count < remaining.len())
|
||||
.then(|| events.last().map(|view| view.seq.to_string()))
|
||||
.flatten();
|
||||
@@ -486,6 +492,7 @@ impl Analysis {
|
||||
matching: wanted.len(),
|
||||
total: all.len(),
|
||||
subscriber: self.pairing().subscriber.clone(),
|
||||
komorebi_time_note,
|
||||
},
|
||||
next_cursor,
|
||||
}
|
||||
|
||||
@@ -757,7 +757,8 @@ pub fn diff_text(data: &DiffData) -> String {
|
||||
/// let analysis = Analysis::open(&session.dir)?;
|
||||
///
|
||||
/// let text = events_text(&analysis.events_answer(&EventQuery::default()).data, false);
|
||||
/// assert!(text.starts_with("1 of 1 events\n#1 00:02.000 command"));
|
||||
/// assert!(text.contains("\n#1 00:02.000 r command"));
|
||||
/// assert!(text.contains("note: 1 of 1 events have no `pushed notification"));
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
#[must_use]
|
||||
@@ -774,6 +775,13 @@ pub fn events_text(data: &EventsData, verbose: bool) -> String {
|
||||
" (recorded as subscriber {name})"
|
||||
))
|
||||
);
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"times: p = when komorebi pushed the notification, r = when the recorder received it (no pushed line in the log){}",
|
||||
data.komorebi_time_note
|
||||
.as_ref()
|
||||
.map_or_else(String::new, |note| format!("\nnote: {note}"))
|
||||
);
|
||||
|
||||
for event in &data.events {
|
||||
let handler = event.handler.as_ref().map_or_else(String::new, |handler| {
|
||||
@@ -785,8 +793,9 @@ pub fn events_text(data: &EventsData, verbose: bool) -> String {
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
format!(" handler{ms}{problems}{}", pushed_text(handler))
|
||||
format!(" handler{ms}{problems}")
|
||||
});
|
||||
let received = received_text(event);
|
||||
let state = match event.state_changed {
|
||||
Some(true) => " state changed",
|
||||
Some(false) => " state unchanged",
|
||||
@@ -794,9 +803,10 @@ pub fn events_text(data: &EventsData, verbose: bool) -> String {
|
||||
};
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"#{:<5} {} {:<9} {}{handler}{state}",
|
||||
"#{:<5} {}{} {:<9} {}{handler}{received}{state}",
|
||||
event.seq,
|
||||
timecode::format(event.video_s),
|
||||
timecode::format(event.komorebi_time.video_s),
|
||||
source_marker(event),
|
||||
format!("{:?}", event.class).to_lowercase(),
|
||||
event.summary,
|
||||
);
|
||||
@@ -1261,6 +1271,31 @@ fn pushed_text(handler: &crate::analysis::views::HandlerView) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// `p` after a time when it is when komorebi pushed the notification, `r` when it is when the
|
||||
/// recorder received it (the log has no pushed line, so that is all there is).
|
||||
fn source_marker(event: &EventView) -> &'static str {
|
||||
match event.komorebi_time.source {
|
||||
crate::analysis::views::TimeSource::Pushed => " p",
|
||||
crate::analysis::views::TimeSource::Received => " r",
|
||||
}
|
||||
}
|
||||
|
||||
/// ` received 00:05.000`: when the recorder got the notification, if that was well after komorebi
|
||||
/// pushed it.
|
||||
fn received_text(event: &EventView) -> String {
|
||||
let delay_ms = (event.video_s - event.komorebi_time.video_s) * 1000.0;
|
||||
if event.komorebi_time.source == crate::analysis::views::TimeSource::Pushed
|
||||
&& delay_ms >= DELIVERY_NOTE_MS
|
||||
{
|
||||
format!(
|
||||
" received {} ({delay_ms:.0} ms after pushed)",
|
||||
timecode::format(event.video_s)
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn event_line(event: &EventView) -> String {
|
||||
let handler = event.handler.as_ref().map_or_else(String::new, |handler| {
|
||||
let ms = handler
|
||||
|
||||
@@ -232,3 +232,30 @@ fn a_handler_that_really_was_slow_is_still_a_slow_handler() {
|
||||
.all(|finding| finding["kind"] != "delivery-batching")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_events_listing_shows_komorebis_time_and_which_it_is() {
|
||||
// pushed lines present: the time is komorebi's, and the received time follows
|
||||
let dir = batched("one-clock-ktime-pushed", true);
|
||||
let events = json(&["events", &dir, "--json"]);
|
||||
let first = &events["data"]["events"][0];
|
||||
assert_eq!(first["komorebi_time"]["source"], "pushed");
|
||||
assert!((first["komorebi_time"]["video_s"].as_f64().expect("time") - 2.005).abs() < 1e-3);
|
||||
assert!(
|
||||
events["data"].get("komorebi_time_note").is_none(),
|
||||
"{events}"
|
||||
);
|
||||
let text = String::from_utf8_lossy(&run(&["events", &dir]).stdout).into_owned();
|
||||
assert!(text.contains("00:02.005 p"), "{text}");
|
||||
assert!(text.contains("received 00:05.000"), "{text}");
|
||||
|
||||
// no subscriber to match the lines against: received, and it says so
|
||||
let dir = batched("one-clock-ktime-received", false);
|
||||
let events = json(&["events", &dir, "--json"]);
|
||||
let first = &events["data"]["events"][0];
|
||||
assert_eq!(first["komorebi_time"]["source"], "received", "{first}");
|
||||
assert!(events["data"]["komorebi_time_note"].is_string(), "{events}");
|
||||
let text = String::from_utf8_lossy(&run(&["events", &dir]).stdout).into_owned();
|
||||
assert!(text.contains("00:05.000 r"), "{text}");
|
||||
assert!(text.contains("note: "), "{text}");
|
||||
}
|
||||
Reference in new issue
Block a user