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

[ASM] Native CallTarget definitions #6252

Open
wants to merge 14 commits into
base: dani/apm/NativeCallSites
Choose a base branch
from

Conversation

daniel-romano-DD
Copy link
Contributor

@daniel-romano-DD daniel-romano-DD commented Nov 6, 2024

Summary of changes

Moved CallTarget definitions to the Native library so we can spare the marshalling.
As from V3, there will not be a situation where a Managed V3 will have to specify its definitions to a newer Native library, we can remove the definitions from the managed part.
We must still keep the ability to receive definitions from a V2 managed library.

Reason for change

Marshalling of definitions from managed to native is taxing. Also, embedding the definitions in each managed library takes space, precious in Serverless scenarions

Implementation details

Moved the generation of the CallTargets definitions to a nuke step, removing them from the managed library.
Created a json file in dependabot folder with all the call target definitions declared. This file is read by the UpdatePackageVersions build step, instead of retrieving them by reflection from the compiled assemblies.
Removed uneeded exports from the native library.

Test coverage

Other details

@daniel-romano-DD daniel-romano-DD changed the base branch from master to dani/apm/NativeCallSites November 6, 2024 21:59
Copy link
Contributor Author

daniel-romano-DD commented Nov 6, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@andrewlock
Copy link
Member

andrewlock commented Nov 6, 2024

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

Execution-time benchmarks measure the whole time it takes to execute a program. And are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are shown in red. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (72ms)  : 64, 79
     .   : milestone, 72,
    master - mean (72ms)  : 64, 80
     .   : milestone, 72,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (988ms)  : 961, 1015
     .   : milestone, 988,
    master - mean (1,107ms)  : 1088, 1127
     .   : milestone, 1107,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (109ms)  : 106, 111
     .   : milestone, 109,
    master - mean (107ms)  : 105, 110
     .   : milestone, 107,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (686ms)  : 670, 701
     .   : milestone, 686,
    master - mean (767ms)  : 746, 787
     .   : milestone, 767,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (92ms)  : 90, 93
     .   : milestone, 92,
    master - mean (92ms)  : 90, 94
     .   : milestone, 92,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (635ms)  : 619, 650
     .   : milestone, 635,
    master - mean (722ms)  : 711, 733
     .   : milestone, 722,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (191ms)  : 186, 195
     .   : milestone, 191,
    master - mean (190ms)  : 185, 196
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (1,097ms)  : 1071, 1124
     .   : milestone, 1097,
    master - mean (1,212ms)  : 1193, 1232
     .   : milestone, 1212,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (276ms)  : 272, 280
     .   : milestone, 276,
    master - mean (276ms)  : 272, 280
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (872ms)  : 844, 900
     .   : milestone, 872,
    master - mean (946ms)  : 923, 969
     .   : milestone, 946,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6252) - mean (265ms)  : 260, 270
     .   : milestone, 265,
    master - mean (265ms)  : 260, 270
     .   : milestone, 265,

    section CallTarget+Inlining+NGEN
    This PR (6252) - mean (851ms)  : 817, 884
     .   : milestone, 851,
    master - mean (926ms)  : 910, 942
     .   : milestone, 926,

Loading

@andrewlock
Copy link
Member

andrewlock commented Nov 6, 2024

Benchmarks Report for tracer 🐌

Benchmarks for #6252 compared to master:

  • 2 benchmarks are faster, with geometric mean 1.323
  • 1 benchmarks are slower, with geometric mean 1.157
  • 2 benchmarks have fewer allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 8.2μs 45.3ns 264ns 0.0118 0.00393 0 5.61 KB
master StartStopWithChild netcoreapp3.1 10.4μs 58.7ns 447ns 0.0214 0.0107 0 5.8 KB
master StartStopWithChild net472 16.5μs 38.9ns 151ns 1.04 0.301 0.0919 6.21 KB
#6252 StartStopWithChild net6.0 8.2μs 46.3ns 328ns 0.0159 0.00797 0 5.61 KB
#6252 StartStopWithChild netcoreapp3.1 9.99μs 54.4ns 303ns 0.0232 0.00928 0 5.8 KB
#6252 StartStopWithChild net472 16.8μs 59.4ns 230ns 1.04 0.305 0.0988 6.21 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 457μs 441ns 1.71μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 646μs 260ns 973ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 848μs 347ns 1.25μs 0.419 0 0 3.3 KB
#6252 WriteAndFlushEnrichedTraces net6.0 461μs 229ns 856ns 0 0 0 2.7 KB
#6252 WriteAndFlushEnrichedTraces netcoreapp3.1 645μs 209ns 782ns 0 0 0 2.7 KB
#6252 WriteAndFlushEnrichedTraces net472 844μs 529ns 2.05μs 0.419 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Faster 🎉 Fewer allocations 🎉

