当前位置: 首页>>代码示例>>C++>>正文


C++ CElapsedTime类代码示例

本文整理汇总了C++中CElapsedTime的典型用法代码示例。如果您正苦于以下问题:C++ CElapsedTime类的具体用法?C++ CElapsedTime怎么用?C++ CElapsedTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CElapsedTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateDeviceInsist

////////////////////////////////////////////////
//
// CreateDeviceInsist
//
// Keep trying create device for a little bit
//
////////////////////////////////////////////////
HRESULT CreateDeviceInsist(uint uiMinTries, uint uiTimeout, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
                           D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface)
{
    HRESULT      hResult;
    CElapsedTime retryTimer;
    uint         uiRetryCount = 0;
    do
    {
        ms_uiCreationAttempts++;
        hResult = pDirect3D->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
        if (hResult == D3D_OK)
        {
            WriteDebugEvent(SString("   -- CreateDeviceInsist succeeded on try #%d", uiRetryCount + 1));
            break;
        }
        Sleep(1);
    } while (++uiRetryCount < uiMinTries || retryTimer.Get() < uiTimeout);

    return hResult;
}
开发者ID:ccw808,项目名称:mtasa-blue,代码行数:27,代码来源:CProxyDirect3D9.cpp

示例2: Load

bool CAccountManager::Load( void )
{
    //Create a registry result
    CRegistryResult result;
    //Select all our required information from the accounts database
    m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "SELECT id,name,password,ip,serial,httppass from accounts" );

    //Initialize all our variables
    m_iAccounts = 0;
    bool bNeedsVacuum = false;
    CElapsedTime activityTimer;
    bool bOutputFeedback = false;
    for ( CRegistryResultIterator iter = result->begin() ; iter != result->end() ; ++iter )
    {
        const CRegistryResultRow& row = *iter;
        //Fill User ID, Name & Password (Required data)
        int iUserID = static_cast < int > ( row[0].nVal );
        SString strName = (const char *)row[1].pVal;
        SString strPassword = (const char *)row[2].pVal;
        SString strIP = (const char *)row[3].pVal;
        SString strSerial = (const char *)row[4].pVal;
        SString strHttpPassAppend = (const char *)row[5].pVal;

        // Check for overlong names and incorrect escapement
        bool bRemoveAccount = false;
        bool bChanged = false;
        if ( strName.length () > 64 )
        {
            // Try to repair name
            if ( strName.length () <= 256 )
            {
                strName = strName.Replace ( "\"\"", "\"", true ).substr ( 0, 64 );
                bChanged = true;
            }

            // If name gone doolally or account with this name already exists, remove account
            if ( strName.length () > 256 || Get ( strName ) )
            {
                bNeedsVacuum = true;
                bRemoveAccount = true;
                CLogger::LogPrintf ( "Removed duplicate or damaged account for %s\n", strName.substr ( 0, 64 ).c_str() );
            }
        }

        // Check for disallowed account names
        if ( strName == "*****" || strName == CONSOLE_ACCOUNT_NAME )
            bRemoveAccount = true;

        // Do account remove if required
        if ( bRemoveAccount )
        {
            m_pDatabaseManager->Execf ( m_hDbConnection, "DELETE FROM accounts WHERE id=?", SQLITE_INTEGER, iUserID );
            m_pDatabaseManager->Execf ( m_hDbConnection, "DELETE FROM userdata WHERE userid=?", SQLITE_INTEGER, iUserID );
            m_pDatabaseManager->Execf ( m_hDbConnection, "DELETE FROM serialusage WHERE userid=?", SQLITE_INTEGER, iUserID );
            continue;
        }

        //Create a new account with the specified information
        CAccount* pAccount = g_pGame->GetAccountManager ()->AddPlayerAccount ( strName, strPassword, iUserID, strIP, strSerial, strHttpPassAppend );

        if ( bChanged )
            pAccount->SetChanged ( bChanged );
        m_iAccounts = std::max ( m_iAccounts, iUserID );

        // Feedback for the user
        if ( activityTimer.Get() > 5000 )
        {
            activityTimer.Reset();
            bOutputFeedback = true;
            CLogger::LogPrintf ( "Reading accounts %d/%d\n", m_List.size(), result->nRows );
        }
    }
    if ( bOutputFeedback )
        CLogger::LogPrintf ( "Reading accounts done.\n");
    if ( bNeedsVacuum )
        m_pDatabaseManager->Execf ( m_hDbConnection, "VACUUM" );

    // Save any upgraded accounts
    {
        CElapsedTime activityTimer;
        bool bOutputFeedback = false;
        uint uiSaveCount = 0;
        for ( CMappedAccountList::const_iterator iter = m_List.begin () ; iter != m_List.end () ; iter++ )
        {
            CAccount* pAccount = *iter;
            if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
            {
                uiSaveCount++;
                Save ( pAccount, false );
                // Feedback for the user
                if ( activityTimer.Get() > 5000 )
                {
                    activityTimer.Reset();
                    bOutputFeedback = true;
                    CLogger::LogPrintf ( "Saving upgraded accounts %d\n", uiSaveCount );
                }
            }
        }

        if ( uiSaveCount > 100 )
//.........这里部分代码省略.........
开发者ID:ljnx86,项目名称:mtasa-blue,代码行数:101,代码来源:CAccountManager.cpp

示例3: TICKS_FROM_SECONDS

///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::PollCommand
//
// Find result for previous command
// Returns false if result not ready.
//
///////////////////////////////////////////////////////////////
bool CDatabaseJobQueueImpl::PollCommand ( CDbJobData* pJobData, uint uiTimeout )
{
    bool bFound = false;
    uint uiTotalWaitTime = 0;
    uint uiWaitTimeWarnThresh = TICKS_FROM_SECONDS( 60 );

    shared.m_Mutex.Lock ();
    while ( true )
    {
        // Should not be called for ignored results
        dassert ( !pJobData->result.bIgnoreResult );

        // Should not be called for collected results
        dassert ( pJobData->stage != EJobStage::FINISHED );

        // See if result has come in yet
        if ( ListContains( shared.m_ResultQueue, pJobData ) )
        {
            ListRemove( shared.m_ResultQueue, pJobData );

            pJobData->stage = EJobStage::FINISHED;
            MapInsert ( m_FinishedList, pJobData );

            // Do callback incase any cleanup is needed
            if ( pJobData->HasCallback () )
            {
                shared.m_Mutex.Unlock ();                 
                pJobData->ProcessCallback ();              
                shared.m_Mutex.Lock ();
            }

            bFound = true;
        }

        if ( bFound || uiTimeout == 0 )
        {
            shared.m_Mutex.Unlock ();
            break;
        }

        CElapsedTime timer;
        shared.m_Mutex.Wait (std::min( uiTimeout, 1000U ) );
        uint uiDelta = (uint)timer.Get() + 1;
        uiTotalWaitTime += uiDelta;

        // If not infinite, subtract time actually waited
        if ( uiTimeout != (uint)-1 )
        {
            if ( uiDelta < uiTimeout )
                uiTimeout -= uiDelta;
            else
                uiTimeout = 0;
        }

        // Issue warning if it's taking a long time
        if ( uiTotalWaitTime > uiWaitTimeWarnThresh )
        {
            shared.m_Mutex.Unlock ();
            g_pGame->GetScriptDebugging()->LogWarning( pJobData->m_LuaDebugInfo, "dbPoll is waiting a long time (%d seconds so far). [Query: %s]", uiTotalWaitTime / 1000, *pJobData->GetCommandStringForLog() );
            shared.m_Mutex.Lock ();
            uiWaitTimeWarnThresh += TICKS_FROM_SECONDS( 60 );
        }
    }

    // Make sure if wait was infinite, we have a result
    assert ( uiTimeout != (uint)-1 || bFound );

    return bFound;
}
开发者ID:tousuke,项目名称:mtasa-blue,代码行数:77,代码来源:CDatabaseJobQueue.cpp

示例4: HasData

///////////////////////////////////////////////////////////////
//
// CMasterServerManager::HasData
//
//
//
///////////////////////////////////////////////////////////////
bool CMasterServerManager::HasData ( void )
{
    // Count how many server have responded
    uint uiHasDataCount = 0;

    for ( uint i = 0 ; i < m_MasterServerList.size () && i < m_iActiveAmount ; i++ )
        if ( m_MasterServerList[i]->HasData () )
            uiHasDataCount++;

    // If two servers responded, then success
    if ( uiHasDataCount >= 2 )
        return true;

    // If less than 2 servers responded, and it's been 2.5 seconds, try to add a new server
    if ( uiHasDataCount < 2 && m_ElapsedTime.Get () > 2500 )
    {
        if ( m_iActiveAmount <= 2 && m_MasterServerList.size () > m_iActiveAmount )
        {
            m_MasterServerList[ m_iActiveAmount++ ]->Refresh ();
        }
    }

    // If one server responded, and it's been 5 seconds, then success
    if ( uiHasDataCount >= 1 && m_ElapsedTime.Get () > 5000 )
        return true;

    return false;
}
开发者ID:EagleShen,项目名称:MTA,代码行数:35,代码来源:CServerBrowser.MasterServerManager.cpp

示例5: DoPulse

///////////////////////////////////////////////////////////////
//
// CPerfStatFunctionTimingImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatFunctionTimingImpl::DoPulse ( void )
{
    // Maybe turn off stats gathering if nobody is watching
    if ( m_bIsActive && m_TimeSinceLastViewed.Get () > 15000 )
        SetActive ( false );

    // Do nothing if not active
    if ( !m_bIsActive )
    {
        m_TimingMap.empty ();
        return;
    }

    // Check if time to cycle the stats
    if ( m_TimeSinceUpdate.Get () >= 5000 )
    {
        m_TimeSinceUpdate.Reset ();

        // For each timed function
        for ( std::map < SString, SFunctionTimingInfo >::iterator iter = m_TimingMap.begin () ; iter != m_TimingMap.end () ; )
        {
            SFunctionTimingInfo& item = iter->second;
            // Update history
            item.iPrevIndex = ( item.iPrevIndex + 1 ) % NUMELMS( item.history );
            item.history[ item.iPrevIndex ] = item.now5s;

            // Reset accumulator
            item.now5s.uiNumCalls = 0;
            item.now5s.fTotalMs = 0;
            item.now5s.fPeakMs = 0;

            // Recalculate last 60 second stats
            item.prev60s.uiNumCalls = 0;
            item.prev60s.fTotalMs = 0;
            item.prev60s.fPeakMs = 0;
            for ( uint i = 0 ; i < NUMELMS( item.history ) ; i++ )
            {
                const STiming& slot = item.history[i];
                item.prev60s.uiNumCalls += slot.uiNumCalls;
                item.prev60s.fTotalMs += slot.fTotalMs;
                item.prev60s.fPeakMs = Max ( item.prev60s.fPeakMs, slot.fPeakMs );
            }

            // Remove from map if no calls in the last 60s
            if ( item.prev60s.uiNumCalls == 0 )
                m_TimingMap.erase ( iter++ );
            else
                ++iter;
        }
    }

    //
    // Update PeakUs threshold
    //
    m_PeakUsRequiredHistory.RemoveOlderThan ( 10000 );
    m_PeakUsThresh = m_PeakUsRequiredHistory.GetLowestValue ( DEFAULT_THRESH_MS * 1000 );
}
开发者ID:EagleShen,项目名称:MTA,代码行数:64,代码来源:CPerfStat.FunctionTiming.cpp

示例6: Draw

///////////////////////////////////////////////////////////////
//
// CMemStats::Draw
//
//
//
///////////////////////////////////////////////////////////////
void CMemStats::Draw ( void )
{
    if ( !m_bEnabled )
        return;

    UpdateFrameStats ();

    // Time to update?
    if ( m_UpdateTimer.Get () > 2000 )
    {
        m_UpdateTimer.Reset ();
        UpdateIntervalStats ();
        CreateTables ();
    }

    float fResWidth = static_cast < float > ( g_pGraphics->GetViewportWidth () );
    float fResHeight = static_cast < float > ( g_pGraphics->GetViewportHeight () );
    float fTotalHeight = 0;

    // Draw tables
    if ( !m_TableList.empty () )
    {

        float fX = fResWidth - m_TableList.front ().GetPixelWidth () - 15;
        float fY = 200 - m_fPosY;

        for ( std::list < CDxTable >::iterator iter = m_TableList.begin () ; iter != m_TableList.end () ; ++iter )
        {
            CDxTable& table = *iter;
            table.Draw ( fX, fY, 0x78000000, 10, 10, 8, 8 );
            float fHeight = table.GetPixelHeight () + 20;
            fY += fHeight;
            fTotalHeight += fHeight;
        }
    }

    // Handle scrolling
    bool bHoldingPageUp = ( GetAsyncKeyState ( VK_PRIOR ) & 0x8000 ) != 0;
    bool bHoldingPageDown = ( GetAsyncKeyState ( VK_NEXT ) & 0x8000 ) != 0;

    if ( bHoldingPageUp )
    {
        m_fPosY = std::max ( 0.f, m_fPosY - 10 );
    }
    if ( bHoldingPageDown )
    {
        float fScrollHeight = fTotalHeight - ( fResHeight - 200 );
        if ( fScrollHeight > 0 )
            m_fPosY = std::min ( fScrollHeight, m_fPosY + 10 );
    }
}
开发者ID:ljnx86,项目名称:mtasa-blue,代码行数:58,代码来源:CMemStats.cpp

示例7: MaybeRecordStats

///////////////////////////////////////////////////////////////
//
// CPerfStatEventPacketUsageImpl::MaybeRecordStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatEventPacketUsageImpl::MaybeRecordStats ( void )
{
    // Someone watching?
    if ( m_TimeSinceGetStats.Get () < 10000 )
    {
        // Time for record update?    // Copy and clear once every 5 seconds
        long long llTime = GetTickCount64_ ();
        if ( llTime >= m_llNextRecordTime )
        {
            m_llNextRecordTime = std::max ( m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9 );

            // Copy into a list and sort
            m_EventUsageSortedList.clear();
            for( std::map < SString, SEventUsage >::iterator iter = m_EventUsageLiveMap.begin() ; iter != m_EventUsageLiveMap.end() ; ++iter )
            {
                iter->second.strName = iter->first;
                m_EventUsageSortedList.push_back( iter->second );
            }

            std::sort ( m_EventUsageSortedList.begin (), m_EventUsageSortedList.end (), 
                [](const SEventUsage& a, const SEventUsage& b)
            {
                return a.iTotal > b.iTotal;
            });

            m_EventUsageLiveMap.clear();
        }
    }
    else
    {
        m_bEnabled = false;
    }
}
开发者ID:Jusonex,项目名称:mtasa-blue,代码行数:40,代码来源:CPerfStat.EventPacketUsage.cpp

示例8: UpdateDebugData

///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::UpdateDebugData
//
// Update info relevant to debugging database jobs
//
///////////////////////////////////////////////////////////////
void CDatabaseJobQueueImpl::UpdateDebugData ( void )
{
    // Update once every 10 seconds
    if ( m_JobCountElpasedTime.Get () < 10000 )
        return;

    shared.m_Mutex.Lock ();

    // Log to console if connection count is creeping up
    if ( shared.m_HandleConnectionMap.size() > m_uiConnectionCountWarnThresh )
    {
        m_uiConnectionCountWarnThresh = shared.m_HandleConnectionMap.size() * 2;
        CLogger::LogPrintf( "Notice: There are now %d database connections\n", shared.m_HandleConnectionMap.size() );
    }

    // Log to console if job count is creeping up
    m_uiJobCount10sMin = std::min < uint > ( m_uiJobCount10sMin, m_ActiveJobHandles.size () );
    if ( m_uiJobCount10sMin > m_uiJobCountWarnThresh )
    {
        m_uiJobCountWarnThresh = m_uiJobCount10sMin * 2;
        CLogger::LogPrintf ( "Notice: %d database query handles active in the last 10 seconds\n", m_uiJobCount10sMin );
    }
    m_JobCountElpasedTime.Reset ();
    m_uiJobCount10sMin = m_ActiveJobHandles.size ();

    CTickCount timeNow = CTickCount::Now ( true );

    // Log old uncollected queries
    for ( CJobQueueType::iterator iter = shared.m_ResultQueue.begin () ; iter != shared.m_ResultQueue.end () ; iter++ )
    {
        CDbJobData* pJobData = *iter;
        if ( !pJobData->result.bLoggedWarning )
        {
            CTickCount age = timeNow - pJobData->result.timeReady;
            if ( age.ToLongLong () > 1000 * 60 * 5 )
            {
                shared.m_Mutex.Unlock ();
                g_pGame->GetScriptDebugging()->LogWarning( pJobData->m_LuaDebugInfo, "Database result uncollected after 5 minutes. [Query: %s]", *pJobData->GetCommandStringForLog() );
                shared.m_Mutex.Lock ();
                pJobData->result.bLoggedWarning = true;
                break;
            }
        }
    }

    shared.m_Mutex.Unlock ();
}
开发者ID:tousuke,项目名称:mtasa-blue,代码行数:54,代码来源:CDatabaseJobQueue.cpp

示例9: MaybeTidyUp

////////////////////////////////////////////////////////////////
//
// CEffectClonerImpl::MaybeTidyUp
//
// Tidy up if been a little while since last time
//
////////////////////////////////////////////////////////////////
void CEffectClonerImpl::MaybeTidyUp ( bool bForceDrasticMeasures, CEffectTemplate* pKeepThis )
{
    if ( !bForceDrasticMeasures && m_TidyupTimer.Get () < 1000 )
        return;

    m_TidyupTimer.Reset ();

    // Everything in Old List can go if not being used
    for ( uint i = 0 ; i < m_OldList.size () ; i++ )
    {
        CEffectTemplate* pEffectTemplate = m_OldList[i];
        if ( pEffectTemplate != pKeepThis && pEffectTemplate->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : 1 ) )
        {
            OutputDebugLine ( "[Shader] CEffectClonerImpl::MaybeTidyUp: Releasing old EffectTemplate" );
            SAFE_RELEASE( pEffectTemplate );
            ListRemoveIndex ( m_OldList, i-- );
        }
    }

    // Complex calculation to guess how long to leave an effect unused before deleting
    // 0=30 mins  100=25 mins  200=16 mins  300=1 sec
    float fTicksAlpha = UnlerpClamped ( 0, m_ValidMap.size (), 300 );
    int iTicks = static_cast < int > ( ( 1 - fTicksAlpha * fTicksAlpha ) * 30 * 60 * 1000 ) + 1000;

#ifdef MTA_DEBUG
    iTicks /= 60;  // Mins to seconds for debug
#endif

    // Valid Effect not used for a little while can go
    for ( std::map < SString, CEffectTemplate* >::iterator iter = m_ValidMap.begin () ; iter != m_ValidMap.end () ; )
    {
        CEffectTemplate* pEffectTemplate = iter->second;
        if ( pEffectTemplate != pKeepThis && pEffectTemplate->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : iTicks ) )
        {
            OutputDebugLine ( "[Shader] CEffectClonerImpl::MaybeTidyUp: Releasing valid EffectTemplate" );
            SAFE_RELEASE( pEffectTemplate );
            m_ValidMap.erase ( iter++ );
        }
        else
            ++iter;
    }

    if ( bForceDrasticMeasures )
    {
        CGraphics::GetSingleton().GetDevice()->EvictManagedResources();
    }
}
开发者ID:Anubhav652,项目名称:mtasa-blue,代码行数:54,代码来源:CRenderItem.EffectCloner.cpp

