From 32b53aaacb8e47f1dd876518356a196ae927d269 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Tue, 29 Nov 2022 00:23:30 +0800 Subject: [PATCH] feat: add tracing spans --- crates/loro-core/src/container/registry.rs | 10 ++++++++++ crates/loro-core/src/container/text/text_container.rs | 7 +++++++ crates/loro-core/src/log_store/encoding.rs | 3 +++ crates/loro-core/src/log_store/import.rs | 6 +++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/loro-core/src/container/registry.rs b/crates/loro-core/src/container/registry.rs index b98b394f..80c403b2 100644 --- a/crates/loro-core/src/container/registry.rs +++ b/crates/loro-core/src/container/registry.rs @@ -8,6 +8,7 @@ use enum_as_inner::EnumAsInner; use fxhash::FxHashMap; use owning_ref::OwningRefMut; use smallvec::SmallVec; +use tracing::instrument; use crate::{ context::Context, @@ -62,6 +63,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn tracker_checkout(&mut self, vv: &crate::VersionVector) { match self { ContainerInstance::Map(x) => x.tracker_checkout(vv), @@ -71,6 +73,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn get_value(&self) -> crate::LoroValue { match self { ContainerInstance::Map(x) => x.get_value(), @@ -80,6 +83,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn update_state_directly( &mut self, hierarchy: &mut Hierarchy, @@ -94,6 +98,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn track_retreat(&mut self, op: &IdSpanVector) { match self { ContainerInstance::Map(x) => x.track_retreat(op), @@ -103,6 +108,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn track_forward(&mut self, op: &IdSpanVector) { match self { ContainerInstance::Map(x) => x.track_forward(op), @@ -112,6 +118,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn track_apply(&mut self, hierarchy: &mut Hierarchy, op: &RichOp, ctx: &mut ImportContext) { match self { ContainerInstance::Map(x) => x.track_apply(hierarchy, op, ctx), @@ -121,6 +128,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn apply_tracked_effects_from( &mut self, h: &mut Hierarchy, @@ -134,6 +142,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn to_export( &mut self, content: crate::op::InnerContent, @@ -147,6 +156,7 @@ impl Container for ContainerInstance { } } + #[instrument(skip_all)] fn to_import(&mut self, content: crate::op::RemoteContent) -> crate::op::InnerContent { match self { ContainerInstance::Map(x) => x.to_import(content), diff --git a/crates/loro-core/src/container/text/text_container.rs b/crates/loro-core/src/container/text/text_container.rs index b2b34c5e..130dfd3a 100644 --- a/crates/loro-core/src/container/text/text_container.rs +++ b/crates/loro-core/src/container/text/text_container.rs @@ -5,6 +5,7 @@ use rle::{ HasLength, RleTree, }; use smallvec::SmallVec; +use tracing::instrument; use crate::{ container::{ @@ -48,6 +49,7 @@ impl TextContainer { } } + #[instrument(skip_all)] pub fn insert(&mut self, ctx: &C, pos: usize, text: &str) -> Option { if text.is_empty() { return None; @@ -88,6 +90,7 @@ impl TextContainer { Some(id) } + #[instrument(skip_all)] pub fn delete(&mut self, ctx: &C, pos: usize, len: usize) -> Option { if len == 0 { return None; @@ -273,6 +276,7 @@ impl Container for TextContainer { } } + #[instrument(skip_all)] fn update_state_directly( &mut self, hierarchy: &mut Hierarchy, @@ -321,6 +325,7 @@ impl Container for TextContainer { self.tracker.forward(spans); } + #[instrument(skip_all)] fn tracker_checkout(&mut self, vv: &crate::VersionVector) { if (!vv.is_empty() || self.tracker.start_vv().is_empty()) && self.tracker.all_vv() >= vv @@ -332,6 +337,7 @@ impl Container for TextContainer { } } + #[instrument(skip_all)] fn track_apply( &mut self, _: &mut Hierarchy, @@ -341,6 +347,7 @@ impl Container for TextContainer { self.tracker.track_apply(rich_op); } + #[instrument(skip_all)] fn apply_tracked_effects_from( &mut self, hierarchy: &mut Hierarchy, diff --git a/crates/loro-core/src/log_store/encoding.rs b/crates/loro-core/src/log_store/encoding.rs index e7a06683..33b22758 100644 --- a/crates/loro-core/src/log_store/encoding.rs +++ b/crates/loro-core/src/log_store/encoding.rs @@ -5,6 +5,7 @@ use rle::{HasLength, RleVec, RleVecWithIndex}; use serde::{Deserialize, Serialize}; use serde_columnar::{columnar, compress, decompress, from_bytes, to_vec, CompressConfig}; use smallvec::smallvec; +use tracing::instrument; use crate::{ change::{Change, ChangeMergeCfg, Lamport, Timestamp}, @@ -92,6 +93,7 @@ struct Encoded { keys: Vec, } +#[instrument(skip_all)] fn encode_changes(store: &LogStore) -> Encoded { let mut client_id_to_idx: FxHashMap = FxHashMap::default(); let mut clients = Vec::with_capacity(store.changes.len()); @@ -187,6 +189,7 @@ fn encode_changes(store: &LogStore) -> Encoded { } } +#[instrument(skip_all)] fn decode_changes( encoded: Encoded, client_id: Option, diff --git a/crates/loro-core/src/log_store/import.rs b/crates/loro-core/src/log_store/import.rs index f080986b..a3031bb2 100644 --- a/crates/loro-core/src/log_store/import.rs +++ b/crates/loro-core/src/log_store/import.rs @@ -1,10 +1,11 @@ +use crate::LogStore; use crate::{ container::registry::ContainerIdx, event::{Diff, RawEvent}, version::{Frontiers, IdSpanVector}, - LogStore, }; use std::{collections::VecDeque, ops::ControlFlow, sync::MutexGuard}; +use tracing::instrument; use fxhash::FxHashMap; @@ -72,6 +73,8 @@ impl LogStore { /// - Stage 1: we iterate over the new changes by causal order, and record them to the tracker. /// - Stage 2: we calculate the effects of the new changes, and apply them to the state. /// - Update the rest of the log store state. + /// + #[instrument(skip_all)] pub fn import(&mut self, mut changes: RemoteClientChanges) { if let ControlFlow::Break(_) = self.tailor_changes(&mut changes) { return; @@ -178,6 +181,7 @@ impl LogStore { (next_vv, next_frontiers) } + #[instrument(skip_all)] pub(crate) fn apply( &mut self, mut container_map: FxHashMap>,