From f2a9e1ebbb5290b38bca3f4aaf04c40eef53406c Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 25 Sep 2023 15:38:08 +0200 Subject: [PATCH] Improve the debugging experience in the puffin reports --- index-scheduler/src/batch.rs | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index ccdcbcbb6..e544c8769 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -17,6 +17,8 @@ tasks individally, but should be much faster since we are only performing one indexing operation. */ +use core::fmt; +use std::borrow::Cow; use std::collections::{BTreeSet, HashSet}; use std::ffi::OsStr; 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 { pub fn index_uid(&self) -> &str { 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 { /// Convert an [`BatchKind`](crate::autobatcher::BatchKind) into a [`Batch`]. /// @@ -581,7 +630,7 @@ impl IndexScheduler { self.breakpoint(crate::Breakpoint::InsideProcessBatch); } - puffin::profile_function!(format!("{:?}", batch)); + puffin::profile_function!(batch.to_string()); match batch { Batch::TaskCancelation { mut task, previous_started_at, previous_processing_tasks } => {