history: Add pretty printing for StructuredHistory
Implement the Display trait in a way which
generates pretty history summary.
@@ -400,6 +400,53 @@ impl From<&HistoryCollectorData> for StructuredHistory {
/// StructuredHistory should be used for printing query history.
impl Display for StructuredHistory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{:#?}", self)
+ writeln!(f, "Queries History:")?;
+ for (i, query) in self.queries.iter().enumerate() {
+ writeln!(f, "=== Query #{} ===", i)?;
+ writeln!(f, "| start_time: {}", query.start_time)?;
+ writeln!(f, "| Non-speculative attempts:")?;
+ write_fiber_attempts(&query.non_speculative_fiber, f)?;
+ for (spec_i, speculative_fiber) in query.speculative_fibers.iter().enumerate() {
+ writeln!(f, "|")?;
+ writeln!(f, "|")?;
+ writeln!(f, "| > Speculative fiber #{}", spec_i)?;
+ writeln!(f, "| fiber start time: {}", speculative_fiber.start_time)?;
+ write_fiber_attempts(speculative_fiber, f)?;
+ }
+ writeln!(f, "|")?;
+ match &query.result {
+ Some(QueryHistoryResult::Success(succ_time)) => {
+ writeln!(f, "| Query successful at {}", succ_time)?;
+ }
+ Some(QueryHistoryResult::Error(err_time, error)) => {
+ writeln!(f, "| Query failed at {}", err_time)?;
+ writeln!(f, "| Error: {}", error)?;
+ }
+ None => writeln!(f, "| Query still running - no final result yet")?,
+ };
+ writeln!(f, "=================")?;
+ }
+ Ok(())
+ }
+}
+
+fn write_fiber_attempts(fiber: &FiberHistory, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ for (i, attempt) in fiber.attempts.iter().enumerate() {
+ if i != 0 {
+ writeln!(f, "|")?;
}
+ writeln!(f, "| - Attempt #{} sent to {}", i, attempt.node_addr)?;
+ writeln!(f, "| request send time: {}", attempt.send_time)?;
+ match &attempt.result {
+ Some(AttemptResult::Success(time)) => writeln!(f, "| Success at {}", time)?,
+ Some(AttemptResult::Error(time, err, retry_decision)) => {
+ writeln!(f, "| Error at {}", time)?;
+ writeln!(f, "| Error: {}", err)?;
+ writeln!(f, "| Retry decision: {:?}", retry_decision)?;
+ }
+ None => writeln!(f, "| No result yet")?,
+ };
+ }
+
+ Ok(())
}
