Permalink
Browse files

added PolCore().internal(5)

logs memoryusage in bytes of each script instance into
log/memoryusagescripts.log
  • Loading branch information...
turleypol committed Dec 2, 2018
1 parent dafb1d7 commit ffa0ef1360bad24d370107615bd6196a7639cb6d
@@ -31,7 +31,7 @@ void MemoryUsage::log()
size_t multibuffer_size = Multi::multidef_buffer.estimateSize();
auto network_size = networkManager.estimateSize();
auto object_sizes = objStorageManager.estimateSize();
auto script_sizes = scriptScheduler.estimateSize();
auto script_sizes = scriptScheduler.estimateSize( false );
size_t settings_size = settingsManager.estimateSize();
size_t state_size = stateManager.estimateSize();
auto config_sizes = configurationbuffer.estimateSize();
@@ -63,7 +63,7 @@ void ScriptScheduler::deinitialize()
}
}
ScriptScheduler::Memory ScriptScheduler::estimateSize() const
ScriptScheduler::Memory ScriptScheduler::estimateSize( bool verbose ) const
{
Memory usage;
memset( &usage, 0, sizeof( usage ) );
@@ -83,47 +83,85 @@ ScriptScheduler::Memory ScriptScheduler::estimateSize() const
}
usage.scriptstorage_count = scrstore.size();
fmt::Writer verbose_w;
if ( verbose )
verbose_w << GET_LOG_FILESTAMP << "\n";
usage.script_size += 3 * sizeof( UOExecutor** ) + runlist.size() * sizeof( UOExecutor* );
if ( verbose )
verbose_w << "runlist:\n";
for ( const auto& exec : runlist )
{
if ( exec != nullptr )
{
usage.script_size += exec->sizeEstimate();
if ( verbose )
verbose_w << exec->scriptname() << " " << exec->sizeEstimate() << "\n";
}
}
usage.script_count += runlist.size();
usage.script_size += 3 * sizeof( UOExecutor** ) + ranlist.size() * sizeof( UOExecutor* );
if ( verbose )
verbose_w << "ranlist:\n";
for ( const auto& exec : ranlist )
{
if ( exec != nullptr )
{
usage.script_size += exec->sizeEstimate();
if ( verbose )
verbose_w << exec->scriptname() << " " << exec->sizeEstimate() << "\n";
}
}
usage.script_count += ranlist.size();
if ( verbose )
verbose_w << "holdlist:\n";
for ( const auto& hold : holdlist )
{
if ( hold.second != nullptr )
{
usage.script_size += hold.second->sizeEstimate();
if ( verbose )
verbose_w << hold.second->scriptname() << " " << hold.second->sizeEstimate() << "\n";
}
usage.script_size += sizeof( Core::polclock_t ) + ( sizeof( void* ) * 3 + 1 ) / 2;
}
usage.script_count += holdlist.size();
usage.script_size += 3 * sizeof( void* );
if ( verbose )
verbose_w << "notimeoutholdlist:\n";
for ( const auto& hold : notimeoutholdlist )
{
if ( hold != nullptr )
{
usage.script_size += hold->sizeEstimate() + 3 * sizeof( void* );
if ( verbose )
verbose_w << hold->scriptname() << " " << hold->sizeEstimate() << "\n";
}
}
usage.script_count += notimeoutholdlist.size();
usage.script_size += 3 * sizeof( void* );
if ( verbose )
verbose_w << "debuggerholdlist:\n";
for ( const auto& hold : debuggerholdlist )
{
if ( hold != nullptr )
{
usage.script_size += hold->sizeEstimate() + 3 * sizeof( void* );
if ( verbose )
verbose_w << hold->scriptname() << " " << hold->sizeEstimate() << "\n";
}
}
usage.script_count += debuggerholdlist.size();
if ( verbose )
{
auto log = OPEN_FLEXLOG( "log/memoryusagescripts.log", false );
FLEXLOG( log ) << verbose_w.str();
CLOSE_FLEXLOG( log );
}
return usage;
}
@@ -46,7 +46,7 @@ class ScriptScheduler : boost::noncopyable
size_t scriptstorage_count;
size_t scriptstorage_size;
};
Memory estimateSize() const;
Memory estimateSize( bool verbose ) const;
void run_ready();
@@ -2005,6 +2005,10 @@ BObjectImp* PolCore::call_method( const char* methodname, Executor& ex )
POLLOG_ERROR << "Forcing assert crash\n";
passert_always( false );
}
else if ( type == 5 )
{
Core::scriptScheduler.estimateSize( true );
}
return new BLong( 1 );
}
else

0 comments on commit ffa0ef1

Please sign in to comment.