Improve the debugging experience in the puffin reports

This commit is contained in:
Kerollmops 2023-09-25 15:38:08 +02:00
parent c45c6cf54c
commit f2a9e1ebbb
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -17,6 +17,8 @@ tasks individally, but should be much faster since we are only performing
one indexing operation. one indexing operation.
*/ */
use core::fmt;
use std::borrow::Cow;
use std::collections::{BTreeSet, HashSet}; use std::collections::{BTreeSet, HashSet};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs::{self, File}; use std::fs::{self, File};
@ -199,6 +201,29 @@ impl Batch {
} }
} }
impl fmt::Display for Batch {
/// A text used when we debug the profiling reports.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let index_uid = self.index_uid();
let tasks = self.ids();
let task = match self {
Batch::TaskCancelation { .. } => Cow::Borrowed("TaskCancelation"),
Batch::TaskDeletion(_) => Cow::Borrowed("TaskDeletion"),
Batch::SnapshotCreation(_) => Cow::Borrowed("SnapshotCreation"),
Batch::Dump(_) => Cow::Borrowed("Dump"),
Batch::IndexOperation { op, .. } => Cow::Owned(op.to_string()),
Batch::IndexCreation { .. } => Cow::Borrowed("IndexCreation"),
Batch::IndexUpdate { .. } => Cow::Borrowed("IndexUpdate"),
Batch::IndexDeletion { .. } => Cow::Borrowed("IndexDeletion"),
Batch::IndexSwap { .. } => Cow::Borrowed("IndexSwap"),
};
match index_uid {
Some(name) => f.write_fmt(format_args!("{task} on {name:?} from tasks: {tasks:?}")),
None => f.write_fmt(format_args!("{task} from tasks: {tasks:?}")),
}
}
}
impl IndexOperation { impl IndexOperation {
pub fn index_uid(&self) -> &str { pub fn index_uid(&self) -> &str {
match self { match self {
@ -213,6 +238,30 @@ impl IndexOperation {
} }
} }
impl fmt::Display for IndexOperation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
IndexOperation::DocumentOperation { .. } => {
f.write_str("IndexOperation::DocumentOperation")
}
IndexOperation::DocumentDeletion { .. } => {
f.write_str("IndexOperation::DocumentDeletion")
}
IndexOperation::IndexDocumentDeletionByFilter { .. } => {
f.write_str("IndexOperation::IndexDocumentDeletionByFilter")
}
IndexOperation::DocumentClear { .. } => f.write_str("IndexOperation::DocumentClear"),
IndexOperation::Settings { .. } => f.write_str("IndexOperation::Settings"),
IndexOperation::DocumentClearAndSetting { .. } => {
f.write_str("IndexOperation::DocumentClearAndSetting")
}
IndexOperation::SettingsAndDocumentOperation { .. } => {
f.write_str("IndexOperation::SettingsAndDocumentOperation")
}
}
}
}
impl IndexScheduler { impl IndexScheduler {
/// Convert an [`BatchKind`](crate::autobatcher::BatchKind) into a [`Batch`]. /// Convert an [`BatchKind`](crate::autobatcher::BatchKind) into a [`Batch`].
/// ///
@ -581,7 +630,7 @@ impl IndexScheduler {
self.breakpoint(crate::Breakpoint::InsideProcessBatch); self.breakpoint(crate::Breakpoint::InsideProcessBatch);
} }
puffin::profile_function!(format!("{:?}", batch)); puffin::profile_function!(batch.to_string());
match batch { match batch {
Batch::TaskCancelation { mut task, previous_started_at, previous_processing_tasks } => { Batch::TaskCancelation { mut task, previous_started_at, previous_processing_tasks } => {