Faster 🎉 in #6252

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.AspNetCoreBenchmark.SendRequest‑net6.0 1.385 195,765.88 141,394.88
Benchmarks.Trace.AspNetCoreBenchmark.SendRequest‑netcoreapp3.1 1.263 213,233.65 168,777.79

Fewer allocations 🎉 in #6252

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.AspNetCoreBenchmark.SendRequest‑netcoreapp3.1 20.89 KB 17.27 KB -3.62 KB -17.32%
Benchmarks.Trace.AspNetCoreBenchmark.SendRequest‑net6.0 18.73 KB 14.47 KB -4.26 KB -22.73%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 198μs 1.15μs 9.58μs 0.195 0 0 18.73 KB
master SendRequest netcoreapp3.1 214μs 1.08μs 4.93μs 0.213 0 0 20.89 KB
master SendRequest net472 0.00101ns 0.000372ns 0.00144ns 0 0 0 0 b
#6252 SendRequest net6.0 142μs 787ns 4.85μs 0.141 0 0 14.47 KB
#6252 SendRequest netcoreapp3.1 171μs 985ns 7.56μs 0.175 0 0 17.27 KB
#6252 SendRequest net472 0.00111ns 0.000391ns 0.00141ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 568μs 2.51μs 9.06μs 0.548 0.274 0 41.45 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 690μs 3.47μs 15.5μs 0.342 0 0 41.85 KB
master WriteAndFlushEnrichedTraces net472 892μs 4.37μs 18.5μs 8.42 2.66 0.443 53.32 KB
#6252 WriteAndFlushEnrichedTraces net6.0 568μs 2.41μs 10.2μs 0.571 0 0 41.44 KB
#6252 WriteAndFlushEnrichedTraces netcoreapp3.1 685μs 2.49μs 9.65μs 0.338 0 0 41.71 KB
#6252 WriteAndFlushEnrichedTraces net472 867μs 3.31μs 12.8μs 8.08 2.55 0.425 53.26 KB
Benchmarks.Trace.DbCommandBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6252

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑net6.0 1.157 1,241.01 1,435.30

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.24μs 0.65ns 2.34ns 0.0143 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.73μs 1.36ns 4.7ns 0.0139 0 0 1.02 KB
master ExecuteNonQuery net472 2.05μs 1.45ns 5.44ns 0.157 0.00102 0 987 B
#6252 ExecuteNonQuery net6.0 1.44μs 0.794ns 2.97ns 0.0144 0 0 1.02 KB
#6252 ExecuteNonQuery netcoreapp3.1 1.78μs 1.16ns 4.2ns 0.0136 0 0 1.02 KB
#6252 ExecuteNonQuery net472 2.12μs 1.07ns 3.99ns 0.156 0.00106 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.21μs 1.38ns 5.16ns 0.014 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.62μs 0.574ns 2.15ns 0.0131 0 0 976 B
master CallElasticsearch net472 2.5μs 2.36ns 9.14ns 0.157 0 0 995 B
master CallElasticsearchAsync net6.0 1.27μs 0.703ns 2.72ns 0.0133 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.65μs 0.741ns 2.87ns 0.0139 0 0 1.02 KB
master CallElasticsearchAsync net472 2.67μs 1.94ns 7.5ns 0.166 0 0 1.05 KB
#6252 CallElasticsearch net6.0 1.32μs 0.851ns 3.29ns 0.0133 0 0 976 B
#6252 CallElasticsearch netcoreapp3.1 1.6μs 1.01ns 3.93ns 0.013 0 0 976 B
#6252 CallElasticsearch net472 2.53μs 1.16ns 4.33ns 0.157 0 0 995 B
#6252 CallElasticsearchAsync net6.0 1.35μs 0.443ns 1.66ns 0.0135 0 0 952 B
#6252 CallElasticsearchAsync netcoreapp3.1 1.71μs 1.14ns 4.25ns 0.0145 0 0 1.02 KB
#6252 CallElasticsearchAsync net472 2.54μs 0.704ns 2.54ns 0.167 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.22μs 0.394ns 1.36ns 0.0132 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.66μs 0.815ns 3.16ns 0.0125 0 0 952 B
master ExecuteAsync net472 1.69μs 1.63ns 6.32ns 0.145 0 0 915 B
#6252 ExecuteAsync net6.0 1.26μs 1.13ns 4.36ns 0.013 0 0 952 B
#6252 ExecuteAsync netcoreapp3.1 1.67μs 1.85ns 7.16ns 0.0125 0 0 952 B
#6252 ExecuteAsync net472 1.78μs 0.675ns 2.43ns 0.145 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.58μs 1.32ns 4.77ns 0.0321 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.26μs 1.28ns 4.8ns 0.0369 0 0 2.85 KB
master SendAsync net472 7.78μs 2.72ns 10.5ns 0.494 0 0 3.12 KB
#6252 SendAsync net6.0 4.44μs 2.2ns 8.52ns 0.031 0 0 2.31 KB
#6252 SendAsync netcoreapp3.1 5.31μs 2.48ns 9.59ns 0.0369 0 0 2.85 KB
#6252 SendAsync net472 7.29μs 5.04ns 19.5ns 0.495 0 0 3.12 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.58μs 0.577ns 2.16ns 0.0229 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.18μs 0.857ns 3.21ns 0.022 0 0 1.64 KB
master EnrichedLog net472 2.66μs 1.47ns 5.08ns 0.25 0 0 1.57 KB
#6252 EnrichedLog net6.0 1.47μs 0.805ns 3.01ns 0.0229 0 0 1.64 KB
#6252 EnrichedLog netcoreapp3.1 2.16μs 0.281ns 0.973ns 0.0218 0 0 1.64 KB
#6252 EnrichedLog net472 2.6μs 1.67ns 6.45ns 0.25 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 119μs 104ns 391ns 0.0588 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 124μs 469ns 1.81μs 0 0 0 4.28 KB
master EnrichedLog net472 156μs 222ns 860ns 0.706 0.235 0 4.46 KB
#6252 EnrichedLog net6.0 120μs 184ns 713ns 0.0602 0 0 4.28 KB
#6252 EnrichedLog netcoreapp3.1 121μs 442ns 1.71μs 0 0 0 4.28 KB
#6252 EnrichedLog net472 151μs 200ns 775ns 0.679 0.226 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 3.02μs 1.31ns 5.07ns 0.031 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.14μs 0.817ns 2.83ns 0.0289 0 0 2.2 KB
master EnrichedLog net472 4.92μs 1.16ns 4.17ns 0.321 0 0 2.02 KB
#6252 EnrichedLog net6.0 3.04μs 1.02ns 3.94ns 0.0301 0 0 2.2 KB
#6252 EnrichedLog netcoreapp3.1 4.16μs 1.16ns 4.5ns 0.0292 0 0 2.2 KB
#6252 EnrichedLog net472 4.9μs 2.11ns 8.17ns 0.319 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.33μs 0.429ns 1.66ns 0.0159 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.83μs 0.845ns 3.27ns 0.0156 0 0 1.14 KB
master SendReceive net472 2.15μs 0.992ns 3.84ns 0.183 0 0 1.16 KB
#6252 SendReceive net6.0 1.31μs 0.657ns 2.46ns 0.0157 0 0 1.14 KB
#6252 SendReceive netcoreapp3.1 1.76μs 0.588ns 2.28ns 0.015 0 0 1.14 KB
#6252 SendReceive net472 2.18μs 1.43ns 5.53ns 0.183 0 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.82μs 5.35ns 20.7ns 0.0225 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.97μs 1.67ns 6.45ns 0.0218 0 0 1.65 KB
master EnrichedLog net472 4.33μs 5.36ns 19.3ns 0.323 0 0 2.04 KB
#6252 EnrichedLog net6.0 2.77μs 9.72ns 37.7ns 0.0221 0 0 1.6 KB
#6252 EnrichedLog netcoreapp3.1 3.97μs 1.68ns 6.52ns 0.0219 0 0 1.65 KB
#6252 EnrichedLog net472 4.36μs 1.08ns 3.88ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 410ns 0.186ns 0.721ns 0.00804 0 0 576 B
master StartFinishSpan netcoreapp3.1 563ns 0.322ns 1.21ns 0.00783 0 0 576 B
master StartFinishSpan net472 701ns 0.974ns 3.64ns 0.0915 0 0 578 B
master StartFinishScope net6.0 517ns 0.475ns 1.84ns 0.00989 0 0 696 B
master StartFinishScope netcoreapp3.1 729ns 0.632ns 2.45ns 0.00936 0 0 696 B
master StartFinishScope net472 854ns 0.698ns 2.61ns 0.104 0 0 658 B
#6252 StartFinishSpan net6.0 402ns 0.494ns 1.85ns 0.00806 0 0 576 B
#6252 StartFinishSpan netcoreapp3.1 557ns 0.843ns 3.26ns 0.00776 0 0 576 B
#6252 StartFinishSpan net472 744ns 0.742ns 2.87ns 0.0916 0 0 578 B
#6252 StartFinishScope net6.0 500ns 0.958ns 3.71ns 0.00971 0 0 696 B
#6252 StartFinishScope netcoreapp3.1 758ns 0.309ns 1.2ns 0.0094 0 0 696 B
#6252 StartFinishScope net472 920ns 3.45ns 13.3ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 649ns 0.313ns 1.17ns 0.00979 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 998ns 0.786ns 3.04ns 0.00948 0 0 696 B
master RunOnMethodBegin net472 1.18μs 0.603ns 2.25ns 0.104 0 0 658 B
#6252 RunOnMethodBegin net6.0 680ns 0.689ns 2.67ns 0.00975 0 0 696 B
#6252 RunOnMethodBegin netcoreapp3.1 939ns 1.04ns 3.9ns 0.00937 0 0 696 B
#6252 RunOnMethodBegin net472 1.13μs 3.84ns 14.9ns 0.105 0 0 658 B

