Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Oct 14, 2024
1 parent 5daf5db commit f154c5c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tracer/build/_build/Build.ExplorationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Target RunSnapshotExplorationTests
return;
}
FileSystemTasks.EnsureCleanDirectory(TestLogsDirectory);
// FileSystemTasks.EnsureCleanDirectory(TestLogsDirectory);
try
{
RunSnapshotExplorationTestsInternal();
Expand Down
35 changes: 30 additions & 5 deletions tracer/build/_build/Build.SnapshotExplorationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ partial class Build
const string SnapshotExplorationEnabledKey = "DD_INTERNAL_SNAPSHOT_EXPLORATION_TEST_ENABLED";
const string SnapshotExplorationProbesPathKey = "DD_INTERNAL_SNAPSHOT_EXPLORATION_TEST_PROBES_PATH";
const string SnapshotExplorationReportPathKey = "DD_INTERNAL_SNAPSHOT_EXPLORATION_TEST_REPORT_PATH";
const char SpecialSeparator = '#';

void RunSnapshotExplorationTestsInternal()
{
Expand Down Expand Up @@ -147,11 +148,37 @@ void ProcessNestedScopes(List<IDictionary<string, object>> scopes, string typeNa
isStatic = (int.Parse(annotations[0], NumberStyles.HexNumber) & 0x0010) > 0;
}

var returnType = ls?.GetType().GetProperty("ReturnType")?.GetValue(ls)?.ToString();
csvBuilder.AppendLine($"{typeName},{scope["Name"]},{GetMethodSignature(returnType, (List<IDictionary<string, object>>)scope["Symbols"])},{Guid.NewGuid()},{isStatic}");
var returnType = ls?.GetType().GetProperty("ReturnType", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(ls)?.ToString();
if (TryGetLine(typeName, scope["Name"].ToString(), returnType, (List<IDictionary<string, object>>)scope["Symbols"], Guid.NewGuid(), isStatic, out var line))
{
csvBuilder.AppendLine(line);
}
else
{
Logger.Warning($"Error to add probe info for: {line}");
}
}
}
}
}

bool TryGetLine(string type, string method, string returnType, List<IDictionary<string, object>> methodParameters, Guid guid, bool isStatic, out string line)
{
try
{
var typeName = SanitiseName(type);
var methodName = SanitiseName(method);
var methodSignature = GetMethodSignature(returnType, methodParameters);
line = $"{typeName},{methodName},{SanitiseName(methodSignature)},{Guid.NewGuid()},{isStatic}";
return !string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(methodName) && !string.IsNullOrEmpty(returnType);
}
catch (Exception e)

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / check-snapshots

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / add-labels

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / verify_span_metadata

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / verify_files_without_nullability

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / bump_package_versions

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / Analyze Profiler

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / verify_source_generators

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / verify_app_trimming_descriptor_generator

The variable 'e' is declared but never used

Check warning on line 175 in tracer/build/_build/Build.SnapshotExplorationTest.cs

View workflow job for this annotation

GitHub Actions / Analyze Tracer

The variable 'e' is declared but never used
{
line = $"Type: {type}, Method: {method}";
return false;
}

string SanitiseName(string name) => name == null ? string.Empty : name.Replace(',', SpecialSeparator);

string GetMethodSignature(string returnType, List<IDictionary<string, object>> symbols)
{
Expand All @@ -160,14 +187,12 @@ string GetMethodSignature(string returnType, List<IDictionary<string, object>> s
return string.Empty;
}

const char parametersSeparator = '#';

var parameterTypes =
(from symbol in symbols
where symbol["SymbolType"].ToString() == "Arg"
select symbol["Type"].ToString())
.ToList();
return $"{returnType} ({string.Join(parametersSeparator, parameterTypes)})";
return $"{returnType} ({string.Join(SpecialSeparator, parameterTypes)})";
}
}

Expand Down
14 changes: 7 additions & 7 deletions tracer/build/_build/BuildVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ public void AddDebuggerEnvironmentVariables(Dictionary<string, string> envVars,

envVars.Add("DD_DYNAMIC_INSTRUMENTATION_ENABLED", "1");
envVars.Add("DD_INTERNAL_DEBUGGER_INSTRUMENT_ALL", "1");

if (description.LineProbesEnabled)
{
envVars.Add("DD_INTERNAL_DEBUGGER_INSTRUMENT_ALL_LINES", "1");
var testRootPath = description.GetTestTargetPath(ExplorationTestsDirectory, framework, BuildConfiguration);
envVars.Add("DD_INTERNAL_DEBUGGER_INSTRUMENT_ALL_LINES_PATH", Path.Combine(testRootPath, LineProbesFileName));
}
// envVars.Add("DD_INTERNAL_WAIT_FOR_DEBUGGER_ATTACH", "1");

if (description.IsSnapshotScenario)
{
Expand All @@ -30,6 +24,12 @@ public void AddDebuggerEnvironmentVariables(Dictionary<string, string> envVars,
envVars.Add(SnapshotExplorationProbesPathKey, Path.Combine(testRootPath, SnapshotExplorationTestProbesFileName));
envVars.Add(SnapshotExplorationReportPathKey, Path.Combine(testRootPath, SnapshotExplorationTestReportFileName));
}
else if (description.LineProbesEnabled)
{
envVars.Add("DD_INTERNAL_DEBUGGER_INSTRUMENT_ALL_LINES", "1");
var testRootPath = description.GetTestTargetPath(ExplorationTestsDirectory, framework, BuildConfiguration);
envVars.Add("DD_INTERNAL_DEBUGGER_INSTRUMENT_ALL_LINES_PATH", Path.Combine(testRootPath, LineProbesFileName));
}

envVars.Add("COMPlus_DbgEnableMiniDump", "1");
envVars.Add("COMPlus_DbgMiniDumpType", "4");
Expand Down
16 changes: 12 additions & 4 deletions tracer/src/Datadog.Trace/ClrProfiler/Instrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Datadog.Trace.ServiceFabric;
using Datadog.Trace.Telemetry;
using Datadog.Trace.Telemetry.Metrics;
using Datadog.Trace.Util;

namespace Datadog.Trace.ClrProfiler
{
Expand Down Expand Up @@ -548,13 +549,20 @@ private static void InitLiveDebugger(Tracer tracer)

if (debuggerSettings.IsSnapshotExplorationTestEnabled)
{
var liveDebugger = LiveDebuggerFactory.Create(new DiscoveryServiceMock(), RcmSubscriptionManager.Instance, settings, serviceName, tracer.TracerManager.Telemetry, debuggerSettings, tracer.TracerManager.GitMetadataTagsProvider);
Log.Debug("Initializing live debugger for snapshot exploration test.");
liveDebugger.WithProbesFromFile();
Task.Run(
async () =>
{
var liveDebugger = LiveDebuggerFactory.Create(new DiscoveryServiceMock(), RcmSubscriptionManager.Instance, settings, serviceName, tracer.TracerManager.Telemetry, debuggerSettings, tracer.TracerManager.GitMetadataTagsProvider);
Log.Debug("Initializing live debugger for snapshot exploration test.");
liveDebugger.WithProbesFromFile();
await liveDebugger.InitializeAsync().ConfigureAwait(false);
try
{
await liveDebugger.InitializeAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Error(ex, "Error initializing live debugger.");
}
});
}
else
Expand Down

0 comments on commit f154c5c

Please sign in to comment.