@@ -32,7 +32,6 @@ internal unsafe class MacOSUltraSampler : UltraSampler
32
32
private UnsafeDictionary < ulong , int > _threadIdToCompressedFrameIndex = new ( MaximumThreadCountForCompressedFrames ) ;
33
33
private UnsafeHashSet < ulong > _activeThreadIds = new ( MaximumThreadCountForCompressedFrames ) ;
34
34
private UnsafeHashSet < ulong > _currentThreadIds = new ( MaximumThreadCountForCompressedFrames ) ;
35
- private UnsafeList < ulong > _tempThreadIds = new ( MaximumThreadCountForCompressedFrames ) ;
36
35
37
36
// Modules
38
37
private const int DefaultImageCount = 1024 ;
@@ -48,6 +47,9 @@ internal unsafe class MacOSUltraSampler : UltraSampler
48
47
49
48
public MacOSUltraSampler ( )
50
49
{
50
+ // Make sure to use the instance to trigger the constructor of the EventSource so that it is registered in the runtime!
51
+ _samplerEventSource = UltraSamplerSource . Log ;
52
+
51
53
_frames = GC . AllocateArray < ulong > ( 4096 , true ) ;
52
54
_allCompressedFrames = GC . AllocateArray < ulong > ( MaximumCompressedFrameTotalCount * MaximumThreadCountForCompressedFrames , true ) ;
53
55
@@ -61,10 +63,7 @@ public MacOSUltraSampler()
61
63
62
64
_callbackDyldAdded = new MacOSLibSystem . dyld_register_callback ( CallbackDyldAdded ) ;
63
65
_callbackDyldRemoved = new MacOSLibSystem . dyld_register_callback ( CallbackDyldRemoved ) ;
64
-
65
- // Make sure to use the instance to trigger the constructor of the EventSource so that it is registered in the runtime!
66
- _samplerEventSource = UltraSamplerSource . Log ;
67
-
66
+
68
67
// Register dyld callbacks
69
68
_initializingModules = true ;
70
69
MacOSLibSystem . _dyld_register_func_for_add_image ( Marshal . GetFunctionPointerForDelegate ( _callbackDyldAdded ) ) ;
@@ -141,6 +140,7 @@ private unsafe void RunImpl()
141
140
}
142
141
else
143
142
{
143
+ ClearThreadStates ( ) ;
144
144
_samplerResumeThreadEvent . WaitOne ( ) ;
145
145
sendManifest = true ;
146
146
}
@@ -152,6 +152,19 @@ private unsafe void RunImpl()
152
152
}
153
153
}
154
154
155
+
156
+ private void ClearThreadStates ( )
157
+ {
158
+ // Reset the state for threads
159
+ _currentThreadIds . Clear ( ) ;
160
+ _activeThreadIds . Clear ( ) ;
161
+ foreach ( var compressedIndex in _threadIdToCompressedFrameIndex . Values )
162
+ {
163
+ _freeCompressedFramesIndices . Add ( compressedIndex ) ;
164
+ }
165
+ _threadIdToCompressedFrameIndex . Clear ( ) ;
166
+ }
167
+
155
168
private static void SendManifest ( )
156
169
{
157
170
// Make sure to always send the manifest before resuming the capture thread
0 commit comments