@andrewlock
Copy link
Member

andrewlock commented Nov 6, 2024

Throughput/Crank Report ⚡

Throughput results for AspNetCoreSimpleController comparing the following branches/commits:

Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red.

Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards!

gantt
    title Throughput Linux x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6252) (11.281M)   : 0, 11280867
    master (11.120M)   : 0, 11120201
    benchmarks/2.9.0 (11.033M)   : 0, 11032866

    section Automatic
    This PR (6252) (7.282M)   : 0, 7282096
    master (7.143M)   : 0, 7143247
    benchmarks/2.9.0 (7.786M)   : 0, 7785853

    section Trace stats
    master (7.563M)   : 0, 7562834

    section Manual
    master (11.052M)   : 0, 11051540

    section Manual + Automatic
    This PR (6252) (6.770M)   : 0, 6769646
    master (6.532M)   : 0, 6532471

    section DD_TRACE_ENABLED=0
    master (10.176M)   : 0, 10176174

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6252) (9.548M)   : 0, 9547654
    master (9.435M)   : 0, 9435139
    benchmarks/2.9.0 (9.495M)   : 0, 9494821

    section Automatic
    This PR (6252) (6.440M)   : 0, 6439756
    master (6.301M)   : 0, 6300608

    section Trace stats
    master (6.646M)   : 0, 6646045

    section Manual
    master (9.564M)   : 0, 9563833

    section Manual + Automatic
    This PR (6252) (5.918M)   : 0, 5917904
    master (5.897M)   : 0, 5897193

    section DD_TRACE_ENABLED=0
    master (8.862M)   : 0, 8862065

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6252) (9.830M)   : 0, 9830291
    master (9.832M)   : 0, 9832351
    benchmarks/2.9.0 (10.020M)   : 0, 10019592

    section Automatic
    This PR (6252) (6.329M)   : 0, 6328761
    master (6.258M)   : 0, 6258447
    benchmarks/2.9.0 (7.255M)   : 0, 7255257

    section Trace stats
    master (6.950M)   : 0, 6950057

    section Manual
    master (9.945M)   : 0, 9945109

    section Manual + Automatic
    This PR (6252) (5.829M)   : 0, 5829405
    master (5.742M)   : 0, 5742033

    section DD_TRACE_ENABLED=0
    master (9.091M)   : 0, 9091089

