Skip to content

Add support for user created buffers for raw profiler hooks - #451

Merged
Wiktor Kopec (wiktork) merged 5 commits into
microsoft:mainfrom
wiktork:dev/wiktork/customBuffer4
Nov 16, 2021
Merged

Add support for user created buffers for raw profiler hooks#451
Wiktor Kopec (wiktork) merged 5 commits into
microsoft:mainfrom
wiktork:dev/wiktork/customBuffer4

Conversation

@wiktork

@wiktork Wiktor Kopec (wiktork) commented Oct 22, 2021

Copy link
Copy Markdown
Member

Adds support for 3 different scenarios in raw profiler hooks:

  • SetILFunctionBody is called right after DefineMethod during ModuleLoad.
  • SetILFunctionBody is called right after DefineMethod during JitCompilationStarted.
  • SetILFunctionBody is called with a custom buffer (one not allocated with our FunctionBodyAllocator)

TODO:

  • GetInstrumentationResults (test only) may result on having a non-zero buffer.

@wiktork Wiktor Kopec (wiktork) changed the title Dev/wiktork/custom buffer4 Add support for user created buffers for raw profiler hooks Oct 22, 2021
Comment thread src/InstrumentationEngine/MethodInfo.cpp
Comment thread src/InstrumentationEngine/MethodInfo.cpp Outdated
@delmyers

Copy link
Copy Markdown

HRESULT MicrosoftInstrumentationEngine::CCorProfilerInfoWrapper::SetILFunctionBody(

Do we need to do something similar for SetILInstrumentedCodeMap? I.E. if there is no CMethodInfoInstance, and user buffers are enabled, then just directly set the code map?


Refers to: src/InstrumentationEngine/CorProfilerInfoWrapper.cpp:434 in c259b82. [](commit_id = c259b82, deletion_comment = False)

Comment thread src/InstrumentationEngine/MethodInfo.cpp
Comment thread src/InstrumentationEngine/CorProfilerInfoWrapper.cpp Outdated

@delmyers Del Myers (delmyers) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🕐

@willxie-eng

William Xie (willxie-eng) commented Oct 25, 2021

Copy link
Copy Markdown
Contributor

Please remember to update the changelog.md file


In reply to: 951147810

Comment thread src/InstrumentationEngine/CorProfilerInfoWrapper.cpp
@wiktork

Copy link
Copy Markdown
Member Author

Do we need to do something similar for SetILInstrumentedCodeMap?

I don't think we need to set these for brand new methods, since there's no mapping from old il to new il. But you are correct, we will fail this call since we won't find the existing method.

@delmyers

Copy link
Copy Markdown

Yeah, I don't know what the CLR will do in this case. Technically, I don't think that you are limited to setting the IL for a method at module load only if it is a brand new method. I can imagine a world where someone reads the IL from disk, creates a new method, and sets the code map before the first jit... but that is probably not a common use case.


In reply to: 952157974

@wiktork

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread InstrumentationEngine.sln
Comment thread src/InstrumentationEngine/MethodInfo.cpp Outdated
@wiktork

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@wiktork
Wiktor Kopec (wiktork) marked this pull request as ready for review November 3, 2021 18:22
@wiktork
Wiktor Kopec (wiktork) requested a review from a team as a code owner November 3, 2021 18:22

PVOID MicrosoftInstrumentationEngine::CCorMethodMalloc::Alloc(_In_ ULONG cb)
{
//TODO Any consecutive calls to Alloc will destroy the previous buffer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Consider failing subsequent calls or leaking the buffer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

leak + log

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It looks like this is the default code flow; we don't have independent cleanup for this buffer, we rely on subsequent AllocCalls or ref counting to cleanup. I will leave this as is for now.

if (moduleId == m_testModule)
{
if (m_firstJit)
{

@wiktork Wiktor Kopec (wiktork) Nov 3, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Extra tests:

  • Double Alloc
  • Order between IM and Raw maintained
  • Order inversion with both modifying the method.
  • Make sure repeat calls to SetILFunctionBody behave as expected.

@wiktork

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@willxie-eng William Xie (willxie-eng) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

Comment thread src/InstrumentationEngine/CorProfilerInfoWrapper.cpp
Comment thread tests/RawProfilerHook/RawProfilerHook/CoRawProfilerHook.cpp
@wiktork

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@wiktork
Wiktor Kopec (wiktork) merged commit 0d1cfa7 into microsoft:main Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raw profiler hook doesn't work with a profiler that adds methods

3 participants