-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added flamegraph * Moved mpc related stuff in util.rs to mpc.rs * Added README on profiling * Fix incorrect default-features * Git ignore flamegraph files * Made building MPC service earlier in tests
- Loading branch information
1 parent
012b2aa
commit a9605c6
Showing
16 changed files
with
189 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/target | ||
.direnv | ||
.DS_Store | ||
|
||
flamegraph*.svg | ||
tmp |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -7,3 +7,7 @@ members = [ | |
"load-tests", | ||
"test-oidc-provider", | ||
] | ||
|
||
[profile.flamegraph] | ||
inherits = "release" | ||
debug = true |
This file contains 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 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 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 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 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 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,103 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::Context; | ||
use async_process::{Child, Command, ExitStatus, Stdio}; | ||
use tokio::runtime::Runtime; | ||
|
||
use mpc_recovery::Cli; | ||
|
||
const PACKAGE: &str = "mpc-recovery"; | ||
const PACKAGE_MULTICHAIN: &str = "mpc-recovery-node"; | ||
|
||
/// NodeProcess holds onto the respective handles such that on drop, it will clean | ||
/// the running process, task, or thread. | ||
pub enum NodeProcess { | ||
Subprocess(async_process::Child), | ||
Threaded(std::thread::JoinHandle<anyhow::Result<()>>), | ||
} | ||
|
||
pub fn executable(release: bool, executable: &str) -> Option<PathBuf> { | ||
let executable = target_dir()? | ||
.join(if release { "release" } else { "debug" }) | ||
.join(executable); | ||
Some(executable) | ||
} | ||
|
||
fn target_dir() -> Option<PathBuf> { | ||
let mut out_dir = Path::new(std::env!("OUT_DIR")); | ||
loop { | ||
if out_dir.ends_with("target") { | ||
break Some(out_dir.to_path_buf()); | ||
} | ||
|
||
match out_dir.parent() { | ||
Some(parent) => out_dir = parent, | ||
None => break None, // We've reached the root directory and didn't find "target" | ||
} | ||
} | ||
} | ||
|
||
pub async fn build(release: bool) -> anyhow::Result<ExitStatus> { | ||
let mut cmd = Command::new("cargo"); | ||
cmd.arg("build") | ||
.arg("--package") | ||
.arg(PACKAGE) | ||
.envs(std::env::vars()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()); | ||
|
||
if release { | ||
cmd.arg("--release"); | ||
} | ||
|
||
Ok(cmd.spawn()?.status().await?) | ||
} | ||
|
||
pub async fn spawn(release: bool, node: &str, cli: Cli) -> anyhow::Result<NodeProcess> { | ||
if cfg!(feature = "flamegraph") { | ||
let handle: std::thread::JoinHandle<anyhow::Result<()>> = std::thread::spawn(|| { | ||
let rt = Runtime::new()?; | ||
rt.block_on(async move { | ||
mpc_recovery::run(cli).await?; | ||
anyhow::Result::<(), anyhow::Error>::Ok(()) | ||
}) | ||
.unwrap(); | ||
Ok(()) | ||
}); | ||
|
||
return Ok(NodeProcess::Threaded(handle)); | ||
} | ||
|
||
let executable = executable(release, PACKAGE) | ||
.with_context(|| format!("could not find target dir while starting {node} node"))?; | ||
let child = Command::new(executable) | ||
.args(cli.into_str_args()) | ||
.env("RUST_LOG", "mpc_recovery=INFO") | ||
.envs(std::env::vars()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.kill_on_drop(true) | ||
.spawn() | ||
.with_context(|| format!("failed to execute {node} node"))?; | ||
|
||
Ok(NodeProcess::Subprocess(child)) | ||
} | ||
|
||
pub fn spawn_multichain( | ||
release: bool, | ||
node: &str, | ||
cli: mpc_recovery_node::cli::Cli, | ||
) -> anyhow::Result<Child> { | ||
let executable = executable(release, PACKAGE_MULTICHAIN) | ||
.with_context(|| format!("could not find target dir while starting {node} node"))?; | ||
|
||
Command::new(&executable) | ||
.args(cli.into_str_args()) | ||
.env("RUST_LOG", "mpc_recovery_node=INFO") | ||
.envs(std::env::vars()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.kill_on_drop(true) | ||
.spawn() | ||
.with_context(|| format!("failed to run {node} node: {}", executable.display())) | ||
} |
This file contains 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.