Ejemplo n.º 1
0
bool CBaseGameStats_Driver::AddBaseDataForSend( KeyValues *pKV, StatSendType_t sendType )
{
	switch ( sendType )
	{
	case STATSEND_APPSHUTDOWN:
#ifdef CLIENT_DLL
		if ( m_iNumLevels > 0 )
		{
			// add playtime data
			KeyValues *pKVData = new KeyValues( "playtime" );
			pKVData->SetInt( "TotalLevelTime", m_flTotalTimeInLevels );
			pKVData->SetInt( "NumLevels", m_iNumLevels );
			pKV->AddSubKey( pKVData );
			return true;
		}
#endif
		break;
	case STATSEND_LEVELSHUTDOWN:
#ifdef CLIENT_DLL
		if ( m_bBufferFull )
		{
			// add perf data
			KeyValues *pKVPerf = new KeyValues( "perfdata" );
			float flAverageFrameRate = AverageStat( &StatsBufferRecord_t::m_flFrameRate );
			float flMinFrameRate = MinStat( &StatsBufferRecord_t::m_flFrameRate );
			float flMaxFrameRate = MaxStat( &StatsBufferRecord_t::m_flFrameRate );

			pKVPerf->SetFloat( "AvgFPS", flAverageFrameRate );
			pKVPerf->SetFloat( "MinFPS", flMinFrameRate );
			pKVPerf->SetFloat( "MaxFPS", flMaxFrameRate );

			pKV->AddSubKey( pKVPerf );

			return true;
		}
#endif
		break;
	}

	return false;
}
Ejemplo n.º 2
0
// get the string record for sending to the server. Contains perf data and hardware/software
// info. Returns NULL if there isn't a good record to send (i.e. not enough data yet).
// A successful Get() resets the stats
char const *CStatsRecorder::GetPerfStatsString( int iType )
{
	switch ( iType )
	{
	case PERFDATA_LEVEL:
	{
		if ( ! m_bBufferFull )
			return NULL;

		float flAverageFrameRate = AverageStat( &StatsBufferRecord_t::m_flFrameRate );
		float flMinFrameRate = MinStat( &StatsBufferRecord_t::m_flFrameRate );
		float flMaxFrameRate = MaxStat( &StatsBufferRecord_t::m_flFrameRate );

		const CPUInformation &cpu = GetCPUInformation();
		MaterialAdapterInfo_t gpu;
		materials->GetDisplayAdapterInfo( materials->GetCurrentAdapter(), gpu );

		CMatRenderContextPtr pRenderContext( materials );
		int dest_width,dest_height;
		pRenderContext->GetRenderTargetDimensions( dest_width, dest_height );

		char szMap[MAX_PATH+1]="";
		Q_FileBase( engine->GetLevelName(), szMap, ARRAYSIZE( szMap ) );

		V_snprintf( s_cPerfString, sizeof( s_cPerfString ), 
			"PERFDATA:AvgFps=%4.2f MinFps=%4.2f MaxFps=%4.2f CPUID=\"%s\" CPUGhz=%2.2f "
			"NumCores=%d GPUDrv=\"%s\" "
			"GPUVendor=%d GPUDeviceID=%d "
			"GPUDriverVersion=\"%d.%d\" DxLvl=%d "
			"Width=%d Height=%d MapName=%s",
			flAverageFrameRate,
			flMinFrameRate,
			flMaxFrameRate,
			cpu.m_szProcessorID,
			cpu.m_Speed * ( 1.0 / 1.0e9 ),
			cpu.m_nPhysicalProcessors,
			SafeString( gpu.m_pDriverName ),
			gpu.m_VendorID,
			gpu.m_DeviceID,
			gpu.m_nDriverVersionHigh,
			gpu.m_nDriverVersionLow,
			g_pMaterialSystemHardwareConfig->GetDXSupportLevel(),
			dest_width, dest_height, szMap
			);
		// get rid of chars that we hate in vendor strings
		for( char *i = s_cPerfString; *i; i++ )
		{
			if ( ( i[0]=='\n' ) || ( i[0]=='\r' )  || ( i[0]==';' ) )
				i[0]=' ';
		}

		// clear buffer
		m_nWriteIndex = 0;
		m_bBufferFull = false;

		return s_cPerfString;
	}
	case PERFDATA_SHUTDOWN:
		V_snprintf( s_cPerfString, sizeof( s_cPerfString ), "PERFDATA:TotalLevelTime:%d NumLevels:%d",
			(int) m_flTotalTimeInLevels, m_iNumLevels );
		return s_cPerfString;

	default:
		Assert( false );
		return NULL;
	}
}