Loading

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Nov 6, 2024

Datadog Report

Branch report: dani/apm/NativeCallTargets
Commit report: b0d7fec
Test service: dd-trace-dotnet

❌ 6 Failed (0 Known Flaky), 527391 Passed, 2043 Skipped, 17h 46m 33.9s Total Time

❌ Failed Tests (6)

This report shows up to 5 failed tests.

  • AllCycleMoreComplexBody - Benchmarks.Trace.Asm.AppSecBodyBenchmark - Details

  • AllCycleMoreComplexBody - Benchmarks.Trace.Asm.AppSecBodyBenchmark - Details

  • AllCycleMoreComplexBody - Benchmarks.Trace.Asm.AppSecBodyBenchmark - Details

  • AllCycleSimpleBody - Benchmarks.Trace.Asm.AppSecBodyBenchmark - Details

  • AllCycleSimpleBody - Benchmarks.Trace.Asm.AppSecBodyBenchmark - Details

@daniel-romano-DD daniel-romano-DD force-pushed the dani/apm/NativeCallTargets branch 2 times, most recently from c803d7d to afed6e3 Compare November 7, 2024 13:21
@daniel-romano-DD daniel-romano-DD added area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) labels Nov 7, 2024
@andrewlock
Copy link
Member

andrewlock commented Nov 8, 2024

