3

我有一个基于位置服务的跟踪和地理围栏应用程序,它将在 iOS 12.2 ff 设备的后台运行数天和数周。

现在,在 iOS 13.2 中,由于 cpu 使用过多,应用程序会在一段时间后终止,但至少要几个小时:

Date/Time:        2019-11-09 23:25:18 +0200
End time:         2019-11-09 23:26:06 +0200
OS Version:       iPhone OS 13.2 (Build 17B84)
Architecture:     arm64
Report Version:   29
Incident Identifier: 5B46660C-A347-477F-8AE2-B1401080892B

Data Source:      Microstackshots
Shared Cache:     0x44db8000 94FD24C8-F407-3A82-8D27-367F5B6C7BEC

Command:          Anchorwatch
Path:             /private/var/containers/Bundle/Application/32CD03B2-449C-4E84-8E06-79FA9B50F3A9/Anchorwatch.app/Anchorwatch
Identifier:       de.sioned.Anchorwatch
Version:          2.2.1 (14)
Beta Identifier:  68A95EFC-B341-476C-9277-D711242471EC
PID:              57424

Event:            cpu usage
Action taken:     Process killed
CPU:              48 seconds cpu time over 48 seconds (99% cpu average), exceeding limit of 80% cpu over 60 seconds
CPU limit:        48s
Limit duration:   60s
CPU used:         48s
CPU duration:     48s
Duration:         48.39s
Duration Sampled: 14.08s
Steps:            16

Hardware model:   iPad6,12
Active cpus:      2


Heaviest stack for the target process:
  16  ??? (libsystem_pthread.dylib + 49032) [0x1c4f64f88]
  16  ??? (libdispatch.dylib + 74516) [0x1c4ecb314]
  16  ??? (libdispatch.dylib + 36344) [0x1c4ec1df8]
  16  ??? (libdispatch.dylib + 33488) [0x1c4ec12d0]
  16  ??? (libdispatch.dylib + 104312) [0x1c4ed2778]
  16  ??? (libdispatch.dylib + 33948) [0x1c4ec149c]
  16  ??? (libdispatch.dylib + 124996) [0x1c4ed7844]
  16  ??? (libdispatch.dylib + 125216) [0x1c4ed7920]
  16  ??? (libsystem_kernel.dylib + 158196) [0x1c50419f4]


Powerstats for:   Anchorwatch [57424]
Bundle ID:        de.sioned.Anchorwatch
Adam ID:          0
Is first party:   No
App version:      2.2.1
Build version:    14
Is Beta:          No
Share with Devs:  No
UUID:             1C943425-70F9-3670-98D0-45D3051B4BB7
Path:             /private/var/containers/Bundle/Application/32CD03B2-449C-4E84-8E06-79FA9B50F3A9/Anchorwatch.app/Anchorwatch
Architecture:     arm64
Footprint:        1046.66 MB
Start time:       2019-11-09 23:25:52 +0200
End time:         2019-11-09 23:26:06 +0200
Num samples:      16 (100%)
CPU Time:         13.971s
Primary state:    15 samples Non-Frontmost App, Non-Suppressed, Kernel mode, Effective Thread QoS Background, Requested Thread QoS Default, Override Thread QoS Unspecified
User Activity:    0 samples Idle, 0 samples Active, 16 samples Unknown
Power Source:     0 samples on Battery, 0 samples on AC, 16 samples Unknown
  16  _pthread_wqthread + 275 (libsystem_pthread.dylib + 49032) [0x1c4f64f88]
    16  _dispatch_workloop_worker_thread + 587 (libdispatch.dylib + 74516) [0x1c4ecb314]
      16  _dispatch_lane_invoke$VARIANT$mp + 419 (libdispatch.dylib + 36344) [0x1c4ec1df8]
        16  _dispatch_lane_serial_drain$VARIANT$mp + 299 (libdispatch.dylib + 33488) [0x1c4ec12d0]
          16  _dispatch_mach_invoke$VARIANT$mp + 471 (libdispatch.dylib + 104312) [0x1c4ed2778]
            16  _dispatch_lane_serial_drain$VARIANT$mp + 759 (libdispatch.dylib + 33948) [0x1c4ec149c]
              16  _dispatch_event_loop_drain$VARIANT$mp + 315 (libdispatch.dylib + 124996) [0x1c4ed7844]
                16  _dispatch_kq_drain + 123 (libdispatch.dylib + 125216) [0x1c4ed7920]
                  16  kevent_id + 8 (libsystem_kernel.dylib + 158196) [0x1c50419f4]
                    1   <User mode>

  Binary Images:
           0x102d80000 -                ???  Anchorwatch             <1C943425-70F9-3670-98D0-45D3051B4BB7>  /private/var/containers/Bundle/Application/32CD03B2-449C-4E84-8E06-79FA9B50F3A9/Anchorwatch.app/Anchorwatch
           0x1c4eb9000 -        0x1c4f2dfff  libdispatch.dylib       <B7EED4C7-560D-3DA6-9B50-ED52A150AAC6>  /usr/lib/system/libdispatch.dylib
           0x1c4f59000 -        0x1c4f69fff  libsystem_pthread.dylib <F8B082D8-24D9-3B1E-B80B-645FC8A88E14>  /usr/lib/system/libsystem_pthread.dylib
           0x1c501b000 -        0x1c5048fff  libsystem_kernel.dylib  <AE4C3D7A-7D08-33E7-BCC6-11AC821B4E48>  /usr/lib/system/libsystem_kernel.dylib

在后台时,应用程序只会将每个位置更新写入 sqlite 数据库并根据安全边界检查当前位置。没有理由假设应用程序在几个小时后突然需要如此高的 CPU 使用率。

我一点也不知道如何解决这个问题,我什至不确定我是否可以对此做任何事情,或者它是否是 13.2 中的一个错误,我必须等待修复。

我的第一个假设是,旧的 iOS 12.0 错误会无故终止后台应用程序并在 12.2 中修复。但这似乎是新事物。我能够在几天内无缘无故地运行测试应用程序 iOS 12 在后台终止应用程序。

任何提示如何解释日志并采取行动?

编辑:

看来,这与iOS 13.2 消息有关:nehelper sent invalid result code [1] for Wi-Fi information request

定位服务以秒为间隔查询 WiFi 接口。Instrument 显示这些查询调用存在内存泄漏。

关闭设备上的 WiFi 似乎可以解决问题,但这并不是真正的解决方案。现在等待 iOS 13.3 离开测试版。

4

1 回答 1

1

事实证明,我正在使用的第三方框架会在第二个间隔内启动对 CNCopyNetworkInfo 的调用。这些调用无法完成,因为我的应用程序没有启用 WiFi 功能,因此对 CNCopyNetworkInfo 的调用导致随着时间的推移累积的小内存泄漏。

启用 WiFi 访问功能后,内存泄漏消失了。

于 2019-11-22T17:55:38.323 回答