Skip to content

Commit 13e306d

Browse files
committed
Try something: move the signal handler detection earlier
1 parent afeae39 commit 13e306d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

.azure-pipelines/steps/run-snapshot-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ steps:
6363
displayName: create test data directories
6464
# to remove once done
6565
- script: |
66-
echo "$(PWD)/dumps/core.%e.%p" | sudo tee /proc/sys/kernel/core_pattern
66+
echo "$(System.DefaultWorkingDirectory)/dumps/core.%e.%p" | sudo tee /proc/sys/kernel/core_pattern
6767
- ${{ else }}:
6868
- bash: |
6969
testAgentTarget="${{ parameters.testAgentTarget }}"

profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/TimerCreateCpuProfiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <unistd.h>
1919

2020
std::atomic<TimerCreateCpuProfiler*> TimerCreateCpuProfiler::Instance = nullptr;
21+
std::atomic<std::uint64_t> TimerCreateCpuProfiler::_nbThreadsInSignalHandler = 0;
2122

2223
TimerCreateCpuProfiler::TimerCreateCpuProfiler(
2324
IConfiguration* pConfiguration,
@@ -29,8 +30,7 @@ TimerCreateCpuProfiler::TimerCreateCpuProfiler(
2930
_pSignalManager{pSignalManager}, // put it as parameter for better testing
3031
_pManagedThreadsList{pManagedThreadsList},
3132
_pProvider{pProvider},
32-
_samplingInterval{pConfiguration->GetCpuProfilingInterval()},
33-
_nbThreadsInSignalHandler{0}
33+
_samplingInterval{pConfiguration->GetCpuProfilingInterval()}
3434
{
3535
Log::Info("Cpu profiling interval: ", _samplingInterval.count(), "ms");
3636
Log::Info("timer_create Cpu profiler is enabled");
@@ -129,9 +129,11 @@ bool TimerCreateCpuProfiler::StopImpl()
129129

130130
bool TimerCreateCpuProfiler::CollectStackSampleSignalHandler(int sig, siginfo_t* info, void* ucontext)
131131
{
132+
_nbThreadsInSignalHandler++;
132133
auto instance = Instance.load();
133134
if (instance == nullptr)
134135
{
136+
_nbThreadsInSignalHandler--;
135137
return false;
136138
}
137139

@@ -210,7 +212,6 @@ struct StackWalkLock
210212

211213
bool TimerCreateCpuProfiler::Collect(void* ctx)
212214
{
213-
_nbThreadsInSignalHandler++;
214215
_totalSampling->Incr();
215216

216217
auto threadInfo = ManagedThreadInfo::CurrentThreadInfo;

profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/TimerCreateCpuProfiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ class TimerCreateCpuProfiler : public ServiceBase
5959
std::shared_mutex _registerLock;
6060
std::shared_ptr<CounterMetric> _totalSampling;
6161
std::shared_ptr<DiscardMetrics> _discardMetrics;
62-
std::atomic<std::uint64_t> _nbThreadsInSignalHandler;
62+
static std::atomic<std::uint64_t> _nbThreadsInSignalHandler;
6363
};

0 commit comments

Comments
 (0)