Skip to main content

nub_host_kvm/metrics/
mod.rs

1/*
2Copyright 2025  The Hyperlight Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17// Counter metric that counter number of times a guest error occurred
18pub(crate) static METRIC_GUEST_ERROR: &str = "guest_errors_total";
19pub(crate) static METRIC_GUEST_ERROR_LABEL_CODE: &str = "code";
20
21// Counter metric that counts the number of times a guest function was called due to timing out
22pub(crate) static METRIC_GUEST_CANCELLATION: &str = "guest_cancellations_total";
23
24// Counter metric that counts the number of times a vCPU was erroneously kicked by a stale cancellation
25// This can happen when a signal from a previous guest call arrives late and interrupts a new call (Linux).
26pub(crate) static METRIC_ERRONEOUS_VCPU_KICKS: &str = "erroneous_vcpu_kicks_total";
27
28/// Executes the given closure and returns its result directly.
29///
30/// (Guest-call timing metrics are not emitted in this build; the
31/// `name` argument is retained for call-site symmetry.)
32pub(crate) fn maybe_time_and_emit_guest_call<T, F: FnOnce() -> T>(_name: &str, f: F) -> T {
33    f()
34}
35
36/// Executes the given closure and returns its result directly.
37///
38/// (Host-call timing metrics are not emitted in this build; the
39/// `name` argument is retained for call-site symmetry.)
40pub(crate) fn maybe_time_and_emit_host_call<T, F: FnOnce() -> T>(_name: &str, f: F) -> T {
41    f()
42}