Skip to content

Commit 88e6763

Browse files
author
Noah Martin
committed
Add more options
1 parent f02a9e6 commit 88e6763

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

ETTrace/ETTraceRunner/ETTrace.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ struct ETTrace: ParsableCommand {
2020

2121
@Flag(name: .shortAndLong, help: "Verbose logging")
2222
var verbose: Bool = false
23+
24+
@Flag(name: .long, help: "Save intermediate files directly from the phone before processing them.")
25+
var saveIntermediate: Bool = false
26+
27+
@Option(name: .shortAndLong, help: "Directory for output files")
28+
var output: String? = nil
2329

2430
@Flag(name: .shortAndLong, help: "Record all threads")
2531
var multiThread: Bool = false
@@ -31,7 +37,7 @@ struct ETTrace: ParsableCommand {
3137
if let dsym = dsyms, dsym.hasSuffix(".dSYM") {
3238
ETTrace.exit(withError: ValidationError("The dsym argument should be set to a folder containing your dSYM files, not the dSYM itself"))
3339
}
34-
let helper = RunnerHelper(dsyms, launch, simulator, verbose, multiThread, sampleRate)
40+
let helper = RunnerHelper(dsyms, launch, simulator, verbose, saveIntermediate, output, multiThread, sampleRate)
3541
Task {
3642
do {
3743
try await helper.start()

ETTrace/ETTraceRunner/RunnerHelper.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ class RunnerHelper {
1919
let launch: Bool
2020
let useSimulator: Bool
2121
let verbose: Bool
22+
let saveIntermediate: Bool
23+
let outputDirectory: String?
2224
let multiThread: Bool
2325
let sampleRate: UInt32
2426

2527
var server: HttpServer? = nil
2628

27-
init(_ dsyms: String?, _ launch: Bool, _ simulator: Bool, _ verbose: Bool, _ multiThread: Bool, _ sampleRate: UInt32) {
29+
init(_ dsyms: String?, _ launch: Bool, _ simulator: Bool, _ verbose: Bool, _ saveIntermediate: Bool, _ outputDirectory: String?, _ multiThread: Bool, _ sampleRate: UInt32) {
2830
self.dsyms = dsyms
2931
self.launch = launch
3032
self.useSimulator = simulator
3133
self.verbose = verbose
34+
self.saveIntermediate = saveIntermediate
35+
self.outputDirectory = outputDirectory
3236
self.multiThread = multiThread
3337
self.sampleRate = sampleRate
3438
}
@@ -65,7 +69,9 @@ class RunnerHelper {
6569
printMessageAndWait()
6670
}
6771

68-
print("Connecting to device.")
72+
if verbose {
73+
print("Connecting to device.")
74+
}
6975

7076
let deviceManager: DeviceManager = useSimulator ? SimulatorDeviceManager(verbose: verbose, relaunch: launch) : PhysicalDevicemanager(verbose: verbose, relaunch: launch)
7177

@@ -80,26 +86,31 @@ class RunnerHelper {
8086
}
8187

8288
_ = readLine()
83-
print(" \r")
8489

8590
if launch {
8691
try await deviceManager.connect()
8792
}
8893

89-
print("Waiting for report to be generated...");
94+
if verbose {
95+
print("Waiting for report to be generated...");
96+
}
9097

9198
let receivedData = try await deviceManager.getResults()
9299

93-
let localFolder = Bundle.main.bundlePath
94-
let outFolder = "\(localFolder)/tmp/emerge-perf-analysis/Documents/emerge-output/"
95-
try FileManager.default.createDirectory(atPath: outFolder, withIntermediateDirectories: true)
96-
let outputPath = "\(outFolder)/output.json"
97-
if FileManager.default.fileExists(atPath: outputPath) {
100+
if saveIntermediate {
101+
let outFolder = "\(NSTemporaryDirectory())/emerge-output"
102+
try FileManager.default.createDirectory(atPath: outFolder, withIntermediateDirectories: true)
103+
let outputPath = "\(outFolder)/output.json"
104+
if FileManager.default.fileExists(atPath: outputPath) {
98105
try FileManager.default.removeItem(atPath: outputPath)
106+
}
107+
FileManager.default.createFile(atPath: outputPath, contents: receivedData)
108+
print("Intermediate file saved to \(outputPath)")
99109
}
100-
FileManager.default.createFile(atPath: outputPath, contents: receivedData)
101110

102-
print("Stopped recording, symbolicating...")
111+
if verbose {
112+
print("Stopped recording, symbolicating...")
113+
}
103114

104115
let responseData = try JSONDecoder().decode(ResponseModel.self, from: receivedData)
105116

@@ -122,7 +133,7 @@ class RunnerHelper {
122133
sampleRate: responseData.sampleRate,
123134
loadedLibraries: responseData.libraryInfo.loadedLibraries,
124135
symbolicator: symbolicator)
125-
let outputUrl = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
136+
let outputUrl = URL(fileURLWithPath: outputDirectory ?? FileManager.default.currentDirectoryPath)
126137

127138
var mainThreadData: Data?
128139
for (threadId, symbolicationResult) in zip(threadIds, flamegraphs) {
@@ -202,7 +213,7 @@ class RunnerHelper {
202213
}
203214
try server?.start(37577)
204215
}
205-
216+
206217
private func saveFlamegraph(_ outJsonData: Data, _ outputUrl: URL, _ threadId: String? = nil) throws {
207218
var saveUrl = outputUrl.appendingPathComponent("output.json")
208219
if let threadId = threadId {

ETTrace/Symbolicator/FlamegraphGenerator.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public enum FlamegraphGenerator {
2727
let rate = sampleRate == 0 ? 4500 : (sampleRate ?? 4500)
2828
// The default sample rate is 4500 microseconds, add 500 because
2929
// the samples have slightly more delay than the rate passed to usleep.
30-
let sampleInterval = Double(rate + 500) / 1000000.0
31-
print("The interval \(sampleInterval)")
30+
let sampleInterval = Double(rate + 500) / 1000000.0
3231
var unattributedTime = 0.0
3332
let partitions = partitions(times, size: 2, step: 1)
3433
var eventTime: Double = 0

0 commit comments

Comments
 (0)