Skip to content

Commit

Permalink
Try to fix sending the manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Dec 15, 2024
1 parent 057970b commit 76803e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ protected override void EnableImpl()
{
_nextModuleEventIndexToLog = 0;
_captureEnabled = true;
// Make sure to always send the manifest before resuming the capture thread
try
{
EventSource.SendCommand(UltraSamplerSource.Log, EventCommand.SendManifest, null);
}
catch
{
// Ignore
}
_resumeCaptureThread.Set();
}

Expand All @@ -103,10 +94,18 @@ private unsafe void RunImpl()
MacOS.MacOSLibSystem.pthread_threadid_np(0, out var currentThreadId)
.ThrowIfError("pthread_threadid_np");

bool sendManifest = true;

while (!_stopped)
{
if (_captureEnabled)
{
if (sendManifest)
{
SendManifest();
sendManifest = false;
}

// Load all pending native module events before sampling
NotifyPendingNativeModuleEvents();

Expand All @@ -119,6 +118,7 @@ private unsafe void RunImpl()
else
{
_resumeCaptureThread.WaitOne();
sendManifest = true;
}
}
}
Expand All @@ -128,6 +128,19 @@ private unsafe void RunImpl()
}
}

private static void SendManifest()
{
// Make sure to always send the manifest before resuming the capture thread
try
{
EventSource.SendCommand(UltraSamplerSource.Log, EventCommand.SendManifest, null);
}
catch
{
// Ignore
}
}

private void CallbackDyldAdded(MacOSLibSystem.mach_header* header, nint slideVmAddr)
{
AddModuleEvent(_initializingModules ? NativeModuleEventKind.AlreadyLoaded : NativeModuleEventKind.Loaded, (nint)header);
Expand Down Expand Up @@ -245,7 +258,7 @@ private static ulong GetDyldCodeSize(nint headerPtr)
}
}
}

return size;
}

Expand Down
Binary file modified src/Ultra.Sampler/libUltraSampler.dylib
Binary file not shown.

0 comments on commit 76803e6

Please sign in to comment.