Benchmarks Report for appsec 🐌

Benchmarks for #6252 compared to master:

  • All benchmarks have the same speed
  • 2 benchmarks have fewer allocations
  • 1 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net6.0 72.3μs 67.8ns 263ns 0.0716 0 0 6 KB
master AllCycleSimpleBody netcoreapp3.1 62.5μs 58.7ns 220ns 0.0938 0 0 6.95 KB
master AllCycleSimpleBody net472 49.1μs 72ns 279ns 1.31 0 0 8.33 KB
master AllCycleMoreComplexBody net6.0 78.4μs 55ns 213ns 0.117 0 0 9.51 KB
master AllCycleMoreComplexBody netcoreapp3.1 69.4μs 56.4ns 211ns 0.139 0 0 10.36 KB
master AllCycleMoreComplexBody net472 56.5μs 85.2ns 330ns 1.87 0.0283 0 11.85 KB
master ObjectExtractorSimpleBody net6.0 145ns 0.12ns 0.448ns 0.00395 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 209ns 0.137ns 0.494ns 0.00369 0 0 272 B
master ObjectExtractorSimpleBody net472 171ns 0.0861ns 0.334ns 0.0446 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 3.04μs 2.64ns 9.86ns 0.0533 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 3.91μs 3.08ns 11.9ns 0.0507 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 4.36μs 1.92ns 7.44ns 0.601 0.00656 0 3.8 KB
#6252 AllCycleSimpleBody net6.0 72.2μs 53.8ns 208ns 0.0721 0 0 6 KB
#6252 AllCycleSimpleBody netcoreapp3.1 63.8μs 36.3ns 126ns 0.0958 0 0 6.95 KB
#6252 AllCycleSimpleBody net472 47.7μs 55.8ns 216ns 1.31 0 0 8.34 KB
#6252 AllCycleMoreComplexBody net6.0 78.6μs 98ns 367ns 0.118 0 0 9.51 KB
#6252 AllCycleMoreComplexBody netcoreapp3.1 69μs 60.6ns 227ns 0.138 0 0 10.37 KB
#6252 AllCycleMoreComplexBody net472 54.8μs 52.6ns 204ns 1.88 0.0272 0 11.85 KB
#6252 ObjectExtractorSimpleBody net6.0 146ns 0.273ns 1.02ns 0.00392 0 0 280 B
#6252 ObjectExtractorSimpleBody netcoreapp3.1 206ns 0.285ns 1.07ns 0.00371 0 0 272 B
#6252 ObjectExtractorSimpleBody net472 165ns 0.124ns 0.462ns 0.0446 0 0 281 B
#6252 ObjectExtractorMoreComplexBody net6.0 3.14μs 3.38ns 12.6ns 0.053 0 0 3.78 KB
#6252 ObjectExtractorMoreComplexBody netcoreapp3.1 3.9μs 1.8ns 6.72ns 0.0509 0 0 3.69 KB
#6252 ObjectExtractorMoreComplexBody net472 4.34μs 3.23ns 12.5ns 0.603 0.0065 0 3.8 KB
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EncodeArgs net6.0 38.2μs 26.2ns 102ns 0.454 0 0 32.4 KB
master EncodeArgs netcoreapp3.1 54.3μs 36.7ns 142ns 0.432 0 0 32.4 KB
master EncodeArgs net472 66.4μs 27.9ns 104ns 5.15 0.0661 0 32.5 KB
master EncodeLegacyArgs net6.0 76.2μs 407ns 2.11μs 0 0 0 2.14 KB
master EncodeLegacyArgs netcoreapp3.1 109μs 254ns 983ns 0 0 0 2.14 KB
master EncodeLegacyArgs net472 154μs 97.1ns 376ns 0.31 0 0 2.15 KB
#6252 EncodeArgs net6.0 38.4μs 26.9ns 104ns 0.441 0 0 32.4 KB
#6252 EncodeArgs netcoreapp3.1 54.7μs 24.9ns 96.6ns 0.439 0 0 32.4 KB
#6252 EncodeArgs net472 66.4μs 41.8ns 162ns 5.14 0.0663 0 32.5 KB
#6252 EncodeLegacyArgs net6.0 78.7μs 374ns 1.45μs 0 0 0 2.14 KB
#6252 EncodeLegacyArgs netcoreapp3.1 105μs 158ns 612ns 0 0 0 2.14 KB
#6252 EncodeLegacyArgs net472 152μs 92.5ns 358ns 0.306 0 0 2.15 KB
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunWafRealisticBenchmark net6.0 185μs 60.9ns 236ns 0 0 0 2.44 KB
master RunWafRealisticBenchmark netcoreapp3.1 198μs 238ns 921ns 0 0 0 2.39 KB
master RunWafRealisticBenchmark net472 210μs 141ns 545ns 0.315 0 0 2.46 KB
master RunWafRealisticBenchmarkWithAttack net6.0 122μs 106ns 381ns 0 0 0 1.47 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 130μs 155ns 598ns 0 0 0 1.46 KB
master RunWafRealisticBenchmarkWithAttack net472 138μs 42.5ns 153ns 0.208 0 0 1.49 KB
#6252 RunWafRealisticBenchmark net6.0 185μs 65.7ns 246ns 0 0 0 2.44 KB
#6252 RunWafRealisticBenchmark netcoreapp3.1 194μs 195ns 757ns 0 0 0 2.39 KB
#6252 RunWafRealisticBenchmark net472 212μs 119ns 461ns 0.314 0 0 2.46 KB
#6252 RunWafRealisticBenchmarkWithAttack net6.0 124μs 70.8ns 274ns 0 0 0 1.47 KB
#6252 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 130μs 213ns 825ns 0 0 0 1.46 KB
#6252 RunWafRealisticBenchmarkWithAttack net472 139μs 47.3ns 177ns 0.207 0 0 1.48 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #6252

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net472 272.91 KB 278.53 KB 5.62 KB 2.06%