示例10: HelperGetToucanDLL

static HMODULE HelperGetToucanDLL()
{
    if (g_toucan_dll)
        return g_toucan_dll;

    // Only scan once every five seconds
    if ( g_NextToucanDLLSearchTime.Get () < 5000 )
        return NULL;

    g_NextToucanDLLSearchTime.SetMaxIncrement ( 500, true );
    g_NextToucanDLLSearchTime.Reset ();

    /*
    ** We need to enumerate the DLLs loaded to find toucan dll.
    ** This is done because the toucan dll changes with each update.
    ** The toucan dll has the following format. "xfire_toucan_{BUILD_NUMBER}.dll"
    ** We simply try to find a dll w/ the prefix "xfire_toucan"
    */
    HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
    if (snapshot_handle != INVALID_HANDLE_VALUE)
    {
        MODULEENTRY32 module_entry;
        module_entry.dwSize = sizeof(MODULEENTRY32); 

        BOOL result = Module32First(snapshot_handle, &module_entry);
        char module_name[] = "xfire_toucan";
        DWORD module_name_len = sizeof(module_name)-1;
        while (result)
        {
            if (CompareStringA(LOCALE_USER_DEFAULT, NORM_IGNORECASE, module_entry.szModule, module_name_len, module_name, module_name_len) == CSTR_EQUAL)
            {
                g_toucan_dll = module_entry.hModule;
                break;
            }
            result = Module32Next(snapshot_handle, &module_entry);
        }

        CloseHandle(snapshot_handle);
    }

    return g_toucan_dll;
}
开发者ID:AdiBoy,项目名称:mtasa-blue,代码行数:42,代码来源:xfire.cpp

