/**
       Update all instances.

    */
    void StatisticalLogicalDiskEnumeration::UpdateInstances()
    {
        scxulong total_reads = 0;
        scxulong total_writes = 0;
#if defined(hpux)
        scxulong total_tTime = 0;
#endif
        scxulong total_rTime = 0;
        scxulong total_wTime = 0;
        scxulong total_transfers = 0;
        scxulong total_rPercent = 0;
        scxulong total_wPercent = 0;
        scxulong total_tPercent = 0;
        SCXCoreLib::SCXHandle<StatisticalLogicalDiskInstance> total = GetTotalInstance();
        if (0 != total)
        {
            total->Reset();
            total->m_online = true;
        }
        
        for (EntityIterator iter = Begin(); iter != End(); iter++)
        {
            SCXCoreLib::SCXHandle<StatisticalLogicalDiskInstance> disk = *iter;
            disk->Update();
            if (0 != total)
            {
                total->m_readsPerSec += disk->m_readsPerSec;
                total->m_writesPerSec += disk->m_writesPerSec;
                total->m_transfersPerSec += disk->m_transfersPerSec;
                total->m_rBytesPerSec += disk->m_rBytesPerSec;
                total->m_wBytesPerSec += disk->m_wBytesPerSec;
                total->m_tBytesPerSec += disk->m_tBytesPerSec;
                total->m_rTime += disk->m_rTime;
                total->m_wTime += disk->m_wTime;
                total->m_tTime += disk->m_tTime;
                total->m_runTime += disk->m_runTime;
                total->m_waitTime += disk->m_waitTime;
                total->m_mbUsed += disk->m_mbUsed;
                total->m_mbFree += disk->m_mbFree;
                total_reads += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_writes += disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#if defined (hpux)
                total_transfers += disk->m_transfers.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_tTime += disk->m_tTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#elif defined (linux)
                total_transfers += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES) + disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_rTime += disk->m_rTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_wTime += disk->m_wTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#elif defined (sun)
                total_transfers += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES) + disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_rTime += disk->m_runTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_wTime += disk->m_waitTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#endif
                total_rPercent += disk->m_rPercentage;
                total_wPercent += disk->m_wPercentage;
                total_tPercent += disk->m_tPercentage;
            }
        }

        if (0 != total)
        {
            if (Size() > 0)
            {
                total->m_rPercentage = total_rPercent/Size();
                total->m_wPercentage = total_wPercent/Size();
                total->m_tPercentage = total_tPercent/Size();
            }
                    
            if (total_reads != 0)
            {
                total->m_secPerRead = static_cast<double>(total_rTime) / static_cast<double>(total_reads) / 1000.0;
            }
            if (total_writes != 0)
            {
                total->m_secPerWrite = static_cast<double>(total_wTime) / static_cast<double>(total_writes) / 1000.0;
            }
            if (total_transfers != 0)
            {
#if defined(hpux)
                total->m_secPerTransfer = static_cast<double>(total_tTime) / static_cast<double>(total_transfers) / 1000.0;
#elif defined(linux) || defined(sun)
                total->m_secPerTransfer = static_cast<double>(total_rTime+total_wTime) / static_cast<double>(total_transfers) / 1000.0;
#endif
            }
        }
    }
    /**
       Update all instances.

    */
    void StatisticalLogicalDiskEnumeration::UpdateInstances()
    {
        scxulong total_reads = 0;
        scxulong total_writes = 0;
#if defined(hpux)
        scxulong total_tTime = 0;
#endif
        scxulong total_rTime = 0;
        scxulong total_wTime = 0;
        scxulong total_transfers = 0;
        scxulong total_rPercent = 0;
        scxulong total_wPercent = 0;
        scxulong total_tPercent = 0;

        set<wstring> diskSet;
        pair<set<wstring>::iterator,bool> Pair;

        SCXCoreLib::SCXHandle<StatisticalLogicalDiskInstance> total = GetTotalInstance();
        if (0 != total)
        {
            total->Reset();
            SCX_LOGTRACE(m_log, L"Device being set to ONLINE for TOTAL instance");
            total->m_online = true;
        }

        for (EntityIterator iter = Begin(); iter != End(); ++iter)
        {
            SCXCoreLib::SCXHandle<StatisticalLogicalDiskInstance> disk = *iter;
            disk->Update();

            Pair = diskSet.insert(disk->m_device);
            if(Pair.second == false)
                continue;

            if (0 != total)
            {
                total->m_readsPerSec += disk->m_readsPerSec;
                total->m_writesPerSec += disk->m_writesPerSec;
                total->m_transfersPerSec += disk->m_transfersPerSec;
                total->m_rBytesPerSec += disk->m_rBytesPerSec;
                total->m_wBytesPerSec += disk->m_wBytesPerSec;
                total->m_tBytesPerSec += disk->m_tBytesPerSec;
                total->m_rTime += disk->m_rTime;
                total->m_wTime += disk->m_wTime;
                total->m_tTime += disk->m_tTime;
                total->m_runTime += disk->m_runTime;
                total->m_waitTime += disk->m_waitTime;
                total->m_mbUsed += disk->m_mbUsed;
                total->m_mbFree += disk->m_mbFree;
                total_reads += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_writes += disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#if defined (hpux)
                total_transfers += disk->m_transfers.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_tTime += disk->m_tTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#elif defined (linux)
                total_transfers += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES) + disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_rTime += disk->m_rTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_wTime += disk->m_wTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#elif defined (sun)
                total_transfers += disk->m_reads.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES) + disk->m_writes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_rTime += disk->m_runTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
                total_wTime += disk->m_waitTimes.GetDelta(MAX_DISKINSTANCE_DATASAMPER_SAMPLES);
#endif
                total_rPercent += disk->m_rPercentage;
                total_wPercent += disk->m_wPercentage;
                total_tPercent += disk->m_tPercentage;
            }
        }

        if (0 != total)
        {
            if (Size() > 0)
            {
                total->m_rPercentage = total_rPercent/Size();
                total->m_wPercentage = total_wPercent/Size();
                total->m_tPercentage = total_tPercent/Size();
            }

            if (total_reads != 0)
            {
                total->m_secPerRead = static_cast<double>(total_rTime) / static_cast<double>(total_reads) / 1000.0;
            }
            if (total_writes != 0)
            {
                total->m_secPerWrite = static_cast<double>(total_wTime) / static_cast<double>(total_writes) / 1000.0;
            }
            if (total_transfers != 0)
            {
#if defined(hpux)
                total->m_secPerTransfer = static_cast<double>(total_tTime) / static_cast<double>(total_transfers) / 1000.0;
#elif defined(linux) || defined(sun)
                total->m_secPerTransfer = static_cast<double>(total_rTime+total_wTime) / static_cast<double>(total_transfers) / 1000.0;
#endif
            }
        }
    }