예제 #1
0
bool StatDumperThread::run()
{
	int delay_ms = Config.MainConfig.GetIntDefault( "StatDumper", "Interval", 120000 );

	if( delay_ms < 1000 )
		delay_ms = 1000;

	int delay_s = delay_ms / 1000;

	if( !Config.MainConfig.GetString( "StatDumper", Filename, "Filename", "stats.xml", MAX_PATH ) )
		strcpy( Filename, "stats.xml" );

#ifdef WIN32
	memset( &m_OldPerfTime100nSec, 0, sizeof( m_OldPerfTime100nSec ) );
	SYSTEM_INFO si;
	GetSystemInfo( &si );
	number_of_cpus = si.dwNumberOfProcessors;
#endif

#ifdef WIN32
	hEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
#else
	struct timeval now;
	struct timespec tv;
	pthread_mutex_init( &mutex, NULL );
	pthread_cond_init( &cond, NULL );
#endif

	running = true;
	for(;;)
	{

		dumper.DumpStats();

#ifdef WIN32
		WaitForSingleObject( hEvent, delay_ms );
#else
		gettimeofday( &now, NULL );
		tv.tv_sec = now.tv_sec + delay_s;
		tv.tv_nsec = now.tv_usec * 1000;
		pthread_mutex_lock( &mutex );
		pthread_cond_timedwait( &cond, &mutex, &tv );
		pthread_mutex_unlock( &mutex );
#endif
		if( !running )
			break;
	}

	return true;
}
예제 #2
0
extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
{
    //strcpy(Filename, Config.MainConfig.GetStringDefault("StatDumper.Filename", "stats.xml").c_str());
    //strcpy(Filename, "stats.xml");
	if(!Config.MainConfig.GetString("StatDumper", Filename, "Filename", "stats.xml", MAX_PATH))
		strcpy(Filename, "stats.xml");

#ifdef WIN32
memset(&m_OldPerfTime100nSec, 0, sizeof(m_OldPerfTime100nSec));
SYSTEM_INFO si;
GetSystemInfo(&si);
number_of_cpus = si.dwNumberOfProcessors;
#endif
    dumper.DumpStats();

	int t = Config.MainConfig.GetIntDefault("StatDumper", "Interval", 120000);
	TimedEvent * te = TimedEvent::Allocate(&dumper, new CallbackP0<StatDumper>(&dumper, &StatDumper::DumpStats), 1, t, 0);
    sWorld.event_AddEvent(te);
}