Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Profiler] Fix LinuxDlIteratePhdrDeadlock test #5963

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading