cmyr / cargo-instruments

A cargo plugin to generate Xcode Instruments trace files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated .trace files can't be opened by Instruments.app - Document Missing Template Error

luker-os opened this issue · comments

I am trying to run cargo-instruments via:

cargo instruments -t alloc

When I do, everything seems to run:

    Finished dev [unoptimized + debuginfo] target(s) in 1.45s
   Profiling target/debug/tmp-exp-01 with template 'Allocations'

and I see a new .trace file generated in ./target/instruments, but if I try to open the file, Instruments fails with the error:

The document “tmp-exp-01_Allocations_2023-07-21_162620-077.trace” could not be opened. Document Missing Template Error

I'm using:
Instruments: Version 14.3.1 (14E300c)
cargo-instruments: 0.4.8
rustc: 1.70.0

Any ideas what might be going on?

Thanks!

two possibilities jump to mind:

  • your application hasn't finished running: I believe the trace file is only generated when the application terminates. If you want to profile an application as it is running, you'll need to use Instruments.app directly to attach to the relevant process
  • your application finished execution so quickly that no samples were captured: I think this produces a different error message, but this might vary between versions, I'm not sure

If it isn't any of those things then let me know and we can start debugging. :)

@cmyr happens to me too, my application is a Web API, when I kill it after doing 10K requests, I get this error. Could it be that stopping the API doesn't trigger gracefully creating the profiling file?

I think the fix here is for cargo-instruments to recognise when it's being terminated from the CTRL+C signal, and to finish writing the traces file. Without that you can't really use it for instrumenting long running processes that don't have a regular shutdown like a web server.

The problem is that we aren't responsible for writing traces; that's up to xctrace, and so we have no control over what it does in response to SIGINT.

The only thing cargo-instruments can offer here is the --time-limit command, which lets you specify a number of seconds to run the app before termination.

If you want to attach to a running application, profile it, and then stop profiling, you'll need to dig into the xctrace command line utility (or just Instruments.app)

The problem is that we aren't responsible for writing traces; that's up to xctrace, and so we have no control over what it does in response to SIGINT.

Right but you're the parent process, that's responsible for running both the app and xctrace. You could spawn those into different process groups, and then when cargo-instruments get a SIGINT, you forward that to the app to terminate it, but not to the xctrace process. Letting it finish writing traces before you finish.

That's an interesting idea, but we don't actually spawn the target process, we just invoke xctrace with the --launch option, and it executes the target. We could change this in theory and do the launching ourselves before attaching xctrace but that's a fairly significant change that I don't really have the appetite for at the moment.