Skip to content

Commit 347716c

Browse files
committed
Updates
1 parent f5fe08e commit 347716c

File tree

4 files changed

+26
-39
lines changed

4 files changed

+26
-39
lines changed

Sources/Sentry/SentryMetricKitIntegration.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,13 @@ - (void)didReceiveDiskWriteExceptionDiagnostic:(MXDiskWriteExceptionDiagnostic *
177177
diagnosticJSON:[diagnostic JSONRepresentation]];
178178
}
179179

180-
- (void)didReceiveHangDiagnosticCallStackTree:(SentryMXCallStackTree *)callStackTree
180+
- (void)didReceiveHangDiagnostic:(MXHangDiagnostic *)diagnostic
181+
callStackTree:(SentryMXCallStackTree *)callStackTree
181182
timeStampBegin:(NSDate *)timeStampBegin
182183
timeStampEnd:(NSDate *)timeStampEnd
183184
{
184-
NSString *hangDuration = @"2s";
185-
// [self.measurementFormatter stringFromMeasurement:diagnostic.hangDuration];
185+
NSString *hangDuration =
186+
[self.measurementFormatter stringFromMeasurement:diagnostic.hangDuration];
186187

187188
NSString *exceptionValue = [NSString
188189
stringWithFormat:@"%@ hangDuration:%@", SentryMetricKitHangDiagnosticType, hangDuration];
@@ -195,9 +196,7 @@ - (void)didReceiveHangDiagnosticCallStackTree:(SentryMXCallStackTree *)callStack
195196
params.exceptionMechanism = SentryMetricKitHangDiagnosticMechanism;
196197
params.timeStampBegin = timeStampBegin;
197198

198-
[self captureMXEvent:callStackTree
199-
params:params
200-
diagnosticJSON:[NSData data]];
199+
[self captureMXEvent:callStackTree params:params diagnosticJSON:[NSData data]];
201200
}
202201

203202
- (void)captureMXEvent:(SentryMXCallStackTree *)callStackTree

Sources/Swift/Core/MetricKit/SentryMXCallStackTree.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Foundation
3838
// a thread backtrace. A flamegraph is just a collection of many thread backtraces
3939
// generated by taking multiple samples. For example a hang from metric kit will
4040
// be a group of samples of the main thread while it is hanging. To make MetricKit
41-
// data compatible with Sentry data this function find the most commonly sampled stack.
41+
// data compatible with Sentry data this function finds the most commonly sampled stack.
4242
// Some metric kit events contain multiple threads (like a crash report) and others
4343
// contain all threads in one flamegraph. That happens when "callStackPerThread"
4444
// is false. In these cases we can't really make a "thread" because

Sources/Swift/Core/MetricKit/SentryMXManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import MetricKit
1515

