Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ members = [
"symbolic_regression",
"web/wasm",
]

[profile.profiling]
inherits = "release"
debug = true
33 changes: 32 additions & 1 deletion symbolic_regression/examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ use symbolic_regression::prelude::*;
// Mirrors `SymbolicRegression.jl/example.jl`.

fn main() {
fn usage() {
eprintln!("Usage: example [--niterations <n>]");
}

let mut args = std::env::args().skip(1);
let mut niterations: usize = 1_000;
while let Some(arg) = args.next() {
match arg.as_str() {
"-h" | "--help" => {
usage();
return;
}
"-n" | "--niterations" => {
let value = args.next().unwrap_or_else(|| {
eprintln!("Missing value for {arg}");
usage();
std::process::exit(2);
});
niterations = value.parse().unwrap_or_else(|_| {
eprintln!("Expected `--niterations` as an integer, got: {value}");
std::process::exit(2);
});
}
_ => {
eprintln!("Unknown arg: {arg}");
usage();
std::process::exit(2);
}
}
}

const N_FEATURES: usize = 5;
const D: usize = 3;
let n_rows = 100;
Expand All @@ -30,7 +61,7 @@ fn main() {

let options = Options::<f32, D> {
operators,
niterations: 200,
niterations,
..Default::default()
};

Expand Down
41 changes: 41 additions & 0 deletions tools/profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

usage() {
cat <<'EOF' >&2
Usage: ./tools/profile.sh

Profiles `symbolic_regression/examples/example.rs` (built with the `profiling` Cargo profile) using Samply.
EOF
}

if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
if [[ $# -ne 0 ]]; then
echo "No args supported." >&2
usage
exit 2
fi

root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root_dir"

export RUSTFLAGS="${RUSTFLAGS:-} -C force-frame-pointers=yes"
cargo --config 'build.rustc-wrapper=""' build -p symbolic_regression --profile profiling --example example

bin="target/profiling/examples/example"

mkdir -p profiles
timestamp="$(date +%Y%m%d-%H%M%S)"

if [[ "$(uname -s)" == "Darwin" ]]; then
samply setup --yes >/dev/null 2>&1 || {
echo "Warning: \`samply setup\` failed; profiling may fail on macOS." >&2
}
fi

out="profiles/example-${timestamp}.json.gz"
echo "Writing profile to: $out" >&2
exec samply record --rate 1000 --symbol-dir "target/profiling/examples" -o "$out" -- "$bin"