目录

应用前台使用时发生闪退,或在后台时退出

问题现象

在前台使用过程中,应用出现闪退,或是应用在后台时,程序终止。

背景知识

问题定位

  1. 从faultlogger目录下查看并无带有应用包名的故障日志。
  2. 从memory_leak目录下查看并无带有应用包名的故障日志。
  3. 在hilog日志下查看故障发生时间日志,搜索kill reason|kill_reason|kill.*【应用包名】,发现有带有应用包名的应用被终止。
    • 终止原因是:LowMemoryKill,低内存。

      priority代表终止优先级,0代表前台应用,从高到低依次终止。

      kill_reason=LowMemoryKill, killing proc[pid=xxx, uid=xxx, procName=com.hx.example, priority=xxx type=x], freedBuf=xxx
    • 终止原因是:StabilityCheckKill,低内存。

      StabilityCheckKill是6.0新增的memmgr终止机制,区别LowMemoryKill仅包含能快速回收的内存,可以提供给用户态使用。

      KillOneProcessByPid process com.hx.example has been Killed, isAncoApp=0, errno=0, pid=23348, freedSize=5391580 KB, rssKB:222888, rssAnonKB:107760, dmaKB:5164672, gpuKB=119148, pssKB=0, childrenFreedKB=0, useAmsKill=0, amsKillResult=-1, useBrokerKill=0, brokerKillResult=-1, useMemmgrKill=1, memmgrKillResult=0, reason=StabilityCheckKill
    • 终止原因是:SWAP_FULL,虚拟内存满。

      同LowMemoryKill,根据priority,从优先级最低的应用进行终止。

      C02699/memmgrservice/MemMgr: KillHelper::WriteKillEvent hisysevent write result=0, send event [FRAMEWORK,PROCESS_KILL], pid=36844, processName=com.hx.example, msg=Kill reason: SWAP_FULL; Current buffer is: 1683456; Freed buffer is: 85436; Killed process [uid is: 20020277, priority is: 382, type is: 3, diffTimeMs is: 1156471], foreground=0

      参考文档获取进程内存信息,找到占用SWAP内存最大的应用,再通过Profiler工具中的Snapshot模板,排查是否存在可疑的泄漏对象。

    • 终止原因是:ILLEGAL_AUDIO_RENDERER_BY_SUSPEND,后台非法放音。
      C01713/resource_schedule_service/SUSPEND_MANAGER: [(ReportKillAppEvent):267] hisysevent write result=0, send event [FRAMEWORK,PROCESS_KILL], pid=30627, processName=com.hm.example, msg=Kill Reason:ILLEGAL_AUDIO_RENDERER_BY_SUSPEND
    • 终止原因是:ILLEGAL_AUDIO_CAPTURER_BY_SUSPEND,后台非法录音。
      C01713/resource_schedule_service/SUSPEND_MANAGER: [(ReportKillAppEvent):277] hisysevent write result=0, send event [FRAMEWORK,PROCESS_KILL], pid=64424, processName=com.hm.example, msg=Kill Reason:ILLEGAL_AUDIO_CAPTURER_BY_SUSPEND, foreground=0
    • 终止原因是:Power Save Clean,整机切换到省电模式或应急模式。
      C01336/foundation/AMS: [app_exit_reason_data_manager.cpp:220]current bundle name: com.hx.example, tokenId:<private>, reason: 6,  exitMsg: Kill Reason:Power Save Clean, abilityName:EntryAbility isSetReason:1
    • 终止原因是:CPU Highload,CPU高负载。
      C01716/resource_schedule_service/RESOURCE_QUOTA_CONTROL: [a92ab77a9eb01c1 0 0][KillApplication:158] hisysevent write result=0, send event [FRAMEWORK,PROCESS_KILL], uid=1000080, pid=38811, processName=com.hx.example:render, KillReason=Kill Reason:CPU Highload, Msg=, FOREGROUND=0

分析结论

修改建议