private void PoolPerformanceData() { while (true) { Int64 NumTotalFiles = NumFilesReceived + NumFilesSkipped; // Get the CPU for the last second. CurrentCPUUsage = PerfCounterProcessorTime.NextValue(); if (CurrentReceivedData > 0 && CurrentTotalUploadCount > 0) { CrashReporterReceiverServicer.WritePerf ( string.Format("CPU Usage: {0:00}%, Received data: {1,5}MB/{2:00.00} of {4:00.00} MB, Uploads:{3,3}, Files:{5,6},{6,6} : {7:00}%", CurrentCPUUsage, (Int64)Math.Truncate(MBInv * TotalReceivedData), MBInv * CurrentReceivedData, UploadCount, MBInv * MaxAllowedBandwidth, NumFilesReceived, NumFilesSkipped, NumTotalFiles > 0 ? 100.0f * NumFilesSkipped / NumTotalFiles : 0.0f) ); } Interlocked.Add(ref TotalReceivedData, CurrentReceivedData); // Reset the the performance data. Interlocked.Exchange(ref CurrentReceivedData, 0); Interlocked.Exchange(ref CurrentTotalUploadCount, 0); // Sleep. System.Threading.Thread.Sleep(1000); } }
/// <summary> Spin loop for a while, maybe we hit an opportunity to start the upload. </summary> private bool TryWaitForStartOperation() { bool bCPUExceeded = false; bool bBandwidthExceeded = false; for (int Index = 0; Index < 4; Index++) { Thread.Sleep(1000); bCPUExceeded = CurrentCPUUsage > MaxAllowedCPUtilizationPct; bBandwidthExceeded = CurrentReceivedData > MaxAllowedBandwidth; if (!bCPUExceeded && !bBandwidthExceeded) { // Found, continue. CrashReporterReceiverServicer.WritePerf("TryWaitForStartOperation was successful"); return(true); } } // Give up. Interlocked.Increment(ref NumFilesSkipped); return(false); }