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

Use string create if net6.0 or greater #4183

Merged
merged 17 commits into from Jun 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions tracer/build/_build/BenchmarkComparison/BenchmarkComparer.cs
Expand Up @@ -57,9 +57,14 @@ public static class BenchmarkComparer
{
var baseBenchmark = GetValueOrDefault(baseBenchmarksByName, id);
var diffBenchmark = GetValueOrDefault(diffBenchmarksByName, id);
if (baseBenchmark is null || diffBenchmark is null)
{
return default;
}

return (Id: id, Base: baseBenchmark, Diff: diffBenchmark);
})
.Where(i => i.Id is not null)
.ToList();
var benchmarkComparisons = matchedBenchmarks
.Select(x => new BenchmarkComparison(x.Id, x.Base, x.Diff, EquivalenceTestConclusion.Unknown))
Expand All @@ -75,9 +80,20 @@ public static class BenchmarkComparer
})
.ToList();

static string GetName(Benchmark benchmark) => benchmark.DisplayInfo.Contains("Toolchain=net472")
? $"{benchmark.FullName}-net472"
: $"{benchmark.FullName}-netcoreapp3.1";
static string GetName(Benchmark benchmark)
{
if (benchmark.DisplayInfo.Contains("Toolchain=net472"))
{
return $"{benchmark.FullName}-net472";
}

if (benchmark.DisplayInfo.Contains("Toolchain=net6.0"))
{
return $"{benchmark.FullName}-net6.0";
}

return $"{benchmark.FullName}-netcoreapp3.1";
}

static T GetValueOrDefault<T>(Dictionary<string, T> dict, string key)
=> dict.TryGetValue(key, out var value) ? value : default;
Expand Down
2 changes: 1 addition & 1 deletion tracer/build/_build/Build.cs
Expand Up @@ -416,7 +416,7 @@ void DeleteReparsePoints(string path)
var (framework, runtimes) = IsOsx switch
{
true => (TargetFramework.NETCOREAPP3_1, "net6.0"),
false => (TargetFramework.NET6_0, "net472 netcoreapp3.1"),
false => (TargetFramework.NET6_0, "net472 netcoreapp3.1 net6.0"),
};

DotNetRun(s => s
Expand Down
Expand Up @@ -138,7 +138,11 @@ internal static string CreateHeader(SpanContext context)
var samplingPriority = context.TraceContext?.SamplingPriority ?? context.SamplingPriority;
var sampled = samplingPriority > 0 ? "1" : "0";

#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"{context.RawTraceId}-{context.RawSpanId}-{sampled}");
#else
return $"{context.RawTraceId}-{context.RawSpanId}-{sampled}";
#endif
}
}
}
Expand Up @@ -122,8 +122,11 @@ internal static string CreateTraceParentHeader(SpanContext context)
{
var samplingPriority = context.TraceContext?.SamplingPriority ?? context.SamplingPriority ?? SamplingPriorityValues.AutoKeep;
var sampled = samplingPriority > 0 ? "01" : "00";

#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"00-{context.RawTraceId}-{context.RawSpanId}-{sampled}");
#else
return $"00-{context.RawTraceId}-{context.RawSpanId}-{sampled}";
#endif
}

internal static string CreateTraceStateHeader(SpanContext context)
Expand Down
Expand Up @@ -90,7 +90,11 @@ public static void GetMessageHeaders(EventArgs? eventArgs, out IServiceRemotingR

public static string GetSpanName(string spanKind)
{
#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"{SpanNamePrefix}.{spanKind}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically there's a potential issue here if spanKind.Length > 128 - SpanNamePrefix.Length. It's very unlikely, and this is internal and we control the spanKind types in this callpath. But it still gives me slight eye twitch! 😄

#else
return $"{SpanNamePrefix}.{spanKind}";
#endif
}

public static Span CreateSpan(
Expand Down