feat: add tracing spans

This commit is contained in:
Zixuan Chen 2022-11-29 00:23:30 +08:00
parent 9efc6749ef
commit 32b53aaacb
4 changed files with 25 additions and 1 deletions

View file

@ -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),

View file

@ -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<C: Context>(&mut self, ctx: &C, pos: usize, text: &str) -> Option<ID> {
if text.is_empty() {
return None;
@ -88,6 +90,7 @@ impl TextContainer {
Some(id)
}
#[instrument(skip_all)]
pub fn delete<C: Context>(&mut self, ctx: &C, pos: usize, len: usize) -> Option<ID> {
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,

View file

@ -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<InternalString>,
}
#[instrument(skip_all)]
fn encode_changes(store: &LogStore) -> Encoded {
let mut client_id_to_idx: FxHashMap<ClientID, ClientIdx> = 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<ClientID>,

View file

@ -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<ContainerIdx, MutexGuard<ContainerInstance>>,