1616
func didReceiveCpuExceptionDiagnostic(_ diagnostic: MXCPUExceptionDiagnostic, callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
1717

18-
func didReceiveHangDiagnosticCallStackTree(_ callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
18+
func didReceiveHangDiagnostic(_ diagnostic: MXHangDiagnostic, callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
1919
}
2020

2121
@available(macOS 12.0, *)
@@ -24,10 +24,10 @@ import MetricKit
2424
@objcMembers @_spi(Private) public final class SentryMXManager: NSObject, MXMetricManagerSubscriber {
2525

2626
static var shared: SentryMXManager?
27-
static public func test(tree: SentryMXCallStackTree) {
28-
let start = Date.now.addingTimeInterval(-60)
29-
shared?.delegate?.didReceiveHangDiagnosticCallStackTree(tree, timeStampBegin: start, timeStampEnd: Date.now)
30-
}
27+
// static public func test(tree: SentryMXCallStackTree) {
28+
// let start = Date.now.addingTimeInterval(-60)
29+
// shared?.delegate?.didReceiveHangDiagnosticCallStackTree(tree, timeStampBegin: start, timeStampEnd: Date.now)
30+
// }
3131

3232
let disableCrashDiagnostics: Bool
3333

@@ -85,7 +85,7 @@ import MetricKit
8585

8686
payload.hangDiagnostics?.forEach { diagnostic in
8787
actOn(callStackTree: diagnostic.callStackTree) { callStackTree in
88-
delegate?.didReceiveHangDiagnosticCallStackTree(callStackTree, timeStampBegin: payload.timeStampBegin, timeStampEnd: payload.timeStampEnd)
88+
delegate?.didReceiveHangDiagnostic(diagnostic, callStackTree: callStackTree, timeStampBegin: payload.timeStampBegin, timeStampEnd: payload.timeStampEnd)
8989
}
9090
}
9191
}

Tests/SentryTests/Integrations/MetricKit/SentryMXCallStackTreeTests.swift

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ final class SentryMXCallStackTreeTests: XCTestCase {
1515
let contents = try contentsOfResource("MetricKitCallstacks/per-thread")
1616
let callStackTree = try SentryMXCallStackTree.from(data: contents)
1717

18-
XCTAssertEqual(false, callStackTree.callStackPerThread)
18+
XCTAssertEqual(true, callStackTree.callStackPerThread)
1919
XCTAssertEqual(2, callStackTree.callStacks.count)
2020
try assertCallStackTree(callStackTree)
2121

2222
let debugMeta = callStackTree.toDebugMeta()
2323
let image = try XCTUnwrap(debugMeta.first { $0.debugID == "9E8D8DE6-EEC1-3199-8720-9ED68EE3F967" })
24-
XCTAssertEqual(414_732, image.imageAddress)
24+
XCTAssertEqual(sentry_formatHexAddressUInt64Swift(4_312_798_220 - 414_732), image.imageAddress)
2525
}
2626

2727
func testDecodeCallStackTree_NotPerThread() throws {
@@ -37,6 +37,18 @@ final class SentryMXCallStackTreeTests: XCTestCase {
3737
XCTAssertEqual(2, secondSamples.count)
3838
}
3939

40+
func testMostCommonStack() throws {
41+
let contents = try contentsOfResource("MetricKitCallstacks/per-thread-flamegraph")
42+
let callStackTree = try SentryMXCallStackTree.from(data: contents)
43+
let threads = callStackTree.sentryMXBacktrace(inAppLogic: nil, handled: false)
44+
XCTAssertEqual(1, threads.count)
45+
let frames = try XCTUnwrap(threads[0].stacktrace).frames
46+
XCTAssertEqual(3, frames.count)
47+
XCTAssertEqual("0x0000000000000000", frames[0].instructionAddress)
48+
XCTAssertEqual("0x0000000000000001", frames[0].instructionAddress)
49+
XCTAssertEqual("0x0000000000000003", frames[0].instructionAddress)
50+
}
51+
4052
func testDecodeCallStackTree_UnknownFieldsPayload() throws {
4153
let contents = try contentsOfResource("MetricKitCallstacks/tree-unknown-fields")
4254
let callStackTree = try SentryMXCallStackTree.from(data: contents)
@@ -69,30 +81,6 @@ final class SentryMXCallStackTreeTests: XCTestCase {
6981
XCTAssertEqual(1, mxFrame.toSamples().count)
7082
XCTAssertEqual(1, mxFrame.toSamples()[0].count)
7183
}
72-
73-
// let firstFrame = try XCTUnwrap(callStack.callStackRootFrames.first)
74-
// XCTAssertEqual(UUID(uuidString: "9E8D8DE6-EEC1-3199-8720-9ED68EE3F967"), firstFrame.binaryUUID)
75-
// XCTAssertEqual(414_732, firstFrame.offsetIntoBinaryTextSegment)
76-
// XCTAssertEqual(1, firstFrame.sampleCount)
77-
// XCTAssertEqual("Sentry", firstFrame.binaryName)
78-
// XCTAssertEqual(4_312_798_220, firstFrame.address)
79-
// XCTAssertEqual(try XCTUnwrap(subFrameCount.first), firstFrame.subFrames?.count)
80-
//
81-
// let secondFrame = try XCTUnwrap(try XCTUnwrap(callStack.callStackRootFrames.element(at: 1)))
82-
// XCTAssertEqual(UUID(uuidString: "CA12CAFA-91BA-3E1C-BE9C-E34DB96FE7DF"), secondFrame.binaryUUID)
83-
// XCTAssertEqual(46_380, secondFrame.offsetIntoBinaryTextSegment)
84-
// XCTAssertEqual(1, secondFrame.sampleCount)
85-
// XCTAssertEqual("iOS-Swift", secondFrame.binaryName)
86-
// XCTAssertEqual(4_310_988_076, secondFrame.address)
87-
// XCTAssertEqual(try XCTUnwrap(subFrameCount.element(at: 1)), secondFrame.subFrames?.count)
88-
//
89-
// let thirdFrame = try XCTUnwrap(try XCTUnwrap(callStack.callStackRootFrames.element(at: 2)))
90-
// XCTAssertEqual(UUID(uuidString: "CA12CAFA-91BA-3E1C-BE9C-E34DB96FE7DF"), thirdFrame.binaryUUID)
91-
// XCTAssertEqual(46_370, thirdFrame.offsetIntoBinaryTextSegment)
92-
// XCTAssertEqual(1, thirdFrame.sampleCount)
93-
// XCTAssertEqual("iOS-Swift", thirdFrame.binaryName)
94-
// XCTAssertEqual(4_310_988_026, thirdFrame.address)
95-
// XCTAssertEqual(try XCTUnwrap(subFrameCount.element(at: 2)), thirdFrame.subFrames?.count ?? 0)
9684
}
9785
}
9886

0 commit comments

Comments
 (0)