Skip to content

Commit 0f353e6

Browse files
chzhij5txfelixzhou
authored andcommitted
耗电监控 (Tencent#305)
* fix(KSCrash): fix logical error preventing queue names collecting kstenerud/KSCrash@5a0569b#diff-492007156e854f9181d731e3dd1eca69 * refactor(KSCrash): refine the system info dict * chore(AppReboot): rearrange rebootType * refactor(CrashBlock): rename the method to get the custom user info * feat(PowerConsume): get the "power-cosuming" calltree of App feat(BatteryCost): add “Battery Cost Stack” collector feat(BatteryCost): the control configuration of getting the battery cost stack feat(BatteryCost): adjust the algorithm to get the battery cost stack perf(BatteryCost): refine the “battery cost” report json feat(BatteryCost): sort the battery-cost-stack tree fix(BatterCost): get info dict with null cstring fix(BatteryCost): do not use oc object after thread_suspend style(BatteryCost): empty warnings, batteryCostStackString-> batteryCostStackArray feat(BatteryCost): add configuration of CPU limit of Battery-Cost-Stack style(BatteryCost): rename “BatterCost” to “PowerConsume” refactor(PowerConsume): add default value for “PowerConsume” CPU limit fix(PowerConsume): modify the algorithm fix(PowerConsume): do not access memory during suspend of thread chore(BatterCost): warning -> debug * feat(CrashBlock): add crash & lag report controll * feat(MemStat): add report strategy * feat(CrashBlock): report crash to no crash report * feat(CrashBlock): add method to know if there are lag files * perf(CrashBlock): crash & lag report more reliable * chore(BlockMonitor): redundant code * restore logger on writing thread before disable memory logging * fix disable memory logging时,主线程“死锁”的问题 * perf(PowerConsume): optimize the method to get power-consuming stack * fix(PowerCoumse): make call tree bug * perf(PowerConsume): calltree redegisn; add repeat-weight; do not collect the stack of the collection thread a. do not collect the stack of the collecting thread b. calltree redesign c. repeat weight * feat(BlockMontiory): check thread print the memory use * feat(KSCrash): fish_hook __cxa_throw * fix(KSCrash): NSException caunght by cpp handler, it deserves a better solution. * Updae KSCrash (The lastest commit following is c63d42bec08c2c9859537f442cdfbc6a653fb3c2 in master branch) Squashed commit of the following: commit 41929b7bfee7b70d4c362c97159877babddbc279 Author: johnzjchen <johnzjchen@tencent.com> Date: Wed Jul 10 14:46:56 2019 +0800 update commit c3ccb28cb6c2e02d7c1159e8846e4d773954ff64 Author: Alexander Belyavskiy <diejmon@gmail.com> Date: Fri Jun 14 08:59:27 2019 +0300 Handle task_threads return status Similar to show it is done in all the other places. commit 4dc1a0b0878089859967ae0d462f7e17dd11f28c Author: Alexander Belyavskiy <diejmon@gmail.com> Date: Fri Jun 14 08:29:51 2019 +0300 Fix memory leak in printPreviousLog commit 492358b54d29a924ae45edc4c6785c72e2949559 Author: Gleb Linnik <glinnik@yandex-team.ru> Date: Wed May 22 14:01:07 2019 +0300 refactor to meet code review requirements commit aa735662ee1cb4e666b6a2c2de7fe1bb089724d5 Author: Gleb Linnik <glinnik@yandex-team.ru> Date: Wed May 22 13:24:22 2019 +0300 fix activeDurationSinceLaunch In case if KSCrash was activated after application has become active # Conflicts: # matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/KSCrash/Recording/KSCrashC.c commit 22e9e8f5a133b4b96a900b35cd70c873e5fad25e Author: xiejunyi <xie.junyi@outlook.com> Date: Tue May 7 15:39:34 2019 +0800 fix lr causes the call stack inaccurate commit 46d5292038b1b22a87dc5a8a22b88d487767883b Author: xiejunyi <xiejunyi@bytedance.com> Date: Fri Mar 8 19:51:37 2019 +0800 fix ksmc_suspendEnvironment() deaklock commit fe07944e504c67dddd74667da3ef252c1ff88d91 Author: Karl Stenerud <kstenerud@gmail.com> Date: Thu Feb 28 08:39:53 2019 +0100 Version # Conflicts: # KSCrash.podspec # matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/KSCrash/Recording/KSCrash.m commit ffca09510bdc4c3f9f1e299b899d603c89c5a7fb Author: Peter Hedlund <phedlund@dexcom.com> Date: Wed Feb 27 08:52:16 2019 -0800 Add null check to prevent crashes on watchOS. commit 3ae055d793cf13b18a3b123d0e299476994d4c52 Author: xiejunyi <xiejunyi@bytedance.com> Date: Thu Feb 21 18:57:41 2019 +0800 fix create multiple threads to update kscrash cached data commit 27e258263d489042de0c1d551407e2bc7637a079 Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Wed Feb 13 12:44:01 2019 +0300 add missing static modifier for internal functions commit 323d50700c51db80572e22d1237827e4d4a7d24a Author: Gleb Linnik <glinnik@yandex-team.ru> Date: Mon Feb 11 12:09:40 2019 +0300 fix active_duration_since_launch commit 6239e0b3464e45ef1937547300662d0850e68045 Author: ziyu.zhang <ziyu.zhang@tendcloud.com> Date: Mon Dec 17 18:02:20 2018 +0800 try to explain why the framewalker works well in arm64 Change-Id: I898a69ad45f52af892c25850e31a718699596f85 commit cdcffaa6f99d57dd8c2674867bf4b5c2a273a16f Author: 王志宇 <wangzhiyu@meituan.com> Date: Mon Oct 29 00:38:27 2018 +0800 Git rid of ARM64e's PAC from return address pointer. commit fef024bdd2f6e2c5645f86b2508838b9b009e57a Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Wed Oct 17 19:53:05 2018 +0300 fix setSearchQueueNames argument type commit 76e316e4be797eeb3f05001b50909fc82056e518 Author: Zuikyo <zuilongzhizhu@gmail.com> Date: Wed Oct 10 14:57:59 2018 +0800 fix ISA_MASK in different iOS version commit 82a8e6cd9db504d3c23bed0ab088918836055b39 Author: Zuik <zuikxyo@gmail.com> Date: Tue Oct 9 22:22:55 2018 +0800 fix ISA_MASK commit 0f9fb53ddc361689b332c263d957c99698beb19d Author: Kevin Tardif <ktardif@reol.com> Date: Tue Sep 25 16:27:48 2018 -0400 Added missing args to KSLOG_ERROR in KSFileUtil utility functions commit 8eec7f98f08fffc22855f88995673d119781100c Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Wed May 16 20:08:14 2018 +0300 fix setCatchZombies method commit 12f7afb5f8d69fb8b41064fe0cfa93951c3d5bd5 Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Wed May 16 19:39:25 2018 +0300 disable queue names searching by default commit 7db774a35d1eebaf16ea1fe81fb6732c82139fb3 Author: langyanduan <langyanduan@gmail.com> Date: Wed May 16 10:56:59 2018 +0800 fixed kstenerud/KSCrash#278 # Conflicts: # matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/KSCrash/Recording/KSCrashCachedData.c commit cd92a5e2eefb0cf0b950bb9db06e89c7c5048f22 Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Sat Mar 3 09:42:21 2018 +0300 fix global variables commit 2b31af18583ef5a8ef2dfe16d7c12acf62da0b07 Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Mon Feb 26 14:03:51 2018 +0300 fix logical error preventing queue names collecting commit cc6fdc9482c593574c6bc73441fae5f93a049142 Author: johnzjchen <johnzjchen@tencent.com> Date: Wed Jul 10 11:43:25 2019 +0800 Revert "fix(KSCrash): fix logical error preventing queue names collecting" This reverts commit ace2598. commit 30ee08a573ea7bc26fea62705f3d9a8f4db8093c Author: Stephen Zhang <stephenxtddd@gmail.com> Date: Fri Dec 22 20:23:25 2017 +0800 Update KSCrashMonitor_Signal.c Reset g_signalStack to initial value in uninstallSignalHandler. commit d7ec741474e73d63ce0514850eeb501efdb865c5 Author: Stephen Zhang <stephenxtddd@gmail.com> Date: Fri Dec 22 20:20:23 2017 +0800 Update KSCrashMonitor_MachException.c Reset g_exceptionPort to initial value in uninstallExceptionHandler, otherwise when reinstall the monitor, this monitor cannot response to mach exception, and the app will be frozen. commit 170fbe61a8c42b76da7c0d6e2fdd23c3b6d7c8ea Author: johnzjchen <johnzjchen@tencent.com> Date: Wed Jul 10 11:33:54 2019 +0800 Clear up some warnings commit 439c58e1e502c4e448ed9aefc76f79448d321f69 Author: Nikolay Volosatov <bamx23@yandex-team.ru> Date: Fri Nov 17 13:42:12 2017 +0300 custom-base-path: add constructor with custom base path commit 2f88875e2661236fd3ef0a3cf9e460d2ec97d05a Author: Yehoshua Nagel <yehoshua@grocerkey.com> Date: Sun Sep 10 11:21:36 2017 +0300 Update KSLogger.h The NONE macro conflicts with other macros in other SDKs. Renaming to be more specific commit fc27e83f401f56065e783957f8e556b021ba6a15 Author: Daniel Griesser <daniel.griesser.86@gmail.com> Date: Thu Aug 31 12:28:37 2017 +0200 Expose uncaughtExceptionHandler as property in KSCrash * feat(KSCrash): report the thread name * docs(PowerConsume): script * test(Sample): update sample
1 parent 68d7507 commit 0f353e6

File tree

65 files changed

+2814
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2814
-469
lines changed

matrix/matrix-iOS/Matrix/Matrix.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1110CEAE228D8BF7002E7353 /* WCPowerConsumeStackCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 1110CEAC228D8BF6002E7353 /* WCPowerConsumeStackCollector.h */; };
11+
1110CEAF228D8BF7002E7353 /* WCPowerConsumeStackCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 1110CEAC228D8BF6002E7353 /* WCPowerConsumeStackCollector.h */; };
12+
1110CEB0228D8BF7002E7353 /* WCPowerConsumeStackCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1110CEAD228D8BF6002E7353 /* WCPowerConsumeStackCollector.mm */; };
13+
1110CEB1228D8BF7002E7353 /* WCPowerConsumeStackCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1110CEAD228D8BF6002E7353 /* WCPowerConsumeStackCollector.mm */; };
1014
1110E02A2243388500A873F9 /* WCFilterStackHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1110E0282243388500A873F9 /* WCFilterStackHandler.h */; };
1115
1110E02B2243388500A873F9 /* WCFilterStackHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1110E0292243388500A873F9 /* WCFilterStackHandler.mm */; };
1216
1110E02D22433D2B00A873F9 /* WCFilterStackHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1110E0282243388500A873F9 /* WCFilterStackHandler.h */; };
@@ -383,6 +387,10 @@
383387
1177FFF32137A53300FDFEB4 /* MatrixTester.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1177FFE421379FE800FDFEB4 /* MatrixTester.mm */; };
384388
11B438EE21F17C6600A0A8C3 /* WCCrashBlockMonitorPlugin+Upload.h in Headers */ = {isa = PBXBuildFile; fileRef = 11B438EC21F17C6600A0A8C3 /* WCCrashBlockMonitorPlugin+Upload.h */; settings = {ATTRIBUTES = (Public, ); }; };
385389
11B438F121F17C7000A0A8C3 /* WCCrashBlockMonitorPlugin+Upload.h in Headers */ = {isa = PBXBuildFile; fileRef = 11B438EC21F17C6600A0A8C3 /* WCCrashBlockMonitorPlugin+Upload.h */; settings = {ATTRIBUTES = (Public, ); }; };
390+
11B71A4B22F45A1F004A7212 /* KSCrash_fishhook.c in Sources */ = {isa = PBXBuildFile; fileRef = 11B71A4922F45A1F004A7212 /* KSCrash_fishhook.c */; };
391+
11B71A4C22F45A1F004A7212 /* KSCrash_fishhook.h in Headers */ = {isa = PBXBuildFile; fileRef = 11B71A4A22F45A1F004A7212 /* KSCrash_fishhook.h */; };
392+
11B71A4D22F45A35004A7212 /* KSCrash_fishhook.c in Sources */ = {isa = PBXBuildFile; fileRef = 11B71A4922F45A1F004A7212 /* KSCrash_fishhook.c */; };
393+
11B71A4E22F45A39004A7212 /* KSCrash_fishhook.h in Headers */ = {isa = PBXBuildFile; fileRef = 11B71A4A22F45A1F004A7212 /* KSCrash_fishhook.h */; };
386394
93DD5872225F3731005C267C /* bundle_name_helper.h in Headers */ = {isa = PBXBuildFile; fileRef = 93DD5870225F3731005C267C /* bundle_name_helper.h */; };
387395
93DD5873225F3731005C267C /* bundle_name_helper.h in Headers */ = {isa = PBXBuildFile; fileRef = 93DD5870225F3731005C267C /* bundle_name_helper.h */; };
388396
93DD5874225F3731005C267C /* bundle_name_helper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93DD5871225F3731005C267C /* bundle_name_helper.mm */; };
@@ -532,6 +540,8 @@
532540
/* End PBXBuildFile section */
533541