Fewer allocations 🎉 in #6252

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 255.27 KB 253.38 KB -1.89 KB -0.74%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 60.49 KB 59.04 KB -1.45 KB -2.39%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 52.9μs 209ns 782ns 0 0 0 43.44 KB
master StringConcatBenchmark netcoreapp3.1 54.2μs 287ns 1.38μs 0 0 0 42.64 KB
master StringConcatBenchmark net472 38μs 165ns 616ns 0 0 0 60.49 KB
master StringConcatAspectBenchmark net6.0 295μs 4.71μs 43.7μs 0 0 0 253.95 KB
master StringConcatAspectBenchmark netcoreapp3.1 354μs 1.97μs 12.1μs 0 0 0 255.27 KB
master StringConcatAspectBenchmark net472 278μs 6.14μs 58.9μs 0 0 0 272.91 KB
#6252 StringConcatBenchmark net6.0 61.1μs 769ns 7.53μs 0 0 0 43.44 KB
#6252 StringConcatBenchmark netcoreapp3.1 62.5μs 869ns 8.65μs 0 0 0 42.64 KB
#6252 StringConcatBenchmark net472 37.6μs 119ns 429ns 0 0 0 59.04 KB
#6252 StringConcatAspectBenchmark net6.0 310μs 1.41μs 5.46μs 0 0 0 255.08 KB
#6252 StringConcatAspectBenchmark netcoreapp3.1 334μs 1.7μs 10.9μs 0 0 0 253.38 KB
#6252 StringConcatAspectBenchmark net472 283μs 6.3μs 61.4μs 0 0 0 278.53 KB

