Skip to content

Commit 09fd447

Browse files
authored
Remove tracing from trivial hot functions (#435)
* Remove tracing from hot functions Signed-off-by: Ludvig Liljenberg <[email protected]> * Add tracy example Signed-off-by: Ludvig Liljenberg <[email protected]> * Unify names of tracing-* examples Signed-off-by: Ludvig Liljenberg <[email protected]> * Clippy Signed-off-by: Ludvig Liljenberg <[email protected]> * Add picture of tracy profiler to readme Signed-off-by: Ludvig Liljenberg <[email protected]> --------- Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 8c73c32 commit 09fd447

File tree

10 files changed

+217
-19
lines changed

10 files changed

+217
-19
lines changed

Cargo.lock

+140-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/hyperlight-metrics-logs-and-traces.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ $env:RUST_LOG='none,hyperlight_host=info,tracing=info'; cargo run --example trac
6262

6363
### Using OTLP exporter and Jaeger
6464

65-
In the [examples/otlp_tracing](../src/hyperlight_host/examples/otlp_tracing) directory, there is an example that shows how to capture and send trace and log information to an otlp_collector using the opentelemetry_otlp crate. With this example the following commands can be used to set the verbosity of the trace output to `INFO` and run the example to generate trace data:
65+
In the [examples/tracing-otlp](../src/hyperlight_host/examples/tracing-otlp) directory, there is an example that shows how to capture and send trace and log information to an otlp_collector using the opentelemetry_otlp crate. With this example the following commands can be used to set the verbosity of the trace output to `INFO` and run the example to generate trace data:
6666

6767
#### Linux
6868

6969
```bash
70-
RUST_LOG='none,hyperlight_host=info,tracing=info' cargo run --example otlp_tracing
70+
RUST_LOG='none,hyperlight_host=info,tracing=info' cargo run --example tracing-otlp
7171
```
7272

7373
#### Windows
7474

7575
```powershell
76-
$env:RUST_LOG='none,hyperlight_host=info,tracing=info';cargo run --example otlp_tracing
76+
$env:RUST_LOG='none,hyperlight_host=info,tracing=info';cargo run --example tracing-otlp
7777
```
7878

7979
The sample will run and generate trace data until any key is pressed.

src/hyperlight_host/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ criterion = "0.5.1"
103103
tracing-chrome = "0.7.2"
104104
metrics-util = "0.19.1"
105105
metrics-exporter-prometheus = "0.17.0"
106+
tracing-tracy = "0.11.4"
106107

107108
[target.'cfg(windows)'.dev-dependencies]
108109
windows = { version = "0.61", features = [

src/hyperlight_host/examples/chrome-tracing/main.rs renamed to src/hyperlight_host/examples/tracing-chrome/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hyperlight_testing::simple_guest_as_string;
2323
use tracing_chrome::ChromeLayerBuilder;
2424
use tracing_subscriber::prelude::*;
2525

26-
// This example can be run with `cargo run --package hyperlight_host --example chrome-tracing --release`
26+
// This example can be run with `cargo run --package hyperlight_host --example tracing-chrome --release`
2727
fn main() -> Result<()> {
2828
// set up tracer
2929
let (chrome_layer, _guard) = ChromeLayerBuilder::new().build();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This is an example of using the tracing-tracy tracing-subscriber. When ran, it will generate traces that can be viewed in the tracy profiler.
2+
3+
You can run it with:
4+
5+
```console
6+
TRACY_NO_EXIT=1 RUST_LOG=trace cargo run --package hyperlight-host --example tracing-tracy --profile release-with-debug
7+
```
8+
9+
and then the client should show up in the profiler GUI:
10+
11+
![pic of tracy profiler](image.png)
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
17+
use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue};
18+
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
19+
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
20+
use hyperlight_host::sandbox_state::transition::Noop;
21+
use hyperlight_host::{GuestBinary, MultiUseSandbox, Result};
22+
use hyperlight_testing::simple_guest_as_string;
23+
use tracing_subscriber::layer::SubscriberExt;
24+
use tracing_subscriber::EnvFilter;
25+
26+
// An example of how to get tracy tracing working with hyperlight.
27+
// Run with:
28+
// TRACY_NO_EXIT=1 RUST_LOG=trace cargo run --package hyperlight-host --example tracing-tracy --profile release-with-debug,
29+
// and then open the `tracy-profiler` GUI, and there should be an option to load the client created by this example.
30+
fn main() -> Result<()> {
31+
tracing::subscriber::set_global_default(
32+
tracing_subscriber::registry()
33+
.with(EnvFilter::from_default_env())
34+
.with(tracing_tracy::TracyLayer::default()),
35+
)
36+
.expect("setup tracy layer");
37+
38+
let simple_guest_path =
39+
simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");
40+
41+
// Create a new sandbox.
42+
let usandbox =
43+
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
44+
45+
let mut sbox = usandbox
46+
.evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
47+
.unwrap();
48+
49+
// do the function call
50+
let current_time = std::time::Instant::now();
51+
let res = sbox.call_guest_function_by_name(
52+
"Echo",
53+
ReturnType::String,
54+
Some(vec![ParameterValue::String("Hello, World!".to_string())]),
55+
)?;
56+
let elapsed = current_time.elapsed();
57+
println!("Function call finished in {:?}.", elapsed);
58+
assert!(matches!(res, ReturnValue::String(s) if s == "Hello, World!"));
59+
Ok(())
60+
}

0 commit comments

Comments
 (0)