1
This commit is contained in:
parent
380074e2f7
commit
71fcbd8bc5
@ -1,6 +1,8 @@
|
|||||||
#include <a8/a8.h>
|
#include <a8/a8.h>
|
||||||
#include <a8/perfmonitor.h>
|
#include <a8/perfmonitor.h>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -10,10 +12,57 @@ namespace a8
|
|||||||
|
|
||||||
void PerfMonitor::Init()
|
void PerfMonitor::Init()
|
||||||
{
|
{
|
||||||
|
mutex_ = std::make_shared<std::mutex>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerfMonitor::UnInit()
|
void PerfMonitor::UnInit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long PerfMonitor::AddV(const std::string key, long long val)
|
||||||
|
{
|
||||||
|
long long result = 0;
|
||||||
|
mutex_->lock();
|
||||||
|
auto itr = dyn_hash_.find(key);
|
||||||
|
if (itr == dyn_hash_.end()) {
|
||||||
|
dyn_hash_[key] = val;
|
||||||
|
result = val;
|
||||||
|
} else {
|
||||||
|
itr->second = itr->second + val;
|
||||||
|
result = itr->second;
|
||||||
|
}
|
||||||
|
mutex_->unlock();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long PerfMonitor::SubV(const std::string key, long long val)
|
||||||
|
{
|
||||||
|
return AddV(key, -val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerfMonitor::SetV(const std::string key, long long val)
|
||||||
|
{
|
||||||
|
mutex_->lock();
|
||||||
|
dyn_hash_[key] = val;
|
||||||
|
mutex_->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
long long PerfMonitor::GetV(const std::string key)
|
||||||
|
{
|
||||||
|
long long result = 0;
|
||||||
|
mutex_->lock();
|
||||||
|
auto itr = dyn_hash_.find(key);
|
||||||
|
if (itr != dyn_hash_.end()) {
|
||||||
|
result = itr->second;
|
||||||
|
}
|
||||||
|
mutex_->unlock();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerfMonitor::Dump()
|
||||||
|
{
|
||||||
|
mutex_->lock();
|
||||||
|
mutex_->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,21 @@ namespace a8
|
|||||||
void Init();
|
void Init();
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
|
long long AddV(const std::string key, long long val);
|
||||||
|
long long SubV(const std::string key, long long val);
|
||||||
|
void SetV(const std::string key, long long val);
|
||||||
|
long long GetV(const std::string key);
|
||||||
|
void Dump();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
long long send_eagain_times = 0;
|
long long send_eagain_times = 0;
|
||||||
long long recv_eagain_times = 0;
|
long long recv_eagain_times = 0;
|
||||||
long long max_send_time = 0;
|
long long max_send_time = 0;
|
||||||
long long max_recv_time = 0;
|
long long max_recv_time = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<std::mutex> mutex_;
|
||||||
|
std::map<std::string, long long> dyn_hash_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user