Comment on lines 12 to 14
"Item1": 2,
"Item2": 0,
"Item3": 0
Copy link
Member

Choose a reason for hiding this comment

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

I know this is not intended to be read by a human, but Item1 Item2andItem3`? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, the version struct is defined as a Tuple...

tracer/missing-nullability-files.csv Show resolved Hide resolved
Comment on lines +62 to +64
// TODO : Temporary build fix
Definitions = null; // InstrumentationDefinitions.GetAllDefinitionsNative();
DerivedDefinitions = null; // InstrumentationDefinitions.GetAllDerivedDefinitionsNative();
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should use the same json file for dependabot... wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, quite possible, but I think the reality is that this isn't supported or used anywhere yet, so it's not worth worrying about until we come back to this IMO

@@ -1,41 +1,42 @@
// <copyright file="NativeCallTargetDefinition2.cs" company="Datadog">
// <copyright file="NativeCallTargetDefinition3.cs" company="Datadog">
Copy link
Member

Choose a reason for hiding this comment

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

3?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we're not sending these from managed -> Native, I'm not sure why we need this file at all? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A couple of tests need this. We'll figure out how to circumvent this in a future PR

Copy link
Member

@andrewlock andrewlock left a comment

Choose a reason for hiding this comment

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

Nice work 👍

Mostly just some small suggestions e.g. be more aggressive about validation and error cases in the generator file - we can just throw as soon as we spot anything invalid, better to break the build than have something invalid in there.

A bigger concern is the changing of the native interface - I don't think we should change the native method that is called from the managed size, just add a new one?

tracer/build/_build/Build.Steps.cs Outdated Show resolved Hide resolved
tracer/build/_build/Build.Utilities.cs Outdated Show resolved Hide resolved

public static void GenerateCallTargets(IEnumerable<TargetFramework> targetFrameworks, Func<string, string> getDllPath, AbsolutePath outputPath, string version, AbsolutePath dependabotPath)
{
Serilog.Log.Debug("Generating CallTarget definitions file ...");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Serilog.Log.Debug("Generating CallTarget definitions file ...");
Logger.Debug("Generating CallTarget definitions file ...");

Comment on lines 139 to 140
TryGetVersion(minimumVersion, ushort.MinValue, out minVersion);
TryGetVersion(maximumVersion, ushort.MaxValue, out maxVersion);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably handle the return value of false here and throw, pointing to the value and the integration with the problem, otherwise we could end up with strange issues:

Suggested change
TryGetVersion(minimumVersion, ushort.MinValue, out minVersion);
TryGetVersion(maximumVersion, ushort.MaxValue, out maxVersion);
if (!TryGetVersion(minimumVersion, ushort.MinValue, out minVersion))
{
throw new InvalidOperationException($"Error: Integration type '{type}' has invalid value for minimum: '{minimumVersion}'");
}
if (!TryGetVersion(maximumVersion, ushort.MaxValue, out maxVersion))
{
throw new InvalidOperationException($"Error: Integration type '{type}' has invalid value for maximum: '{maximumVersion}'");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, but this is already covered in the SourceCodeGenerator. Although I could add more checks here

Copy link
Member

Choose a reason for hiding this comment

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

But we don't want the source code generator any more after this PR do we? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nop, but yep, but nop, but yep... The IntegrationOptions is calling GetIntegrationId, so... We might want to look for an alternative method in a following PR

@@ -183,7 +129,7 @@ public static int RegisterIastAspects(string[] aspects)
}
}

public static int RegisterCallTargetDefinitions(string id, NativeCallTargetDefinition2[] items, uint enabledCategories)
public static int RegisterCallTargetDefinitions(string id, NativeCallTargetDefinition3[] items, uint enabledCategories)
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused, we don't need this method do we, we shouldn't be calling it from anywhere as I understand it 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is used to test the category enablement / disablement feature. It's just an entry point that executes the same code that is invoked with the built in definitions

Comment on lines -20 to +19
RegisterCallTargetDefinitions
RegisterCallTargetDefinitions3
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be exactly what we don't want to do 🤔 We shouldn't remove the RegisterCallTargetDefinitions method, it needs to remain there, unchanged. And we don't need RegisterCallTargetDefinitions3 because it will never be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Legacy init uses InitProfiler in version mismatch scenarios. RegisterCallTargetDefs was called when no mismatch was found, so not needed anymore (but for testing purposes)

@@ -15,671 +15,8 @@ namespace Datadog.Trace.ClrProfiler
{
internal static partial class InstrumentationDefinitions
{
internal static NativeCallTargetDefinition2[] Instrumentations;

static InstrumentationDefinitions()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to generate this file at all any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InterationOption is still invoking the GetIntegrationId function...

{(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics"),(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware"),(WCHAR*)WStr("DisplayException"),g_callTargets_Sig_159,3,2,0,0,2,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.StackTraceLeak.DeveloperExceptionPageMiddlewareIntegration"),CallTargetKind::Default,4,164},
{(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics"),(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware"),(WCHAR*)WStr("DisplayException"),g_callTargets_Sig_157,2,3,0,0,6,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.StackTraceLeak.DeveloperExceptionPageMiddlewareIntegration_Pre_3_0_0"),CallTargetKind::Default,4,164},
{(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics"),(WCHAR*)WStr("Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl"),(WCHAR*)WStr("DisplayException"),g_callTargets_Sig_157,2,7,0,0,8,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.StackTraceLeak.DeveloperExceptionPageMiddlewareIntegration_Pre_3_0_0"),CallTargetKind::Default,4,164},
{(WCHAR*)WStr("System.Web"),(WCHAR*)WStr("System.Web.HttpResponse"),(WCHAR*)WStr("WriteErrorMessage"),g_callTargets_Sig_267,3,4,0,0,4,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.StackTraceLeak.HttpResponseIntegration"),CallTargetKind::Default,4,1},
Copy link
Member

Choose a reason for hiding this comment

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

As for callsites, I wonder if we can omit the NETFX-only integrations in linux/macos, but that's an optimization for later if we want to consider it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhm, interesting. Noted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -203,8 +203,7 @@ class CorProfiler : public CorProfilerBase
//
// Tracer Integration methods #2
//
long RegisterCallTargetDefinitions(WCHAR* id, CallTargetDefinition2* items, int size,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can or should delete this. I think this is exactly the sort of method that we explicitly should never touch 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's never used in version mismatch scenarios

Copy link
Contributor

@anna-git anna-git left a comment

Choose a reason for hiding this comment

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

nice work! I'm not sure I've understood all the ins and outs, but from asm pov it looks good, just a few comments for my understanding, thanks

parameterTypeNames = GetStringArray(namedArgument.Argument.Value);
break;
case nameof(InstrumentAttributeProperties.CallTargetType):
//callTargetType = (namedArgument.Argument.Value as INamedTypeSymbol)?.ToDisplayString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this case be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, maybe. I put a breakpoint there that never triggered. Good catch

targetParameterTypes: parameterTypeNames ?? Array.Empty<string>(),
minimumVersion: minVersion,
maximumVersion: maxVersion,
instrumentationTypeName: callTargetType ?? type.FullName,
Copy link
Contributor

Choose a reason for hiding this comment

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

if the case above is removed, call target type will always be null?

}
}

public static void DisableTracerCLRProfiler()
Copy link
Contributor

Choose a reason for hiding this comment

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

so we don't need this anymore? I still see it in the Native.def exports though ( same for the ones above I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, some cleaning is still needed. Good catch

@daniel-romano-DD daniel-romano-DD force-pushed the dani/apm/NativeCallTargets branch 2 times, most recently from df76b2f to d1bb046 Compare November 15, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:asm area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants