Skip to content

Commit e62a49a

Browse files
committed
Some pr feedback
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 1518045 commit e62a49a

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl HypervisorHandler {
435435
.try_read();
436436

437437
let res = HistogramMetric::time_and_emit_guest_call(
438-
function_name.clone(),
438+
&function_name,
439439
|| {
440440
hv.dispatch_call_from_host(
441441
dispatch_function_addr,

src/hyperlight_host/src/metrics/metrics_macro.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
/// Crate-internal trait for defining metrics.
218
pub(crate) trait NamedMetric {
319
/// The name of the metric.
@@ -15,7 +31,6 @@ macro_rules! define_metrics {
1531
$(
1632
$metric_type:ident $( < $( $gen:tt ),+ > )? {
1733
$(
18-
$( #[cfg($feature:meta)] )?
1934
$variant:ident $( { $($field_name:ident : $field_ty:ty),* $(,)? } )? => {
2035
name: $name:expr,
2136
description: $description:expr,
@@ -30,7 +45,6 @@ macro_rules! define_metrics {
3045
#[allow(dead_code)]
3146
pub(crate) enum $metric_type $( < $( $gen ),+ > )? {
3247
$(
33-
$( #[cfg($feature)] )?
3448
$variant $( { $($field_name : $field_ty),* } )?
3549
),*
3650
}
@@ -39,7 +53,6 @@ macro_rules! define_metrics {
3953
fn name(&self) -> &'static str {
4054
match self {
4155
$(
42-
$( #[cfg($feature)] )?
4356
Self::$variant { .. } => $name,
4457
)*
4558
}
@@ -48,7 +61,6 @@ macro_rules! define_metrics {
4861
fn description(&self) -> &'static str {
4962
match self {
5063
$(
51-
$( #[cfg($feature)] )?
5264
Self::$variant { .. } => $description,
5365
)*
5466
}
@@ -57,7 +69,6 @@ macro_rules! define_metrics {
5769
fn unit(&self) -> metrics::Unit {
5870
match self {
5971
$(
60-
$( #[cfg($feature)] )?
6172
Self::$variant { .. } => $unit,
6273
)*
6374
}

src/hyperlight_host/src/metrics/mod.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2024 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
use std::sync::Once;
218
use std::time::Duration;
319

@@ -54,7 +70,7 @@ impl HistogramMetric {
5470
/// Note: If the `function_call_metrics` feature is not enabled, this function
5571
/// will simply execute the closure without measuring time or emitting metrics.
5672
pub(crate) fn time_and_emit_guest_call<T, F: FnOnce() -> T>(
57-
#[allow(unused_variables)] name: String,
73+
#[allow(unused_variables)] name: &str,
5874
f: F,
5975
) -> T {
6076
cfg_if::cfg_if! {
@@ -64,7 +80,7 @@ impl HistogramMetric {
6480
let start = Instant::now();
6581
let result = f();
6682
let duration = start.elapsed();
67-
HistogramMetric::GuestCallDuration { name, duration }.emit();
83+
HistogramMetric::GuestCallDuration { name: name.to_string(), duration }.emit();
6884
result
6985
} else {
7086
f()
@@ -78,7 +94,7 @@ impl HistogramMetric {
7894
/// Note: If the `function_call_metrics` feature is not enabled, this function
7995
/// will simply execute the closure without measuring time or emitting metrics.
8096
pub(crate) fn time_and_emit_host_call<T, F: FnOnce() -> T>(
81-
#[allow(unused_variables)] name: String,
97+
#[allow(unused_variables)] name: &str,
8298
f: F,
8399
) -> T {
84100
cfg_if::cfg_if! {
@@ -88,7 +104,7 @@ impl HistogramMetric {
88104
let start = Instant::now();
89105
let result = f();
90106
let duration = start.elapsed();
91-
HistogramMetric::HostCallDuration { name, duration }.emit();
107+
HistogramMetric::HostCallDuration { name: name.to_string(), duration }.emit();
92108
result
93109
} else {
94110
f()

src/hyperlight_host/src/sandbox/host_funcs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn call_host_func_impl(
182182
seccompiler::apply_filter(&seccomp_filter)?;
183183
}
184184

185-
HistogramMetric::time_and_emit_host_call(name.to_string(), || func.call(args.clone()))
185+
HistogramMetric::time_and_emit_host_call(name, || func.call(args))
186186
}
187187

188188
cfg_if::cfg_if! {

0 commit comments

Comments
 (0)