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

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

Open
luker-os opened this issue Jul 21, 2023 · 6 comments

Comments

@luker-os
Copy link

luker-os commented Jul 21, 2023

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
Copy link
Owner

cmyr commented Jul 25, 2023

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. :)

@amitassaraf
Copy link

@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
Copy link

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
Copy link
Owner

cmyr commented Oct 12, 2023

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
Copy link

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
Copy link
Owner

cmyr commented Oct 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants