Skip to content

Commit 704a954

Browse files
committed
Change implementation totally to just use the metrics crate's macro directly
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent e62a49a commit 704a954

File tree

7 files changed

+174
-430
lines changed

7 files changed

+174
-430
lines changed

Justfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ test-rust target=default-target features="": (test-rust-int "rust" target featur
8989
# ignored tests - these tests need to run serially or with specific properties
9090
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} test_trace -p hyperlight-host --lib -- --ignored
9191
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} test_drop -p hyperlight-host --lib -- --ignored
92-
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} hypervisor::metrics::tests::test_gather_metrics -p hyperlight-host --lib -- --ignored
93-
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} sandbox::metrics::tests::test_gather_metrics -p hyperlight-host --lib -- --ignored
94-
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} test_metrics -p hyperlight-host --lib -- --ignored
9592
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} --test integration_test log_message -- --ignored
9693
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} sandbox::uninitialized::tests::test_log_trace -p hyperlight-host --lib -- --ignored
9794
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} hypervisor::hypervisor_handler::tests::create_1000_sandboxes -p hyperlight-host --lib -- --ignored
98-
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} metrics::tests::test_description_called_once -p hyperlight-host --lib -- --ignored
95+
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact --ignored
96+
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact --ignored
9997
{{ set-trace-env-vars }} cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} --lib sandbox::outb::tests::test_log_outb_log -- --ignored
10098

10199
test-seccomp target=default-target features="":

src/hyperlight_host/src/func/guest_err.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
1818

1919
use crate::error::HyperlightError::{GuestError, OutBHandlingError, StackOverflow};
2020
use crate::mem::shared_mem::HostSharedMemory;
21-
use crate::metrics::{CounterMetric, EmittableMetric};
21+
use crate::metrics::{METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE};
2222
use crate::sandbox::mem_mgr::MemMgrWrapper;
2323
use crate::{log_then_return, Result};
2424
/// Check for a guest error and return an `Err` if one was found,
@@ -29,7 +29,7 @@ pub(crate) fn check_for_guest_error(mgr: &MemMgrWrapper<HostSharedMemory>) -> Re
2929
ErrorCode::NoError => Ok(()),
3030
ErrorCode::OutbError => match mgr.as_ref().get_host_error()? {
3131
Some(host_err) => {
32-
CounterMetric::guest_error(guest_err.code.into()).emit();
32+
metrics::counter!(METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE => (guest_err.code as u64).to_string()).increment(1);
3333

3434
log_then_return!(OutBHandlingError(
3535
host_err.source.clone(),
@@ -40,11 +40,11 @@ pub(crate) fn check_for_guest_error(mgr: &MemMgrWrapper<HostSharedMemory>) -> Re
4040
None => Ok(()),
4141
},
4242
ErrorCode::StackOverflow => {
43-
CounterMetric::guest_error(guest_err.code.into()).emit();
43+
metrics::counter!(METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE => (guest_err.code as u64).to_string()).increment(1);
4444
log_then_return!(StackOverflow());
4545
}
4646
_ => {
47-
CounterMetric::guest_error(guest_err.code.into()).emit();
47+
metrics::counter!(METRIC_GUEST_ERROR, METRIC_GUEST_ERROR_LABEL_CODE => (guest_err.code as u64).to_string()).increment(1);
4848
log_then_return!(GuestError(guest_err.code, guest_err.message.clone()));
4949
}
5050
}

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use crate::mem::mgr::SandboxMemoryManager;
4848
use crate::mem::ptr::{GuestPtr, RawPtr};
4949
use crate::mem::ptr_offset::Offset;
5050
use crate::mem::shared_mem::{GuestSharedMemory, HostSharedMemory, SharedMemory};
51-
use crate::metrics::HistogramMetric;
5251
#[cfg(gdb)]
5352
use crate::sandbox::config::DebugInfo;
5453
use crate::sandbox::hypervisor::{get_available_hypervisor, HypervisorType};
@@ -434,7 +433,7 @@ impl HypervisorHandler {
434433
.lock
435434
.try_read();
436435

437-
let res = HistogramMetric::time_and_emit_guest_call(
436+
let res = crate::metrics::time_and_emit_guest_call(
438437
&function_name,
439438
|| {
440439
hv.dispatch_call_from_host(

src/hyperlight_host/src/hypervisor/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tracing::{instrument, Span};
1919

2020
use crate::error::HyperlightError::ExecutionCanceledByHost;
2121
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
22-
use crate::metrics::{CounterMetric, EmittableMetric};
22+
use crate::metrics::METRIC_GUEST_CANCELLATION;
2323
use crate::{log_then_return, new_error, HyperlightError, Result};
2424

2525
/// Util for handling x87 fpu state
@@ -311,7 +311,7 @@ impl VirtualCPU {
311311
#[cfg(target_os = "linux")]
312312
hvh.set_run_cancelled(true);
313313
}
314-
CounterMetric::guest_cancellation().emit();
314+
metrics::counter!(METRIC_GUEST_CANCELLATION).increment(1);
315315
log_then_return!(ExecutionCanceledByHost());
316316
}
317317
Ok(HyperlightExit::Unknown(reason)) => {

src/hyperlight_host/src/metrics/metrics_macro.rs

-79
This file was deleted.

0 commit comments

Comments
 (0)