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
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
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 &gt;= 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
553
Sep ’23
Tracking down a memory leak
I've discovered that my app has a memory leak, where when I close a window, it disappears from the screen but it (along with all its views, view controllers, and associated objects) actually doesn't get released. Instruments doesn't register it as a leak. It does show a few unidentified malloc leaks, but nowhere near enough to account for a window full of stuff. Xcode's memory graph doesn't show any leaks either, and I've combed through it looking for retain cycles or unwanted captures in blocks. I've fixed a few, but it hasn't been enough to actually get the window released. What other tactics are there for finding this kind of leak? The project is here for anyone feeling adventurous: https://github.com/Uncommon/Xit
3
0
6.1k
Sep ’23
How to export Stack Trace using xctrace
I am trying to export .trace file data to xml using the following command xctrace export --input report.trace --xpath '/trace-toc/run[@number="1"]/tracks/track[@name="Leaks"]/details/detail[@name="Leaks"]' --output output.xml <?xml version="1.0"?> <trace-query-result> <node xpath='//trace-toc[1]/run[1]/tracks[1]/track[2]/details[1]/detail[1]'><row leaked-object="Swift.StringStorage" size="131072" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x130018000"/> <row leaked-object="Swift.StringStorage" size="131072" responsible-frame="&lt;Allocated Prior To Attach&gt;" count="1" responsible-library="" address="0x140118000"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="&lt;Allocated Prior To Attach&gt;" count="1" responsible-library="" address="0x60000152d6e0"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x6000015f56e0"/> <row leaked-object="Swift.StringStorage" size="131072" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x120028000"/> <row leaked-object="Swift.StringStorage" size="131072" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x120048000"/> <row leaked-object="Swift.StringStorage" size="131072" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x130038000"/> <row leaked-object="Swift.StringStorage" size="131072" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x130058000"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x6000015038d0"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x600001508ea0"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x60000150a4c0"/> <row leaked-object="MemoryLeaker" size="48" responsible-frame="_swift_allocObject_" count="1" responsible-library="libswiftCore.dylib" address="0x60000150cfc0"/> </node></trace-query-result> Data is being converted to xml but without any details of the Stack Trace Is there any documentation that shows how I can include the Stack Trace as well? Does xctrace support any other export format besides XML? Thanks
1
0
1k
Aug ’23
Instruments: could not locate ReferenceCycles event
I've been using Instruments from Xcode 14.3 (MacOS 13.5) on my Intel-based MacBook Pro for a while and starting recently "CPU Profiling" instrument no longer could be configure to trigger sampling on PMI events. I've checked "CPU Counters" instruments, and it could not use ReferenceCycles event neither as a trigger, nor for sampling: I can start recording with such configuration, but it stops immediately with an error related to unavailable event, after that Instruments app hangs. Is it a known issue? Maybe something could be tweaked using, for instance, sysctl to enable ReferenceCycles counter back? I tried rebooting the laptop, but it didn't help.
1
0
546
Aug ’23
ITMS-90338: Non-public API usage
We are facing the below mentioned error frequently while submitting the different apps in the App Store. When we are uploading the first build, we are receiving the below mentioned error and if we increment the build version, and on re submitting we are not facing the same issue again. Could you please guide us on what caused this issue? Xcode Version: 14.2 Error : ITMS-90338: Non-public API usage - The app contains one or more corrupted binaries. Rebuild the app and resubmit.. If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed.
2
0
940
Aug ’23
Allocations/Leaks Instrument Error: Required kernel recording resources are in use by another document.
The Leaks instrument is suddenly giving me the error "Required kernel recording resources are in use by another document." I see this has come up with Xcode 12 on iOS, but now it's happening when profiling a Mac application on Monterey 12.3.1 and Xcode 13.3. I get the same behaviour on a debug or release build. The Allocations instrument on its own also gives the same error. The Time Profiler intrument launches without issue. Regardless of the (useless) error, it's possible this is a signing issue, since Intruments is also constantly asking for a password when launching the process. Does anyone have any insight into what is causing this?
6
1
2.7k
Aug ’23
Specifying recording options in xctrace CLI
Hello, I'm curious to learn if there's a way to specify recording parameters programmatically to xctrace. The docs, (in particular, create-parameter) imply that there's a mechanism for defining parameters and then specifying their values on the command line. From https://help.apple.com/instruments/developer/mac/current/#/dev494862765 : <create-parameter> Element Creates a parameter specific to this instrument. **Parameters show up in the UI and command line as recording options.** However, I only ever see these recording options in the UI. Latest Xcode15 beta 6 xctrace doesn't seem to mention anything else about recording parameters, from what I was able to tell. This is true for both custom instruments (where I defined create-parameter myself), and for 1st-party instruments such as Time Profiler (e.g. high-frequency-sampling). As a workaround I've been able to make custom instruments that import the relevant schemas and mark them as dependencies/required-inputs (then I can set the individual options). Is this the expected workflow for recording options? Am I misreading the docs? Just to clarify -- these parameters DO in fact appear from the UI, but are absent from xctrace . Thank you!
1
0
487
Aug ’23
Cannot get CPU profile via xctrace
Hi, I'm a new owner of Apple laptop since I always using PC. I'm an experienced perf user but now I'm happy having my MBP2021 laptop so I need to learn new tools. I found that xctrace is the new way to capture profiles on Apple devices so I've installed one and ran on my app. Unfortunately, I didn't manage to make it work. Here is my script: ❯ xctrace record --template 'CPU Counters' --launch -- ./target/release/deps/flower-b0a05df673ad26db tests::test_run Starting recording with the CPU Counters template. Launching process: flower-b0a05df673ad26db. Ctrl-C to stop the recording Target app exited, ending recording... Recording completed. Saving output file... Output file saved as: Launch_flower-b0a05df673ad26db_2022-05-09_21.02.47_4E6DC3F7.trace. ❯ xctrace import --template 'CPU Counters' --input Launch_flower-b0a05df673ad26db_2022-05-09_21.02.47_4E6DC3F7.trace Import failed with error: Cannot find matching importer for url: Launch_flower-b0a05df673ad26db_2022-05-09_21.02.47_4E6DC3F7.trace/ -- file:///Users/pzixel/Documents/Repos/flower/ I tried to find any information about to how to make it work but failed. I hope I can find some support here.
4
0
2.8k
Aug ’23
Allocations Instrument failed to attach to target process
When trying to use the Allocations Instrument I get the following error when pressing record: Unable to issue sandbox extension for path: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 15.2.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/liboainject.dylib Longer story: I can not get Xcode to launch a simulator with 15.5 so I downloaded the 15.2 runtime and created a simulator with that. Is there a step I missed downgrading to the older runtime? I'm trying to debug the 15.5 failure separately.
2
0
2.0k
Jul ’23