cmyr / cargo-instruments

A cargo plugin to generate Xcode Instruments trace files
MIT License
681 stars 34 forks source link

Passing ARGS which begin with `--`? #89

Open morrisonlevi opened 1 year ago

morrisonlevi commented 1 year ago

I'm trying to run a command like this:

cargo instruments --all-features --bench $bench -t time --profile-time 5

Where --profile-time 5 is supposed to be an argument to the benchmark for criterion: https://bheisler.github.io/criterion.rs/book/user_guide/profiling.html.

However, I get an error:

error: Found argument '--profile-time' which wasn't expected, or isn't valid in this context

I tried the classic -- e.g.

cargo instruments --all-features --bench $bench -t time -- --profile-time 5

I didn't get an error, but the benchmark definitely didn't run for 5 seconds. I'm not sure exactly what happened.

cmyr commented 1 year ago

hmm, interesting. In this example, who is supposed to be handling that flag? I don't imagine it's handled by cargo/rustc (since they don't know about criterion) and so I imagine it's being handled by whatever is executed in criterion to handle running a benchmark, but I'm not really sure how that works, and I'm not sure how best to pass arguments to that process. It's even possible that this flag is handled at compile time, and actually modifies the generated binary?

I'm not going to have time to investigate this much myself, but if you're curious to dig into it the first question to figure out would be, basically: who is handling this flag generally? Is it rustc, the criterion bench runner, or the final binary? If it's the bench runner I'm not sure there's an answer, since afaik criterion doesn't get invoked when you run a bench target through cargo instruments; we just ask rustc to build the bench target, it creates an executable, and we run that.

codetheweb commented 2 months ago

For anyone else that stumbles onto this, --* arguments are handled correctly. If you're trying to use Criterion with cargo-instruments, you need to add the --bench flag to tell the Criterion binary to actually benchmark, like this:

cargo instruments --profile bench -t time --bench <benchmark-name>  -- --bench --profile-time 60