cmyr / cargo-instruments

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

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

Open luker-os opened 1 year ago

luker-os commented 1 year ago

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!

cmyr commented 1 year ago

two possibilities jump to mind:

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

amitassaraf commented 1 year ago

@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?

XAMPPRocky commented 1 year ago

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.

cmyr commented 1 year ago

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)

XAMPPRocky commented 1 year ago

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.

cmyr commented 1 year ago

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.