aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/ProfileEventsScope.cpp
blob: 92f75f4f5b0ff14b2f9bc15ed893ddb2bd563cff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <Common/ProfileEventsScope.h>

namespace DB
{


ProfileEventsScope::ProfileEventsScope()
    : performance_counters_holder(std::make_unique<ProfileEvents::Counters>())
    , performance_counters_scope(performance_counters_holder.get())
    , previous_counters_scope(CurrentThread::get().attachProfileCountersScope(performance_counters_scope))
{
}

ProfileEventsScope::ProfileEventsScope(ProfileEvents::Counters * performance_counters_scope_)
    : performance_counters_scope(performance_counters_scope_)
    , previous_counters_scope(CurrentThread::get().attachProfileCountersScope(performance_counters_scope))
{
}

std::shared_ptr<ProfileEvents::Counters::Snapshot> ProfileEventsScope::getSnapshot()
{
    return std::make_shared<ProfileEvents::Counters::Snapshot>(performance_counters_scope->getPartiallyAtomicSnapshot());
}

ProfileEventsScope::~ProfileEventsScope()
{
    /// Restore previous performance counters
    CurrentThread::get().attachProfileCountersScope(previous_counters_scope);
}


}