添加性能监控

This commit is contained in:
aozhiwei 2019-04-11 21:23:46 +08:00
parent ad57cf3f2b
commit 31654772a4
4 changed files with 84 additions and 15 deletions

View File

@ -19,7 +19,9 @@ enum EntityType_e
ET_Projectile = 8,
ET_Smoke = 9,
ET_Bullet = 20
ET_Bullet = 20,
ET_MAX
};
enum EntitySubType_e

View File

@ -1,6 +1,8 @@
#include "precompile.h"
#include <a8/mutable_xobject.h>
#include <a8/timer.h>
#include <a8/udplog.h>
#include "playermgr.h"
#include "player.h"
@ -24,24 +26,40 @@ const int ANDROID_NUM = 0;
const int ANDROID_NUM = 10;
#endif
void Room::Initialize()
Room::~Room()
{
}
void Room::Init()
{
ShuaAndroid();
CreateThings();
#if 0
a8::Timer::Instance()->AddRepeatTimer(
1000 * 5,
a8::XParams(),
[] (const a8::XParams& param)
{
stats_timer_ = a8::Timer::Instance()->AddRepeatTimer(
1000 * 5,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
if (!room->game_over) {
room->OutputDebugLog();
}
}
);
}
}
);
#endif
void Room::UnInit()
{
if (!stats_timer_) {
a8::Timer::Instance()->DeleteTimer(stats_timer_);
stats_timer_ = nullptr;
}
}
void Room::Update(int delta_time)
{
long long begin_tick = a8::XGetTickCount();
elapsed_time_ += delta_time;
while (elapsed_time_ >= 50) {
if (frame_no % 2 == 0) {
@ -149,6 +167,10 @@ void Room::Update(int delta_time)
++frame_no;
elapsed_time_ -= 50;
}
long long end_tick = a8::XGetTickCount();
if (end_tick - begin_tick > profile.max_rundelay) {
profile.max_rundelay = end_tick - begin_tick;
}
}
bool Room::IsFull()
@ -763,8 +785,9 @@ void Room::UpdateGas()
break;
}
if (gas_data.gas_mode != GasInactive) {
if (alive_count_ <= 1) {
if (!game_over && alive_count_ <= 1) {
game_over = true;
game_over_frameno = frame_no;
}
for (auto& pair : human_hash_) {
if (pair.second->dead) {
@ -811,5 +834,38 @@ bool Room::GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float s
void Room::OutputDebugLog()
{
a8::UdpLog::Instance()->Debug("roomid:%d max_rundelay:%d frame_no:%d game_over:%d game_over_frameno:%d "
"elapsed_time:%d alive_count:%d current_uniid:%d "
"state:%d accountid_hash.size:%d moveable_hash_.size:%d "
"uniid_hash.size:%d human_hash.size:%d be_added_hash:%d",
{
room_uuid,
profile.max_rundelay,
frame_no,
game_over ? 1 : 0,
game_over_frameno,
elapsed_time_,
current_uniid,
state_,
accountid_hash_.size(),
moveable_hash_.size(),
uniid_hash_.size(),
human_hash_.size(),
be_added_hash_.size()
});
{
int entity_num_arr[ET_MAX] = {0};
a8::MutableXObject* logobj = a8::MutableXObject::NewObject();
for (auto& pair : uniid_hash_) {
if (pair.second->entity_type >= 0 && pair.second->entity_type < ET_MAX) {
++(entity_num_arr[pair.second->entity_type]);
}
}
for (int i = 0; i < ET_MAX; ++i) {
logobj->SetVal(a8::XValue(i).GetString(), entity_num_arr[i]);
}
a8::UdpLog::Instance()->Debug("roomid:%d %s", {room_uuid, logobj->ToJsonStr()});
delete logobj;
}
profile.max_rundelay = 0;
}

View File

@ -9,6 +9,12 @@ namespace MetaData
struct Building;
}
struct RoomProfile
{
long long max_rundelay = 0;
};
struct timer_list;
class Entity;
class Bullet;
class Human;
@ -23,8 +29,12 @@ public:
long long frame_no = 0;
GasData gas_data;
bool game_over = false;
long long game_over_frameno = 0;
RoomProfile profile;
void Initialize();
~Room();
void Init();
void UnInit();
void Update(int delta_time);
bool IsFull();
int GetPlayerNum();
@ -74,6 +84,7 @@ private:
private:
a8::TimerAttacher timer_attacher_;
timer_list* stats_timer_ = nullptr;
int elapsed_time_ = 0;
int alive_count_ = 0;

View File

@ -41,7 +41,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
abort();
}
room->map_meta = MetaMgr::Instance()->GetMap(1001);
room->Initialize();
room->Init();
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room;
} else {