Skip to content
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

An attempt at supporting criterion benchmarks #229

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dinghy-lib/src/apple/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use log::debug;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
use std::io::{BufRead, BufReader};
use std::io::{BufRead, BufReader, self};
use std::path::Path;
use std::process::{self, Stdio};
use std::time::Duration;
Expand Down Expand Up @@ -550,7 +550,12 @@ fn launch_app(dev: &AppleSimDevice, app_args: &[&str], _envs: &[&str]) -> Result
let mut xcrun_args: Vec<&str> = vec!["simctl", "launch", "-w", stdout_param, &dev.id, "Dinghy"];
xcrun_args.extend(app_args);
debug!("Launching app via xcrun using args: {:?}", xcrun_args);
let criterion_path = Path::new(&install_path)
.join("criterion")
.to_string_lossy()
.into_owned();
let launch_output = process::Command::new("xcrun")
.env("SIMCTL_CHILD_CRITERION_HOME", criterion_path.clone())
.args(&xcrun_args)
.log_invocation(1)
.output()?;
Expand Down Expand Up @@ -601,6 +606,8 @@ fn launch_app(dev: &AppleSimDevice, app_args: &[&str], _envs: &[&str]) -> Result
.lines()
.rev()
.find(|line| line.contains("exited with status"));
// This will fail if criterion didn't run.
let _ = copy_recursively(criterion_path, "./target/criterion");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty cool. I do wonder why the coping is only happening one way? It seems like we want to send the target/criterion directories contents to the device before running, then let it modify them, then copy them back to target/criterion.

Don't we need different criterion target directories per target or really per device? If I'm benchmarking 3 on 3 models of iPhones and 3 models of Apple Watches, I don't want those benchmark results to be mixed. Maybe I'm missing something though?

if let Some(exit_status_line) = exit_status_line {
let words: Vec<&str> = exit_status_line.split_whitespace().rev().collect();
if let Some(exit_status) = words.get(1) {
Expand All @@ -620,6 +627,19 @@ fn launch_app(dev: &AppleSimDevice, app_args: &[&str], _envs: &[&str]) -> Result
panic!("Failed to get the exit status line from lldb: {}", output);
}
}
pub fn copy_recursively(source: impl AsRef<Path>, destination: impl AsRef<Path>) -> io::Result<()> {
fs::create_dir_all(&destination)?;
for entry in fs::read_dir(source.as_ref())? {
let entry = entry?;
let filetype = entry.file_type()?;
if filetype.is_dir() {
copy_recursively(entry.path(), destination.as_ref().join(entry.file_name()))?;
} else {
fs::copy(entry.path(), destination.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}

fn launch_lldb_simulator(
dev: &AppleSimDevice,
Expand Down