Skip to content

Commit

Permalink
Enable to log tracing information for RTI
Browse files Browse the repository at this point in the history
  • Loading branch information
chanijjani committed Feb 27, 2024
1 parent 094dfaf commit 0ba4eff
Show file tree
Hide file tree
Showing 6 changed files with 969 additions and 42 deletions.
1 change: 1 addition & 0 deletions rust/rti/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
byteorder = "1"
priority-queue = "1.3.2"
zerocopy = { version = "0.7.32", features = ["derive"] }
18 changes: 18 additions & 0 deletions rust/rti/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ mod net_common;
mod net_util;
mod server;
mod tag;
mod trace;

use std::error::Error;

use crate::constants::*;
use crate::federate_info::*;
use crate::rti_common::*;
use crate::rti_remote::*;
use crate::trace::Trace;

use server::Server;

const RTI_TRACE_FILE_NAME: &str = "rti.lft";

#[derive(PartialEq, PartialOrd, Clone)]
pub enum ClockSyncStat {
ClockSyncOff,
Expand Down Expand Up @@ -124,6 +128,8 @@ pub fn process_args(rti: &mut RTIRemote, argv: &[String]) -> Result<(), &'static
}
idx += 1;
// TODO: idx += process_clock_sync_args();
} else if arg == "-t" || arg == "--tracing" {
rti.base_mut().set_tracing_enabled(true);
} else if arg == " " {
// Tolerate spaces
continue;
Expand Down Expand Up @@ -162,6 +168,7 @@ fn usage(argc: usize, argv: &[String]) {
println!(" (period in nanoseconds, default is 5 msec). Only applies to 'on'.");
println!(" - exchanges-per-interval <n>: Controls the number of messages that are exchanged for each");
println!(" clock sync attempt (default is 10). Applies to 'init' and 'on'.");
println!(" -t, --tracing Turn on tracing.");

println!("Command given:");
let mut idx = 0;
Expand All @@ -172,6 +179,17 @@ fn usage(argc: usize, argv: &[String]) {
}

pub fn initialize_federates(rti: &mut RTIRemote) {
if rti.base().tracing_enabled() {
let _lf_number_of_workers = rti.base().number_of_scheduling_nodes();
rti.base_mut()
.set_trace(Trace::trace_new(RTI_TRACE_FILE_NAME));
Trace::start_trace(
rti.base_mut().trace(),
_lf_number_of_workers.try_into().unwrap(),
);
println!("Tracing the RTI execution in {} file.", RTI_TRACE_FILE_NAME);
}

for i in 0..rti.base().number_of_scheduling_nodes() {
let mut federate = FederateInfo::new();
// FIXME: Handle "as u16" properly.
Expand Down
40 changes: 37 additions & 3 deletions rust/rti/src/rti_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::net_util::NetUtil;
use crate::rti_remote::RTIRemote;
use crate::tag;
use crate::tag::{Instant, Interval, Tag, FOREVER};
use crate::trace::{Trace, TraceDirection, TraceEvent};
use crate::FederateInfo;
use crate::SchedulingNodeState::*;

Expand Down Expand Up @@ -827,7 +828,7 @@ impl SchedulingNode {
{
let locked_rti = _f_rti.read().unwrap();
let idx: usize = fed_id.into();
let fed: &FederateInfo = &locked_rti.base().scheduling_nodes()[idx];
let fed = &locked_rti.base().scheduling_nodes()[idx];
let e = fed.enclave();
if e.state() == SchedulingNodeState::NotConnected
|| Tag::lf_tag_compare(&tag, &e.last_granted()) <= 0
Expand Down Expand Up @@ -857,6 +858,14 @@ impl SchedulingNode {
1 + mem::size_of::<i64>(),
);

Trace::log_trace(
_f_rti.clone(),
TraceEvent::SendTag,
fed_id,
&tag,
start_time,
TraceDirection::To,
);
// This function is called in notify_advance_grant_if_safe(), which is a long
// function. During this call, the socket might close, causing the following write_to_socket
// to fail. Consider a failure here a soft failure and update the federate's status.
Expand Down Expand Up @@ -950,6 +959,14 @@ impl SchedulingNode {
1 + mem::size_of::<i64>(),
);

Trace::log_trace(
_f_rti.clone(),
TraceEvent::SendPTag,
fed_id,
&tag,
start_time,
TraceDirection::To,
);
// This function is called in notify_advance_grant_if_safe(), which is a long
// function. During this call, the socket might close, causing the following write_to_socket
// to fail. Consider a failure here a soft failure and update the federate's status.
Expand Down Expand Up @@ -1279,9 +1296,9 @@ pub struct RTICommon {

// Boolean indicating that tracing is enabled.
tracing_enabled: bool,
// Pointer to a tracing object
// TODO: trace_t* trace;

// Pointer to a tracing object
trace: Trace,
// The RTI mutex for making thread-safe access to the shared state.
// TODO: lf_mutex_t* mutex;
}
Expand All @@ -1294,6 +1311,7 @@ impl RTICommon {
max_stop_tag: Tag::never_tag(),
num_scheduling_nodes_handling_stop: 0,
tracing_enabled: false,
trace: Trace::trace_new(""),
}
}

Expand All @@ -1317,6 +1335,14 @@ impl RTICommon {
self.num_scheduling_nodes_handling_stop
}

pub fn tracing_enabled(&self) -> bool {
self.tracing_enabled
}

pub fn trace(&mut self) -> &mut Trace {
&mut self.trace
}

pub fn set_max_stop_tag(&mut self, max_stop_tag: Tag) {
self.max_stop_tag = max_stop_tag.clone();
}
Expand All @@ -1331,6 +1357,14 @@ impl RTICommon {
) {
self.num_scheduling_nodes_handling_stop = num_scheduling_nodes_handling_stop;
}

pub fn set_tracing_enabled(&mut self, tracing_enabled: bool) {
self.tracing_enabled = tracing_enabled;
}

pub fn set_trace(&mut self, trace: Trace) {
self.trace = trace;
}
}

struct TagAdvanceGrant {
Expand Down
Loading

0 comments on commit 0ba4eff

Please sign in to comment.