Skip to content

pass module version id to instrumentation wrappers#488

Merged
lucaspimentel merged 17 commits intomasterfrom
lpimentel/pass-module-version-id-to-instrumentation-wrappers
Aug 22, 2019
Merged

pass module version id to instrumentation wrappers#488
lucaspimentel merged 17 commits intomasterfrom
lpimentel/pass-module-version-id-to-instrumentation-wrappers

Conversation

@lucaspimentel
Copy link
Member

@lucaspimentel lucaspimentel commented Aug 22, 2019

Changes proposed in this pull request:

  • CLR Profiler
    • push module_version_id pointer onto stack before calling wrapper methods
    • change some log message to include the name of the target method instead of the caller
  • Integrations
    • add long moduleVersionPtr parameter to every integration wrapper method
    • add MethodBuild.Start() overload that takes long moduleVersionPtr
    • replace uses of Assembly.GetCallingAssembly() with moduleVersionPtr

@lucaspimentel lucaspimentel added type:enhancement Improvement to an existing feature area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) labels Aug 22, 2019
@lucaspimentel lucaspimentel added this to the 1.6.3 milestone Aug 22, 2019
@lucaspimentel lucaspimentel requested a review from a team as a code owner August 22, 2019 21:53
@lucaspimentel lucaspimentel self-assigned this Aug 22, 2019
var graphQLAssembly = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => a.GetName().Name.Equals(GraphQLAssemblyName))
.Single();
.Single(a => a.GetName().Name.Equals(GraphQLAssemblyName));
Copy link
Member Author

@lucaspimentel lucaspimentel Aug 22, 2019

Choose a reason for hiding this comment

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

Completely unrelated, but I couldn't help myself. Resharper points it out in bright green on my dark background.

rewriter_wrapper.SetILPosition(pInstr);
rewriter_wrapper.LoadInt32(pInstr->m_opcode);
rewriter_wrapper.LoadInt32(method_def_md_token);
rewriter_wrapper.LoadInt64(reinterpret_cast<INT64>(module_version_id_ptr));
Copy link
Member Author

Choose a reason for hiding this comment

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

We treat the address of module_version_id as an INT64 and we push it into the stack before calling the wrapper method.

var returnType = method.ReturnType;
var parameters = method.GetParameters().Select(p => p.ParameterType).ToArray();

var requiredParameterTypes = new[] { typeof(int), typeof(int), typeof(long) };
Copy link
Member Author

Choose a reason for hiding this comment

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

Since I was adding another parameter to all wrappers, I though it useful to add this validation.

Copy link
Member

@colin-higgins colin-higgins left a comment

Choose a reason for hiding this comment

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

Looks good to me! 🎉 🎉 🎉


// we add 3 parameters to every wrapper method: opcode, mdToken, and
// module_version_id
const short added_parameters_count = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this change, this helps my sanity 😄

Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

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

Looks good!

@lucaspimentel lucaspimentel merged commit 657208b into master Aug 22, 2019
@lucaspimentel lucaspimentel deleted the lpimentel/pass-module-version-id-to-instrumentation-wrappers branch August 22, 2019 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) type:enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants