微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

由于CPU使用率导致应用程序在后台崩溃

如何解决由于CPU使用率导致应用程序在后台崩溃

我有一个用SwiftUI编写的锻炼跟踪应用程序。由于我什至不知道代码的哪部分是问题,因此无需深入研究代码,它正在使用CoreLocation获取位置更新,并使用CoreData保存与位置相关的数据。似乎它在前台运行时一切正常,但是在后台运行40分钟-60分钟后,它崩溃了。当我阅读日志时,会看到以下日志。我无法从日志中了解应该在代码中的哪里寻找解决方案?我在占用过多cpu容量的后台执行什么操作,是否保存到CoreData?由于该应用程序在后台运行,因此所有UI更新都应该自动暂停,对吗?您能否在日志中看到一些可以提示我问题所在的信息。

我在Apple上看到此页面https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/WorkLessInTheBackground.html 解决“逃脱后台应用程序崩溃”下的部分,但我看不到日志中引用的内容。你能?有什么建议可以解决我的问题吗?

Data Source:      Microstackshots
Shared Cache:     0x26630000 806C7B9F-DF16-345B-9D6C-B3FAB1733341

Command:          OutdoorWorkout
Path:             /private/var/containers/Bundle/Application/XXXXXXXX-XXXXXXX/OutdoorWorkout.app/OutdoorWorkout
Identifier:       WorkoutBundleID
Version:          1.0 (1)
Beta Identifier:  4D39B290-3181-42D0-BC89-10E43C4A441F
PID:              21776

Event:            cpu usage
Action taken:     Process killed
cpu:              48 seconds cpu time over 59 seconds (82% cpu average),exceeding limit of 80% cpu over 60 seconds
cpu limit:        48s
Limit duration:   60s
cpu used:         48s
cpu duration:     59s
Duration:         58.76s
Duration Sampled: 53.49s
Steps:            11

Hardware model:   iPhone12,1
Active cpus:      6


Heaviest stack for the target process:
  11  ??? (libdyld.dylib + 4996) [0x1a688b384]
  11  ??? (OutdoorWorkout + 138608) [0x100795d70]
  11  ??? (UIKitCore + 10938180) [0x1aabc1744]
  11  ??? (GraphicsServices + 13772) [0x1b0df05cc]
  11  ??? (CoreFoundation + 682952) [0x1a6a0ebc8]
  11  ??? (CoreFoundation + 684764) [0x1a6a0f2dc]
  11  ??? (CoreFoundation + 683596) [0x1a6a0ee4c]
  11  ??? (CoreFoundation + 704796) [0x1a6a1411c]
  11  ??? (SwiftUI + 368820) [0x1df0a00b4]
  11  ??? (SwiftUI + 368524) [0x1df09ff8c]
  11  ??? (SwiftUI + 368668) [0x1df0a001c]
  11  ??? (SwiftUI + 1954804) [0x1df2233f4]
  11  ??? (SwiftUI + 1841768) [0x1df207a68]
  11  ??? (SwiftUI + 4643360) [0x1df4b3a20]
  11  ??? (SwiftUI + 1841824) [0x1df207aa0]
  11  ??? (SwiftUI + 1841460) [0x1df207934]
  11  ??? (SwiftUI + 1842352) [0x1df207cb0]
  11  ??? (SwiftUI + 1842940) [0x1df207efc]
  11  ??? (AttributeGraph + 37600) [0x1d324c2e0]
  11  ??? (AttributeGraph + 17276) [0x1d324737c]
  11  ??? (AttributeGraph + 16064) [0x1d3246ec0]
  9   ??? (AttributeGraph + 115316) [0x1d325f274]
  9   ??? (SwiftUI + 3002020) [0x1df322ea4]
  9   ??? (SwiftUI + 3001388) [0x1df322c2c]
  9   ??? (OutdoorWorkout + 48056) [0x10077fbb8]
  9   ??? (OutdoorWorkout + 48980) [0x10077ff54]
  9   ??? (SwiftUI + 3251672) [0x1df35fdd8]
  4   ??? (OutdoorWorkout + 50624) [0x1007805c0]
  4   ??? (SwiftUI + 4883608) [0x1df4ee498]
  4   ??? (OutdoorWorkout + 61856) [0x1007831a0]
  4   ??? (SwiftUI + 5396712) [0x1df56b8e8]
  4   ??? (OutdoorWorkout + 65172) [0x100783e94]
  4   ??? (OutdoorWorkout + 63348) [0x100783774]
  4   ??? (OutdoorWorkout + 453660) [0x1007e2c1c]
  4   ??? (OutdoorWorkout + 440244) [0x1007df7b4]
  4   ??? (OutdoorWorkout + 425960) [0x1007dbfe8]
  4   ??? (libswiftCore.dylib + 1299560) [0x1b439d468]
  4   ??? (OutdoorWorkout + 462292) [0x1007e4dd4]
  4   ??? (OutdoorWorkout + 421692) [0x1007daf3c]
  4   ??? (OutdoorWorkout + 428164) [0x1007dc884]
  4   ??? (libswiftCore.dylib + 1460088) [0x1b43c4778]
  4   ??? (libswiftCore.dylib + 1461172) [0x1b43c4bb4]
  4   ??? (libswiftCore.dylib + 353072) [0x1b42b6330]
  4   ??? (libswiftCore.dylib + 353312) [0x1b42b6420]
  4   ??? (libswiftCore.dylib + 2949328) [0x1b45300d0]
  4   ??? (libswiftCore.dylib + 2949284) [0x1b45300a4]
  4   ??? (libswiftCore.dylib + 1464092) [0x1b43c571c]
  2   ??? (libswiftCore.dylib + 1469228) [0x1b43c6b2c]
  1   ??? (libswiftCore.dylib + 505172) [0x1b42db554]
  1   ??? (libsystem_malloc.dylib + 45860) [0x1a6781324]


