-
Notifications
You must be signed in to change notification settings - Fork 48
Support guest profiling for components #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //! Tests for guest profiling functionality. | ||
|
|
||
| use { | ||
| crate::{ | ||
| common::{Test, TestResult}, | ||
| viceroy_test, | ||
| }, | ||
| hyper::StatusCode, | ||
| std::time::Duration, | ||
| viceroy_lib::GuestProfileConfig, | ||
| }; | ||
|
|
||
| viceroy_test!(guest_profiling_works, |is_component| { | ||
| // Create a temporary directory for the profile output | ||
| let temp_dir = tempfile::tempdir()?; | ||
| let profile_dir = temp_dir.path().join("profiles"); | ||
| std::fs::create_dir(&profile_dir)?; | ||
|
|
||
| let resp = Test::using_fixture("noop.wasm") | ||
| .adapt_component(is_component) | ||
| .with_guest_profiling(GuestProfileConfig { | ||
| path: profile_dir.clone(), | ||
| sample_period: Duration::from_micros(50), | ||
| }) | ||
| .against_empty() | ||
| .await?; | ||
|
|
||
| // Verify the request succeeded | ||
| assert_eq!(resp.status(), StatusCode::OK); | ||
|
|
||
| // Verify that a profile file was created in the directory | ||
| let profile_files: Vec<_> = std::fs::read_dir(&profile_dir)? | ||
| .filter_map(|e| e.ok()) | ||
| .filter(|e| e.path().extension().and_then(|s| s.to_str()) == Some("json")) | ||
| .collect(); | ||
|
|
||
| assert!( | ||
| !profile_files.is_empty(), | ||
| "At least one profile JSON file should be created in {:?}", | ||
| profile_dir | ||
| ); | ||
|
|
||
| // Verify the first profile file has content and is valid JSON | ||
| let first_profile = &profile_files[0]; | ||
| let metadata = std::fs::metadata(first_profile.path())?; | ||
| assert!(metadata.len() > 0, "Profile file should not be empty"); | ||
|
|
||
| let profile_content = std::fs::read_to_string(first_profile.path())?; | ||
| let _: serde_json::Value = serde_json::from_str(&profile_content)?; | ||
|
|
||
| Ok(()) | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be a
with_profiling_strategymethod for setting theprofiling_strategyfield?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had plumbed that through but didn't write additional tests for those bits (as my changes are isolated to guest profiling). The naming and plumbing of some of these config bits is a bit confusing as the profiling strategy is unique to native profiling (not guest).
I have some changes now that consolidate things down to a single
profiling_configwhich consolidates the guest/native/none paths in a single field. It's a fairly large change in terms of files touched, so I'm inclined to land this change as-is and then separately open up that change for review separately as it is beyond the scope of what we're changing here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#598