I'm having an issue with my swiftui macOS application where it is continually consuming more memory over time and after a couple of hours will grind to a halt. I've watched a few videos now on how to use Xcode Memory Graph and Instruments to identify the source of a leak (I assume it is a leak). These videos all provide very obvious issues as examples but mine seems more elusive and I don't know how to identify which part of my code is the cause of the issue.
After running instruments I see the following but the leaked objects are not always consistent:
Xcode Memory Graph shows NSSet as the culprit which is shown under CoreFoundation (not my App). I really am a beginner here and because it's not showing me somewhere in my app that I can go and investigate I'm really stuck.
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
Created
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.
I'm unable to capture Bluetooth logs via PacketLogger from my iPhone 11 (iOS 18.2) and iPad Pro (iPadOS 17.5.1) with Mac mini M2 macOS 15.2 (24C101).
I've installed Bluetooth profile on both devices, restarted multiple times connected to the computer, it shows device as online, however PacketLogger captures nothing at all.
For test I've installed profile on macOS and PacketLogger captures everything as it should. I saw some posts here from earlier this year, that people were having similar problems with PacketLogger. Please suggest a solution or confirm that it is a known bug.
Topic:
Developer Tools & Services
SubTopic:
Instruments
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 ?
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
Hey,
In the UI of the Instruments app, I can change the recording mode to immediate. Is that possible when using xctrace? It seems to use deferred as a default.
I've tried to create a template, set the recording mode to immediate, and use that template for recording. However, that doesn't seem to work. At least the exported TOC of the .trace will have the following summary:
<summary>
<start-date>2025-01-11T13:00:11.365+01:00</start-date>
<end-date>2025-01-11T13:00:30.525+01:00</end-date>
<duration>19.160279</duration>
<end-reason>Target app exited</end-reason>
<instruments-version>16.0 (16A242d)</instruments-version>
<template-name>core_animation_fps</template-name>
<recording-mode>Deferred</recording-mode>
<time-limit>12 hours</time-limit>
</summary>
This issue might be related to: https://developer.apple.com/forums/thread/735948
Thanks a lot!
Hi there,
How to let instruments - app launch template wait for process to launch , rather than actively launch by instruments?
I need to profile the app launch performance when clicking a push notification or cold launch via a url link. How to let instruments to wait for the process and collect the data?
Currently, I tried the command
xctrace record --template "App Launch"
--attach MyApp
--device-name 'Phone-Dev'
--output mytrace.trace
But it soon failed with 'Cannot find process matching name: MyApp'. How to make it work?
Topic:
Developer Tools & Services
SubTopic:
Instruments
Hello,
I’m encountering an issue with the Instruments app while running a benchmark on an M2 Ultra Mac Studio. Despite being certain that GPU activities involving memory read and write operations are occurring, all related performance counters consistently return 0.
Interestingly, this problem does not occur when using the same code on an M1 MacBook Air, where the counters behave as expected.
What could be causing this discrepancy? Any insights or suggestions would be greatly appreciated.
Thank you!
Topic:
Developer Tools & Services
SubTopic:
Instruments
Tags:
Metal
Metal Performance Shaders
metal-cpp
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.
Hey folks,
We are looking for a way to increase the sampling frequency beyong what's currently called "high frequency sampling" for CPU profiler (or time profiler -- doesn't really matter for us).
We are aware that this is not offered through the UI but wondering if we can somehow experimentally enable this via the .tracetemplate (plist).
Basically, we see that samplingRate exists (in the plist) but don't see it having an effect on the actual runs. The resulting trace file always lists sample-rate-micro-seconds="1000" for the data table. E.g.,
<table trigger="time" pmc-events="Cycles" target-pid="SINGLE" schema="counters-profile" needs-kernel-callstack="0" sample-rate-micro-seconds="1000"/>
Cheers
Topic:
Developer Tools & Services
SubTopic:
Instruments
* [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
I am a developer creating an app for iOS 16 and my app mysteriously started showing a blank screen during previews and the simulator. I profiled the app launch with Instruments, and the results said that dlopen was running on the main thread for the whole minutes of profiling:
Hi,
I’m encountering an issue while using xctrace & instruments to profile an application on macOS. Specifically, when trying to record a trace using the CPU Profiler template, I get the following errors:
Failed to start the recording: configureHardwareCounters: Failed set kpc configuration: Operation not permitted.
Unexpected failure: Couriers have returned unexpectedly.
macOS Version: 15.3.1
Chip: Apple M4 Pro
Xcode Version: Xcode 16.2
It looks like, for some reason, our apps are using a bunch of power sometimes. sysdiagnose has this in the power log:
Never mind. Including the output of sysdiagnose has "sensitive language," and it won't tell me what is sensitive, making this a waste of my time.
ETA: Ok, I I can attach the file: power.log
I've gone through the energy documentation, but it seems geared towards embedded, not macOS, so I'm not sure how I can figure this out more. The extra problem, of course, is that we have a network extension, two daemons, and a GUI app. 😄
Hi,
When I run the new Processor Trace instrument on a simple C or C++ console app, it hangs in "Analyzing - Transferring data" upon finishing the measurement.
When I run it without any other instrument, I get the error:
Failed to stop recording session: Data Providers emitted errors: CPUTrace
Any ideas what I could try, or how to get a more verbose log of this failure?
Best, Ronny
P.S.: I'm using a Macbook Pro M4 Pro 14". MacOs Version 15.4 Beta (24E5228e)
I've discovered what appears to be a system-level memory leak when pressing any key in Swift UI projects. This issue occurs even in a completely empty SwiftUI project with no custom code or event handlers.
When monitoring with Instruments' Leaks tool, I observe multiple memory leaks each time any key is pressed. These leaks consist primarily of:
NSExtraData objects (240 bytes each)
NSMenuItem objects (112 bytes each)
Other AppKit and Foundation objects
Has anyone else encountered this issue? How can I fix this behavior? While the leaks are small (about 5-6KB per keypress), they could potentially accumulate in applications where keyboard input is frequent.
I am using XCode16 and macOS 14.7.2. Previously, using the instruments on an iPhone with iOS 14.3 was normal, but when I upgraded to iOS 18, the instruments often couldn't find the library.
I have to restart the instruments to restore normal operation, but the problem will occur again after using it for a period of time
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