Powerstats for:   OutdoorWorkout [21776]
Bundle ID:        WorkoutBundleID
Adam ID:          0
Is first party:   No
App version:      1.0
Build version:    1
Is Beta:          No
Share with Devs:  No
UUID:             66A62427-9651-3C4E-8E72-FAAF0682DD5C
Path:             /private/var/containers/Bundle/Application/XXXXXXXX-XXXXXXX/OutdoorWorkout.app/OutdoorWorkout
Architecture:     arm64
Footprint:        85.62 MB
Start time:       2020-09-06 13:50:39 -0400
End time:         2020-09-06 13:51:33 -0400
Num samples:      11 (100%)
cpu Time:         45.764s
Primary state:    11 samples Non-Frontmost App,Non-Suppressed,User mode,Effective Thread QoS Background,Requested Thread QoS User Interactive,Override Thread QoS Unspecified
User Activity:    11 samples Idle,0 samples Active
Power Source:     11 samples on Battery,0 samples on AC
  11  start + 3 (libdyld.dylib + 4996) [0x1a688b384]
    11  ??? (OutdoorWorkout + 138608) [0x100795d70]
      11  UIApplicationMain + 1935 (UIKitCore + 10938180) [0x1aabc1744]
        11  GSEventRunModal + 163 (GraphicsServices + 13772) [0x1b0df05cc]
          11  CFRunLoopRunSpecific + 479 (CoreFoundation + 682952) [0x1a6a0ebc8]
            11  __CFRunLoopRun + 1003 (CoreFoundation + 684764) [0x1a6a0f2dc]
              11  __CFRunLoopDoObservers + 419 (CoreFoundation + 683596) [0x1a6a0ee4c]
                11  __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 35 (CoreFoundation + 704796) [0x1a6a1411c]
                  11  @objc closure #1 in static NSRunLoop.addobserver + 55 (SwiftUI + 368820) [0x1df0a00b4]
                    11  closure #1 in static NSRunLoop.addobserver + 15 (SwiftUI + 368524) [0x1df09ff8c]
                      11  static NSRunLoop.flushObservers + 135 (SwiftUI + 368668) [0x1df0a001c]
                        11  thunk for @escaping @callee_guaranteed -> () + 27 (SwiftUI + 1954804) [0x1df2233f4]
                          11  closure #1 in ViewGraph.asyncTransaction<A> + 147 (SwiftUI + 1841768) [0x1df207a68]
                            11  VieWrendererHost.updateViewGraph<A> + 91 (SwiftUI + 4643360) [0x1df4b3a20]
                              11  closure #1 in closure #1 in ViewGraph.asyncTransaction<A> + 23 (SwiftUI + 1841824) [0x1df207aa0]
                                11  ViewGraph.flushTransactions + 187 (SwiftUI + 1841460) [0x1df207934]
                                  11  closure #1 in ViewGraph.flushTransactions + 255 (SwiftUI + 1842352) [0x1df207cb0]
                                    11  ViewGraph.runTransaction + 215 (SwiftUI + 1842940) [0x1df207efc]
                                      11  AG::Subgraph::update + 727 (AttributeGraph + 37600) [0x1d324c2e0]
                                        11  AG::Graph::update_attribute + 375 (AttributeGraph + 17276) [0x1d324737c]
                                          11  AG::Graph::UpdateStack::update + 447 (AttributeGraph + 16064) [0x1d3246ec0]
                                            9   partial apply + 39 (AttributeGraph + 115316) [0x1d325f274]
                                              9   protocol witness for static UntypedAttribute._update in conformance GeometryReader<A>.Child + 39 (SwiftUI + 3002020) [0x1df322ea4]
                                                9   GeometryReader.Child.update + 403 (SwiftUI + 3001388) [0x1df322c2c]
                                                  9   ??? (OutdoorWorkout + 48056) [0x10077fbb8]
                                                    9   ??? (OutdoorWorkout + 48980) [0x10077ff54]
                                                      9   vstack.init + 183 (SwiftUI + 3251672) [0x1df35fdd8]
                                                        4   ??? (OutdoorWorkout + 50624) [0x1007805c0]
                                                          4   HStack.init + 183 (SwiftUI + 4883608) [0x1df4ee498]
                                                            4   ??? (OutdoorWorkout + 61856) [0x1007831a0]
                                                              4   Group<A>.init + 91 (SwiftUI + 5396712) [0x1df56b8e8]
                                                                4   ??? (OutdoorWorkout + 65172) [0x100783e94]
                                                                  4   ??? (OutdoorWorkout + 63348) [0x100783774]
                                                                    4   ??? (OutdoorWorkout + 453660) [0x1007e2c1c]
                                                                      4   ??? (OutdoorWorkout + 440244) [0x1007df7b4]
                                                                        4   ??? (OutdoorWorkout + 425960) [0x1007dbfe8]
                                                                          4   Sequence.forEach + 479 (libswiftCore.dylib + 1299560) [0x1b439d468]
                                                                            4   ??? (OutdoorWorkout + 462292) [0x1007e4dd4]
                                                                              4   ??? (OutdoorWorkout + 421692) [0x1007daf3c]
                                                                                4   ??? (OutdoorWorkout + 428164) [0x1007dc884]
                                                                                  4   Sequence.sorted + 255 (libswiftCore.dylib + 1460088) [0x1b43c4778]
                                                                                    4   MutableCollection<>.sort + 1027 (libswiftCore.dylib + 1461172) [0x1b43c4bb4]
                                                                                      4   protocol witness for MutableCollection._withUnsafeMutableBufferPointerIfSupported<A> in conformance ContiguousArray<A> + 27 (libswiftCore.dylib + 353072) [0x1b42b6330]
                                                                                        4   ContiguousArray.withContiguousMutableStorageIfAvailable<A> + 195 (libswiftCore.dylib + 353312) [0x1b42b6420]
                                                                                          4   partial apply for thunk for @callee_guaranteed -> (@error @owned Error) + 27 (libswiftCore.dylib + 2949328) [0x1b45300d0]
                                                                                            4   partial apply for closure #1 in MutableCollection<>.sort + 103 (libswiftCore.dylib + 2949284) [0x1b45300a4]
                                                                                              4   UnsafeMutableBufferPointer._stableSortImpl + 703 (libswiftCore.dylib + 1464092) [0x1b43c571c]
                                                                                                2   MutableCollection<>._insertionSort + 1620 (libswiftCore.dylib + 1469228) [0x1b43c6b2c]
                                                                                                  1   protocol witness for Collection.subscript.read in conformance [A : B].Keys + 43 (libswiftCore.dylib + 505172) [0x1b42db554]
                                                                                                    1   nanov2_free_definite_size + 36 (libsystem_malloc.dylib + 45860) [0x1a6781324]
                                                                                                  1   free + 131 (libsystem_malloc.dylib + 65084) [0x1a6785e3c]
                                                                                                    1   nanov2_pointer_size + 140 (libsystem_malloc.dylib + 45028) [0x1a6780fe4]
                                                                                                1   MutableCollection<>._insertionSort + 1827 (libswiftCore.dylib + 1469436) [0x1b43c6bfc]
                                                                                                  1   _platform_memmove + 0 (libsystem_platform.dylib + 21712) [0x1a679c4d0]
                                                                                                1   MutableCollection<>._insertionSort + 1620 (libswiftCore.dylib + 1469228) [0x1b43c6b2c]
                                                        3   ??? (OutdoorWorkout + 51752) [0x100780a28]
                                                          3   HStack.init + 183 (SwiftUI + 4883608) [0x1df4ee498]
                                                            3   ??? (OutdoorWorkout + 77032) [0x100786ce8]
                                                              3   ??? (OutdoorWorkout + 67180) [0x10078466c]
                                                                3   vstack.init + 183 (SwiftUI + 3251672) [0x1df35fdd8]
                                                                  3   ??? (OutdoorWorkout + 72716) [0x100785c0c]
                                                                    3   ??? (OutdoorWorkout + 68860) [0x100784cfc]
                                                                      3   Group<A>.init + 91 (SwiftUI + 5396712) [0x1df56b8e8]
                                                                        3   ??? (OutdoorWorkout + 65172) [0x100783e94]
                                                                          3   ??? (OutdoorWorkout + 70752) [0x100785460]
                                                                            3   ??? (OutdoorWorkout + 439112) [0x1007df348]
                                                                              3   ??? (OutdoorWorkout + 433956) [0x1007ddf24]
                                                                                3   Sequence.sorted + 255 (libswiftCore.dylib + 1460088) [0x1b43c4778]
                                                                                  3   MutableCollection<>.sort + 1027 (libswiftCore.dylib + 1461172) [0x1b43c4bb4]
                                                                                    3   protocol witness for MutableCollection._withUnsafeMutableBufferPointerIfSupported<A> in conformance ContiguousArray<A> + 27 (libswiftCore.dylib + 353072) [0x1b42b6330]
                                                                                      3   ContiguousArray.withContiguousMutableStorageIfAvailable<A> + 195 (libswiftCore.dylib + 353312) [0x1b42b6420]
                                                                                        3   partial apply for thunk for @callee_guaranteed -> (@error @owned Error) + 27 (libswiftCore.dylib + 2949328) [0x1b45300d0]
                                                                                          3   partial apply for closure #1 in MutableCollection<>.sort + 103 (libswiftCore.dylib + 2949284) [0x1b45300a4]
                                                                                            3   UnsafeMutableBufferPointer._stableSortImpl + 703 (libswiftCore.dylib + 1464092) [0x1b43c571c]
                                                                                              1   MutableCollection<>._insertionSort + 1827 (libswiftCore.dylib + 1469436) [0x1b43c6bfc]
                                                                                                1   DYLD-STUB$$WebCore::BaseAudioSharedUnit::captureFailed (.cold.1) + 0 (WebCore + 30739780) [0x1b04f9d44]
                                                                                              1   MutableCollection<>._insertionSort + 1699 (libswiftCore.dylib + 1469308) [0x1b43c6b7c]
                                                                                                1   ??? (OutdoorWorkout + 462612) [0x1007e4f14]
                                                                                                  1   ??? (OutdoorWorkout + 424912) [0x1007dbbd0]
                                                                                                    1   swift::Metadataimpl::ValueWitnesses<swift::Metadataimpl::NativeBox<unsigned long long,8ul,8ul> >::destroy + 0 (libswiftCore.dylib + 3235380) [0x1b4575e34]
                                                                                              1   MutableCollection<>._insertionSort + 1375 (libswiftCore.dylib + 1468984) [0x1b43c6a38]
                                                                                                1   protocol witness for Collection.subscript.read in conformance UnsafeMutableBufferPointer<A> + 67 (libswiftCore.dylib + 2479440) [0x1b44bd550]
                                                                                                  1   UnsafeMutableBufferPointer.subscript.read + 67 (libswiftCore.dylib + 2479548) [0x1b44bd5bc]
                                                                                                    1   malloc + 32 (libsystem_malloc.dylib + 65616) [0x1a6786050]
                                                        2   ??? (OutdoorWorkout + 56168) [0x100781b68]
                                                          2   Group<A>.init + 91 (SwiftUI + 5396712) [0x1df56b8e8]
                                                            2   ??? (OutdoorWorkout + 89672) [0x100789e48]
                                                              2   ??? (OutdoorWorkout + 87744) [0x1007896c0]
                                                                2   ??? (OutdoorWorkout + 430448) [0x1007dd170]
                                                                  2   ??? (OutdoorWorkout + 429740) [0x1007dceac]
                                                                    2   ??? (OutdoorWorkout + 425960) [0x1007dbfe8]
                                                                      2   Sequence.forEach + 479 (libswiftCore.dylib + 1299560) [0x1b439d468]
                                                                        2   ??? (OutdoorWorkout + 462292) [0x1007e4dd4]
                                                                          2   ??? (OutdoorWorkout + 421692) [0x1007daf3c]
                                                                            2   ??? (OutdoorWorkout + 428164) [0x1007dc884]
                                                                              2   Sequence.sorted + 255 (libswiftCore.dylib + 1460088) [0x1b43c4778]
                                                                                2   MutableCollection<>.sort + 1027 (libswiftCore.dylib + 1461172) [0x1b43c4bb4]
                                                                                  2   protocol witness for MutableCollection._withUnsafeMutableBufferPointerIfSupported<A> in conformance ContiguousArray<A> + 27 (libswiftCore.dylib + 353072) [0x1b42b6330]
                                                                                    2   ContiguousArray.withContiguousMutableStorageIfAvailable<A> + 195 (libswiftCore.dylib + 353312) [0x1b42b6420]
                                                                                      2   partial apply for thunk for @callee_guaranteed -> (@error @owned Error) + 27 (libswiftCore.dylib + 2949328) [0x1b45300d0]
                                                                                        2   partial apply for closure #1 in MutableCollection<>.sort + 103 (libswiftCore.dylib + 2949284) [0x1b45300a4]
                                                                                          2   UnsafeMutableBufferPointer._stableSortImpl + 703 (libswiftCore.dylib + 1464092) [0x1b43c571c]
                                                                                            1   MutableCollection<>._insertionSort + 1827 (libswiftCore.dylib + 1469436) [0x1b43c6bfc]
                                                                                              1   objc_msgSend + 32 (libobjc.A.dylib + 6784) [0x1a67aaa80]
                                                                                            1   MutableCollection<>._insertionSort + 1419 (libswiftCore.dylib + 1469028) [0x1b43c6a64]
                                                                                              1   objc_msgSend + 44 (libobjc.A.dylib + 6796) [0x1a67aaa8c]
                                            1   partial apply for protocol witness for static UntypedAttribute._update in conformance DynamicLayoutViewChildGeometry + 35 (SwiftUI + 2017560) [0x1df232918]
                                              1   specialized LayoutQuery<>.update + 187 (SwiftUI + 3582596) [0x1df3b0a84]
                                                1   specialized _Layout.updateOutputAttribute<A> + 271 (SwiftUI + 3588720) [0x1df3b2270]
                                                  1   specialized static LayoutComputerDelegate.update<A> + 115 (SwiftUI + 4095736) [0x1df42def8]
                                                    1   specialized closure #1 in Hvstack.updateOutput<A> + 47 (SwiftUI + 3493992) [0x1df39b068]
                                                      1   specialized closure #1 in Hvstack.updateOutput<A> + 191 (SwiftUI + 3494196) [0x1df39b134]
                                                        1   closure #1 in StackLayout.Storage.update + 259 (SwiftUI + 3479700) [0x1df397894]
                                                          1   StackLayout.Header.init + 435 (SwiftUI + 3480444) [0x1df397b7c]
                                                            1   accumulateSpacing #1 in StackLayout.Header.init(layoutContext:proxies:majorAxis:minorAxisAlignment:uniformSpacing:childStorage:capacity:resizeChildrenWithTrailingOverflow:) + 315 (SwiftUI + 3482316) [0x1df3982cc]
                                                              1   LayoutTraitsProxy.spacing + 71 (SwiftUI + 929492) [0x1df128ed4]
                                                                1   LayoutComputer.EngineDelegate.spacing + 67 (SwiftUI + 4097740) [0x1df42e6cc]
                                                                  1   UnaryLayoutEngine.spacing + 79 (SwiftUI + 1704952) [0x1df1e63f8]
                                                                    1   protocol witness for UnaryLayout.spacing in conformance _PaddingLayout + 43 (SwiftUI + 4472428) [0x1df489e6c]
                                                                      1   StackLayout.Storage.spacing + 0 (SwiftUI + 3476344) [0x1df396b78]
                                            1   partial apply for specialized protocol witness for static UntypedAttribute._update in conformance UnaryLayoutComputerQuery<A> + 35 (SwiftUI + 1720128) [0x1df1e9f40]
                                              1   specialized UnaryChildGeometryQuery.update + 75 (SwiftUI + 1689492) [0x1df1e2794]
                                                1   AG::Graph::input_value_ref + 140 (AttributeGraph + 61252) [0x1d3251f44]

  Binary Images:
           0x100774000 -                ???  OutdoorWorkout              <66A62427-9651-3C4E-8E72-FAAF0682DD5C>  /private/var/containers/Bundle/Application/XXXXXXXX-XXXXXXX/OutdoorWorkout.app/OutdoorWorkout
           0x1a6776000 -        0x1a6796fff  libsystem_malloc.dylib   <32E63B4B-0CB6-3798-A0D0-CEB99793BB08>  /usr/lib/system/libsystem_malloc.dylib
           0x1a6797000 -        0x1a679dfff  libsystem_platform.dylib <BF25A4DA-33AF-325F-8C87-36DA4CEF0EFD>  /usr/lib/system/libsystem_platform.dylib
           0x1a67a9000 -        0x1a67dafff  libobjc.A.dylib          <B83466F5-56A4-3CA7-BDD1-3E363185282D>  /usr/lib/libobjc.A.dylib
           0x1a688a000 -        0x1a68befff  libdyld.dylib            <9DB07277-A537-351D-AB86-5408CB5F12C3>  /usr/lib/system/libdyld.dylib
           0x1a6968000 -        0x1a6ce4fff  CoreFoundation           <7769FFAC-4FCD-332D-A4BE-DA2F0E2FFEA5>  /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
           0x1aa153000 -        0x1ab2cbfff  UIKitCore                <5AD0DCE8-0414-3CF9-97A5-13CED9C31CF7>  /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
           0x1ae7a9000 -        0x1b0616fff  WebCore                  <596E181C-ABAC-3774-82DC-993327B74B46>  /System/Library/PrivateFrameworks/WebCore.framework/WebCore
           0x1b0ded000 -        0x1b0df5fff  GraphicsServices         <1881CB29-FB7C-30D6-AB2F-F89962BB7055>  /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
           0x1b4260000 -        0x1b462afff  libswiftCore.dylib       <EA3DC236-04D9-3F9B-905F-FAEA6CDB5805>  /usr/lib/swift/libswiftCore.dylib
           0x1d3243000 -        0x1d327ffff  AttributeGraph           <A382CA95-E8E5-3A77-9E97-F913CE38D4CB>  /System/Library/PrivateFrameworks/AttributeGraph.framework/AttributeGraph
           0x1df046000 -        0x1df709fff  SwiftUI                  <FC9F7A9B-A496-3884-8C9A-48957BEC5D6E>  /System/Library/Frameworks/SwiftUI.framework/SwiftUI

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。