Problem recording CPU Counters on an M1: xctrace record: Failed to start the recording: Failed to force all hardware CPU counters

Context

I'm trying to profile a binary (a simple C++ program compiled into dummy.o) and collect CPU Counters data. I have a configuration that works fine from the Instruments Counters GUI (see Screenshots below).

I've exported this configuration to a template file named prof1.tracetemplate.

Problem

When I try to run a recording with that same template from the command line with xctrace (I also tried with sudo):

$ xctrace record --template prof1.tracetemplate --launch dummy.o     

I get the following errors:

Starting recording with the prof1 template. Launching process: dummy.o. Ctrl-C to stop the recording Run issues were detected (trace is still ready to be viewed):

  • [Error] Unexpected failure: Couriers have returned unexpectedly.

  • [Error] Failed to start the recording: Failed to force all hardware CPU counters: 13.

  • [Error] Failed to pause recording session: Cannot pause session session unless it's running. Current state: kSessionError

  • [Error] Unexpected failure: Data source agent failed to arm.

Recording failed with errors. Saving output file... Output file saved as: Launch_dummy.o_2024-01-31_14.22.32_0B6E1A78.trace

System

  • Chip: Apple M1
  • macOS: 14.1.1 (23B81)
  • xctrace version: 15.2 (15C500b)
  • xcode version: 15.2 (15C500b)

Screenshots

Replies

Hi there,

if I understand correctly, you are saying your custom template works when you use it from Instruments but not from xctrace? That does sound like a bug in xctrace.

Could you file a bug report and attach the custom template file you created (you can find it under ~/Library/Application Support/Instruments/Templates/).

Please also specify the xctrace command you used and information about the Instruments version and target device (like you did above). If you also have source code for the dummy executable you can attach so we can build it ourselves, that would be even better.

If you post the feedback-ID, which you get after filing the bug report, here in this thread, that makes it easier for us to connect to make sure it goes to the right team and connect it to this forum post.