Skip to content

Commit de70a4c

Browse files
committed
update guests to use the tracing crate to intrument functions
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent c00b401 commit de70a4c

File tree

7 files changed

+70
-5
lines changed

7 files changed

+70
-5
lines changed

src/tests/rust_guests/callbackguest/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests/rust_guests/callbackguest/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ edition = "2021"
77
hyperlight-guest = { path = "../../../hyperlight_guest" }
88
hyperlight-guest-bin = { path = "../../../hyperlight_guest_bin" }
99
hyperlight-common = { path = "../../../hyperlight_common", default-features = false }
10+
hyperlight-guest-tracing = { path = "../../../hyperlight_guest_tracing" }
1011

1112
[features]
1213
default = []
13-
trace_guest = ["hyperlight-guest-bin/trace_guest"]
14+
trace_guest = ["hyperlight-guest-bin/trace_guest", "hyperlight-guest/trace_guest", "hyperlight-guest-tracing/trace"]
1415
unwind_guest = ["hyperlight-common/unwind_guest"]
15-
mem_profile = ["hyperlight-common/mem_profile", "hyperlight-guest-bin/mem_profile"]
16+
mem_profile = ["hyperlight-common/mem_profile", "hyperlight-guest-bin/mem_profile"]

src/tests/rust_guests/callbackguest/src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use hyperlight_guest_bin::guest_function::register::register_function;
3737
use hyperlight_guest_bin::guest_logger::log_message;
3838
use hyperlight_guest_bin::host_comm::{call_host_function, print_output_with_host_print};
3939

40+
#[hyperlight_guest_tracing::trace_function]
4041
fn send_message_to_host_method(
4142
method_name: &str,
4243
guest_message: &str,
@@ -52,6 +53,7 @@ fn send_message_to_host_method(
5253
Ok(get_flatbuffer_result(res))
5354
}
5455

56+
#[hyperlight_guest_tracing::trace_function]
5557
fn guest_function(function_call: &FunctionCall) -> Result<Vec<u8>> {
5658
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
5759
send_message_to_host_method("HostMethod", "Hello from GuestFunction, ", message)
@@ -63,6 +65,7 @@ fn guest_function(function_call: &FunctionCall) -> Result<Vec<u8>> {
6365
}
6466
}
6567

68+
#[hyperlight_guest_tracing::trace_function]
6669
fn guest_function1(function_call: &FunctionCall) -> Result<Vec<u8>> {
6770
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
6871
send_message_to_host_method("HostMethod1", "Hello from GuestFunction1, ", message)
@@ -74,6 +77,7 @@ fn guest_function1(function_call: &FunctionCall) -> Result<Vec<u8>> {
7477
}
7578
}
7679

80+
#[hyperlight_guest_tracing::trace_function]
7781
fn guest_function2(function_call: &FunctionCall) -> Result<Vec<u8>> {
7882
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
7983
send_message_to_host_method("HostMethod1", "Hello from GuestFunction2, ", message)
@@ -85,6 +89,7 @@ fn guest_function2(function_call: &FunctionCall) -> Result<Vec<u8>> {
8589
}
8690
}
8791

92+
#[hyperlight_guest_tracing::trace_function]
8893
fn guest_function3(function_call: &FunctionCall) -> Result<Vec<u8>> {
8994
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
9095
send_message_to_host_method("HostMethod1", "Hello from GuestFunction3, ", message)
@@ -96,6 +101,7 @@ fn guest_function3(function_call: &FunctionCall) -> Result<Vec<u8>> {
96101
}
97102
}
98103

104+
#[hyperlight_guest_tracing::trace_function]
99105
fn guest_function4(_: &FunctionCall) -> Result<Vec<u8>> {
100106
call_host_function::<()>(
101107
"HostMethod4",
@@ -108,6 +114,7 @@ fn guest_function4(_: &FunctionCall) -> Result<Vec<u8>> {
108114
Ok(get_flatbuffer_result(()))
109115
}
110116

117+
#[hyperlight_guest_tracing::trace_function]
111118
fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
112119
if let (
113120
ParameterValue::String(message),
@@ -141,6 +148,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result<Vec<u8>> {
141148
}
142149
}
143150

151+
#[hyperlight_guest_tracing::trace_function]
144152
fn call_error_method(function_call: &FunctionCall) -> Result<Vec<u8>> {
145153
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
146154
send_message_to_host_method("ErrorMethod", "Error From Host: ", message)
@@ -152,11 +160,13 @@ fn call_error_method(function_call: &FunctionCall) -> Result<Vec<u8>> {
152160
}
153161
}
154162

163+
#[hyperlight_guest_tracing::trace_function]
155164
fn call_host_spin(_: &FunctionCall) -> Result<Vec<u8>> {
156165
call_host_function::<()>("Spin", None, ReturnType::Void)?;
157166
Ok(get_flatbuffer_result(()))
158167
}
159168

169+
#[hyperlight_guest_tracing::trace_function]
160170
fn host_call_loop(function_call: &FunctionCall) -> Result<Vec<u8>> {
161171
if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] {
162172
loop {
@@ -171,6 +181,7 @@ fn host_call_loop(function_call: &FunctionCall) -> Result<Vec<u8>> {
171181
}
172182

173183
#[no_mangle]
184+
#[hyperlight_guest_tracing::trace_function]
174185
pub extern "C" fn hyperlight_main() {
175186
let print_output_def = GuestFunctionDefinition::new(
176187
"PrintOutput".to_string(),
@@ -258,6 +269,7 @@ pub extern "C" fn hyperlight_main() {
258269
}
259270

260271
#[no_mangle]
272+
#[hyperlight_guest_tracing::trace_function]
261273
pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> {
262274
Err(HyperlightGuestError::new(
263275
ErrorCode::GuestFunctionNotFound,

src/tests/rust_guests/simpleguest/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests/rust_guests/simpleguest/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ edition = "2021"
77
hyperlight-guest = { path = "../../../hyperlight_guest" }
88
hyperlight-guest-bin = { path = "../../../hyperlight_guest_bin" }
99
hyperlight-common = { path = "../../../hyperlight_common", default-features = false }
10+
hyperlight-guest-tracing = { path = "../../../hyperlight_guest_tracing" }
1011
log = {version = "0.4", default-features = false }
1112

1213
[features]
1314
default = []
14-
trace_guest = ["hyperlight-guest-bin/trace_guest"]
15+
trace_guest = ["hyperlight-guest-bin/trace_guest", "hyperlight-guest/trace_guest", "hyperlight-guest-tracing/trace"]
1516
unwind_guest = ["hyperlight-common/unwind_guest"]
1617
mem_profile = ["hyperlight-common/mem_profile", "hyperlight-guest-bin/mem_profile"]
1718

0 commit comments

Comments
 (0)