From 912a92f84fc273ac7beafeedb157cf526a82f116 Mon Sep 17 00:00:00 2001 From: Andriy Berestovskyy Date: Tue, 28 Nov 2023 11:27:01 +0100 Subject: [PATCH 1/2] Update Cargo.toml --- rust/performance_counters/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/performance_counters/Cargo.toml b/rust/performance_counters/Cargo.toml index 24572aebb..518b314bd 100644 --- a/rust/performance_counters/Cargo.toml +++ b/rust/performance_counters/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -candid = "0.9.11" -ic-cdk = "0.11.3" +candid = "0.10.0" +ic-cdk = "0.12.0" ic-cdk-macros = "0.8.1" From b00a5ffdca9b741a79a53643b8a59e18ee49184c Mon Sep 17 00:00:00 2001 From: Andriy Berestovskyy Date: Wed, 29 Nov 2023 18:30:07 +0100 Subject: [PATCH 2/2] Add `example` function --- .../performance_counters.did | 1 + rust/performance_counters/src/lib.rs | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/rust/performance_counters/performance_counters.did b/rust/performance_counters/performance_counters.did index c1fceeda5..716c7c7ce 100644 --- a/rust/performance_counters/performance_counters.did +++ b/rust/performance_counters/performance_counters.did @@ -1,4 +1,5 @@ service : { "for_update" : () -> (nat64, nat64); "for_composite_query" : () -> (nat64, nat64) query; + "example" : () -> (nat64, nat64) query; }; diff --git a/rust/performance_counters/src/lib.rs b/rust/performance_counters/src/lib.rs index f450f49aa..c6c6934ca 100644 --- a/rust/performance_counters/src/lib.rs +++ b/rust/performance_counters/src/lib.rs @@ -22,7 +22,10 @@ // of `composite_query_helper`). // // In the future, the IC might expose more performance counters. -use ic_cdk::api::{call_context_instruction_counter, instruction_counter}; +use ic_cdk::{ + api::{call_context_instruction_counter, instruction_counter, performance_counter}, + call, id, +}; /// Pretty print the `title` and a corresponding `tuple` with counters. fn pretty_print(title: N, counters: (T, T)) { @@ -54,11 +57,15 @@ fn nested_composite_query_call() -> (u64, u64) { counters() } +/// Emulate a nested inter-canister update call. +#[ic_cdk_macros::query] +fn nested_call() {} + //////////////////////////////////////////////////////////////////////// // Canister interface //////////////////////////////////////////////////////////////////////// -/// Example usage: `dfx canister call performance_counters for_update` +/// Example usage: `dfx deploy && dfx canister call performance_counters for_update` #[ic_cdk_macros::update] async fn for_update() -> (u64, u64) { do_some_work(); @@ -91,7 +98,7 @@ async fn for_update() -> (u64, u64) { after_2nd } -/// Example usage: `dfx canister call performance_counters for_composite_query` +/// Example usage: `dfx deploy && dfx canister call performance_counters for_composite_query` #[ic_cdk_macros::query(composite = true)] async fn for_composite_query() -> (u64, u64) { do_some_work(); @@ -123,3 +130,16 @@ async fn for_composite_query() -> (u64, u64) { after_2nd } + +/// Example usage: `dfx deploy && dfx canister call performance_counters example` +#[ic_cdk_macros::query(composite = true)] +async fn example() -> (u64, u64) { + do_some_work(); + call::<(), ()>(id(), "nested_call", ()).await.unwrap(); + + do_some_work(); + call::<(), ()>(id(), "nested_call", ()).await.unwrap(); + + do_some_work(); + (performance_counter(0), performance_counter(1)) +}