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

Change ICorProfilerMethodEnum to use the COMPtr #6334

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

tonyredondo
Copy link
Member

@tonyredondo tonyredondo commented Nov 21, 2024

Summary of changes

This PR changes the way we handle ICorProfilerMethodEnum to use the COMPtr to release it when it's out of scope.

Reason for change

Match the rejitprofiler test in the dotnet runtime repo: https://github.com/dotnet/runtime/blob/98049e56a415d9bcf2d002fba71f399ba08cf39c/src/tests/profiler/native/rejitprofiler/rejitprofiler.cpp#L280-L281

and instead of manually calling Release use the COMPtrHolder to automatically release it.

…older` to release it when it's out of scope.
@tonyredondo tonyredondo requested a review from a team as a code owner November 21, 2024 16:22
@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Nov 21, 2024

Datadog Report

Branch report: tony/use-comptrholder-part1
Commit report: 876fa79
Test service: dd-trace-dotnet

✅ 0 Failed, 453816 Passed, 3241 Skipped, 28h 31m 22.38s Total Time

@andrewlock
Copy link
Member

andrewlock commented Nov 21, 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 (6334) - mean (72ms)  : 61, 84
     .   : milestone, 72,
    master - mean (71ms)  : 64, 78
     .   : milestone, 71,

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (1,108ms)  : 1084, 1132
     .   : milestone, 1108,
    master - mean (1,109ms)  : 1083, 1135
     .   : milestone, 1109,

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

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (764ms)  : 752, 777
     .   : milestone, 764,
    master - mean (772ms)  : 752, 791
     .   : milestone, 772,

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

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (721ms)  : 701, 740
     .   : milestone, 721,
    master - mean (726ms)  : 711, 741
     .   : milestone, 726,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6334) - mean (190ms)  : 186, 194
     .   : milestone, 190,
    master - mean (192ms)  : 186, 198
     .   : milestone, 192,

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (1,210ms)  : 1190, 1230
     .   : milestone, 1210,
    master - mean (1,214ms)  : 1192, 1237
     .   : milestone, 1214,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6334) - mean (275ms)  : 271, 279
     .   : milestone, 275,
    master - mean (278ms)  : 272, 284
     .   : milestone, 278,

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (946ms)  : 912, 979
     .   : milestone, 946,
    master - mean (949ms)  : 933, 965
     .   : milestone, 949,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6334) - mean (267ms)  : 264, 270
     .   : milestone, 267,
    master - mean (266ms)  : 262, 270
     .   : milestone, 266,

    section CallTarget+Inlining+NGEN
    This PR (6334) - mean (927ms)  : 909, 944
     .   : milestone, 927,
    master - mean (931ms)  : 914, 948
     .   : milestone, 931,

Loading

@andrewlock
Copy link
Member

Benchmarks Report for tracer 🐌

Benchmarks for #6334 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.136
  • 1 benchmarks are slower, with geometric mean 1.125
  • 1 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.8μs 42ns 230ns 0.0188 0.00753 0 5.61 KB
master StartStopWithChild netcoreapp3.1 10μs 51.3ns 281ns 0.0189 0.00944 0 5.81 KB
master StartStopWithChild net472 16.2μs 43.1ns 167ns 1.05 0.296 0.0961 6.2 KB
#6334 StartStopWithChild net6.0 7.93μs 45.3ns 336ns 0.0153 0.00765 0 5.6 KB
#6334 StartStopWithChild netcoreapp3.1 10μs 53.4ns 298ns 0.0196 0.00982 0 5.8 KB
#6334 StartStopWithChild net472 16.3μs 37.6ns 146ns 1.04 0.31 0.098 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 474μs 258ns 931ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 664μs 654ns 2.45μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 856μs 427ns 1.6μs 0.428 0 0 3.3 KB
#6334 WriteAndFlushEnrichedTraces net6.0 476μs 220ns 850ns 0 0 0 2.7 KB
#6334 WriteAndFlushEnrichedTraces netcoreapp3.1 661μs 234ns 876ns 0 0 0 2.7 KB
#6334 WriteAndFlushEnrichedTraces net472 865μs 341ns 1.32μs 0.431 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 146μs 789ns 4.25μs 0.218 0 0 14.47 KB
master SendRequest netcoreapp3.1 166μs 970ns 8.57μs 0.158 0 0 17.27 KB
master SendRequest net472 0.000716ns 0.000382ns 0.00143ns 0 0 0 0 b
#6334 SendRequest net6.0 149μs 872ns 7.99μs 0.147 0 0 14.47 KB
#6334 SendRequest netcoreapp3.1 174μs 1.35μs 13.4μs 0.114 0 0 17.27 KB
#6334 SendRequest net472 0.00112ns 0.000547ns 0.00205ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #6334

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑net6.0 41.79 KB 41.52 KB -268 B -0.64%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 583μs 3.09μs 16μs 0.595 0 0 41.79 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 679μs 3.14μs 14.4μs 0.345 0 0 41.77 KB
master WriteAndFlushEnrichedTraces net472 869μs 3.17μs 11.9μs 8.13 2.57 0.428 53.33 KB
#6334 WriteAndFlushEnrichedTraces net6.0 574μs 3.19μs 20.9μs 0.563 0 0 41.52 KB
#6334 WriteAndFlushEnrichedTraces netcoreapp3.1 695μs 3.56μs 16.7μs 0.334 0 0 41.74 KB
#6334 WriteAndFlushEnrichedTraces net472 874μs 4.08μs 16.3μs 8.19 2.59 0.431 53.33 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.24μs 2.91ns 11.3ns 0.0138 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.78μs 2.34ns 9.07ns 0.0133 0 0 1.02 KB
master ExecuteNonQuery net472 2.1μs 1.38ns 5.34ns 0.157 0.00105 0 987 B
#6334 ExecuteNonQuery net6.0 1.31μs 1.74ns 6.73ns 0.0143 0 0 1.02 KB
#6334 ExecuteNonQuery netcoreapp3.1 1.88μs 2.01ns 7.77ns 0.014 0 0 1.02 KB
#6334 ExecuteNonQuery net472 2.07μs 2.75ns 10.6ns 0.157 0.00102 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6334

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net6.0 1.125 1,234.58 1,388.70

Faster 🎉 in #6334

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑netcoreapp3.1 1.136 1,748.16 1,538.73

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.23μs 0.314ns 1.17ns 0.0137 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.49μs 0.862ns 3.11ns 0.0128 0 0 976 B
master CallElasticsearch net472 2.52μs 0.928ns 3.59ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.29μs 3.82ns 14.8ns 0.0134 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.75μs 1.03ns 3.99ns 0.0139 0 0 1.02 KB
master CallElasticsearchAsync net472 2.65μs 1.02ns 3.95ns 0.167 0 0 1.05 KB
#6334 CallElasticsearch net6.0 1.39μs 0.709ns 2.65ns 0.0134 0 0 976 B
#6334 CallElasticsearch netcoreapp3.1 1.6μs 0.407ns 1.47ns 0.0127 0 0 976 B
#6334 CallElasticsearch net472 2.67μs 1.68ns 6.52ns 0.157 0 0 995 B
#6334 CallElasticsearchAsync net6.0 1.31μs 0.744ns 2.78ns 0.0131 0 0 952 B
#6334 CallElasticsearchAsync netcoreapp3.1 1.54μs 1.33ns 4.99ns 0.0138 0 0 1.02 KB
#6334 CallElasticsearchAsync net472 2.63μs 1.81ns 7.02ns 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.35μs 0.484ns 1.88ns 0.0135 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.62μs 0.915ns 3.42ns 0.0129 0 0 952 B
master ExecuteAsync net472 1.84μs 0.611ns 2.29ns 0.145 0 0 915 B
#6334 ExecuteAsync net6.0 1.29μs 0.339ns 1.27ns 0.0135 0 0 952 B
#6334 ExecuteAsync netcoreapp3.1 1.67μs 1.7ns 6.35ns 0.0132 0 0 952 B
#6334 ExecuteAsync net472 1.8μs 0.423ns 1.64ns 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.35μs 1.56ns 6.03ns 0.033 0 0 2.31 KB
master SendAsync netcoreapp3.1 5.38μs 3.21ns 12.4ns 0.0375 0 0 2.85 KB
master SendAsync net472 7.32μs 2.05ns 7.93ns 0.493 0 0 3.12 KB
#6334 SendAsync net6.0 4.62μs 1.67ns 6.26ns 0.0319 0 0 2.31 KB
#6334 SendAsync netcoreapp3.1 5.23μs 2.05ns 7.96ns 0.0365 0 0 2.85 KB
#6334 SendAsync net472 7.36μs 1.87ns 7.26ns 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.59μs 1.74ns 6.76ns 0.0225 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.28μs 0.944ns 3.53ns 0.0216 0 0 1.64 KB
master EnrichedLog net472 2.57μs 1.54ns 5.55ns 0.25 0 0 1.57 KB
#6334 EnrichedLog net6.0 1.55μs 1.18ns 4.4ns 0.0226 0 0 1.64 KB
#6334 EnrichedLog netcoreapp3.1 2.28μs 1.14ns 4.28ns 0.0219 0 0 1.64 KB
#6334 EnrichedLog net472 2.75μs 1.02ns 3.8ns 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 163ns 630ns 0.0595 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 123μs 273ns 1.06μs 0 0 0 4.28 KB
master EnrichedLog net472 151μs 215ns 834ns 0.682 0.227 0 4.46 KB
#6334 EnrichedLog net6.0 118μs 172ns 668ns 0.06 0 0 4.28 KB
#6334 EnrichedLog netcoreapp3.1 123μs 170ns 637ns 0 0 0 4.28 KB
#6334 EnrichedLog net472 153μs 110ns 428ns 0.684 0.228 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.07μs 1.4ns 5.24ns 0.0299 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.09μs 1.16ns 4.35ns 0.0286 0 0 2.2 KB
master EnrichedLog net472 4.92μs 2.69ns 10.4ns 0.32 0 0 2.02 KB
#6334 EnrichedLog net6.0 3.06μs 0.731ns 2.83ns 0.0306 0 0 2.2 KB
#6334 EnrichedLog netcoreapp3.1 4.3μs 1.62ns 6.27ns 0.0279 0 0 2.2 KB
#6334 EnrichedLog net472 4.86μs 1.1ns 4.1ns 0.32 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.46μs 0.875ns 3.39ns 0.016 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.8μs 1.04ns 4.03ns 0.0152 0 0 1.14 KB
master SendReceive net472 2.13μs 1.07ns 3.85ns 0.183 0 0 1.16 KB
#6334 SendReceive net6.0 1.39μs 1.31ns 5.06ns 0.016 0 0 1.14 KB
#6334 SendReceive netcoreapp3.1 1.75μs 1.69ns 6.53ns 0.0149 0 0 1.14 KB
#6334 SendReceive net472 2.04μs 1.02ns 3.82ns 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.66μs 1.2ns 4.65ns 0.0226 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.78μs 1.52ns 5.67ns 0.0227 0 0 1.65 KB
master EnrichedLog net472 4.29μs 2.97ns 11.5ns 0.323 0 0 2.04 KB
#6334 EnrichedLog net6.0 2.88μs 1.39ns 5.21ns 0.0216 0 0 1.6 KB
#6334 EnrichedLog netcoreapp3.1 3.96μs 1.31ns 4.89ns 0.0218 0 0 1.65 KB
#6334 EnrichedLog net472 4.4μs 2.6ns 9.75ns 0.324 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 490ns 1.16ns 4.49ns 0.00816 0 0 576 B
master StartFinishSpan netcoreapp3.1 598ns 0.944ns 3.53ns 0.0079 0 0 576 B
master StartFinishSpan net472 635ns 1.16ns 4.5ns 0.0916 0 0 578 B
master StartFinishScope net6.0 553ns 0.346ns 1.29ns 0.00974 0 0 696 B
master StartFinishScope netcoreapp3.1 708ns 0.648ns 2.51ns 0.0095 0 0 696 B
master StartFinishScope net472 836ns 1.26ns 4.86ns 0.104 0 0 658 B
#6334 StartFinishSpan net6.0 462ns 0.704ns 2.63ns 0.00817 0 0 576 B
#6334 StartFinishSpan netcoreapp3.1 546ns 1ns 3.89ns 0.00774 0 0 576 B
#6334 StartFinishSpan net472 657ns 1.6ns 6.2ns 0.0916 0 0 578 B
#6334 StartFinishScope net6.0 515ns 1.01ns 3.9ns 0.00982 0 0 696 B
#6334 StartFinishScope netcoreapp3.1 676ns 0.677ns 2.53ns 0.00943 0 0 696 B
#6334 StartFinishScope net472 895ns 1.54ns 5.75ns 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 724ns 1.13ns 4.39ns 0.00982 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 920ns 0.973ns 3.64ns 0.00926 0 0 696 B
master RunOnMethodBegin net472 1.09μs 2.49ns 9.66ns 0.104 0 0 658 B
#6334 RunOnMethodBegin net6.0 658ns 1.34ns 5.18ns 0.00978 0 0 696 B
#6334 RunOnMethodBegin netcoreapp3.1 889ns 1.82ns 7.05ns 0.00954 0 0 696 B
#6334 RunOnMethodBegin net472 1.13μs 1.51ns 5.86ns 0.104 0 0 658 B

Copy link
Collaborator

@gleocadie gleocadie left a comment

Choose a reason for hiding this comment

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

LGTM

@gleocadie
Copy link
Collaborator

@tonyredondo why not this one

?

@andrewlock andrewlock added type:refactor area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) identified-by:crashtracking labels Nov 22, 2024
@tonyredondo tonyredondo changed the title Change ICorProfilerMethodEnum to use the COMPtrHolder Change ICorProfilerMethodEnum to use the COMPtr Nov 22, 2024
@tonyredondo
Copy link
Member Author

@tonyredondo why not this one

?

you're right 🤦🏻 fixed in 49c9328

@tonyredondo tonyredondo merged commit 31bf06f into master Nov 22, 2024
78 of 82 checks passed
@tonyredondo tonyredondo deleted the tony/use-comptrholder-part1 branch November 22, 2024 12:55
@github-actions github-actions bot added this to the vNext-v3 milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) identified-by:crashtracking type:refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants