Our customers are large enterprises and we need to be able to collect traces on our customers' endpoints in support cases. Especially critical are performance problems.
So far we've instructed our customers to use ktrace:
sudo ktrace artrace -p appname --type=profile
We would then open this trace in Instruments with the CPU profile and load our own symbols.
The problem is, that symbols for system libraries are missing. In one instance we see that all of the high load is coming from a syscall made by libpcap. But all symbols other than our own are missing.
How can we collect traces which include those symbols?
I tried to use
ktrace symbolicate
in tests where I recorded a trace and then used ktrace symbolicate to collect system lib symbols, but it fails for most libraries, including libpcap and the syscalls. This is somewhat surprising, because dyld_info -exports /usr/lib/libpcap.A.dylib is able to print the symbols including offsets.
So what is the recommended workflow for this scenario?
Installing Xcode is of course not an option on a customer machine, especially not in an enterprise scenario.
Instruments
RSS for tagInstruments is a performance-analysis and testing tool for iOS, iPadOS, watchOS, tvOS, and macOS apps.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi everyone,
(I am running on an M2 MacBook Pro 14 inch with 96 GB of memory)
I've been profiling with Instruments to find out why program suddenly goes from full CPU usage (all of my threads active and all cores working) to about 33% CPU usage. An Instruments system trace is showing me a massive performance cliff where I suddenly get taken off the performance cores and only run on efficiency cores. The performance cores are then occupied by "kernel.release.t6020". What is this thing?
I have kernel callstacks enabled but I only get the instruction pointer and have no symbols for any of those callstacks. I'm accustomed to Windows development where kernel symbols are available so you can see deeply into the kernel to know why you're spending time there (for example, semaphore wait or thread scheduling). Is there a way for me to get a similar level of information or kernel symbols so I can see what the kernel is doing?
Around the time I observe the performance cliff, I also noticed in the narrative view some of the preemptions are done "because thread was balanced off CPU i (P Core) to optimize the system's CPU performance". What does this mean? Have I begun to hit some sort of thermal limit?
Here are some example screenshots of what I am seeing in Instruments:
Topic:
Developer Tools & Services
SubTopic:
Instruments
I'm developing a library and using XCTest for unit tests. While trying to profile the test suite, I noticed that Instruments seems to report a leak every single time the async throwing setup function is called, no matter what.
For example,
This will report a leak:
final class LeakTests: XCTestCase {
override func setUp() async throws {
try await super.setUp()
}
func testLeak() async throws {
try await Task.sleep(nanoseconds: 5_000_000_000)
}
}
This will not report a leak:
final class LeakTests: XCTestCase {
// override func setUp() async throws {
// try await super.setUp()
// }
func testLeak() async throws {
try await Task.sleep(nanoseconds: 5_000_000_000)
}
}
Any ideas on why this might be happening, or should I just file a bug report? It makes it quite difficult to use the leak detection for unit tests, as it shows hundreds of leaks when the whole suite is ran.
I am currently reviewing the tutorial documentation for the instruments. (Instruments Tutorials: https://developer.apple.com/tutorials/instruments/identifying-a-hang)
It seems very useful, so I want to follow the tutorials step by step.
However, I am having trouble downloading the sample project files; it appears that the 7z file is broken.
(https://developer.apple.com/instruments/tutorials/downloads/InitialVersion.7z)
Can anyone help me with how to download the project files properly?
Context
I created a short script to CPU profile a program from the command line. I am able to record via the Instruments app, but when I try from the command line I get the following error shown below. This example is just profiling the grep command.
Error:
% cpu_profile /usr/bin/grep \
--recursive "Brendan Gregg" \
"$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
Profiling /usr/bin/grep into /tmp/cpu_profile_grep.trace
Starting recording with the CPU Profiler template. Launching process: grep.
Ctrl-C to stop the recording
Run issues were detected (trace is still ready to be viewed):
* [Error] Failed to start the recording: Failed to force all hardware CPU counters: 13.
Recording failed with errors. Saving output file...
Script:
#!/bin/sh
set -o errexit
set -o nounset
if [ "$#" -lt 1 ]
then
echo "Usage $0 <program> [arguments...]" 1>&2
exit 1
fi
PROGRAM="$(realpath "$1")"
shift
OUTPUT="/tmp/cpu_profile_$(basename "$PROGRAM").trace"
echo "Profiling $PROGRAM into $OUTPUT" 1>&2
# Delete potential previous traces
rm -rf "$OUTPUT"
xcrun xctrace record \
--template 'CPU Profiler' \
--no-prompt \
--output "$OUTPUT" \
--target-stdout - \
--launch -- "$PROGRAM" "$@"
open "$OUTPUT"
I think the error has to do with xctrace based on this post, but according to this post it should have been resolved in MacOS version 15.4.
System
Chip: Apple M3 Pro
macOS: Sequoia 15.4.1
xctrace version: 16.0 (16E140)
xcrun version: 70.
Xcode version: 16.3 (16E140)
Working Screenshots from Instruments App:
Topic:
Developer Tools & Services
SubTopic:
Instruments
Tags:
Developer Tools
Instruments
Xcode
Debugging
When running instruments or when debug memory in Xcode, I am getting same error as
An unknown error occurred launching the helper task
Xcode: Xcode16.3
OS: 15.5 Beta (24F5068b)
Mac mini: Apple M2 Pro
Hi :wave:
I am not sure that I use it right, I was not able to profile using these events:
I am on a M1 Pro machine using macOS 15.5.
I just wonder if these events are support on Apple Sillicon.
Topic:
Developer Tools & Services
SubTopic:
Instruments
I’m seeing inconsistent call stacks and usage percentages in the Time Profiler between two Instruments builds:
• Xcode 16.0’s Instruments Version 16.0 (16A242d)
• Xcode 16.3’s Instruments Version 16.0 (16E140)
When I open an old .trace file recorded with the 16A242d profiler in the newer 16E140 Instruments, the call trees and percentage breakdowns no longer match. It looks like the latest Instruments now exposes or collapses different frames (e.g. system libraries, inline code) by default.
I rely on these call stacks as a baseline to track performance regressions and verify optimizations over time. Unfortunately, every Xcode/Instruments update changes what I see, making it impossible to compare profiles across versions.
My questions:
Is there a way in Instruments 16.0 (16E140) to restore the exact call-tree view and percentage calculations that 16A242d produced?
Failing that, is there a recommended workflow or tool for capturing CPU profiles in a way that remains stable and comparable, regardless of Xcode or Instruments version?
Any guidance on achieving consistent, version-independent performance measurements would be greatly appreciated!
Hi,
My name is Hani Nemati, and I work at Microsoft, where we support several macOS applications such as Microsoft Edge and Teams. I’m also the primary contributor to Microsoft Performance Tools for Apple (https://github.com/microsoft/Microsoft-Performance-Tools-Apple), an open-source project aimed at improving trace analysis across platforms.
We are exploring ways to enhance our performance tracing capabilities on macOS and are particularly interested in the ability to attach PMU (Performance Monitoring Unit) counters to context switch events during trace collection. For reference, this capability is supported on Linux via LTTng using the add-context option (https://lttng.org/man/1/lttng-add-context/v2.13), and on Windows through Windows Performance Recorder (WPR), which allows PMU counters to be added at the start and end of context switches, enabling delta computation.
Would it be possible to introduce similar support in Instruments for macOS?
I’d appreciate any guidance or suggestions you might have on this request.
Thank you,
Hani Nemati
Email: hanemati@microsoft
We have 2 iPhones (16 pro - iOS 18.2, 16 regular - iOS 18.5 ) in single app mode and sometimes we need to shut them down manually. After holding Power and VolumeUp, shutdown screen appears as usual, but the slider isn't responding to touch, as well as the whole screen. After force restart using volume buttons, this issue disappears, but reappears after next phone restart.
If we disable single app mode -the issue is gone and touch screen works every time on shutdown screen. Both iPhones share the same behavior.
Is there any other way to reliably shut down the iPhone locally without using MDM or a way to fix this issue?
There is a WWDC session about this cool instrument to detect hangs on-device:
https://developer.apple.com/videos/play/wwdc2022/10082/
I very like this tool; it's handy and gives useful stack traces, but the threshold of 250 ms is practically too high to use in a testing environment. It would be better if there was an option like 100 ms or something like that.
I think most of the people can see the scrolling hang with a duration of 100-250 ms, and it would be cool to detect such hangs with this instrument.
Is there a way to set a lower threshold, or can Apple consider adding such a threshold?
Thank you!
Topic:
Developer Tools & Services
SubTopic:
Instruments
I cannot my AirPods 3rd gen to my phone it won’t play videos or music when connected. Screen bugs out some times doesn’t see when I swipe. Too many bugs .
Hi there,
In a project that I am working on, whenever I try running instruments for allocations to see the memory allocations that are happening under the hood, I see the statistics, and the traces updating, however the chart never updates.
I have made new projects on the machine, and I have tried different Xcode versions, and they all show the chart just fine. I have tried running the project on other machines with no success. I have double checked the arguments and options on the active schema I am trying to profile with the schema of a new project and they are identical.
Here is a picture of how it looks:
My questions are as follows:
What properties and settings can disable the chart from showing up?
What diagnostic steps recommended that I should take?
I can not share a reproducible as this is the only project I have with this problem and it is not mine, but please tell me if there is anything else I can provide in order to debug this.
All the best
Parsa
Topic:
Developer Tools & Services
SubTopic:
Instruments
Tags:
Xcode
Developer Tools
Instruments
Debugging
Can somebody help me find the official documentation for instruments?
Google brings you to this forum, then the link at the top of this forum for Instruments documentation brings you to the Xcode page, which links to these Apple developer docs, wherein a search returns nothing for "Instruments". Searching these Xcode docs for "Instruments" returns only this specific use case on analyzing HTTP traffic.
Topic:
Developer Tools & Services
SubTopic:
Instruments
Good afternoon)
I am doing one of the test projects to create a PKPASS and a server to update this file on the device, as well as sending PUSH-a. APN service is used with JWT Bearer token. The server is written in Java Springboot.
We try to send push notification, pkpass update happens, response from APN 200 OK. But there is no notification, can you please tell me why this is happening?
I am also sending you a sample request:
curl -v -X POST
-H "apns-push-type: alert"
-H "apns-id: 5af474c5-a212-42f3-9f99-70a9e587e1e2"
-H "apns-topic: pas.example225"
-H "apns-expiration: 0"
-H "authorization: bearer eyJraWQiOiJGQ0pQVFFMV1ZNIiwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiI2N0ZGUTY1TEQzIiwiaWF0IjoxNzMwMzY3NzQ4fQ.FGXSLCR6mxkQyi7bNliZKZbVdN3m0xQzFSMUDRFU4aAYIgsgflk5MDEkS9k5riMHp10wpr80b20uq9cuPnoQqw"
--data '{"aps":{"alert":{"title":"title","subtitle":"subtitle","body":"body"}}}' \
P.S. I checked JWT on the page: https://icloud.developer.apple.com JWT was built correctly.
Thank you for your reply)
Translated with DeepL.com (free version)
I've been developing an app for macOS for some time. As I've been approaching the app's final development stages, I decided to try Instruments as I've suspected a memory leak was occurring, since my app's memory usage slowly grows over time. Instruments has found one leak, and I've spent considerable time trying to find the cause. Long story short, I've ended up with just an EmptyView() and Instruments were still showing a leak. I've tried creating a new project with a placeholder "Hello, world!" text, and Instruments were still detecting a leak. Am I doing something wrong here? Maybe I'm not using Instruments correctly? Or is this a bug? My Instruments version is 16.0, macOS Sequoia 15.1.
While I was recently profiling some code from a Swift library, I noticed that XCTest added in signposts for the measurement tests, which I found really helpful to "home in" on the code I wanted to profile digging around in the stack trace.
I tried to add my own signposts to provide just a bit of my own markers in there, but while it compiles and profiles equivalently, the signposts just aren't showing up. This is with Xcode 16.1, macOS Sequoia (15.1) and a swift library, using XCTest and profiling within one of the unit tests.
Is there something in this sequence that doesn't allow the library to set up signposts and have instruments collect them?
The flow I'm using:
import os
let subsystem = "MyLibrary"
class MyClass {
let logger: Logger = .init(subsystem: subsystem, category: "fastloop")
let signposter: OSSignposter
init() {
signposter = OSSignposter(logger: logger)
}
func goFast() {
let signpostId = signposter.makeSignpostID()
let state = signposter.beginInterval("tick", id: signpostId)
// ... do a bunch of work here - all synchronous
signposter.endInterval("tick", state)
}
}
Is there something I'm doing incorrectly in using this API, or not enabling to allow those signposts to be collected by the profiler?
I do see the signposts that XCTests injects into the system, just not any of the ones I'm creating.
Hello, I would like to obtain the average CPU usage of a trace I ran through instruments by looking at the cpu profiler. Is there any way to do this? Or should I be using another instrument.
six months have passed since I bought this iPhone 13. till 3 months it was having the battery health of 100% but now it is draining rapidly. It drained to 99% in November.at the beginning of December it was 98%. on 23 December 97% and now on new year its 96%. can anybody tell me why ?
* [Error] Failed to stop recording session: Failed stoping ktrace session.
(xcode-select version 2409)
So why can't it stop the ktrace session? And how long has that typo been around? 😄 (Look, I've kept typos in log messages for years because it differentiated that message from other messages.)
Topic:
Developer Tools & Services
SubTopic:
Instruments