From 72502c017b8f55f201ba52e5d8846be039c44777 Mon Sep 17 00:00:00 2001 From: Andriy Berestovskyy Date: Fri, 23 Jun 2023 12:31:48 +0200 Subject: [PATCH] RUN-636: Add per-call context instruction counter --- spec/changelog.adoc | 1 + spec/index.adoc | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/changelog.adoc b/spec/changelog.adoc index dccc264ef..14dc536a1 100644 --- a/spec/changelog.adoc +++ b/spec/changelog.adoc @@ -4,6 +4,7 @@ [#unreleased] === ∞ (unreleased) * Spec: User delegations include a principal scope +* Spec: Add per-call context performance counter [#0_18_9] === 0.18.9 (2022-12-06) diff --git a/spec/index.adoc b/spec/index.adoc index 791af1fcf..47b2c76db 100644 --- a/spec/index.adoc +++ b/spec/index.adoc @@ -1461,19 +1461,17 @@ Passing zero as an argument to the function deactivates the timer and thus preve [#system-api-performance-counter] === Performance counter -The canister can query the "performance counter", which is a deterministic monotonically increasing integer approximating the amount of work the canister has done since the beginning of the current execution. +The canister can query the "performance counter" to get a deterministic integer approximation of different canister activities. Developers might use this data to profile and optimize the canister performance. `+ic0.performance_counter : (counter_type : i32) -> i64+` The argument `type` decides which performance counter to return: -* 0 : instruction counter. The number of WebAssembly instructions the system has determined that the canister has executed. +* 0 : message execution instruction counter. The number of WebAssembly instructions the canister has executed since the beginning of the current message execution. The system resets this counter at the beginning of each <>. -In the future, we might expose more performance counters. +* 1 : call context instruction counter. The number of WebAssembly instructions the canister has executed since the creation of the current call context. The system sets this counter to zero during the <>. The counter is monotonically increasing across a few <>, until the <>. -The system resets the counter at the beginning of each <> invocation. - -The main purpose of this counter is to facilitate in-canister performance profiling. +In the future, the IC might expose more performance counters. [#system-api-controller-check] === Controller check @@ -2857,6 +2855,7 @@ State after:: .... +[#call-context-creation] ==== Call context creation Before invoking a heartbeat, a global timer, or a message to a public entry point, a call context is created for bookkeeping purposes. @@ -3169,6 +3168,7 @@ S with } .... +[#call-context-removal] ==== Call context removal If there is no call, downstream call context, or response that references a call context, and the call context does not need to respond (because it has already responded or its origin is a system task that does not await a response), then the call context can be removed.