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 fxhash::FxHashMap;
use owning_ref::OwningRefMut; use owning_ref::OwningRefMut;
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::instrument;
use crate::{ use crate::{
context::Context, context::Context,
@ -62,6 +63,7 @@ impl Container for ContainerInstance {
} }
} }
#[instrument(skip_all)]
fn tracker_checkout(&mut self, vv: &crate::VersionVector) { fn tracker_checkout(&mut self, vv: &crate::VersionVector) {
match self { match self {
ContainerInstance::Map(x) => x.tracker_checkout(vv), ContainerInstance::Map(x) => x.tracker_checkout(vv),
@ -71,6 +73,7 @@ impl Container for ContainerInstance {
} }
} }
#[instrument(skip_all)]
fn get_value(&self) -> crate::LoroValue { fn get_value(&self) -> crate::LoroValue {
match self { match self {
ContainerInstance::Map(x) => x.get_value(), ContainerInstance::Map(x) => x.get_value(),
@ -80,6 +83,7 @@ impl Container for ContainerInstance {
} }
} }
#[instrument(skip_all)]
fn update_state_directly( fn update_state_directly(
&mut self, &mut self,
hierarchy: &mut Hierarchy, hierarchy: &mut Hierarchy,
@ -94,6 +98,7 @@ impl Container for ContainerInstance {
} }
} }
#[instrument(skip_all)]
fn track_retreat(&mut self, op: &IdSpanVector) { fn track_retreat(&mut self, op: &IdSpanVector) {
match self { match self {
ContainerInstance::Map(x) => x.track_retreat(op), 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) { fn track_forward(&mut self, op: &IdSpanVector) {
match self { match self {
ContainerInstance::Map(x) => x.track_forward(op), 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) { fn track_apply(&mut self, hierarchy: &mut Hierarchy, op: &RichOp, ctx: &mut ImportContext) {
match self { match self {
ContainerInstance::Map(x) => x.track_apply(hierarchy, op, ctx), 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( fn apply_tracked_effects_from(
&mut self, &mut self,
h: &mut Hierarchy, h: &mut Hierarchy,
@ -134,6 +142,7 @@ impl Container for ContainerInstance {
} }
} }
#[instrument(skip_all)]
fn to_export( fn to_export(
&mut self, &mut self,
content: crate::op::InnerContent, 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 { fn to_import(&mut self, content: crate::op::RemoteContent) -> crate::op::InnerContent {
match self { match self {
ContainerInstance::Map(x) => x.to_import(content), ContainerInstance::Map(x) => x.to_import(content),

View file

@ -5,6 +5,7 @@ use rle::{
HasLength, RleTree, HasLength, RleTree,
}; };
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::instrument;
use crate::{ use crate::{
container::{ 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> { pub fn insert<C: Context>(&mut self, ctx: &C, pos: usize, text: &str) -> Option<ID> {
if text.is_empty() { if text.is_empty() {
return None; return None;
@ -88,6 +90,7 @@ impl TextContainer {
Some(id) Some(id)
} }
#[instrument(skip_all)]
pub fn delete<C: Context>(&mut self, ctx: &C, pos: usize, len: usize) -> Option<ID> { pub fn delete<C: Context>(&mut self, ctx: &C, pos: usize, len: usize) -> Option<ID> {
if len == 0 { if len == 0 {
return None; return None;
@ -273,6 +276,7 @@ impl Container for TextContainer {
} }
} }
#[instrument(skip_all)]
fn update_state_directly( fn update_state_directly(
&mut self, &mut self,
hierarchy: &mut Hierarchy, hierarchy: &mut Hierarchy,
@ -321,6 +325,7 @@ impl Container for TextContainer {
self.tracker.forward(spans); self.tracker.forward(spans);
} }
#[instrument(skip_all)]
fn tracker_checkout(&mut self, vv: &crate::VersionVector) { fn tracker_checkout(&mut self, vv: &crate::VersionVector) {
if (!vv.is_empty() || self.tracker.start_vv().is_empty()) if (!vv.is_empty() || self.tracker.start_vv().is_empty())
&& self.tracker.all_vv() >= vv && self.tracker.all_vv() >= vv
@ -332,6 +337,7 @@ impl Container for TextContainer {
} }
} }
#[instrument(skip_all)]
fn track_apply( fn track_apply(
&mut self, &mut self,
_: &mut Hierarchy, _: &mut Hierarchy,
@ -341,6 +347,7 @@ impl Container for TextContainer {
self.tracker.track_apply(rich_op); self.tracker.track_apply(rich_op);
} }
#[instrument(skip_all)]
fn apply_tracked_effects_from( fn apply_tracked_effects_from(
&mut self, &mut self,
hierarchy: &mut Hierarchy, hierarchy: &mut Hierarchy,

View file

@ -5,6 +5,7 @@ use rle::{HasLength, RleVec, RleVecWithIndex};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_columnar::{columnar, compress, decompress, from_bytes, to_vec, CompressConfig}; use serde_columnar::{columnar, compress, decompress, from_bytes, to_vec, CompressConfig};
use smallvec::smallvec; use smallvec::smallvec;
use tracing::instrument;
use crate::{ use crate::{
change::{Change, ChangeMergeCfg, Lamport, Timestamp}, change::{Change, ChangeMergeCfg, Lamport, Timestamp},
@ -92,6 +93,7 @@ struct Encoded {
keys: Vec<InternalString>, keys: Vec<InternalString>,
} }
#[instrument(skip_all)]
fn encode_changes(store: &LogStore) -> Encoded { fn encode_changes(store: &LogStore) -> Encoded {
let mut client_id_to_idx: FxHashMap<ClientID, ClientIdx> = FxHashMap::default(); let mut client_id_to_idx: FxHashMap<ClientID, ClientIdx> = FxHashMap::default();
let mut clients = Vec::with_capacity(store.changes.len()); 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( fn decode_changes(
encoded: Encoded, encoded: Encoded,
client_id: Option<ClientID>, client_id: Option<ClientID>,

View file

@ -1,10 +1,11 @@
use crate::LogStore;
use crate::{ use crate::{
container::registry::ContainerIdx, container::registry::ContainerIdx,
event::{Diff, RawEvent}, event::{Diff, RawEvent},
version::{Frontiers, IdSpanVector}, version::{Frontiers, IdSpanVector},
LogStore,
}; };
use std::{collections::VecDeque, ops::ControlFlow, sync::MutexGuard}; use std::{collections::VecDeque, ops::ControlFlow, sync::MutexGuard};
use tracing::instrument;
use fxhash::FxHashMap; 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 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. /// - Stage 2: we calculate the effects of the new changes, and apply them to the state.
/// - Update the rest of the log store state. /// - Update the rest of the log store state.
///
#[instrument(skip_all)]
pub fn import(&mut self, mut changes: RemoteClientChanges) { pub fn import(&mut self, mut changes: RemoteClientChanges) {
if let ControlFlow::Break(_) = self.tailor_changes(&mut changes) { if let ControlFlow::Break(_) = self.tailor_changes(&mut changes) {
return; return;
@ -178,6 +181,7 @@ impl LogStore {
(next_vv, next_frontiers) (next_vv, next_frontiers)
} }
#[instrument(skip_all)]
pub(crate) fn apply( pub(crate) fn apply(
&mut self, &mut self,
mut container_map: FxHashMap<ContainerIdx, MutexGuard<ContainerInstance>>, mut container_map: FxHashMap<ContainerIdx, MutexGuard<ContainerInstance>>,