Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed May 7, 2024
1 parent b090b26 commit 4ea8274
Show file tree
Hide file tree
Showing 5 changed files with 570 additions and 171 deletions.
7 changes: 6 additions & 1 deletion src/context_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl ContextManager {
registered_object_handles.insert(startup_task_handle);
let mut client = Client::new(client.open_timeline(startup_task_timeline_id).await?);

let common_timeline_attr_kvs = trd.setup_common_timeline_attrs(&cfg, &mut client).await?;
//let common_timeline_attr_kvs = trd.setup_common_timeline_attrs(&cfg, &mut client).await?;
let common_timeline_attr_kvs = Default::default();

let mut importer = ContextManager {
single_task_timeline: cfg.plugin.single_task_timeline,
Expand Down Expand Up @@ -297,6 +298,7 @@ impl ContextManager {
handle: ContextHandle,
trd: &TR,
) -> Result<(), Error> {
/*
let tl_details = trd.timeline_details(handle, self.startup_task_name.as_deref())?;
let mut attr_kvs = self.common_timeline_attr_kvs.clone();
Expand All @@ -316,11 +318,13 @@ impl ContextManager {
);
self.client.inner().timeline_metadata(attr_kvs).await?;
*/

Ok(())
}
}

/*
pub(crate) fn arg_to_attr_val(arg: &Argument) -> AttrVal {
match arg {
Argument::I8(v) => AttrVal::Integer(i64::from(*v)),
Expand All @@ -334,3 +338,4 @@ pub(crate) fn arg_to_attr_val(arg: &Argument) -> AttrVal {
Argument::String(v) => AttrVal::String(v.clone().into()),
}
}
*/
85 changes: 85 additions & 0 deletions src/context_manager_new.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use crate::{
attr::{EventAttrKey, TimelineAttrKey},
config::{PluginConfig, TraceRecorderConfig},
error::Error,
recorder_data::{ContextHandle, EventAttributes, RecorderDataExt, TimelineAttributes},
};
use auxon_sdk::api::{AttrVal, TimelineId};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::hash::Hash;
use trace_recorder_parser::{
streaming::event::{Event, EventCode, EventType, TrackingEventCounter},
time::{StreamingInstant, Timestamp},
types::{Argument, FormatString, FormattedString, ObjectHandle, UserEventChannel},
};
use tracing::{debug, warn};
use uuid::Uuid;

#[derive(Debug)]
pub struct ContextEvent {
pub context: ObjectHandle,
pub global_ordering: u128,
pub attributes: EventAttributes,
// In fully-linearized interaction mode, every event has a nonce.
// When true, this event contains an interaction from the previous
// event and the previous event's nonce should be visible in
// the conventional attribute key.
pub add_previous_event_nonce: bool,
}

type RemoteTimelineId = TimelineId;
type RemoteInteractionNonce = i64;
type InteractionNonce = i64;
type RemoteContext = ObjectHandle;
type ContextSwitchInteraction = (RemoteContext, RemoteTimelineId, RemoteInteractionNonce);

#[derive(Debug)]
pub struct TimelineMeta {
id: TimelineId,
context: ObjectHandle,
attributes: TimelineAttributes,
/// The nonce recorded on the last event.
/// Effectively a timeline-local event counter so we can draw arbitrary interactions
nonce: InteractionNonce,
}

#[derive(Debug)]
pub struct ContextManager {
cfg: TraceRecorderConfig,
common_timeline_attrs: TimelineAttributes,

global_ordering: u128,
time_rollover_tracker: StreamingInstant,
event_counter_tracker: TrackingEventCounter,

objects_to_timelines: HashMap<ObjectHandle, TimelineMeta>,
// State for fully-linearized interaction mode
// TODO
// State for ipc interaction mode
// TODO
}

impl ContextManager {
pub fn new<TR: RecorderDataExt>(cfg: TraceRecorderConfig, trd: &TR) -> Result<Self, Error> {
todo!()
}

pub fn timeline_meta(&self, handle: ObjectHandle) -> Result<&TimelineMeta, Error> {
self.objects_to_timelines
.get(&handle)
.ok_or(Error::TaskTimelineLookup(handle))
}

pub fn process_event<TR: RecorderDataExt>(
&mut self,
event_code: EventCode,
event: &Event,
trd: &TR,
) -> Result<ContextEvent, Error> {
// NOTE: We get events in logical (and tomporal) order, so only need
// a local counter for ordering
self.global_ordering = self.global_ordering.saturating_add(1);

todo!()
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use opts::{
FormatArgAttributeKeysItem, FormatArgAttributeKeysSet, ReflectorOpts, RenameMap, RenameMapItem,
TraceRecorderOpts,
};
pub use recorder_data::{NanosecondsExt, RecorderDataExt, TimelineDetails};
pub use recorder_data::{NanosecondsExt, RecorderDataExt};

pub const PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -18,6 +18,7 @@ pub mod client;
pub mod command;
pub mod config;
pub mod context_manager;
pub mod context_manager_new;
pub mod deviant_event_parser;
pub mod error;
pub mod interruptor;
Expand Down
Loading

0 comments on commit 4ea8274

Please sign in to comment.