Skip to content

Commit

Permalink
对象池需要实时监管,监测大小和数量
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengine committed Jul 28, 2014
1 parent 895042d commit 4d00d93
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 20 deletions.
4 changes: 4 additions & 0 deletions kbe/src/lib/cstdkbe/objectpool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class ObjectPool
mutex_.unlockMutex();
return buf;
}

size_t max()const{ return max_; }

bool isDestroyed()const{ return isDestroyed_; }
protected:
OBJECTS objects_; // 对象缓冲器

Expand Down
5 changes: 4 additions & 1 deletion kbe/src/lib/entitydef/entity_macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ public: \
ScriptDefModule::PROPERTYDESCRIPTION_UIDMAP& propertyDescrs = \
scriptModule_->getCellPropertyDescriptions_uidmap(); \
\
while(mstream->opsize() > 0) \
size_t count = 0; \
\
while(mstream->opsize() > 0 && count < propertyDescrs.size()) \
{ \
(*mstream) >> uid; \
ScriptDefModule::PROPERTYDESCRIPTION_UIDMAP::iterator iter = propertyDescrs.find(uid); \
Expand All @@ -395,6 +397,7 @@ public: \
PyObject* pyobj = iter->second->createFromStream(mstream); \
PyDict_SetItemString(cellData, iter->second->getName(), pyobj); \
Py_DECREF(pyobj); \
++count; \
} \
\
return cellData; \
Expand Down
1 change: 1 addition & 0 deletions kbe/src/lib/helper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SRCS = \
profiler \
script_loglevel \
sys_info \
watch_pools \
watcher

ifndef KBE_ROOT
Expand Down
8 changes: 8 additions & 0 deletions kbe/src/lib/helper/helper90.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
RelativePath=".\sys_info.cpp"
>
</File>
<File
RelativePath=".\watch_pools.cpp"
>
</File>
<File
RelativePath=".\watcher.cpp"
>
Expand Down Expand Up @@ -234,6 +238,10 @@
RelativePath=".\sys_info.hpp"
>
</File>
<File
RelativePath=".\watch_pools.hpp"
>
</File>
<File
RelativePath=".\watcher.hpp"
>
Expand Down
230 changes: 230 additions & 0 deletions kbe/src/lib/helper/watch_pools.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2012 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/

#include "watcher.hpp"
#include "watch_pools.hpp"
#include "network/bundle.hpp"
#include "network/address.hpp"
#include "network/endpoint.hpp"
#include "network/tcp_packet.hpp"
#include "network/udp_packet.hpp"
#include "network/tcp_packet_receiver.hpp"
#include "network/udp_packet_receiver.hpp"

