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:

  • 3 benchmarks are faster, with geometric mean 1.269
  • 1 benchmarks are slower, with geometric mean 1.134
  • 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 7.94μs 40.8ns 200ns 0.0155 0.00777 0 5.61 KB
master StartStopWithChild netcoreapp3.1 10.1μs 57.2ns 370ns 0.015 0.00499 0 5.8 KB
master StartStopWithChild net472 16.1μs 41.1ns 159ns 1.04 0.294 0.0875 6.21 KB
#6252 StartStopWithChild net6.0 8.07μs 46.1ns 360ns 0.0116 0.0077 0 5.61 KB
#6252 StartStopWithChild netcoreapp3.1 10.2μs 55.7ns 320ns 0.0151 0.00503 0 5.81 KB
#6252 StartStopWithChild net472 16.1μs 56.4ns 211ns 1.02 0.28 0.08 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 506μs 215ns 806ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 648μs 312ns 1.12μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 875μs 753ns 2.91μs 0.431 0 0 3.3 KB
#6252 WriteAndFlushEnrichedTraces net6.0 487μs 262ns 1.01μs 0 0 0 2.7 KB
#6252 WriteAndFlushEnrichedTraces netcoreapp3.1 664μs 524ns 1.96μs 0 0 0 2.7 KB
#6252 WriteAndFlushEnrichedTraces net472 859μs 688ns 2.66μs 0.422 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.348 196,032.01 145,463.02
Benchmarks.Trace.AspNetCoreBenchmark.SendRequest‑netcoreapp3.1 1.279 220,789.94 172,577.77 several?

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 197μs 1.13μs 8.13μs 0.198 0 0 18.73 KB
master SendRequest netcoreapp3.1 222μs 1.18μs 9μs 0.206 0 0 20.89 KB
master SendRequest net472 0.00052ns 0.000242ns 0.000907ns 0 0 0 0 b
#6252 SendRequest net6.0 146μs 822ns 5.27μs 0.147 0 0 14.47 KB
#6252 SendRequest netcoreapp3.1 175μs 1.02μs 9.66μs 0.173 0 0 17.27 KB
#6252 SendRequest net472 0.00196ns 0.000674ns 0.00261ns 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 575μs 2.78μs 13μs 0.579 0 0 41.55 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 675μs 3.17μs 12.3μs 0.324 0 0 41.87 KB
master WriteAndFlushEnrichedTraces net472 858μs 3.67μs 14.2μs 8.39 2.52 0.419 53.29 KB
#6252 WriteAndFlushEnrichedTraces net6.0 558μs 2.51μs 10.6μs 0.568 0 0 41.46 KB
#6252 WriteAndFlushEnrichedTraces netcoreapp3.1 690μs 3.44μs 20.1μs 0.381 0 0 41.82 KB
#6252 WriteAndFlushEnrichedTraces net472 850μs 2.84μs 11μs 8.13 2.57 0.428 53.26 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.32μs 1.31ns 5.06ns 0.0146 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.73μs 1.3ns 4.69ns 0.0139 0 0 1.02 KB
master ExecuteNonQuery net472 2.01μs 1.54ns 5.96ns 0.156 0.00101 0 987 B
#6252 ExecuteNonQuery net6.0 1.33μs 1.09ns 4.23ns 0.0147 0 0 1.02 KB
#6252 ExecuteNonQuery netcoreapp3.1 1.79μs 1.28ns 4.79ns 0.0134 0 0 1.02 KB
#6252 ExecuteNonQuery net472 2.01μs 1.72ns 6.67ns 0.157 0.001 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.15μs 0.379ns 1.42ns 0.0138 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.49μs 0.517ns 1.93ns 0.0134 0 0 976 B
master CallElasticsearch net472 2.48μs 1.06ns 3.95ns 0.157 0 0 995 B
master CallElasticsearchAsync net6.0 1.28μs 0.475ns 1.78ns 0.0134 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.66μs 0.8ns 3.1ns 0.0133 0 0 1.02 KB
master CallElasticsearchAsync net472 2.63μs 0.664ns 2.39ns 0.166 0 0 1.05 KB
#6252 CallElasticsearch net6.0 1.25μs 0.99ns 3.7ns 0.0137 0 0 976 B
#6252 CallElasticsearch netcoreapp3.1 1.61μs 0.717ns 2.78ns 0.0129 0 0 976 B
#6252 CallElasticsearch net472 2.54μs 1.04ns 4.05ns 0.158 0 0 995 B
#6252 CallElasticsearchAsync net6.0 1.31μs 1.02ns 3.83ns 0.0131 0 0 952 B
#6252 CallElasticsearchAsync netcoreapp3.1 1.65μs 0.602ns 2.25ns 0.014 0 0 1.02 KB
#6252 CallElasticsearchAsync net472 2.6μs 1.51ns 5.84ns 0.166 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.15μs 0.63ns 2.36ns 0.0132 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.73μs 0.229ns 0.857ns 0.0129 0 0 952 B
master ExecuteAsync net472 1.84μs 0.377ns 1.36ns 0.145 0 0 915 B
#6252 ExecuteAsync net6.0 1.14μs 1.3ns 5.03ns 0.0133 0 0 952 B
#6252 ExecuteAsync netcoreapp3.1 1.66μs 1.24ns 4.8ns 0.0126 0 0 952 B
#6252 ExecuteAsync net472 1.81μs 0.782ns 2.93ns 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.47μs 1.08ns 4.04ns 0.0314 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.15μs 1.92ns 7.17ns 0.0385 0 0 2.85 KB
master SendAsync net472 7.35μs 1.79ns 6.94ns 0.495 0 0 3.12 KB
#6252 SendAsync net6.0 4.32μs 1.68ns 6.3ns 0.0316 0 0 2.31 KB
#6252 SendAsync netcoreapp3.1 5.47μs 2.53ns 9.81ns 0.0382 0 0 2.85 KB
#6252 SendAsync net472 7.24μs 1.94ns 7.53ns 0.496 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.54μs 2.82ns 10.9ns 0.0229 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.35μs 1.44ns 5.38ns 0.0224 0 0 1.64 KB
master EnrichedLog net472 2.69μs 2.11ns 8.17ns 0.25 0 0 1.57 KB
#6252 EnrichedLog net6.0 1.59μs 0.752ns 2.81ns 0.0231 0 0 1.64 KB
#6252 EnrichedLog netcoreapp3.1 2.29μs 1.22ns 4.57ns 0.0227 0 0 1.64 KB
#6252 EnrichedLog net472 2.59μs 1.11ns 4.29ns 0.249 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 103ns 400ns 0.0599 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 125μs 107ns 386ns 0 0 0 4.28 KB
master EnrichedLog net472 152μs 137ns 532ns 0.681 0.227 0 4.46 KB
#6252 EnrichedLog net6.0 118μs 202ns 784ns 0.059 0 0 4.28 KB
#6252 EnrichedLog netcoreapp3.1 124μs 170ns 657ns 0 0 0 4.28 KB
#6252 EnrichedLog net472 151μs 122ns 471ns 0.678 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.23μs 0.93ns 3.6ns 0.0313 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.18μs 1.33ns 5.13ns 0.0293 0 0 2.2 KB
master EnrichedLog net472 4.89μs 2.3ns 8.61ns 0.32 0 0 2.02 KB
#6252 EnrichedLog net6.0 3.05μs 1.57ns 6.07ns 0.0304 0 0 2.2 KB
#6252 EnrichedLog netcoreapp3.1 4.24μs 1.6ns 6.21ns 0.0297 0 0 2.2 KB
#6252 EnrichedLog net472 4.96μs 1.65ns 6.4ns 0.318 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.31μs 1.72ns 6.66ns 0.0157 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.83μs 1.26ns 4.71ns 0.0155 0 0 1.14 KB
master SendReceive net472 2.02μs 1.06ns 3.67ns 0.183 0 0 1.16 KB
#6252 SendReceive net6.0 1.34μs 0.848ns 3.29ns 0.016 0 0 1.14 KB
#6252 SendReceive netcoreapp3.1 1.8μs 0.737ns 2.85ns 0.0152 0 0 1.14 KB
#6252 SendReceive net472 2.11μs 0.673ns 2.61ns 0.184 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.62μs 0.737ns 2.86ns 0.0221 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.93μs 2.07ns 8.02ns 0.0216 0 0 1.65 KB
master EnrichedLog net472 4.46μs 2.62ns 10.1ns 0.323 0 0 2.04 KB
#6252 EnrichedLog net6.0 2.7μs 1.24ns 4.65ns 0.023 0 0 1.6 KB
#6252 EnrichedLog netcoreapp3.1 3.94μs 2.62ns 10.2ns 0.0214 0 0 1.65 KB
#6252 EnrichedLog net472 4.39μs 2.16ns 8.07ns 0.323 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Faster 🎉 Same allocations ✔️

