Skip to content

Commit

Permalink
Display durations nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Dec 13, 2024
1 parent 19f158e commit d292f6b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,12 @@ pub trait VM: Sized {

fn sys_state_clear_all(&mut self) -> VMResult<()>;

fn sys_sleep(&mut self, wake_up_time_since_unix_epoch: Duration)
-> VMResult<AsyncResultHandle>;
/// Note: `now_since_unix_epoch` is only used for debugging purposes
fn sys_sleep(
&mut self,
wake_up_time_since_unix_epoch: Duration,
now_since_unix_epoch: Option<Duration>,
) -> VMResult<AsyncResultHandle>;

fn sys_call(&mut self, target: Target, input: Bytes) -> VMResult<AsyncResultHandle>;

Expand Down
6 changes: 3 additions & 3 deletions src/tests/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn sleep_suspends() {
.run(|vm| {
vm.sys_input().unwrap();

let h1 = vm.sys_sleep(Duration::from_secs(1)).unwrap();
let h1 = vm.sys_sleep(Duration::from_secs(1), None).unwrap();
vm.notify_await_point(h1);
let h1_result = vm.take_async_result(h1);
if let Err(SuspendedOrVMError::Suspended(_)) = &h1_result {
Expand Down Expand Up @@ -67,7 +67,7 @@ fn sleep_completed() {
.run(|vm| {
vm.sys_input().unwrap();

let h1 = vm.sys_sleep(Duration::from_secs(1)).unwrap();
let h1 = vm.sys_sleep(Duration::from_secs(1), None).unwrap();
vm.notify_await_point(h1);
let h1_result = vm.take_async_result(h1);
if let Err(SuspendedOrVMError::Suspended(_)) = &h1_result {
Expand Down Expand Up @@ -115,7 +115,7 @@ fn sleep_still_sleeping() {
.run(|vm| {
vm.sys_input().unwrap();

let h1 = vm.sys_sleep(Duration::from_secs(1)).unwrap();
let h1 = vm.sys_sleep(Duration::from_secs(1), None).unwrap();
vm.notify_await_point(h1);
let h1_result = vm.take_async_result(h1);
if let Err(SuspendedOrVMError::Suspended(_)) = &h1_result {
Expand Down
22 changes: 18 additions & 4 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::fmt;
use std::mem::size_of;
use std::time::Duration;
use strum::IntoStaticStr;
use tracing::{enabled, instrument, Level};
use tracing::{debug, enabled, instrument, Level};

mod context;
pub(crate) mod errors;
Expand Down Expand Up @@ -442,12 +442,26 @@ impl super::VM for CoreVM {
fields(restate.invocation.id = self.debug_invocation_id(), restate.journal.index = self.context.journal.index(), restate.protocol.version = %self.version),
ret
)]
fn sys_sleep(&mut self, wake_up_time: Duration) -> VMResult<AsyncResultHandle> {
invocation_debug_logs!(self, "Executing 'Sleep for {wake_up_time:?}'");
fn sys_sleep(
&mut self,
wake_up_time_since_unix_epoch: Duration,
now_since_unix_epoch: Option<Duration>,
) -> VMResult<AsyncResultHandle> {
if self.is_processing() {
if let Some(now_since_unix_epoch) = now_since_unix_epoch {
debug!(
"Executing 'Sleeping for {:?}'",
wake_up_time_since_unix_epoch - now_since_unix_epoch
);
} else {
debug!("Executing 'Sleeping");
}
}

self.do_transition(SysCompletableEntry(
"SysSleep",
SleepEntryMessage {
wake_up_time: u64::try_from(wake_up_time.as_millis())
wake_up_time: u64::try_from(wake_up_time_since_unix_epoch.as_millis())
.expect("millis since Unix epoch should fit in u64"),
..Default::default()
},
Expand Down

0 comments on commit d292f6b

Please sign in to comment.