add perfmonitor

This commit is contained in:
aozhiwei 2020-06-12 15:06:14 +08:00
parent f402a38a41
commit 1ea33dd844
9 changed files with 54 additions and 36 deletions

View File

@ -112,7 +112,7 @@ void IMConn::on_disconnect(a8::AsyncTcpClient* sender)
void IMConn::on_socketread(a8::AsyncTcpClient* sender, char* buf, unsigned int len) void IMConn::on_socketread(a8::AsyncTcpClient* sender, char* buf, unsigned int len)
{ {
#if 0 #if 0
++App::Instance()->perf.read_count; ++PerfMonitor::Instance()->read_count;
#endif #endif
if (recv_bufflen_ + len > 2 * PACK_MAX) { if (recv_bufflen_ + len > 2 * PACK_MAX) {
recv_bufflen_ = 0; recv_bufflen_ = 0;

View File

@ -112,7 +112,7 @@ void MSConn::on_disconnect(a8::AsyncTcpClient* sender)
void MSConn::on_socketread(a8::AsyncTcpClient* sender, char* buf, unsigned int len) void MSConn::on_socketread(a8::AsyncTcpClient* sender, char* buf, unsigned int len)
{ {
#if 0 #if 0
++App::Instance()->perf.read_count; ++PerfMonitor::Instance()->read_count;
#endif #endif
if (recv_bufflen_ + len > 2 * PACK_MAX) { if (recv_bufflen_ + len > 2 * PACK_MAX) {
recv_bufflen_ = 0; recv_bufflen_ = 0;

View File

@ -23,6 +23,7 @@
#include "playermgr.h" #include "playermgr.h"
#include "groupmgr.h" #include "groupmgr.h"
#include "dbengine.h" #include "dbengine.h"
#include "perfmonitor.h"
#include "MSConnMgr.h" #include "MSConnMgr.h"
#include "IMConnMgr.h" #include "IMConnMgr.h"
@ -56,14 +57,14 @@ static void SavePerfLog()
"in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d " "in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d "
"max_join_time:%d", "max_join_time:%d",
{ {
App::Instance()->perf.max_run_delay_time, PerfMonitor::Instance()->max_run_delay_time,
App::Instance()->perf.max_timer_idle, PerfMonitor::Instance()->max_timer_idle,
App::Instance()->perf.in_data_size, PerfMonitor::Instance()->in_data_size,
App::Instance()->perf.out_data_size, PerfMonitor::Instance()->out_data_size,
App::Instance()->msgnode_size_, App::Instance()->msgnode_size_,
App::Instance()->perf.read_count, PerfMonitor::Instance()->read_count,
App::Instance()->perf.max_login_time, PerfMonitor::Instance()->max_login_time,
App::Instance()->perf.max_join_time, PerfMonitor::Instance()->max_join_time,
}); });
a8::UdpLog::Instance()->Info(" run_times:%d timer_times:%d event_times:%d free_times:%d " a8::UdpLog::Instance()->Info(" run_times:%d timer_times:%d event_times:%d free_times:%d "
" shutdown_times:%d connect_times:%d close_times:%d " " shutdown_times:%d connect_times:%d close_times:%d "
@ -81,14 +82,10 @@ static void SavePerfLog()
(long long)a8::IoLoop::Instance()->error_times, (long long)a8::IoLoop::Instance()->error_times,
(long long)a8::IoLoop::Instance()->immsg_times (long long)a8::IoLoop::Instance()->immsg_times
}); });
#if 1 PerfMonitor::Instance()->max_run_delay_time = 0;
App::Instance()->perf.max_run_delay_time = 0; PerfMonitor::Instance()->max_timer_idle = 0;
App::Instance()->perf.max_timer_idle = 0; PerfMonitor::Instance()->max_login_time = 0;
App::Instance()->perf.max_login_time = 0; PerfMonitor::Instance()->max_join_time = 0;
App::Instance()->perf.max_join_time = 0;
#else
App::Instance()->perf = PerfMonitor();
#endif
} }
bool App::Init(int argc, char* argv[]) bool App::Init(int argc, char* argv[])
@ -213,8 +210,8 @@ int App::Run()
QuickExecute(); QuickExecute();
SlowerExecute(); SlowerExecute();
a8::tick_t end_tick = a8::XGetTickCount(); a8::tick_t end_tick = a8::XGetTickCount();
if (end_tick - begin_tick > perf.max_run_delay_time) { if (end_tick - begin_tick > PerfMonitor::Instance()->max_run_delay_time) {
perf.max_run_delay_time = end_tick - begin_tick; PerfMonitor::Instance()->max_run_delay_time = end_tick - begin_tick;
} }
Schedule(); Schedule();
} }
@ -296,8 +293,8 @@ void App::Schedule()
if (!HasTask()) { if (!HasTask()) {
int sleep_time = a8::Timer::Instance()->GetIdleableMillSeconds(); int sleep_time = a8::Timer::Instance()->GetIdleableMillSeconds();
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time)); loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
if (sleep_time > perf.max_timer_idle) { if (sleep_time > PerfMonitor::Instance()->max_timer_idle) {
perf.max_timer_idle = sleep_time; PerfMonitor::Instance()->max_timer_idle = sleep_time;
} }
} }
} }

View File

@ -61,7 +61,6 @@ private:
volatile bool terminated = false; volatile bool terminated = false;
volatile bool shutdowned = false; volatile bool shutdowned = false;
std::set<int> flags; std::set<int> flags;
PerfMonitor perf;
a8::uuid::SnowFlake uuid; a8::uuid::SnowFlake uuid;
public: public:

View File

@ -0,0 +1,13 @@
#include "precompile.h"
#include "perfmonitor.h"
void PerfMonitor::Init()
{
}
void PerfMonitor::UnInit()
{
}

View File

@ -0,0 +1,21 @@
#pragma once
class PerfMonitor : public a8::Singleton<PerfMonitor>
{
private:
PerfMonitor() {};
friend class a8::Singleton<PerfMonitor>;
public:
int max_run_delay_time = 0;
int max_dispatchmsg_time = 0;
int max_timer_idle = 0;
long long max_login_time = 0;
long long max_join_time = 0;
long long out_data_size = 0;
long long in_data_size = 0;
long long read_count = 0;
void Init();
void UnInit();
};

View File

@ -1,17 +1,5 @@
#pragma once #pragma once
struct PerfMonitor
{
int max_run_delay_time = 0;
int max_dispatchmsg_time = 0;
int max_timer_idle = 0;
long long max_login_time = 0;
long long max_join_time = 0;
long long out_data_size = 0;
long long in_data_size = 0;
long long read_count = 0;
};
struct Friend struct Friend
{ {
std::string account_id; std::string account_id;

@ -1 +1 @@
Subproject commit c6c7cb379e997ce3808edff38e822eda3da19915 Subproject commit d73ff7eb0c53e6d93db95b14d0fb5945fae24649

@ -1 +1 @@
Subproject commit 4e1a34704dc08d0279e78c275989f10f85fd6cc2 Subproject commit 6a5392433ccd85ffbfea9a904fde0f5bae22c155