Skip to content

Commit

Permalink
[Profiler] Fix LinuxDlIteratePhdrDeadlock test (#5963)
Browse files Browse the repository at this point in the history
  • Loading branch information
gleocadie authored Aug 30, 2024
1 parent c8a41a2 commit 6156310
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions profiler/src/Demos/Samples.Computer01/ComputerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class ComputerService
private NullThreadNameBugCheck _nullThreadNameBugCheck;
private MethodsSignature _methodsSignature;
private SigSegvHandlerExecution _sigsegvHandler;
#if NETCOREAPP3_0_OR_GREATER
private LinuxDlIteratePhdrDeadlock _linuxDlIteratePhdrDeadlock;
#endif

#if NET5_0_OR_GREATER
private OpenLdapCrash _openldapCrash;
Expand Down Expand Up @@ -182,9 +184,11 @@ public void StartService(Scenario scenario, int nbThreads, int parameter)
StartStringConcat(parameter);
break;

#if NETCOREAPP3_0_OR_GREATER
case Scenario.LinuxDlIteratePhdrDeadlock:
StartLinuxDlIteratePhdrDeadlock();
break;
#endif

default:
throw new ArgumentOutOfRangeException(nameof(scenario), $"Unsupported scenario #{_scenario}");
Expand Down Expand Up @@ -317,9 +321,11 @@ public void StopService()
StopStringConcat();
break;

#if NETCOREAPP3_0_OR_GREATER
case Scenario.LinuxDlIteratePhdrDeadlock:
StopLinuxDlIteratePhdrDeadlock();
break;
#endif
}
}

Expand Down Expand Up @@ -584,11 +590,13 @@ private void StartLinuxMallocDeadlock()
_linuxMallockDeadlock.Start();
}

#if NETCOREAPP3_0_OR_GREATER
private void StartLinuxDlIteratePhdrDeadlock()
{
_linuxDlIteratePhdrDeadlock = new LinuxDlIteratePhdrDeadlock();
_linuxDlIteratePhdrDeadlock.Start();
}
#endif

private void StartMeasureAllocations()
{
Expand Down Expand Up @@ -764,10 +772,12 @@ private void StopLinuxMallocDeadlock()
_linuxMallockDeadlock.Stop();
}

#if NETCOREAPP3_0_OR_GREATER
private void StopLinuxDlIteratePhdrDeadlock()
{
_linuxDlIteratePhdrDeadlock.Stop();
}
#endif

private void StopMeasureAllocations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc.
// </copyright>

#if NETCOREAPP3_0_OR_GREATER
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -17,6 +20,13 @@ internal class LinuxDlIteratePhdrDeadlock
private Task _exceptionTask;
private Thread _worker;

public LinuxDlIteratePhdrDeadlock()
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), DllImportResolver);
}

private static string ApiWrapperPath { get; } = Environment.GetEnvironmentVariable("LD_PRELOAD");

public void Start()
{
if (_stopEvent != null)
Expand Down Expand Up @@ -87,10 +97,20 @@ public void Stop()
_stopEvent = null;
}

[DllImport("libdl.so", EntryPoint = "dlopen")]
private static IntPtr DllImportResolver(string resolverName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (resolverName == "DatadogApiWrapper")
{
return NativeLibrary.Load(ApiWrapperPath, assembly, searchPath);
}

return IntPtr.Zero;
}

[DllImport("DatadogApiWrapper", EntryPoint = "dlopen")]
private static extern IntPtr Dlopen(string filename, int flags);

[DllImport("libdl.so", EntryPoint = "dlclose")]
[DllImport("DatadogApiWrapper", EntryPoint = "dlclose")]
private static extern void DlClose(IntPtr handle);

private void ExecuteCallToDlOpenDlClose()
Expand Down Expand Up @@ -122,3 +142,4 @@ private bool IsEventSet()
}
}
}
#endif

0 comments on commit 6156310

Please sign in to comment.