534542
/* Begin PBXFileReference section */
543+
1110CEAC228D8BF6002E7353 /* WCPowerConsumeStackCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WCPowerConsumeStackCollector.h; sourceTree = "<group>"; };
544+
1110CEAD228D8BF6002E7353 /* WCPowerConsumeStackCollector.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WCPowerConsumeStackCollector.mm; sourceTree = "<group>"; };
535545
1110E0282243388500A873F9 /* WCFilterStackHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WCFilterStackHandler.h; sourceTree = "<group>"; };
536546
1110E0292243388500A873F9 /* WCFilterStackHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WCFilterStackHandler.mm; sourceTree = "<group>"; };
537547
11203FA920EE10A20022FF96 /* MatrixDeviceInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MatrixDeviceInfo.h; sourceTree = "<group>"; };
@@ -724,6 +734,8 @@
724734
1177FFE321379FE800FDFEB4 /* MatrixTester.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MatrixTester.h; sourceTree = "<group>"; };
725735
1177FFE421379FE800FDFEB4 /* MatrixTester.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MatrixTester.mm; sourceTree = "<group>"; };
726736
11B438EC21F17C6600A0A8C3 /* WCCrashBlockMonitorPlugin+Upload.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WCCrashBlockMonitorPlugin+Upload.h"; sourceTree = "<group>"; };
737+
11B71A4922F45A1F004A7212 /* KSCrash_fishhook.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = KSCrash_fishhook.c; sourceTree = "<group>"; };
738+
11B71A4A22F45A1F004A7212 /* KSCrash_fishhook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSCrash_fishhook.h; sourceTree = "<group>"; };
727739
11E683E52103231D00E4EADC /* NSApplicationEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSApplicationEvent.h; sourceTree = "<group>"; };
728740
11E683E62103231D00E4EADC /* NSApplicationEvent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSApplicationEvent.mm; sourceTree = "<group>"; };
729741
93DD5870225F3731005C267C /* bundle_name_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bundle_name_helper.h; sourceTree = "<group>"; };
@@ -994,6 +1006,8 @@
9941006
114E67F620AAC0CE0045083D /* KSCrashMonitor_AppState.h */,
9951007
114E67F720AAC0CE0045083D /* KSCrashMonitor_CPPException.cpp */,
9961008
114E67F820AAC0CE0045083D /* KSCrashMonitor_CPPException.h */,
1009+
11B71A4A22F45A1F004A7212 /* KSCrash_fishhook.h */,
1010+
11B71A4922F45A1F004A7212 /* KSCrash_fishhook.c */,
9971011
114E67F920AAC0CE0045083D /* KSCrashMonitor_Deadlock.h */,
9981012
114E67FA20AAC0CE0045083D /* KSCrashMonitor_Deadlock.m */,
9991013
114E67FB20AAC0CE0045083D /* KSCrashMonitor_MachException.c */,
@@ -1187,6 +1201,8 @@
11871201
children = (
11881202
114E687020AAC0CE0045083D /* WCCPUHandler.h */,
11891203
114E687120AAC0CE0045083D /* WCCPUHandler.mm */,
1204+
1110CEAC228D8BF6002E7353 /* WCPowerConsumeStackCollector.h */,
1205+
1110CEAD228D8BF6002E7353 /* WCPowerConsumeStackCollector.mm */,
11901206
114E687F20AAC0CE0045083D /* WCGetMainThreadUtil.h */,
11911207
114E688020AAC0CE0045083D /* WCGetMainThreadUtil.mm */,
11921208
114E687420AAC0CE0045083D /* WCMainThreadHandler.h */,
@@ -1473,6 +1489,7 @@
14731489
116461052111AF190069B5DE /* KSDate.h in Headers */,
14741490
116461062111AF190069B5DE /* Optional.h in Headers */,
14751491
BB77AD4A22368582008C67D9 /* prettywriter.h in Headers */,
1492+
1110CEAE228D8BF7002E7353 /* WCPowerConsumeStackCollector.h in Headers */,
14761493
BB77AD8622368582008C67D9 /* dtoa.h in Headers */,
14771494
116461182111AF190069B5DE /* KSCrashMonitorType.h in Headers */,
14781495
116461072111AF190069B5DE /* KSCrashMonitor_System.h in Headers */,
@@ -1523,6 +1540,7 @@
15231540
1164612A2111AF190069B5DE /* WCDumpReportTaskData.h in Headers */,
15241541
1164612D2111AF190069B5DE /* KSCrashMonitor_NSException.h in Headers */,
15251542
BB77AD1222368582008C67D9 /* memory_logging.h in Headers */,
1543+
11B71A4C22F45A1F004A7212 /* KSCrash_fishhook.h in Headers */,
15261544
BB77AD5222368582008C67D9 /* encodedstream.h in Headers */,
15271545
116461302111AF190069B5DE /* KSCrashMonitor_AppState.h in Headers */,
15281546
116461312111AF190069B5DE /* WCCPUHandler.h in Headers */,
@@ -1642,6 +1660,7 @@
16421660
1166068521369E1E00F4ED74 /* KSCrash.h in Headers */,
16431661
1166068B21369E1E00F4ED74 /* NSError+SimpleConstructor.h in Headers */,
16441662
1166068C21369E1E00F4ED74 /* NSApplicationEvent.h in Headers */,
1663+
1110CEAF228D8BF7002E7353 /* WCPowerConsumeStackCollector.h in Headers */,
16451664
1166068D21369E1E00F4ED74 /* Demangle.h in Headers */,
16461665
BB77AD0C22368582008C67D9 /* dyld_image_info.h in Headers */,
16471666
1166068E21369E1E00F4ED74 /* KSDate.h in Headers */,
@@ -1692,6 +1711,7 @@
16921711
116606B321369E1E00F4ED74 /* WCDumpReportTaskData.h in Headers */,
16931712
116606B621369E1E00F4ED74 /* KSCrashMonitor_NSException.h in Headers */,
16941713
BB77AD1422368582008C67D9 /* memory_logging.h in Headers */,
1714+
11B71A4E22F45A39004A7212 /* KSCrash_fishhook.h in Headers */,
16951715
BB77AD5422368582008C67D9 /* encodedstream.h in Headers */,
16961716
116606B921369E1E00F4ED74 /* KSCrashMonitor_AppState.h in Headers */,
16971717
116606BA21369E1E00F4ED74 /* WCCPUHandler.h in Headers */,
@@ -1897,6 +1917,7 @@
18971917
93DD5874225F3731005C267C /* bundle_name_helper.mm in Sources */,
18981918
116460C52111AF190069B5DE /* KSJSONCodec.c in Sources */,
18991919
116460C62111AF190069B5DE /* KSSysCtl.c in Sources */,
1920+
1110CEB0228D8BF7002E7353 /* WCPowerConsumeStackCollector.mm in Sources */,
19001921
116460C72111AF190069B5DE /* KSCrashMonitor_NSException.m in Sources */,
19011922
BB77ACFA22368582008C67D9 /* memory_report_generator.cpp in Sources */,
19021923
116460C92111AF190069B5DE /* KSCrashC.c in Sources */,
@@ -1913,6 +1934,7 @@
19131934
116460D12111AF190069B5DE /* WCGetCallStackReportHandler.mm in Sources */,
19141935
116460D22111AF190069B5DE /* MatrixPluginConfig.mm in Sources */,
19151936
116460D32111AF190069B5DE /* KSSignalInfo.c in Sources */,
1937+
11B71A4B22F45A1F004A7212 /* KSCrash_fishhook.c in Sources */,
19161938
116460D42111AF190069B5DE /* KSCrashMonitor_System.m in Sources */,
19171939
116460D52111AF190069B5DE /* KSFileUtils.c in Sources */,
19181940
BB77ACFE22368582008C67D9 /* dyld_image_info.cpp in Sources */,
@@ -2003,6 +2025,7 @@
20032025
93DD5875225F3731005C267C /* bundle_name_helper.mm in Sources */,
20042026
1166065221369E1E00F4ED74 /* KSCrashMonitor_NSException.m in Sources */,
20052027
1110E0322243741500A873F9 /* WCFilterStackHandler.mm in Sources */,
2028+
1110CEB1228D8BF7002E7353 /* WCPowerConsumeStackCollector.mm in Sources */,
20062029
BB77ACFC22368582008C67D9 /* memory_report_generator.cpp in Sources */,
20072030
1166065421369E1E00F4ED74 /* KSCrashC.c in Sources */,
20082031
1166065521369E1E00F4ED74 /* KSCrashReport.c in Sources */,
@@ -2019,6 +2042,7 @@
20192042
1166065D21369E1E00F4ED74 /* MatrixPluginConfig.mm in Sources */,
20202043
1166065E21369E1E00F4ED74 /* KSSignalInfo.c in Sources */,
20212044
1166065F21369E1E00F4ED74 /* KSCrashMonitor_System.m in Sources */,
2045+
11B71A4D22F45A35004A7212 /* KSCrash_fishhook.c in Sources */,
20222046
1166066021369E1E00F4ED74 /* KSFileUtils.c in Sources */,
20232047
BB77AD0022368582008C67D9 /* dyld_image_info.cpp in Sources */,
20242048
1166066121369E1E00F4ED74 /* WCCrashReportInfoUtil.mm in Sources */,

matrix/matrix-iOS/Matrix/Matrix/AppReboot/MatrixAppRebootType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ typedef enum : NSUInteger {
2626
MatrixAppRebootTypeQuitByExit,
2727
MatrixAppRebootTypeQuitByUser,
2828
MatrixAppRebootTypeAppSuspendOOM, // OOM, out of memory
29-
MatrixAppRebootTypeAppSuspendCrash,
3029
MatrixAppRebootTypeAppBackgroundOOM,
3130
MatrixAppRebootTypeAppForegroundOOM,
32-
MatrixAppRebootTypeAppForegroundDeadLoop,
3331
MatrixAppRebootTypeOtherReason,
32+
MatrixAppRebootTypeAppForegroundDeadLoop,
33+
MatrixAppRebootTypeAppSuspendCrash,
3434
} MatrixAppRebootType;
3535

3636
#endif /* MatrixAppRebootType_h */

matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/CrashBlockPlugin/Main/BlockMonitor/Handler/WCCPUHandler.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
@interface WCCPUHandler : NSObject
2020

21+
- (id)initWithCPULimit:(float)cpuLimit;
22+
23+
2124
- (BOOL)cultivateCpuUsage:(float)cpuUsage periodTime:(float)periodSec;
2225

2326
/**
@@ -26,12 +29,4 @@
2629
*/
2730
- (BOOL)isBackgroundCPUTooSmall;
2831

29-
/**
30-
* get current CPU usage
31-
*
32-
* @return current cpu usage. Single core is full 100%, dual core is full 200%, and so on.
33-
*/
34-
+ (float)getCurrentCpuUsage;
35-
36-
3732
@end

matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/CrashBlockPlugin/Main/BlockMonitor/Handler/WCCPUHandler.mm

Lines changed: 61 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@
2828

2929
#import "MatrixLogDef.h"
3030

31-
#define kForegroundOverEightySecLimit 60 // foreground CPU over 80%.
32-
#define kBakcgroundOverEightySecLimit 60 // background CPU over 80%.
33-
#define TICK_TOCK_COUNT 60
31+
static float kOverCPULimit = 80.;
32+
static float kOverCPULimitSecLimit = 60.;
33+
static int TICK_TOCK_COUNT = 60;
3434

3535
@interface WCCPUHandler () {
3636
NSUInteger m_tickTok;
37+
38+
float m_totalCPUCost;
39+
float m_totalTrackingTime;
40+
BOOL m_bTracking;
3741

38-
BOOL m_bLastOverEighty;
39-
float m_foregroundOverEightyTotalSec;
40-
float m_backgroundOverEightyTotalSec;
4142
float m_backgroundTotalCPU;
4243
float m_backgroundTotalSec;
4344
BOOL m_background;
@@ -49,13 +50,21 @@ @interface WCCPUHandler () {
4950
@implementation WCCPUHandler
5051

5152
- (id)init
53+
{
54+
return [self initWithCPULimit:80.];
55+
}
56+
57+
- (id)initWithCPULimit:(float)cpuLimit
5258
{
5359
self = [super init];
5460
if (self) {
61+
kOverCPULimit = cpuLimit;
62+
5563
m_tickTok = 0;
56-
m_bLastOverEighty = NO;
57-
m_foregroundOverEightyTotalSec = 0;
58-
m_backgroundOverEightyTotalSec = 0;
64+
m_bTracking = NO;
65+
66+
m_totalTrackingTime = 0.;
67+
m_totalCPUCost = 0.;
5968

6069
m_background = NO;
6170
m_backgroundTotalCPU = 0.;
@@ -94,63 +103,74 @@ - (void)didEnterBackground
94103
}
95104

96105
// ============================================================================
97-
#pragma mark - CPU Related -
106+
#pragma mark - CPU Related
98107
// ============================================================================
99108

100109
- (BOOL)isBackgroundCPUTooSmall
101110
{
102111
return m_backgroundCPUTooSmall;
103112
}
104113

114+
// run on the check child thread
105115
- (BOOL)cultivateCpuUsage:(float)cpuUsage periodTime:(float)periodSec
106116
{
107117
[self cultivateBackgroundCpu:cpuUsage periodTime:periodSec];
108118

119+
if (periodSec < 0 || periodSec > 5.) {
120+
MatrixDebug(@"abnormal period sec : %f", periodSec);
121+
return NO;
122+
}
123+
109124
if (m_tickTok > 0) {
110125
m_tickTok -= 1; // Annealing algorithm
111126
if (m_tickTok == 0) {
112127
MatrixInfo(@"tick tok over");
113128
}
129+
return NO;
114130
}
115131

116-
if (cpuUsage > 80. && m_tickTok == 0 && m_bLastOverEighty == NO) {
132+
if (cpuUsage > kOverCPULimit && m_bTracking == NO) {
117133
MatrixInfo(@"start track cpu usage");
118-
m_foregroundOverEightyTotalSec = 0;
119-
m_backgroundOverEightyTotalSec = 0;
120-
m_bLastOverEighty = YES;
134+
m_totalCPUCost = 0.;
135+
m_totalTrackingTime = 0.;
136+
m_bTracking = YES;
137+
}
138+
139+
if (m_bTracking == NO) {
140+
return NO;
121141
}
122-
if (cpuUsage <= 80. && m_bLastOverEighty == YES) {
142+
143+
m_totalTrackingTime += periodSec;
144+
m_totalCPUCost += periodSec * cpuUsage;
145+
146+
float halfCPUZone = kOverCPULimit * m_totalTrackingTime / 2.;
147+
148+
if (m_totalCPUCost < halfCPUZone) {
123149
MatrixInfo(@"stop track cpu usage");
124-
m_foregroundOverEightyTotalSec = 0;
125-
m_backgroundOverEightyTotalSec = 0;
126-
m_bLastOverEighty = NO;
150+
m_totalCPUCost = 0.;
151+
m_totalTrackingTime = 0.;
152+
m_bTracking = NO;
153+
return NO;
127154
}
128155

129-
BOOL exceedLimit = NO;
130-
if (m_bLastOverEighty && m_tickTok == 0) {
131-
if (m_background) {
132-
m_foregroundOverEightyTotalSec = 0;
133-
m_backgroundOverEightyTotalSec += periodSec;
134-
if (m_backgroundOverEightyTotalSec > kBakcgroundOverEightySecLimit) {
135-
MatrixInfo(@"background, exceed cpu limit");
136-
exceedLimit = YES;
137-
}
138-
} else {
139-
m_backgroundOverEightyTotalSec = 0;
140-
m_foregroundOverEightyTotalSec += periodSec;
141-
if (m_foregroundOverEightyTotalSec > kForegroundOverEightySecLimit) {
142-
MatrixInfo(@"foreground, exceed cpu limit");
143-
exceedLimit = YES;
144-
}
156+
if (m_totalTrackingTime >= kOverCPULimitSecLimit) {
157+
BOOL exceedLimit = NO;
158+
float fullCPUZone = halfCPUZone + halfCPUZone;
159+
if (m_totalCPUCost > fullCPUZone) {
160+
MatrixInfo(@"exceed cpu limit");
161+
exceedLimit = YES;
145162
}
163+
164+
if (exceedLimit) {
165+
m_totalCPUCost = 0;
166+
m_totalTrackingTime = 0.;
167+
m_bTracking = NO;
168+
m_tickTok += TICK_TOCK_COUNT;
169+
}
170+
return exceedLimit;
146171
}
147-
if (exceedLimit) {
148-
m_foregroundOverEightyTotalSec = 0;
149-
m_backgroundOverEightyTotalSec = 0;
150-
m_tickTok += TICK_TOCK_COUNT;
151-
}
152-
153-
return exceedLimit;
172+
173+
return NO;
154174
}
155175

156176
- (void)cultivateBackgroundCpu:(float)cpuUsage periodTime:(float)periodSec
@@ -173,60 +193,4 @@ - (void)cultivateBackgroundCpu:(float)cpuUsage periodTime:(float)periodSec
173193
m_backgroundTotalSec += periodSec;
174194
}
175195

176-
177-
+ (float)getCurrentCpuUsage
178-
{
179-
kern_return_t kr;
180-
task_info_data_t tinfo;
181-
mach_msg_type_number_t task_info_count;
182-
183-
task_info_count = TASK_INFO_MAX;
184-
kr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t) tinfo, &task_info_count);
185-
if (kr != KERN_SUCCESS) {
186-
return -1;
187-
}
188-
189-
thread_array_t thread_list;
190-
mach_msg_type_number_t thread_count;
191-
192-
thread_info_data_t thinfo;
193-
mach_msg_type_number_t thread_info_count;
194-
195-
thread_basic_info_t basic_info_th;
196-
197-
// get threads in the task
198-
kr = task_threads(mach_task_self(), &thread_list, &thread_count);
199-
if (kr != KERN_SUCCESS) {
200-
return -1;
201-
}
202-
203-
long tot_sec = 0;
204-
long tot_usec = 0;
205-
float tot_cpu = 0;
206-
int j;
207-
208-
for (j = 0; j < thread_count; j++) {
209-
thread_info_count = THREAD_INFO_MAX;
210-
kr = thread_info(thread_list[j], THREAD_BASIC_INFO,
211-
(thread_info_t) thinfo, &thread_info_count);
212-
if (kr != KERN_SUCCESS) {
213-
return -1;
214-
}
215-
216-
basic_info_th = (thread_basic_info_t) thinfo;
217-
218-
if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {
219-
tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
220-
tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;
221-
tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float) TH_USAGE_SCALE * 100.0;
222-
}
223-
224-
} // for each thread
225-
226-
kr = vm_deallocate(mach_task_self(), (vm_offset_t) thread_list, thread_count * sizeof(thread_t));
227-
assert(kr == KERN_SUCCESS);
228-
229-
return tot_cpu;
230-
}
231-
232196
@end

0 commit comments

Comments
 (0)