Skip to content

Commit

Permalink
Create a stub of performance_counter (#41)
Browse files Browse the repository at this point in the history
The stub will be replaced with a proper implementation once its semantics gets clarified.
  • Loading branch information
marcin-dziadus authored Sep 30, 2021
1 parent 26285f5 commit a47a1d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/IC/Canister/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ systemAPI esref =

, toImport "ic0" "msg_method_name_size" msg_method_name_size
, toImport "ic0" "msg_method_name_copy" msg_method_name_copy
, toImport "ic0" "accept_message" accept_message

, toImport "ic0" "accept_message" accept_message
, toImport "ic0" "time" get_time
, toImport "ic0" "performance_counter" performance_counter

, toImport "ic0" "debug_print" debug_print
, toImport "ic0" "trap" explicit_trap
Expand Down Expand Up @@ -521,6 +522,10 @@ systemAPI esref =
Timestamp ns <- gets (env_time . env)
return (fromIntegral ns)

-- TODO: implement once semantics of performance_counter is known.
performance_counter :: () -> HostM s Word64
performance_counter () = return 0

debug_print :: (Int32, Int32) -> HostM s ()
debug_print (src, size) = do
-- TODO: This should be a non-trapping copy
Expand Down
1 change: 1 addition & 0 deletions src/IC/Test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ icTests = withAgentConfig $ testGroup "Interface Spec acceptance tests"
, t "msg_method_name" "F" $ ignore methodName
, t "accept_message" never acceptMessage -- due to double accept
, t "time" star $ ignore getTime
, t "performance_counter" star $ ignore performanceCounter
, t "debug_print" star $ debugPrint "hello"
, t "trap" never $ trap "this better traps"
]
Expand Down
3 changes: 3 additions & 0 deletions src/IC/Test/Universal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ stable64Write = op 48
onHeartbeat :: Exp 'B -> Prog
onHeartbeat = op 49

performanceCounter :: Exp 'I64
performanceCounter = op 50

-- Some convenience combinators

-- This allows us to write byte expressions as plain string literals
Expand Down
7 changes: 7 additions & 0 deletions universal-canister/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod ic0 {
pub fn data_certificate_copy(dst: u32, offset: u32, size: u32) -> ();

pub fn time() -> u64;
pub fn performance_counter() -> u64;
}
}

Expand Down Expand Up @@ -258,6 +259,12 @@ pub fn accept_message() {
unsafe { ic0::accept_message() }
}

pub fn performance_counter() -> u64 {
unsafe {
ic0::performance_counter()
}
}

pub fn method_name() -> Vec<u8> {
let len: u32 = unsafe { ic0::msg_method_name_size() };
let mut bytes = vec![0; len as usize];
Expand Down
2 changes: 2 additions & 0 deletions universal-canister/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ fn eval(ops: Ops) {
// canister heartbeat script
49 => set_heartbeat(stack.pop_blob()),

50 => stack.push_int64(api::performance_counter()),

_ => api::trap_with(&format!("unknown op {}", op)),
}
}
Expand Down

0 comments on commit a47a1d3

Please sign in to comment.