iOS uses Metrickit to collect crash logs

iOS uses Metrickit to collect crash logs

What is Metrickit

MetricKit is a tool introduced by Apple in iOS 13 that aggregates and analyzes reports on each device regarding exception and crash diagnostics as well as power and performance metrics.

Why use MetricKit to collect crash logs

Currently, some open source frameworks on the market, such as KSCrash and PLCrashReport, cannot capture some crashes. For example, PLCrashReport cannot capture stack overflow crashes, SIGKILL, SIGQUIT and other signal crashes. KSCrash can only capture part of SIGKILL crashes.

Metrickit flaws

  • Currently only supports crash log collection after iOS14
  • The crash log does not return the specific crash time and startup time, and the crash scene information does not contain any other information except the stack.
  • If segment migration compilation technology is used, the address and uuid of the main program macho cannot match.

The crash log of iOS14 will be called back once every 24 hours, which has low timeliness. After iOS15, the crash log will be returned after the next startup, but it has been verified that some will be called back immediately, while others will not, and the pattern is unpredictable.

Start access

1. Add MetricKit

2. Add MetricKit listeners

 if ( @ available ( iOS 14.0 , * )) {

MXMetricManager * manager = [ MXMetricManager sharedManager ];

if ( self && manager && [ manager respondsToSelector : @ selector ( addSubscriber :)]) {

[ manager addSubscriber : self ];

}

}

3. The listener implements the MXMetricManagerSubscriber protocol method. The payloadDic contains the last crash log stack and information of this application.

 // If Apple has data, it will call back after registering the monitor

- ( void ) didReceiveDiagnosticPayloads :( NSArray < MXDiagnosticPayload * > * _Nonnull ) payloads API_AVAILABLE ( ios ( 14.0 )) {

if ( @ available ( iOS 14.0 , * )) {

for ( MXDiagnosticPayload * payload in payloads ) {

NSDictionary * payloadDic = [ payload dictionaryRepresentation ];



});

}

}

}

4. Log assembly key code examples

 NSArray * callStackRootFrames = [ dicFrame ArrayValueForKey : kMetrkitCallStackRootFramesKey ];

if ( callStackRootFrames . count <= 0 ) {

continue ;

}

NSDictionary * dicZero = [ callStackRootFrames ObjectAtIndex : 0 ];

int rootIndex = 0 ;

while ( dicZero && dicZero . count > 0 ) {

NSString * binaryUUID = [ dicZero stringValueForKey : kMetrkitBinaryUUIDKey ];

NSString * binaryName = [ dicZero stringValueForKey : kMetrkitBinaryNameKey ];

long long baseAdd = [[ dicZero NumberValueForKey : kMetrkitOffsetIntoBinaryTextSegmentKey ] longLongValue ];

long long address = [[ dicZero numberValueForKey : kMetrkitAddressKey ] longLongValue ];

NSArray * subFrames = [ dicZero arrayValueForKey : kMetrkitSubFramesKey ];

[ strStack appendFormat : @ "%d %@ 0x%llx 0x%llx + %lld\n" , rootIndex , binaryName , baseAdd , address , address - model . baseAddress ];

rootIndex ++ ;

if ( subFrames && subFrames . count >= 0 ) {

dicZero = [ subFrames ObjectAtIndex : 0 ];

} else {

dicZero = nil ;

}

MetricKit return fields meaning and details

JSON overall format

crashDiagnostics Details

Each crash is a dictionary with the following contents:

diagnosticMetaData dictionary details

 | terminationReason | String | Crash reason | RBSTerminateContext domain : 10 code : 0x8BADF00D
explanation : scene - update watchdog transgression : application : 6308
exhausted real ( wall clock ) time allowance of 10.00 seconds |

callStackTree dictionary details

callStacks array details

The elements in the array are dictionaries, as follows

callStackRootFrames array details

The elements in the array are dictionaries, as follows

diskWriteExceptionDiagnostics Details

Each crash is a dictionary with the following contents:

diagnosticMetaData dictionary details

callStackTree dictionary details

callStacks array details

The elements in the array are dictionaries, as follows

callStackRootFrames array details

The elements in the array are dictionaries, as follows

cpuExceptionDiagnostics Details

Each crash is a dictionary with the following contents:

diagnosticMetaData dictionary details

callStackTree dictionary details

callStacks array details

The elements in the array are dictionaries, as follows

callStackRootFrames array details

The elements in the array are dictionaries, as follows

hangDiagnostics Details

diagnosticMetaData dictionary details

callStackTree dictionary details

callStacks array details


callStackRootFrames array details

<<:  Let's talk about phantom types in Swift

>>:  Apple discontinues iPod Touch, ending 20-year iPod legend

Recommend

CHIMA: 2022 Hospital Cloud Service Application Status Survey Report

In order to understand the application status of ...

Science in the Week: Will Tying Your Hair Often Make Your Hairline Higher?

2022, Week 7, Issue 5, Total Issue 21 It’s almost...

How to salvage a screwed holiday marketing campaign

How to make holiday marketing most effective in t...

618 Advertising tips for the education and training industry!

With the arrival of the 618 mid-year sale, educat...

seo tutorial, what are the advanced search engine commands commonly used in SEO?

Some commonly used advanced search engine command...

Giant ships also have Iron Man's "armor"? The "secret weapon" in shipbuilding

Did you know that behind those giant ships that t...

How to plan a “national topic” to trigger user growth?

Recently, many people’s Moments have been flooded...

AARRR model, analyzing NetEase Wugou Reading!

1. Product Background 1. Product Introduction Net...

Convincing "deep fakes" just to make you smile?

Leviathan Press: I personally think Walter Schere...

Double Eleven "Building Activity" Addictive Model!

Late October to early November is an unstable per...

Moon dust looks like this! The microscopic universe under the microscope

Electron microscope view of a diatom Silicon chip...