Instruments

RSS for tag

Instruments is a performance-analysis and testing tool for iOS, iPadOS, watchOS, tvOS, and macOS apps.

Posts under Instruments tag

94 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Sudden Drop in CPU Utilization in macOS App After Extended Operation
I'm struggling with CPU performance and memory optimization for a macOS app I'm developing. I'm writing to ask for advice!!! The app I am developing consists of continuous real-time calculations and graphical elements. If I monitor the individual components, the CPU usage is as follows FetchAudioData (captures real-time data with Timer & performs calculations): 20%-30%. MEMU (graphics operation 1): 30% to 40%. FullScreen (graphics task 2): 20% to 40%. I run the app and see a CPU load of 50% to 100% consistently, based on 600% full capacity. However, after 3-4 hours of operation, the CPU utilization suddenly drops to around 10%. (It's hard to determine the exact cause because it's hard to monitor continuously during this time) Additionally, I aware of some memory issues and are dealing with them, but they don't appear to be fatal leaks, so I relegated them to lower priority tasks for now. At a crossroads, Should I prioritize code optimization, fix the small memory issue first, spend three to four hours of close monitoring, or perform a deeper understanding of the Mac system? The analysis process through Profile in Instruments is also tricky in terms of catching the exact moment of a sudden change in CPU utilization. I'm looking for advice from people who have some experience with performance/memory optimization in iOS environments, not necessarily macOS. I'm also wondering why the thread count in the picture goes into the 3000s after 3-4 hours. I'm also wondering if this is an issue with asynchronous processing. Any advice would be greatly appreciated in the comments. Thanks.
4
0
910
Sep ’23
Memory leak in watchOS app
I have been working on an watchOS version of my iOS app using SwiftData. I have a TabView and on one of the views there is a plus button in the bottom bar. It contains a navigation link. When I tap it for some reason two of the views are stacked and I have to click the back button twice to pop both. After that, when I navigate to another view in the TabView, the app freezes. I checked this in instruments and apparently in "All heap and Anonymous VM" and also "All heap allocations" it is generating hundreds of thousands of objects with category "Malloc 32 bytes" and responsible library "libswiftCore.dylib" and responsible caller "swift_allocObject." This is happening every second, all while the app is frozen. The body of the file that includes the plus button(only watchOS): List(sessions) { session in HStack { VStack { HStack { if session.selected == false { Text(session.name ?? "no name") } else { Text(session.name ?? "no name") .font(.system(size: 12)) Text("(Selected)") .font(.system(size: 12)) } Spacer() } Spacer() HStack { Text(session.cube ?? "no cube") Spacer() } } Spacer() if session.cube == "3x3" { Image(systemName: "square.grid.3x3") .font(.title2) } else if session.cube == "2x2" { Image(systemName: "square.grid.2x2") .font(.title2) } else { Image("4x4") .font(.title2) } } .contentShape(Rectangle()) .onTapGesture { if selectedSession.count >= 1 { if session.selected == true { return } else { withAnimation { selectedSession[0].selected = false usleep(100000) session.selected = true } } } else { withAnimation { session.selected?.toggle() } } } } .navigationTitle("Sessions") .toolbar { ToolbarItemGroup(placement: .bottomBar) { Spacer() NavigationLink { AddSessionView() } label: { Image(systemName: "plus") } } } (Remember that this is only occurring on watches) The body of the file that the plus button goes to: ScrollView { VStack { TextField("Name", text: $name) .font(.caption) .frame(maxHeight: 50) Picker("Cube", selection: $cube) { ForEach(cubes, id: \.self) { cube in Text(cube) } } .onChange(of: cube) { getImage() } .frame(minHeight: 50) Button("Create") { if name != "" { if cube == "Playground" { playground = true cube = "3x3" } let session = Session(name: name, cube: cube, image: image, pinned: false, selected: false, playground: playground) modelContext.insert(session) if playground { playground = false } dismiss() } } } } The getImage() function that the onChange calls: private func getImage() { switch cube { case "3x3": image = "square.grid.3x3" case "2x2": image = "square.grid.2x2" case "4x4": image = "4x4" default: print("this will never execute") image = "square.grid.3x3" } } Any help appreciated.
0
0
552
Sep ’23
Background Asset. Failed because the app and extension do not share any application groups.
Hi everyone. We try to implement background assets to our project. And and encountered this problem. When try to send background event from terminal xcrun backgroundassets-debug --simulate --app-periodic-check -d [DEVICE_ID] -b [APP_BUNDLE_IDENTIFIER] In console.app in device log we saw this type of logs Text version :) Resetting extension runtime for: [APP_BUNDLE_IDENTIFIER] Application info for ([APP_BUNDLE_IDENTIFIER]) is being updated based on URL:(N/A) Failed to find represented extension point. (ID:[APP_BUNDLE_IDENTIFIER] Event (7) dropped for client ([APP_BUNDLE_IDENTIFIER]) failed because the app and extension do not share any application groups. Tried on Xcode 15, iOS 17.0.2, MacOS 14 App Info.plist (in yml style) ---- part <key>app-group</key> <string>group.com.*******.MobileFWDemo</string> <key>app-group-asset</key> <string>group.com.*******.BackgroundAsset.Container</string> <key>BAInitialDownloadRestrictions</key> <dict> <key>BADownloadAllowance</key> <integer>1610612736</integer> <key>BADownloadDomainAllowList</key> <array> <string>devstreaming-cdn.apple.com</string> <string>developer.apple.com</string> <string>http://example.com/</string> <string>https://www.learningcontainer.com/</string> <string>https://file-examples.com</string> </array> <key>BAEssentialDownloadAllowance</key> <integer>1073741824</integer> </dict> <key>BAManifestURL</key> <string>https://developer.apple.com/sample-code/background-assets/SessionsManifest.plist</string> <key>BAMaxInstallSize</key> <string>1610612736</string> ----- part In BAExtension info.plist <dict> <key>app-group</key> <string>group.com.*******.MobileFWDemo</string> <key>app-group-asset</key> <string>group.com.*******.BackgroundAsset.Container</string> <key>EXAppExtensionAttributes</key> <dict> <key>EXExtensionPointIdentifier</key> <string>com.apple.background-asset-downloader-extension</string> <key>EXPrincipalClass</key> <string>BackgroundDownloadHandler</string> </dict> </dict> App Entitlement <dict> <key>aps-environment</key> <string>development</string> <key>com.apple.developer.applesignin</key> <array> <string>Default</string> </array> <key>com.apple.developer.associated-domains</key> <array> <string>applinks:******.onelink.me</string> </array> <key>com.apple.developer.game-center</key> <true/> <key>com.apple.security.application-groups</key> <array> <string>group.com.******.BackgroundAsset.Container</string> <string>group.com.******.MobileFWDemo</string> </array> </dict> Extension Entitlement <dict> <key>com.apple.security.application-groups</key> <array> <string>group.com.*******.MobileFWDemo</string> <string>group.com.*******.BackgroundAsset.Container</string> </array> </dict> Method - not called - (NSSet<BADownload *> *)downloadsForRequest:(BAContentRequest)contentRequest manifestURL:(NSURL *)manifestURL extensionInfo:(BAAppExtensionInfo *)extensionInfo After add Background Asset Extension a new warning appeared in the logs: Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (00000006:kIOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted) Maybe it wiil be connected to my problem. Could someone help ?)
1
1
700
Sep ’23
Leaks Instrument Does Not Find Leaks on Sonoma
The Leaks Instrument in Sonoma never reports any leaks. This is happening on Sonoma only. Instruments on Ventura reports the leaks appropriately. This feels like a bug in Instruments on Sonoma, but I wanted to check in here to see if maybe I'm doing something wrong. Steps to dupe: On a Sonoma machine, create a Mac OS Application Project in Xcode, using xibs and Objective-C. In the app delegate create a method: - (IBAction)leak:(id)sender { NSLog(@"LEAK!"); int* ptr = ( int* )malloc( 5 * sizeof(int) ); } In the MainMenu.xib, create a button in the window and connect it to the leak action. Build and Run. Launch Instruments and choose the Leaks tool. Attach Instruments to your running application and start recording. Click the Leak button in your app any number of times. Stop recording in Instruments. RESULT: Instruments reports no leaks found. WORKAROUND: To see leaks on Sonoma I can do so in the Terminal using leaks with these steps: Launch Terminal export MallocStackLogging=1 leaks -atExit -- /Users/zack/Library/Developer/Xcode/DerivedData/Leaker-fkhkydpehobufngumikoydtpyxsc/Build/Products/Debug/Leaker.app/Contents/MacOS/Leaker NOTE: this leaks command takes the path to the actual built binary. The app will launch. Click the Leak button any number of times. Quit the app. For example, clicking the Leak button 7 times, the leaks tool reports: STACK OF 7 INSTANCES OF 'ROOT LEAK: <malloc in -[AppDelegate leak:]>': 19 dyld 0x183e39058 start + 2224 18 ZJ.Leaker 0x10207d12c main + 60 main.m:14 17 com.apple.AppKit 0x187a33708 NSApplicationMain + 880 16 com.apple.AppKit 0x187a5c460 -[NSApplication run] + 512 15 com.apple.AppKit 0x187e8f1bc -[NSApplication _handleEvent:] + 60 14 com.apple.AppKit 0x18823bc08 -[NSApplication(NSEventRouting) sendEvent:] + 1556 13 com.apple.AppKit 0x187b9482c -[NSWindow(NSEventRouting) sendEvent:] + 284 12 com.apple.AppKit 0x187b94b6c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 364 11 com.apple.AppKit 0x187c093b4 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3472 10 com.apple.AppKit 0x187c0a5e8 -[NSControl mouseDown:] + 448 9 com.apple.AppKit 0x187c0b114 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 488 8 com.apple.AppKit 0x187c0b25c -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 144 7 com.apple.AppKit 0x187c0b850 NSControlTrackMouse + 1480 6 com.apple.AppKit 0x187c0e220 -[NSButtonCell _sendActionFrom:] + 88 5 com.apple.AppKit 0x187c0e2fc -[NSCell _sendActionFrom:] + 204 4 com.apple.AppKit 0x187c0e3d4 __26-[NSCell _sendActionFrom:]_block_invoke + 100 3 com.apple.AppKit 0x187c0e490 -[NSControl sendAction:to:] + 72 2 com.apple.AppKit 0x187c0e68c -[NSApplication(NSResponder) sendAction:to:from:] + 460 1 ZJ.Leaker 0x10207d2b8 -[AppDelegate leak:] + 88 AppDelegate.m:34 0 libsystem_malloc.dylib 0x183ff4ad0 _malloc_zone_malloc_instrumented_or_legacy + 276 ==== 7 (224 bytes) << TOTAL >> 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000ca5bc0> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000ca6e80> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000ca74a0> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000cb8520> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000cc0840> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000cc09a0> [32] 1 (32 bytes) ROOT LEAK: <malloc in -[AppDelegate leak:] 0x600000cc7a00> [32]
2
0
717
Oct ’23
Instruments - No PMI Record Found
Instruments CPU Profiler failed to start the profilable app (get-task-allow is set to true) with error "No PMI Record Found". Device is iPhone 13 Pro currently running iOS 17.0.3. Tried to profile in instruments shipped with Xcode 14.3.1, Xcode 15.0.1 and Xcode 15.1 Beta, same issue across. If it helps, I was able to successfully profile on iPhone X running iOS f16.7 using Xcode 14.2 instruments.
3
1
1.5k
Oct ’23
macOS SwiftUI Table Performance Issue
Has anyone else created a macOS SwiftUI app that uses a Table with a largish (~1000) number of entries? My app works OK at about 100 entries, but slows down as the number of entries increase. How slow? An instrumented test with 1219 entries shows a Hang of over 13 seconds from simply clicking/selecting an item in the table. Instruments says the time is mostly spent in _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION. Digging deeper I see AG::Subgraph::update(unsigned int) and descendants account for about half of the hang time. My app is using @Observable on macOS 14 and is being tested on an M2 Max Studio. There are other reported hangs. All seem to be in Swift/SwiftUI code.
6
1
1.3k
Mar ’24
Instruments in XCode 15.0.1 does not support CPU counters in A16(iPhone 14 Pro Max) with iOS 17.1?
Instruments in XCode 14 used to support CPU counters in A16 with iOS 16.x, but after I upgrade iOS to 17.1 and also XCode to 15.0.1, In "CPU Counters", it says "CPU Name: Unsupported" and thus I cannot choose "Sample by" events etc. Found some link on this:https://stackoverflow.com/questions/77344529/is-latest-instruments-not-support-a17-pro-for-cpu-counters Please help to confirm this is some known issue, and if so, how to fix it. Thanks!
3
0
969
May ’24
Instruments 15.0.1 on Sonoma 14.1.1 and CORE_ACTIVE_CYCLE kernel always 0
Hi, I have a few traces where I have samples for kernel (and other processes), yet kernel is always 0 for any CPU Counter selected. There are other processes with an equivalent number of samples where the counter values appear. Perhaps there is a bit of 'art' to get the kernel counters to populate? I am trying to understand the workload from the system perspective (not simply the narrower process perspective), and it would be helpful to have the counter values. I've tried running for extended durations, yet that doesn't seem to adjust the counted events. I've adjusted to include "High Frequency Sampling" to resolve issues with VMware counter collection. Yet.. I need help to enable counter values to appear for kernel. Sam
3
0
395
Nov ’23
How do I list iPhones and iPads currently connected to my MAC??
To run UI tests on actual devices, I use the following command to list devices possibly connected to my MAC: xcrun xctrace list devices As you know it shows a list of simulators and actual devices. BUT it also shows actual devices NOT currently connected to my MAC. If they are not currently connected, I do not wish to see them. Once a device is connected, it seems to always show up in the [== Devices ==] list. Even after I disconnect the device it will still show up there. And my software thinks it can run tests on these devices. Does anyone know how to get a correct list of devices which are currently connected to the MAC??
0
1
428
Nov ’23
Instruments 15.0.1: Unintended Recording of Additional Process Traces
I'm tracing a process, specifically focusing on the Metal device track, which records frames from other processes like Terminal, WindowServer, and sometimes processes that utilize the GPU. I attempted tracing with all apps closed and only Instruments running. However, it also records traces for Instruments. This behavior wasn't present in previous versions of Instruments. Was there a recent change in Instruments/Xcode 15.0.1? I cannot find any relevant information about this in the release notes either. Is there a way to configure Instruments to record only the running process?
1
0
399
Nov ’23