2017-01-25 18:40:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-07-28 17:34:02 +00:00
|
|
|
#include <shared_mutex>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/Stopwatch.h>
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-28 12:34:39 +00:00
|
|
|
|
2017-01-25 18:40:44 +00:00
|
|
|
class ProfilingScopedWriteRWLock
|
|
|
|
{
|
|
|
|
public:
|
2020-02-28 12:34:39 +00:00
|
|
|
|
2020-07-20 13:06:44 +00:00
|
|
|
ProfilingScopedWriteRWLock(std::shared_mutex & rwl_, ProfileEvents::Event event) :
|
2020-02-28 12:34:39 +00:00
|
|
|
scoped_write_lock(rwl_)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
|
|
}
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
2017-07-28 17:34:02 +00:00
|
|
|
std::unique_lock<std::shared_mutex> scoped_write_lock;
|
2017-01-25 18:40:44 +00:00
|
|
|
};
|
|
|
|
|
2020-02-28 12:34:39 +00:00
|
|
|
|
2017-01-25 18:40:44 +00:00
|
|
|
class ProfilingScopedReadRWLock
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 17:34:02 +00:00
|
|
|
ProfilingScopedReadRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
|
2017-04-01 07:20:54 +00:00
|
|
|
scoped_read_lock(rwl)
|
|
|
|
{
|
|
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
|
|
}
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
2017-07-28 17:34:02 +00:00
|
|
|
std::shared_lock<std::shared_mutex> scoped_read_lock;
|
2017-01-25 18:40:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|