示例11: DoPulse

///////////////////////////////////////////////////////////////
//
// CPerfStatDebugTableImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatDebugTableImpl::DoPulse ( void )
{
    // Do remove old once every second
    if ( m_TimeSinceRemoveOld.Get () < 1000 )
        return;
    m_TimeSinceRemoveOld.Reset ();

    LOCK_SCOPE ( m_CS );

    CTickCount nowTickCount = CTickCount::Now ( true );

    // Remove old
    for ( std::map < SString, SLineInfo >::iterator iter = m_LineMap.begin () ; iter != m_LineMap.end () ; )
    {
        SLineInfo& info = iter->second;
        if ( info.bHasEndTime && info.endTickCount < nowTickCount )
            m_LineMap.erase ( iter++ );
        else
            ++iter;
    }
}
开发者ID:pombredanne,项目名称:openvice,代码行数:28,代码来源:CPerfStat.DebugTable.cpp

示例12: GetStats

///////////////////////////////////////////////////////////////
//
// CPerfStatEventPacketUsageImpl::GetStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatEventPacketUsageImpl::GetStats ( CPerfStatResult* pResult, const std::map < SString, int >& strOptionMap, const SString& strFilter )
{
    m_TimeSinceGetStats.Reset ();
    m_bEnabled = true;
    MaybeRecordStats();

    //
    // Set option flags
    //
    bool bHelp = MapContains ( strOptionMap, "h" );

    //
    // Process help
    //
    if ( bHelp )
    {
        pResult->AddColumn ( "Event Packet usage help" );
        pResult->AddRow ()[0] ="Option h - This help";
        return;
    }

    // Add columns
    pResult->AddColumn ( "Type" );
    pResult->AddColumn ( "Name" );
    pResult->AddColumn ( "msgs/sec" );
    pResult->AddColumn ( "5 sec.msgs" );

    // Fill rows
    for ( uint i = 0 ; i < m_EventUsageSortedList.size() && i < 30 ; i++ )
    {
        const SEventUsage& usage = m_EventUsageSortedList[i];

        // Add row
        SString* row = pResult->AddRow ();

        SString strType;
        if ( usage.iEventOut )
            strType += "Event ";
        if ( usage.iElementDataOut )
            strType += "ElementData ";
        if ( usage.iElementDataRelay )
            strType += "ElementData(Relay) ";

        int c = 0;
        row[c++] = strType;
        row[c++] = usage.strName;
        row[c++] = SString ( "%d", ( usage.iTotal + 4 ) / 5 );
        row[c++] = SString ( "%d", usage.iTotal );
    }
}
开发者ID:Jusonex,项目名称:mtasa-blue,代码行数:57,代码来源:CPerfStat.EventPacketUsage.cpp

