Skip to content

Commit 54be04e

Browse files
weissiJohannes Weiss
andauthored
fix warnings (#34)
Don't run symbolizer's potentially blocking `start`/`shutdown` methods on the Swift Concurrency thread pool. Co-authored-by: Johannes Weiss <[email protected]>
1 parent 171dae0 commit 54be04e

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Scripts/smoke-test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ socket_path="$tmpdir/swipr.sock"
1616
PROFILE_RECORDER_SERVER_URL=unix://"$socket_path" \
1717
"$tmpdir"/build/release/swipr-mini-demo \
1818
--blocking --burn-cpu --array-appends \
19+
--tsp true \
1920
--output "$output"/samples.swipr \
2021
--iterations 1000 \
2122
--profiling-server &

Sources/ProfileRecorderSampleConversion/Sampler+Conversion.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import ProfileRecorder
16+
import ProfileRecorderHelpers
1617
import Logging
1718
import NIO
1819
import _NIOFileSystem
@@ -119,17 +120,22 @@ extension ProfileRecorderSampler {
119120
_ body: (String) async throws -> R
120121
) async throws -> R {
121122
let symbolizer = ProfileRecorderSampler._makeDefaultSymbolizer()
122-
try symbolizer.start()
123-
defer {
124-
try! symbolizer.shutdown()
123+
try await NIOThreadPool.singleton.runIfActive {
124+
try symbolizer.start()
125+
}
126+
return try await asyncDo {
127+
return try await self._withSamples(
128+
sampleCount: sampleCount,
129+
timeBetweenSamples: timeBetweenSamples,
130+
format: .perfSymbolized,
131+
symbolizer: symbolizer,
132+
logger: logger,
133+
body
134+
)
135+
} finally: { _ in
136+
try await NIOThreadPool.singleton.runIfActive {
137+
try symbolizer.shutdown()
138+
}
125139
}
126-
return try await self._withSamples(
127-
sampleCount: sampleCount,
128-
timeBetweenSamples: timeBetweenSamples,
129-
format: .perfSymbolized,
130-
symbolizer: symbolizer,
131-
logger: logger,
132-
body
133-
)
134140
}
135141
}

Sources/ProfileRecorderServer/Server.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ public struct ProfileRecorderServer: Sendable {
319319
}
320320

321321
let symbolizer = ProfileRecorderSampler._makeDefaultSymbolizer()
322-
try symbolizer.start()
323-
defer {
324-
try! symbolizer.shutdown()
322+
try await NIOThreadPool.singleton.runIfActive {
323+
try symbolizer.start()
325324
}
326325

327326
return try await asyncDo {
@@ -399,6 +398,9 @@ public struct ProfileRecorderServer: Sendable {
399398
if let udsPath = configuration.unixDomainSocketPath {
400399
_ = try? await FileSystem.shared.removeItem(at: FilePath(udsPath))
401400
}
401+
try await NIOThreadPool.singleton.runIfActive {
402+
try symbolizer.shutdown()
403+
}
402404
}
403405
}
404406

0 commit comments

Comments
 (0)