Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void Run(ICollection<string> assemblyPaths, params string[] output
File.WriteAllText(filename, json, utf8NoBom);

// CallTarget
var calltargetPath = Path.Combine(outputDirectory, "src", "Datadog.Trace", "ClrProfiler", "InstrumentationDefinitions.cs");
var calltargetPath = Path.Combine(outputDirectory, "src", "Datadog.Trace", "ClrProfiler", "InstrumentationDefinitions.Generated.cs");
Console.WriteLine($"Writing {calltargetPath}...");
using var fs = new FileStream(calltargetPath, FileMode.Create, FileAccess.Write, FileShare.None);
using var sw = new StreamWriter(fs, utf8NoBom);
Expand All @@ -83,49 +83,56 @@ public static void Run(ICollection<string> assemblyPaths, params string[] output

static void WriteCallTargetDefinitionFile(StreamWriter swriter, IEnumerable<CallTargetDefinitionSource> callTargetIntegrations)
{
swriter.WriteLine("// <copyright file=\"InstrumentationDefinitions.cs\" company=\"Datadog\">");
swriter.WriteLine("// <copyright file=\"InstrumentationDefinitions.Generated.cs\" company=\"Datadog\">");
swriter.WriteLine("// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.");
swriter.WriteLine("// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.");
swriter.WriteLine("// </copyright>\n");
swriter.WriteLine("// </copyright>");
swriter.WriteLine();
swriter.WriteLine("namespace Datadog.Trace.ClrProfiler");
swriter.WriteLine("{");
swriter.WriteLine(" internal static class InstrumentationDefinitions");
swriter.WriteLine(" internal static partial class InstrumentationDefinitions");
swriter.WriteLine(" {");
swriter.WriteLine(" internal static NativeCallTargetDefinition[] GetAllDefinitions()");
swriter.WriteLine(" private static NativeCallTargetDefinition[] GetDefinitionsArray()");
swriter.WriteLine(" {");
swriter.WriteLine(" return new NativeCallTargetDefinition[]");
swriter.WriteLine(" {");
foreach (var integration in callTargetIntegrations.Distinct())
foreach (var integrationGroup in callTargetIntegrations.Distinct().GroupBy(i => i.IntegrationName))
{
swriter.Write($" new(");
swriter.Write($"\"{integration.TargetAssembly}\", ");
swriter.Write($"\"{integration.TargetType}\", ");
swriter.Write($"\"{integration.TargetMethod}\", ");
swriter.WriteLine($" // {integrationGroup.Key}");

swriter.Write($" new[] {{ ");
for (var s = 0; s < integration.TargetSignatureTypes.Length; s++)
foreach (var integration in integrationGroup)
{
if (s == integration.TargetSignatureTypes.Length - 1)
{
swriter.Write($"\"{integration.TargetSignatureTypes[s]}\"");
}
else
swriter.Write($" new(");
swriter.Write($"\"{integration.TargetAssembly}\", ");
swriter.Write($"\"{integration.TargetType}\", ");
swriter.Write($"\"{integration.TargetMethod}\", ");

swriter.Write($" new[] {{ ");
for (var s = 0; s < integration.TargetSignatureTypes.Length; s++)
{
swriter.Write($"\"{integration.TargetSignatureTypes[s]}\", ");
if (s == integration.TargetSignatureTypes.Length - 1)
{
swriter.Write($"\"{integration.TargetSignatureTypes[s]}\"");
}
else
{
swriter.Write($"\"{integration.TargetSignatureTypes[s]}\", ");
}
}
}

swriter.Write(" }, ");

swriter.Write($"{integration.TargetMinimumMajor}, ");
swriter.Write($"{integration.TargetMinimumMinor}, ");
swriter.Write($"{integration.TargetMinimumPatch}, ");
swriter.Write($"{integration.TargetMaximumMajor}, ");
swriter.Write($"{integration.TargetMaximumMinor}, ");
swriter.Write($"{integration.TargetMaximumPatch}, ");
swriter.Write($"\"{integration.WrapperAssembly}\", ");
swriter.Write($"\"{integration.WrapperType}\"");
swriter.WriteLine($"),");
swriter.Write(" }, ");

swriter.Write($"{integration.TargetMinimumMajor}, ");
swriter.Write($"{integration.TargetMinimumMinor}, ");
swriter.Write($"{integration.TargetMinimumPatch}, ");
swriter.Write($"{integration.TargetMaximumMajor}, ");
swriter.Write($"{integration.TargetMaximumMinor}, ");
swriter.Write($"{integration.TargetMaximumPatch}, ");
swriter.Write($"assemblyFullName, ");
swriter.Write($"\"{integration.WrapperType}\"");
swriter.WriteLine($"),");
}
swriter.WriteLine();
}
swriter.WriteLine(" };");
swriter.WriteLine(" }");
Expand Down Expand Up @@ -164,9 +171,10 @@ from attribute in attributes
let wrapperType = callTargetType
from assemblyNames in GetPropertyValue<string[]>(attribute, "AssemblyNames")
let versionRange = GetPropertyValue<object>(attribute, "VersionRange")
orderby assemblyNames, GetPropertyValue<string>(attribute, "TypeName"), GetPropertyValue<string>(attribute, "MethodName")
orderby integrationName, assemblyNames, GetPropertyValue<string>(attribute, "TypeName"), GetPropertyValue<string>(attribute, "MethodName")
select new CallTargetDefinitionSource
{
IntegrationName = integrationName,
TargetAssembly = assemblyNames,
TargetType = GetPropertyValue<string>(attribute, "TypeName"),
TargetMethod = GetPropertyValue<string>(attribute, "MethodName"),
Expand Down Expand Up @@ -536,6 +544,8 @@ protected override Assembly Load(AssemblyName assemblyName)

public class CallTargetDefinitionSource
{
public string IntegrationName { get; init; }

public string TargetAssembly { get; init; }

public string TargetType { get; init; }
Expand All @@ -561,6 +571,7 @@ public class CallTargetDefinitionSource
public string WrapperType { get; init; }

protected bool Equals(CallTargetDefinitionSource other) =>
IntegrationName == other.IntegrationName &&
TargetAssembly == other.TargetAssembly &&
TargetType == other.TargetType &&
TargetMethod == other.TargetMethod &&
Expand Down Expand Up @@ -595,9 +606,23 @@ public override bool Equals(object obj)
return Equals((CallTargetDefinitionSource)obj);
}

public override int GetHashCode() => HashCode.Combine(TargetAssembly, TargetType, TargetMethod) + HashCode.Combine(TargetMinimumMajor, TargetMinimumMinor, TargetMinimumPatch,
TargetMaximumMajor, TargetMaximumMinor, TargetMaximumPatch,
WrapperAssembly, WrapperType);
public override int GetHashCode()
{
var hash = new HashCode();
hash.Add(IntegrationName);
hash.Add(TargetAssembly);
hash.Add(TargetType);
hash.Add(TargetMethod);
hash.Add(TargetMinimumMajor);
hash.Add(TargetMinimumMinor);
hash.Add(TargetMinimumPatch);
hash.Add(TargetMaximumMajor);
hash.Add(TargetMaximumMinor);
hash.Add(TargetMaximumPatch);
hash.Add(WrapperAssembly);
hash.Add(WrapperType);
return hash.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ void CorProfiler::InitializeProfiler(CallTargetDefinition* items, int size)
{
auto _ = trace::Stats::Instance()->InitializeProfilerMeasure();

Logger::Info("InitializeProfiler:: received from managed side: ", size, " integrations.");
Logger::Info("InitializeProfiler: received from managed side: ", size, " integrations.");
if (items != nullptr && rejit_handler != nullptr)
{
std::vector<IntegrationMethod> integrationMethods;
Expand Down Expand Up @@ -1180,7 +1180,7 @@ void CorProfiler::InitializeProfiler(CallTargetDefinition* items, int size)
integration_methods_.push_back(integration);
}

Logger::Info("InitializeProfiler:: Total integrations in profiler: ", integration_methods_.size());
Logger::Info("InitializeProfiler: Total integrations in profiler: ", integration_methods_.size());
}
}

Expand Down
Loading