-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: MetricKit TestVersion 1 (#2476)
This PR adds a first iteration of sending MetricKitData of MXCrashDiagnostic, MXCPUExceptionDiagnostic, and MXDiskWriteExceptionDiagnostic to Sentry. This PRs aim is to have the code running in the iOS-Swift test app via TestFlight to get some real MetricKit data of MXCPUExceptionDiagnostic, and MXDiskWriteExceptionDiagnostic. MXCrashDiagnostic exists solely for validating the stacktrace symbolication.
- Loading branch information
1 parent
98fb18f
commit 5ed4bee
Showing
28 changed files
with
1,817 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Samples/iOS-Swift/iOS-Swift/Tools/DiskWriteException.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Foundation | ||
import Sentry | ||
|
||
/** | ||
* The system throws an exception and generates a report when the disk writes from your app exceed a certain threshold in a 24-hour period. | ||
* See https://developer.apple.com/documentation/xcode/reducing-disk-write. | ||
* Therefore we write plenty of data to disk on a background thread to hopefully trigger a DiskWriteException. | ||
*/ | ||
class DiskWriteException { | ||
|
||
private let dispatchQueue = DispatchQueue(label: "DiskWriteException", attributes: [.concurrent]) | ||
private let folder: URL | ||
private var running = false | ||
|
||
init() { | ||
// swiftlint:disable force_unwrapping | ||
let cachesDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! | ||
// swiftlint:enable force_unwrapping | ||
folder = cachesDirectory.appendingPathComponent("DiskWriteException/") | ||
} | ||
|
||
func continuouslyWriteToDisk() { | ||
if running { | ||
return | ||
} | ||
|
||
running = true | ||
|
||
dispatchQueue.async { | ||
do { | ||
let fileManager = FileManager.default | ||
try fileManager.createDirectory(at: self.folder, withIntermediateDirectories: true) | ||
|
||
let url = self.folder.appendingPathComponent("SomeBytes.txt") | ||
fileManager.createFile(atPath: url.absoluteString, contents: nil) | ||
|
||
// Keep writing random data to SomeBytes.txt | ||
while true { | ||
var data = Data() | ||
for _ in 0..<100_000 { | ||
let random = UInt8.random(in: 0...10) | ||
data.append(Data(repeating: random, count: 50)) | ||
} | ||
|
||
try data.write(to: url, options: .atomic) | ||
self.delay() | ||
} | ||
} catch { | ||
SentrySDK.capture(error: error) | ||
} | ||
} | ||
} | ||
|
||
private func delay(timeout: Double = 0.1) { | ||
let group = DispatchGroup() | ||
group.enter() | ||
|
||
self.dispatchQueue.asyncAfter(deadline: .now() + timeout) { | ||
group.leave() | ||
} | ||
|
||
group.wait() | ||
} | ||
|
||
func deleteFiles() { | ||
let fileManager = FileManager.default | ||
do { | ||
if fileManager.fileExists(atPath: folder.path) { | ||
try fileManager.removeItem(at: folder) | ||
} | ||
} catch { | ||
SentrySDK.capture(error: error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.