示例13: RecordStats

///////////////////////////////////////////////////////////////
//
// CClientPerfStatPacketUsageImpl::RecordStats
//
//
//
///////////////////////////////////////////////////////////////
void CClientPerfStatPacketUsageImpl::RecordStats ( void )
{
    if ( m_TimeSinceGetStats.Get () < 10000 )
    {
        // Save previous sample so we can calc the delta values
        memcpy ( m_PrevPacketStats, m_PacketStats, sizeof ( m_PacketStats ) );
        memcpy ( m_PacketStats, g_pNet->GetPacketStats (), sizeof ( m_PacketStats ) );
    }
    else
    {
        // No one watching
        memset ( m_PrevPacketStats, 0, sizeof ( m_PacketStats ) );
        memset ( m_PacketStats, 0, sizeof ( m_PacketStats ) );
    }
}
开发者ID:EagleShen,项目名称:MTA,代码行数:22,代码来源:CClientPerfStat.PacketUsage.cpp

示例14: MaybeRecordStats

///////////////////////////////////////////////////////////////
//
// CPerfStatRPCPacketUsageImpl::MaybeRecordStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatRPCPacketUsageImpl::MaybeRecordStats ( void )
{
    // Someone watching?
    if ( m_TimeSinceGetStats.Get () < 10000 )
    {
        // Time for record update?    // Copy and clear once every 5 seconds
        long long llTime = GetTickCount64_ ();
        if ( llTime >= m_llNextRecordTime )
        {
            m_llNextRecordTime = Max ( m_llNextRecordTime + 5000, llTime + 5000 / 10 * 9 );

            // Save previous sample so we can calc the delta values
            memcpy ( m_PrevPacketStatsIn, m_PacketStatsIn, sizeof ( m_PacketStatsIn ) );
            memcpy ( m_PacketStatsIn, m_PacketStatsLiveIn, sizeof ( m_PacketStatsIn ) );

            memcpy ( m_PrevPacketStatsOut, m_PacketStatsOut, sizeof ( m_PacketStatsOut ) );
            memcpy ( m_PacketStatsOut, m_PacketStatsLiveOut, sizeof ( m_PacketStatsOut ) );

            if ( m_iStatsCleared == 1 )
            {
                // Prime if was zeroed
                memcpy ( m_PrevPacketStatsIn, m_PacketStatsIn, sizeof ( m_PacketStatsIn ) );
                memcpy ( m_PrevPacketStatsOut, m_PacketStatsOut, sizeof ( m_PacketStatsOut ) );
                m_iStatsCleared = 2;
            }
            else
            if ( m_iStatsCleared == 2 )
                m_iStatsCleared = 0;
        }
    }
    else
    {
        // No one watching
        if ( !m_iStatsCleared )
        {
            memset ( m_PrevPacketStatsIn, 0, sizeof ( m_PacketStatsIn ) );
            memset ( m_PacketStatsIn, 0, sizeof ( m_PacketStatsIn ) );
            memset ( m_PrevPacketStatsOut, 0, sizeof ( m_PacketStatsOut ) );
            memset ( m_PacketStatsOut, 0, sizeof ( m_PacketStatsOut ) );
            m_iStatsCleared = 1;
        }
    }
}
开发者ID:AdiBoy,项目名称:mtasa-blue,代码行数:50,代码来源:CPerfStat.RPCPacketUsage.cpp

