Пример #1
0
/// Runs the benchmark minimizer
/// This simply runs n_iterations iterations as fast as possible, timing the result
/// and reporting it to the user.
void CBenchmark::run()
{
	// setup locals
	mIsRunning = true;
	int n_iterations = 1000;
	double chi2r = 0;
	double time = 0;

	int start = GetMilliCount();

	int iterations;
	for(iterations = 0; iterations < n_iterations && mRun; iterations++)
	{
		mWorkerThread->GetChi(&mChis[0], mChis.size());
		chi2r = ComputeChi2r(mChis, mNParams);

		if(iterations % 100 == 0)
			printf("Iteration %i Chi2r: %f\n", iterations, chi2r);
	}

	// Calculate the time, print out a nice message.
	time = double(GetMilliSpan(start)) / 1000;
	cout << "Benchmark Test completed!" << endl;
	cout << "Completed " << iterations << " iterations in " << time << " seconds." << endl;
	cout << "Throughput: " << iterations/time << " iterations/second." << endl;

	mIsRunning = false;
}
Пример #2
0
/* activate the 1st timer, if it is time */
void TimerActivate()
{
   int object_id,message_id;
   UINT64 now;
   val_type timer_val;
   parm_node p[1];
   
   if (numActiveTimers == 0)
      return;
   
   now = GetMilliCount();
   if (now >= timer_heap[0]->time)
   {
   /*
     if (now - timers->time > TIMER_DELAY_WARN)
       dprintf("Timer handled %i.%03is late\n",
         (now-timers->time)/1000,(now-timers->time)%1000);
   */

      object_id = timer_heap[0]->object_id;
      message_id = timer_heap[0]->message_id;
      
      timer_val.v.tag = TAG_TIMER;
      timer_val.v.data = timer_heap[0]->timer_id;
      
      p[0].type = CONSTANT;
      p[0].value = timer_val.int_val;
      p[0].name_id = TIMER_PARM;

      TimerHeapRemove(0);

      SendTopLevelBlakodMessage(object_id,message_id,1,p);
   }
}
Пример #3
0
int CBenchmark::GetMilliSpan( int nTimeStart )
{
	int nSpan = GetMilliCount() - nTimeStart;
	if ( nSpan < 0 )
		nSpan += 0x100000 * 1000;
	return nSpan;
}
Пример #4
0
user_node * CreateNewUser(int account_id,int class_id)
{   
   user_node *u;

   val_type system_id_const,name_val;
   parm_node p[2];
   char buf[100];
   
   u = (user_node *)AllocateMemory(MALLOC_ID_USER,sizeof(user_node));

   u->account_id = account_id;

   system_id_const.v.tag = TAG_OBJECT;
   system_id_const.v.data = GetSystemObjectID();

   p[0].type = CONSTANT;
   p[0].value = system_id_const.int_val;
   p[0].name_id = SYSTEM_PARM;

   sprintf(buf,"User%i%i%i",account_id,GetTime()%100000,GetMilliCount()%1000);
   
   name_val.v.tag = TAG_RESOURCE;
   name_val.v.data = AddDynamicResource(buf);
	 
   p[1].type = CONSTANT;
   p[1].value = name_val.int_val;
   p[1].name_id = NAME_PARM;
   
   u->object_id = CreateObject(class_id,2,p);

   u->next = users;
   users = u;

   return u;
}
Пример #5
0
void SaveEachTimer(timer_node *t)
{
	int save_time;
	object_node *o;
	char *s;
	
	o = GetObjectByID(t->object_id);
	if (o == NULL)
	{
		eprintf("SaveEachTimer can't get object %i\n",t->object_id);
		return;
	}
	
	s = GetNameByID(t->message_id);
	if (!s)
	{
		eprintf("SaveEachTimer is not saving invalid timer %i\n",t->object_id);
		return;
	}
	
	SaveGameWriteByte(SAVE_GAME_TIMER);
	SaveGameWriteInt(t->timer_id);
	SaveGameWriteInt(t->object_id);
	SaveGameWriteString(GetNameByID(t->message_id));
	
	save_time = (int)(t->time - GetMilliCount());
	if (save_time < 0)
		save_time = 0;
	SaveGameWriteInt(save_time);
}
Пример #6
0
//public method
int MilliSecTime::GetMilliSpan(int StartTime)
{
	int nSpan = GetMilliCount() - StartTime;
	if (nSpan < 0)
	nSpan += 0x100000 * 1000;

return nSpan;
}
Пример #7
0
//public method
int MilliSecTime::GetMilliSpan()
{
	int nSpan = GetMilliCount() - nTimeStart;
	if (nSpan < 0)
	nSpan += 0x100000 * 1000;

return nSpan;
}
Пример #8
0
INT64 GetMainLoopWaitTime()
{
	INT64 ms;
	if (timers == NULL)
		ms = 500;
	else
	{
		ms = timers->time - GetMilliCount();
		if (ms <= 0)
			ms = 0;
		
		if (ms > 500)
			ms = 500;
	}	 
	return ms;
}
Пример #9
0
int CreateTimer(int object_id,int message_id,int milliseconds)
{
   timer_node *t;

   if (numActiveTimers == num_timer_nodes)
      ReallocTimerNodes();

   t = timer_heap[numActiveTimers];
   t->timer_id = next_timer_num++;
   t->object_id = object_id;
   t->message_id = message_id;
   t->time = GetMilliCount() + milliseconds;

   TimerAddNode(t);

   return next_timer_num - 1;
}
Пример #10
0
/* activate the 1st timer, if it is time */
void TimerActivate()
{
   timer_node *temp;
   int object_id,message_id;
   UINT64 now;
   val_type timer_val;
   parm_node p[1];
   
   if (timers == NULL)
      return;
   
   now = GetMilliCount();
   if (now > timers->time)
   {
	/*
     if (now - timers->time > TIMER_DELAY_WARN)
       dprintf("Timer handled %i.%03is late\n",
	       (now-timers->time)/1000,(now-timers->time)%1000);
	*/

      object_id = timers->object_id;
      message_id = timers->message_id;
      
      timer_val.v.tag = TAG_TIMER;
      timer_val.v.data = timers->timer_id;
      
      p[0].type = CONSTANT;
      p[0].value = timer_val.int_val;
      p[0].name_id = TIMER_PARM;
      
      temp = timers;
      timers = timers->next;
      
      /* put deleted timer on deleted_timer list */
      StoreDeletedTimer(temp);
      
      SendTopLevelBlakodMessage(object_id,message_id,1,p);
   }
}
Пример #11
0
Bool LoadTimer(int timer_id,int object_id,char *message_name,int milliseconds)
{
   object_node *o;
   timer_node *t;
   message_node *m;

   o = GetObjectByID(object_id);
   if (o == NULL)
   {
      eprintf("LoadTimer can't find object %i\n",object_id);
      return False;
   }

   m = GetMessageByName(o->class_id,message_name,NULL);
   if (m == NULL) 
   {
      eprintf("LoadTimer can't find message name %s\n",message_name);
      return False;
   }

   if (numActiveTimers == num_timer_nodes)
      ReallocTimerNodes();

   t = timer_heap[numActiveTimers];
   t->timer_id = timer_id;
   t->object_id = object_id;
   t->message_id = m->message_id;
   t->time = GetMilliCount() + milliseconds;

   TimerAddNode(t);

   /* the timers weren't saved in numerical order, but they were
    * compacted to first x non-negative integers
    */
   if (timer_id >= next_timer_num)
      next_timer_num = timer_id + 1;

   return True;
}
Пример #12
0
int CreateTimer(int object_id,int message_id,int milliseconds)
{
   timer_node *t;

   if (deleted_timers == NULL)
      t = (timer_node *)AllocateMemory(MALLOC_ID_TIMER,sizeof(timer_node));
   else
   {
      /* dprintf("recovering former timer id %i\n",deleted_timers->timer_id); */
      t = deleted_timers;
      deleted_timers = deleted_timers->next;
   }
      
   t->timer_id = next_timer_num++;
   t->object_id = object_id;
   t->message_id = message_id;
   t->time = GetMilliCount() + milliseconds;

   AddTimerNode(t);
   numActiveTimers++;

   return t->timer_id;
}
Пример #13
0
Bool LoadTimer(int timer_id,int object_id,char *message_name,int milliseconds)
{
   object_node *o;
   timer_node *t;
   message_node *m;

   o = GetObjectByID(object_id);
   if (o == NULL)
   {
      eprintf("LoadTimer can't find object %i\n",object_id);
      return False;
   }

   m = GetMessageByName(o->class_id,message_name,NULL);
   if (m == NULL) 
   {
      eprintf("LoadTimer can't find message name %s\n",message_name);
      return False;
   }

   t = (timer_node *)AllocateMemory(MALLOC_ID_TIMER,sizeof(timer_node));
   t->timer_id = timer_id;
   t->object_id = object_id;
   t->message_id = m->message_id;
   t->time = GetMilliCount() + milliseconds;

   AddTimerNode(t);
   numActiveTimers++;

   /* the timers weren't saved in numerical order, but they were
    * compacted to first x non-negative integers
    */
   if (timer_id >= next_timer_num)
      next_timer_num = timer_id + 1;

   return True;
}
Пример #14
0
void ServiceTimers(void)
{
   MSG msg;
   INT64 ms;

   StartupComplete(); /* for the interface to report no errors on startup */
   InterfaceUpdate();
   lprintf("Status: %i accounts\n",GetNextAccountID());

   lprintf("-------------------------------------------------------------------------------------\n");
   dprintf("-------------------------------------------------------------------------------------\n");
   eprintf("-------------------------------------------------------------------------------------\n");

   in_main_loop = True;
   SetWindowText(hwndMain, ConfigStr(CONSOLE_CAPTION));

	AsyncSocketStart();

   for(;;)
   {
      if (timers == NULL)
			ms = 500;
      else
      {
			ms = timers->time - GetMilliCount();
			if (ms <= 0)
				ms = 0;
	 
			if (ms > 500)
				ms = 500;
      }	 
      
      if (MsgWaitForMultipleObjects(0,NULL,0,(DWORD)ms,QS_ALLINPUT) == WAIT_OBJECT_0)
      {
	 while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	 {
	    if (msg.message == WM_QUIT)
	    {
	       lprintf("ServiceTimers shutting down the server\n");   
	       return;
	    }
	    
	    switch (msg.message)
	    {
	    case WM_BLAK_MAIN_READ :
	       EnterServerLock();
	       
	       PollSession(msg.lParam);
	       TimerActivate();
	       
	       LeaveServerLock();
	       break;
	    case WM_BLAK_MAIN_RECALIBRATE :
	       /* new soonest timer, so we should recalculate our time left... 
		  so we just need to restart the loop! */
	       break;
	    case WM_BLAK_MAIN_DELETE_ACCOUNT :
	       EnterServerLock();
	       DeleteAccountAndAssociatedUsersByID(msg.lParam);
	       LeaveServerLock();
	       break;

	    case WM_BLAK_MAIN_VERIFIED_LOGIN :
	       EnterServerLock();
	       VerifiedLoginSession(msg.lParam);
	       LeaveServerLock();
	       break;
       case WM_BLAK_MAIN_LOAD_GAME :
          EnterServerLock();
          LoadFromKod(msg.lParam);
          LeaveServerLock();
          break;

	    default :
	       dprintf("ServiceTimers got unknown message %i\n",msg.message);
	       break;
	    }
	 }
      }
      else
      {
	 /* a Blakod timer is ready to go */
	 
	 EnterServerLock();
	 PollSessions(); /* really just need to check session timers */
	 TimerActivate();
	 LeaveServerLock();
      }
   }
}
Пример #15
0
//public method
void MilliSecTime::setTimeStart()
{
	nTimeStart = GetMilliCount();
}
Пример #16
0
/* returns the return value of the blakod */
int SendTopLevelBlakodMessage(int object_id,int message_id,int num_parms,parm_node parms[])
{
	int ret_val = 0;
	UINT64 start_time = 0;
	int interp_time = 0;
	int posts = 0;
	int accumulated_num_interpreted = 0;
	
	if (message_depth != 0)
	{
		eprintf("SendTopLevelBlakodMessage called with message_depth %i\n",message_depth);
	}
	
	kod_stat.debugging = ConfigBool(DEBUG_UNINITIALIZED);
	
	start_time = GetMilliCount();
	kod_stat.num_top_level_messages++;
	trace_session_id = INVALID_ID;
	num_interpreted = 0;
	
	ret_val = SendBlakodMessage(object_id,message_id,num_parms,parms);
	
	while (post_q.next != post_q.last)
	{
		posts++;
		
		accumulated_num_interpreted += num_interpreted;
		num_interpreted = 0;
		
		if (accumulated_num_interpreted > 10*ConfigInt(BLAKOD_MAX_STATEMENTS))
		{
			bprintf("SendTopLevelBlakodMessage too many instructions in posted followups\n");
			
			dprintf("SendTopLevelBlakodMessage too many instructions in posted followups\n");
			dprintf("  OBJECT %i CLASS %s MESSAGE %s (%i) some followups are being aborted\n",
				object_id,
				GetClassByID(GetObjectByID(object_id)->class_id)->class_name,
				GetNameByID(message_id), message_id);
			
			break;
		}
		
		/* posted messages' return value is ignored */
		SendBlakodMessage(post_q.data[post_q.last].object_id,post_q.data[post_q.last].message_id,
			post_q.data[post_q.last].num_parms,post_q.data[post_q.last].parms);
		
		post_q.last = (post_q.last + 1) % MAX_POST_QUEUE;
	}
	
	interp_time = (int)(GetMilliCount() - start_time);
	kod_stat.interpreting_time += interp_time;
	if (interp_time > kod_stat.interpreting_time_highest)
	{
		kod_stat.interpreting_time_highest = interp_time;
		kod_stat.interpreting_time_message_id = message_id;
		kod_stat.interpreting_time_object_id = object_id;
		kod_stat.interpreting_time_posts = posts;
	}
	if (interp_time > 1000)
	{
		kod_stat.interpreting_time_over_second++;
		kod_stat.interpreting_time_message_id = message_id;
		kod_stat.interpreting_time_object_id = object_id;
		kod_stat.interpreting_time_posts = posts;
	}
	
	if (num_interpreted > kod_stat.num_interpreted_highest)
		kod_stat.num_interpreted_highest = num_interpreted;
	
	kod_stat.num_interpreted += num_interpreted;
	if (kod_stat.num_interpreted > 1000000000L)
	{
		kod_stat.num_interpreted -= 1000000000L;
		kod_stat.billions_interpreted++;
	}
	
	if (message_depth != 0)
	{
		eprintf("SendTopLevelBlakodMessage returning with message_depth %i\n",message_depth);
	}
	
	return ret_val;
}