namespace KBEngine {

//-------------------------------------------------------------------------------------
int32 watchBundlePool_size()
{
return (int)Mercury::Bundle::ObjPool().objects().size();
}

int32 watchBundlePool_max()
{
return (int)Mercury::Bundle::ObjPool().max();
}

bool watchBundlePool_isDestroyed()
{
return Mercury::Bundle::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchAddressPool_size()
{
return (int)Mercury::Address::ObjPool().objects().size();
}

int32 watchAddressPool_max()
{
return (int)Mercury::Address::ObjPool().max();
}

bool watchAddressPool_isDestroyed()
{
return Mercury::Address::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchMemoryStreamPool_size()
{
return (int)MemoryStream::ObjPool().objects().size();
}

int32 watchMemoryStreamPool_max()
{
return (int)MemoryStream::ObjPool().max();
}

bool watchMemoryStreamPool_isDestroyed()
{
return MemoryStream::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
/*
int32 watchWitnessPool_size()
{
return (int)Witness::ObjPool().objects().size();
}
int32 watchWitnessPool_max()
{
return (int)Witness::ObjPool().max();
}
bool watchWitnessPool_isDestroyed()
{
return Witness::ObjPool().isDestroyed();
}
*/

//-------------------------------------------------------------------------------------
int32 watchTCPPacketPool_size()
{
return (int)Mercury::TCPPacket::ObjPool().objects().size();
}

int32 watchTCPPacketPool_max()
{
return (int)Mercury::TCPPacket::ObjPool().max();
}

bool watchTCPPacketPool_isDestroyed()
{
return Mercury::TCPPacket::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchTCPPacketReceiverPool_size()
{
return (int)Mercury::TCPPacketReceiver::ObjPool().objects().size();
}

int32 watchTCPPacketReceiverPool_max()
{
return (int)Mercury::TCPPacketReceiver::ObjPool().max();
}

bool watchTCPPacketReceiverPool_isDestroyed()
{
return Mercury::TCPPacketReceiver::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchUDPPacketPool_size()
{
return (int)Mercury::UDPPacket::ObjPool().objects().size();
}

int32 watchUDPPacketPool_max()
{
return (int)Mercury::UDPPacket::ObjPool().max();
}

bool watchUDPPacketPool_isDestroyed()
{
return Mercury::UDPPacket::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchUDPPacketReceiverPool_size()
{
return (int)Mercury::UDPPacketReceiver::ObjPool().objects().size();
}

int32 watchUDPPacketReceiverPool_max()
{
return (int)Mercury::UDPPacketReceiver::ObjPool().max();
}

bool watchUDPPacketReceiverPool_isDestroyed()
{
return Mercury::UDPPacketReceiver::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
int32 watchEndPointPool_size()
{
return (int)Mercury::EndPoint::ObjPool().objects().size();
}

int32 watchEndPointPool_max()
{
return (int)Mercury::EndPoint::ObjPool().max();
}

bool watchEndPointPool_isDestroyed()
{
return Mercury::EndPoint::ObjPool().isDestroyed();
}

//-------------------------------------------------------------------------------------
bool WatchPool::initWatchPools()
{
WATCH_OBJECT("objectPools/Bundle/size", &watchBundlePool_size);
WATCH_OBJECT("objectPools/Bundle/max", &watchBundlePool_max);
WATCH_OBJECT("objectPools/Bundle/isDestroyed", &watchBundlePool_isDestroyed);

WATCH_OBJECT("objectPools/Address/size", &watchAddressPool_size);
WATCH_OBJECT("objectPools/Address/max", &watchAddressPool_max);
WATCH_OBJECT("objectPools/Address/isDestroyed", &watchAddressPool_isDestroyed);

WATCH_OBJECT("objectPools/MemoryStream/size", &watchMemoryStreamPool_size);
WATCH_OBJECT("objectPools/MemoryStream/max", &watchMemoryStreamPool_max);
WATCH_OBJECT("objectPools/MemoryStream/isDestroyed", &watchMemoryStreamPool_isDestroyed);

/*
WATCH_OBJECT("objectPools/Witness/size", &watchWitnessPool_size);
WATCH_OBJECT("objectPools/Witness/max", &watchWitnessPool_max);
WATCH_OBJECT("objectPools/Witness/isDestroyed", &watchWitnessPool_isDestroyed);
*/

WATCH_OBJECT("objectPools/TCPPacket/size", &watchTCPPacketPool_size);
WATCH_OBJECT("objectPools/TCPPacket/max", &watchTCPPacketPool_max);
WATCH_OBJECT("objectPools/TCPPacket/isDestroyed", &watchTCPPacketPool_isDestroyed);

WATCH_OBJECT("objectPools/TCPPacketReceiver/size", &watchTCPPacketReceiverPool_size);
WATCH_OBJECT("objectPools/TCPPacketReceiver/max", &watchTCPPacketReceiverPool_max);
WATCH_OBJECT("objectPools/TCPPacketReceiver/isDestroyed", &watchTCPPacketReceiverPool_isDestroyed);

WATCH_OBJECT("objectPools/UDPPacket/size", &watchUDPPacketPool_size);
WATCH_OBJECT("objectPools/UDPPacket/max", &watchUDPPacketPool_max);
WATCH_OBJECT("objectPools/UDPPacket/isDestroyed", &watchUDPPacketPool_isDestroyed);

WATCH_OBJECT("objectPools/UDPPacketReceiver/size", &watchUDPPacketReceiverPool_size);
WATCH_OBJECT("objectPools/UDPPacketReceiver/max", &watchUDPPacketReceiverPool_max);
WATCH_OBJECT("objectPools/UDPPacketReceiver/isDestroyed", &watchUDPPacketReceiverPool_isDestroyed);

WATCH_OBJECT("objectPools/EndPoint/size", &watchEndPointPool_size);
WATCH_OBJECT("objectPools/EndPoint/max", &watchEndPointPool_max);
WATCH_OBJECT("objectPools/EndPoint/isDestroyed", &watchEndPointPool_isDestroyed);
return true;
}

//-------------------------------------------------------------------------------------
bool WatchPool::finiWatchPools()
{
return true;
}

//-------------------------------------------------------------------------------------

}
38 changes: 38 additions & 0 deletions kbe/src/lib/helper/watch_pools.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2012 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __WATCH_POOLS_HANDLER__
#define __WATCH_POOLS_HANDLER__

#include "cstdkbe/cstdkbe.hpp"
#include "helper/debug_helper.hpp"

namespace KBEngine {

class WatchPool
{
public:
static bool initWatchPools();
static bool finiWatchPools();
};

}

#endif
3 changes: 2 additions & 1 deletion kbe/src/lib/server/serverapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
#include "cstdkbe/memorystream.hpp"
#include "helper/console_helper.hpp"
#include "helper/sys_info.hpp"
#include "helper/watch_pools.hpp"
#include "resmgr/resmgr.hpp"

#include "../../server/baseappmgr/baseappmgr_interface.hpp"
Expand Down Expand Up @@ -182,7 +183,7 @@ bool ServerApp::initializeWatcher()
WATCH_OBJECT("gametime", this, &ServerApp::time);

return Mercury::initializeWatcher() && Resmgr::getSingleton().initializeWatcher() &&
threadPool_.initializeWatcher();
threadPool_.initializeWatcher() && WatchPool::initWatchPools();
}

//-------------------------------------------------------------------------------------
Expand Down

0 comments on commit 4d00d93

Please sign in to comment.