示例15: GetStats

///////////////////////////////////////////////////////////////
//
// CPerfStatRPCPacketUsageImpl::GetStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatRPCPacketUsageImpl::GetStats(CPerfStatResult* pResult, const std::map<SString, int>& strOptionMap, const SString& strFilter)
{
    m_TimeSinceGetStats.Reset();
    MaybeRecordStats();

    //
    // Set option flags
    //
    bool bHelp = MapContains(strOptionMap, "h");

    //
    // Process help
    //
    if (bHelp)
    {
        pResult->AddColumn("RPC Packet usage help");
        pResult->AddRow()[0] = "Option h - This help";
        return;
    }

    // Add columns
    pResult->AddColumn("Packet type");
    pResult->AddColumn("Incoming.msgs/sec");
    pResult->AddColumn("Incoming.bytes/sec");
    pResult->AddColumn("Incoming.cpu");
    pResult->AddColumn("Outgoing.msgs/sec");
    pResult->AddColumn("Outgoing.bytes/sec");
    pResult->AddColumn("Outgoing.cpu");

    if (m_iStatsCleared)
    {
        pResult->AddRow()[0] = "Sampling... Please wait";
    }

    long long llTickCountNow = CTickCount::Now().ToLongLong();

    // Fill rows
    for (uint i = 0; i < 256; i++)
    {
        // Calc incoming delta values
        SPacketStat statInDelta;
        {
            const SRPCPacketStat& statInPrev = m_PrevPacketStatsIn[i];
            const SRPCPacketStat& statInNow = m_PacketStatsIn[i];
            statInDelta.iCount = statInNow.iCount - statInPrev.iCount;
            statInDelta.iTotalBytes = statInNow.iTotalBytes - statInPrev.iTotalBytes;
            // statInDelta.totalTime   = statInNow.totalTime - statInPrev.totalTime;
        }

        if (!statInDelta.iCount)
        {
            // Once displayed, keep a row displayed for at least 20 seconds
            if (llTickCountNow - m_ShownPacketStatsIn[i] > 20000)
                continue;
        }
        else
        {
            m_ShownPacketStatsIn[i] = llTickCountNow;
        }

        // Add row
        SString* row = pResult->AddRow();

        int c = 0;
        // Turn "CRPCFunctions::PLAYER_WEAPON" into "64_Player_weapon"
        SString strPacketDesc = EnumToString((CRPCFunctions::eRPCFunctions)i).SplitRight("CRPCFunctions::", NULL, -1).ToLower();
        row[c++] = SString("%d_", i) + strPacketDesc.Left(1).ToUpper() + strPacketDesc.SubStr(1);

        if (statInDelta.iCount)
        {
            row[c++] = SString("%d", (statInDelta.iCount + 4) / 5);
            row[c++] = CPerfStatManager::GetScaledByteString((statInDelta.iTotalBytes + 4) / 5);
            row[c++] = "n/a";
        }
        else
        {
            row[c++] = "-";
            row[c++] = "-";
            row[c++] = "-";
        }

        row[c++] = "-";
        row[c++] = "-";
        row[c++] = "-";
    }

    // Fill rows
    for (uint i = 0; i < 256; i++)
    {
        // Calc outgoing delta values
        SRPCPacketStat statOutDelta;
        {
            const SRPCPacketStat& statOutPrev = m_PrevPacketStatsOut[i];
//.........这里部分代码省略.........
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:101,代码来源:CPerfStat.RPCPacketUsage.cpp


注:本文中的CElapsedTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。