示例#1
0
void ProfileBegin( char* name )
{
   unsigned int i = 0;

   while( i < NUM_PROFILE_SAMPLES && g_samples[i].bValid == true ) {
      if( strcmp( g_samples[i].szName, name ) == 0 ) {
         //Found the sample
         g_samples[i].iOpenProfiles++;
         g_samples[i].iProfileInstances++;
         g_samples[i].fStartTime = GetExactTime();
         ASSERT( g_samples[i].iOpenProfiles == 1, "max 1 open at once" );
         return;
       }
       i++;
   }

   if( i >= NUM_PROFILE_SAMPLES ) {
      FAIL("Exceeded Max Available Profile Samples");
      return;
   }

   strcpy( g_samples[i].szName, name );
   g_samples[i].bValid = true;
   g_samples[i].iOpenProfiles = 1;
   g_samples[i].iProfileInstances = 1;
   g_samples[i].fAccumulator = 0.0f;
   g_samples[i].fStartTime = GetExactTime();
   g_samples[i].fChildrenSampleTime = 0.0f;
}
示例#2
0
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	{
		g_dfProcessLoadTime = GetExactTime();
		//TraceMsgA("%s DvoIPCPlaySDK is loaded.\r\n", __FUNCTION__);
		InitializeCriticalSection(&g_csListDxCache);
		InitializeCriticalSection(&g_csListPlayertoFree);
#ifdef _DEBUG
		InitializeCriticalSection(&g_csPlayerHandles);
		g_nPlayerHandles = 0;
#endif
		//CDvoPlayer::CheckSnapshotWnd(g_hSnapShotWnd);
		g_bThread_ClosePlayer = true;
		g_hEventThreadExit = CreateEvent(nullptr, true, false, nullptr);
		g_hThread_ClosePlayer = CreateThread(nullptr, 0, Thread_Helper, nullptr, 0, 0);
	}
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
	{
// 		HWND hSnapWnd = FindWindow(nullptr, _T("DVO SnapShot"));
// 		if (hSnapWnd)
// 			PostMessage(hSnapWnd, WM_QUIT,0,0);
		
		g_bThread_ClosePlayer = false;
		DWORD dwExitCode = 0;
		GetExitCodeThread(g_hThread_ClosePlayer, &dwExitCode);
		if (dwExitCode == STILL_ACTIVE)
			if (WaitForSingleObject(g_hEventThreadExit, 2000) == WAIT_TIMEOUT)
			{
				TraceMsgA("%s %d(%s) WaitForSingleObject Timeout.\n)", __FILE__, __LINE__, __FUNCTION__);
			}
		Sleep(10);
		GetExitCodeThread(g_hThread_ClosePlayer, &dwExitCode);
		if (dwExitCode != STILL_ACTIVE)
			TerminateThread(g_hThread_ClosePlayer, 0);
		CloseHandle(g_hThread_ClosePlayer);
		DeleteCriticalSection(&g_csListPlayertoFree);
#if _DEBUG
		DeleteCriticalSection(&g_csPlayerHandles);
#endif
		DeleteCriticalSection(&g_csListDxCache);
		//TraceMsgA("%s DvoIPCPlaySDK is Unloaded.\r\n", __FUNCTION__);
		CloseHandle(g_hEventThreadExit);
		g_hEventThreadExit = nullptr;
	}
		break;
	}
	return TRUE;
}
示例#3
0
void ProfileInit( void )
{
   unsigned int i;

   for( i=0; i<NUM_PROFILE_SAMPLES; i++ ) {
      g_samples[i].bValid = false;
      g_history[i].bValid = false;
   }

   g_startProfile = GetExactTime();

   g_ProfileText = new Engine::LabelWidget("blank", vec2(100.0f, 768.0f / 2));
   g_GUI.addWidget(g_ProfileText);
}
示例#4
0
void ProfileEnd( const char* name )
{
   unsigned int i = 0;
   unsigned int numParents = 0;

   while( i < NUM_PROFILE_SAMPLES && g_samples[i].bValid == true )
   {
      if( strcmp( g_samples[i].szName, name ) == 0 )
      {  //Found the sample
         unsigned int inner = 0;
         int parent = -1;
         float fEndTime = GetExactTime();
         g_samples[i].iOpenProfiles--;

         //Count all parents and find the immediate parent
         while( g_samples[inner].bValid == true ) {
            if( g_samples[inner].iOpenProfiles > 0 )
            {  //Found a parent (any open profiles are parents)
               numParents++;
               if( parent < 0 )
               {  //Replace invalid parent (index)
                  parent = inner;
               }
               else if( g_samples[inner].fStartTime >=
                        g_samples[parent].fStartTime )
               {  //Replace with more immediate parent
                  parent = inner;
               }
            }
            inner++;
         }

         //Remember the current number of parents of the sample
         g_samples[i].iNumParents = numParents;

         if( parent >= 0 )
         {  //Record this time in fChildrenSampleTime (add it in)
            g_samples[parent].fChildrenSampleTime += fEndTime -
                                                     g_samples[i].fStartTime;
         }

         //Save sample time in accumulator
         g_samples[i].fAccumulator += fEndTime - g_samples[i].fStartTime;
         return;
      }
      i++;
   }
}
示例#5
0
void ProfileDumpOutputToBuffer( void )
{
   unsigned int i = 0;

   g_endProfile = GetExactTime();
   MarkTimeThisTick();

   string output;
   output += " Ave  :  Min  :  Max  :   #   : Profile Name\n";
   output += "--------------------------------------------\n";

   while( i < NUM_PROFILE_SAMPLES && g_samples[i].bValid == true ) {
      unsigned int indent = 0;
      float sampleTime, percentTime, aveTime, minTime, maxTime;
      string indentedName;
      string ave, min, max, num;

      if( g_samples[i].iOpenProfiles < 0 ) {
         FAIL("ProfileEnd() called without a ProfileBegin()");
      }
      else if( g_samples[i].iOpenProfiles > 0 ) {
         FAIL("ProfileBegin() called without a ProfileEnd()");
      }

      sampleTime = g_samples[i].fAccumulator - g_samples[i].fChildrenSampleTime;
	  float deltaTime = g_endProfile - g_startProfile;
      percentTime = ( sampleTime / deltaTime ) * 100.0f;

      aveTime = minTime = maxTime = percentTime;

      //Add new measurement into the history and get the ave, min, and max
      StoreProfileInHistory( g_samples[i].szName, percentTime );
      GetProfileFromHistory( g_samples[i].szName, &aveTime, &minTime, &maxTime );

      //Format the data
	  const int fieldSize = 5;
	  ave = Engine::ftoa(aveTime);
	  min = Engine::ftoa(minTime);
	  max = Engine::ftoa(maxTime);
	  num = Engine::itoa(g_samples[i].iProfileInstances);

	  ave = Engine::fitToFieldSize(ave, fieldSize, Engine::JUSTIFY_LEFT);
      min = Engine::fitToFieldSize(min, fieldSize, Engine::JUSTIFY_LEFT);
      max = Engine::fitToFieldSize(max, fieldSize, Engine::JUSTIFY_LEFT);
      num = Engine::fitToFieldSize(num, fieldSize, Engine::JUSTIFY_CENTER);

      indentedName.clear();
      for(indent=0; indent<g_samples[i].iNumParents; indent++)
         indentedName += "   ";
	  indentedName += g_samples[i].szName;

	  output += ave + " : " + min + " : " + max + " : " + num + " : " + indentedName + "\n";
      i++;
   }

   {  //Reset samples for next frame
      unsigned int i;
      for( i=0; i<NUM_PROFILE_SAMPLES; i++ ) {
         g_samples[i].bValid = false;
      }
      g_startProfile = GetExactTime();
   }

   if(g_ProfileText)
   {
	   g_ProfileText->setLabel(output);
	   g_ProfileText->m_bVisible = g_Application.displayDebugData;
   }
}