Faster 🎉 in #6252

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑netcoreapp3.1 1.185 799.13 674.30

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 398ns 0.233ns 0.903ns 0.00805 0 0 576 B
master StartFinishSpan netcoreapp3.1 561ns 0.48ns 1.86ns 0.00776 0 0 576 B
master StartFinishSpan net472 621ns 0.231ns 0.893ns 0.0916 0 0 578 B
master StartFinishScope net6.0 501ns 0.409ns 1.58ns 0.00978 0 0 696 B
master StartFinishScope netcoreapp3.1 799ns 0.426ns 1.65ns 0.0095 0 0 696 B
master StartFinishScope net472 908ns 0.452ns 1.75ns 0.104 0 0 658 B
#6252 StartFinishSpan net6.0 424ns 0.356ns 1.38ns 0.00814 0 0 576 B
#6252 StartFinishSpan netcoreapp3.1 546ns 0.574ns 2.22ns 0.00792 0 0 576 B
#6252 StartFinishSpan net472 649ns 1.4ns 5.03ns 0.0917 0 0 578 B
#6252 StartFinishScope net6.0 498ns 0.388ns 1.5ns 0.00983 0 0 696 B
#6252 StartFinishScope netcoreapp3.1 674ns 0.537ns 2.01ns 0.00938 0 0 696 B
#6252 StartFinishScope net472 868ns 0.725ns 2.81ns 0.105 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6252

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net6.0 1.134 602.41 682.94

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 602ns 0.221ns 0.855ns 0.00987 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 975ns 0.49ns 1.83ns 0.00927 0 0 696 B
master RunOnMethodBegin net472 1.18μs 0.483ns 1.87ns 0.104 0 0 658 B
#6252 RunOnMethodBegin net6.0 683ns 0.428ns 1.66ns 0.00994 0 0 696 B
#6252 RunOnMethodBegin netcoreapp3.1 961ns 3.84ns 14.4ns 0.00945 0 0 696 B
#6252 RunOnMethodBegin net472 1.17μs 1.1ns 4.11ns 0.104 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.114M)   : 0, 11114362
    master (11.197M)   : 0, 11197381
    benchmarks/2.9.0 (11.033M)   : 0, 11032866

    section Automatic
    This PR (6252) (7.264M)   : 0, 7263739
    master (7.192M)   : 0, 7192384
    benchmarks/2.9.0 (7.786M)   : 0, 7785853

    section Trace stats
    master (7.476M)   : 0, 7475872

    section Manual
    master (11.271M)   : 0, 11270878

    section Manual + Automatic
    This PR (6252) (6.603M)   : 0, 6603211
    master (6.621M)   : 0, 6620931

    section DD_TRACE_ENABLED=0
    master (10.177M)   : 0, 10176556

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6252) (9.404M)   : 0, 9403660
    master (9.640M)   : 0, 9639769
    benchmarks/2.9.0 (9.495M)   : 0, 9494821

    section Automatic
    This PR (6252) (6.459M)   : 0, 6458527
    master (6.385M)   : 0, 6384570

    section Trace stats
    master (6.740M)   : 0, 6739552

    section Manual
    master (9.612M)   : 0, 9611974

    section Manual + Automatic
    This PR (6252) (5.983M)   : 0, 5982868
    master (5.891M)   : 0, 5890550

    section DD_TRACE_ENABLED=0
    master (8.839M)   : 0, 8838985

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6252) (10.052M)   : 0, 10052259
    master (10.121M)   : 0, 10120763
    benchmarks/2.9.0 (10.020M)   : 0, 10019592

    section Automatic
    This PR (6252) (6.619M)   : 0, 6618774
    master (6.469M)   : 0, 6469072
    benchmarks/2.9.0 (7.255M)   : 0, 7255257

    section Trace stats
    master (6.864M)   : 0, 6863851

    section Manual
    master (9.854M)   : 0, 9854162

    section Manual + Automatic
    This PR (6252) (6.288M)   : 0, 6288423
    master (5.906M)   : 0, 5906154

    section DD_TRACE_ENABLED=0
    master (9.224M)   : 0, 9224050

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), 571041 Passed, 4731 Skipped, 47h 1m 8.18s 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