Skip to content

[Profiler] Add contention profiler based on Clr Events#3115

Merged
gleocadie merged 5 commits into
masterfrom
gleocadie/contention-profiler-from-events
Aug 25, 2022
Merged

[Profiler] Add contention profiler based on Clr Events#3115
gleocadie merged 5 commits into
masterfrom
gleocadie/contention-profiler-from-events

Conversation

@gleocadie

@gleocadie gleocadie commented Aug 23, 2022

Copy link
Copy Markdown
Collaborator

Summary of changes

Add contention profiler.

Reason for change

This is a new feature.

Implementation details

This implementation relies on the CLR Events infrastructure put in place by @chrisnas. Once a ContentionStop event is received, we stackwalk the current thread, extract from the event the lock duration and create the sample.

Test coverage

Add a new test scenario in Computer01 to generate contention and ensure it works accordingly.

Other details

@github-actions github-actions Bot added the area:profiler Issues related to the continous-profiler label Aug 23, 2022
@gleocadie
gleocadie force-pushed the gleocadie/contention-profiler-from-events branch 5 times, most recently from 2df3650 to 343b76f Compare August 23, 2022 14:17
@gleocadie
gleocadie marked this pull request as ready for review August 24, 2022 15:14
@gleocadie
gleocadie requested a review from a team as a code owner August 24, 2022 15:14

@chrisnas chrisnas 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.

Don't forget to:

  • update EnabledProfilers.cpp
        if (pConfiguration->IsAllocationProfilingEnabled())
        {
            _enabledProfilers |= RuntimeProfiler::Allocations;
        }
        **if (pConfiguration->IsContentionProfilingEnabled())
        {
            _enabledProfilers |= RuntimeProfiler::Contention;
        }**
  • uncomment Contention enum value in IEnabledProfilers.h
  • add tag in libddprofexporter.cpp
    if (enabledProfilers->IsEnabled(RuntimeProfiler::Allocations))
    {
        if (!emptyList)
        {
            buffer << separator;
        }
        buffer << "allocations";
        emptyList = false;
    }
    **if (enabledProfilers->IsEnabled(RuntimeProfiler::Contention))
    {
        if (!emptyList)
        {
            buffer << separator;
        }
        buffer << "contention";
        emptyList = false;
    }**

Comment thread profiler/src/ProfilerEngine/Datadog.Profiler.Native/ClrEventsParser.cpp Outdated
const auto result = pStackFramesCollector->CollectStackSample(threadInfo, &hrCollectStack);
if (result->GetFramesCount() == 0)
{
Log::Warn("Failed to walk stack for sampled contention: ", HResultConverter::ToStringWithCode(hrCollectStack));

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.

Since there is no sampling, we might send too many logs in this case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Same, besides, if we fail how will we know ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(also done in the exception profiler)

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.

Could log once and then every 10 or 50

Comment thread profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp Outdated
Comment thread profiler/test/Datadog.Profiler.Native.Tests/ConfigurationTest.cpp Outdated
@gleocadie
gleocadie force-pushed the gleocadie/contention-profiler-from-events branch from 4d1e0bf to e77566f Compare August 25, 2022 07:54

@chrisnas chrisnas 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.

LGTM

@gleocadie
gleocadie merged commit 2bdbc87 into master Aug 25, 2022
@gleocadie
gleocadie deleted the gleocadie/contention-profiler-from-events branch August 25, 2022 11:56
@github-actions github-actions Bot added this to the vNext milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:profiler Issues related to the continous-profiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants