Skip to content

Commit

Permalink
Separate statistics from functional average latency
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 14, 2022
1 parent 3e5e5d2 commit 1a4eb48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
9 changes: 5 additions & 4 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
tracking::TrackingManager, AlvrButtonType_BUTTON_TYPE_BINARY,
AlvrButtonType_BUTTON_TYPE_SCALAR, AlvrButtonValue, AlvrButtonValue__bindgen_ty_1,
AlvrDeviceMotion, AlvrQuat, EyeFov, OculusHand, CLIENTS_UPDATED_NOTIFIER,
DISCONNECT_CLIENT_NOTIFIER, HAPTICS_SENDER, RESTART_NOTIFIER, SERVER_DATA_MANAGER,
STATISTICS_MANAGER, VIDEO_SENDER,
DISCONNECT_CLIENT_NOTIFIER, HAPTICS_SENDER, LAST_AVERAGE_TOTAL_LATENCY, RESTART_NOTIFIER,
SERVER_DATA_MANAGER, STATISTICS_MANAGER, VIDEO_SENDER,
};
use alvr_audio::{AudioDevice, AudioDeviceType};
use alvr_common::{
Expand Down Expand Up @@ -844,9 +844,9 @@ async fn connection_pipeline() -> StrResult {
stats.report_tracking_received(tracking.target_timestamp);

let head_prediction_s =
stats.average_total_latency().as_secs_f32() * hmd_multiplier;
LAST_AVERAGE_TOTAL_LATENCY.lock().as_secs_f32() * hmd_multiplier;
let controllers_prediction_s =
stats.average_total_latency().as_secs_f32() * controller_multiplier;
LAST_AVERAGE_TOTAL_LATENCY.lock().as_secs_f32() * controller_multiplier;

unsafe {
crate::SetTracking(
Expand All @@ -871,6 +871,7 @@ async fn connection_pipeline() -> StrResult {
async move {
loop {
let client_stats = receiver.recv().await?.header;
*LAST_AVERAGE_TOTAL_LATENCY.lock() = client_stats.average_total_pipeline_latency;

if let Some(stats) = &mut *STATISTICS_MANAGER.lock() {
let game_frame_interval =
Expand Down
1 change: 1 addition & 0 deletions alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static SERVER_DATA_MANAGER: Lazy<RwLock<ServerDataManager>> =
static RUNTIME: Lazy<Mutex<Option<Runtime>>> = Lazy::new(|| Mutex::new(Runtime::new().ok()));
static WINDOW: Lazy<Mutex<Option<Arc<alcro::UI>>>> = Lazy::new(|| Mutex::new(None));

static LAST_AVERAGE_TOTAL_LATENCY: Lazy<Mutex<Duration>> = Lazy::new(|| Mutex::new(Duration::ZERO));
static STATISTICS_MANAGER: Lazy<Mutex<Option<StatisticsManager>>> = Lazy::new(|| Mutex::new(None));

static VIDEO_SENDER: Lazy<Mutex<Option<mpsc::UnboundedSender<(VideoFrameHeaderPacket, Vec<u8>)>>>> =
Expand Down
8 changes: 0 additions & 8 deletions alvr/server/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub struct StatisticsManager {
fec_failures_partial_sum: usize,
fec_percentage: u32,
battery_gauges: HashMap<u64, f32>,
last_average_total_latency: Duration,
}

impl StatisticsManager {
Expand All @@ -61,7 +60,6 @@ impl StatisticsManager {
fec_failures_partial_sum: 0,
fec_percentage: 0,
battery_gauges: HashMap::new(),
last_average_total_latency: Duration::ZERO,
}
}

Expand Down Expand Up @@ -137,8 +135,6 @@ impl StatisticsManager {
client_stats: ClientStatistics,
game_frame_interval: Duration,
) -> Duration {
self.last_average_total_latency = client_stats.average_total_pipeline_latency;

if let Some(frame) = self
.history_buffer
.iter_mut()
Expand Down Expand Up @@ -239,8 +235,4 @@ impl StatisticsManager {
Duration::ZERO
}
}

pub fn average_total_latency(&self) -> Duration {
self.last_average_total_latency
}
}

0 comments on commit 1a4eb48

Please sign in to comment.