private TestResourceSnapshot GetTestResourceSnapshot(TestStage testStage, IAssemblyInfo assemblyInfo)
        {
            var timeStamp    = DateTime.UtcNow;
            var assemblyName = GetAssemblyShortName(assemblyInfo);
            var cpuUsage     = _metricCacher.GetValue(MetricCacher.Keys.Server.CpuUsage, _cpuUsageCalculator.Calculate);

            var memoryInfo = _metricCacher.GetValue <MemoryInfoResult>(MetricCacher.Keys.Server.MemoryInfoExtended);

            var snapshot = new TestResourceSnapshot
            {
                TotalScratchAllocatedMemory = new Size(MemoryInformation.GetTotalScratchAllocatedMemory(), SizeUnit.Bytes).GetValue(SizeUnit.Megabytes),
                TotalDirtyMemory            = new Size(MemoryInformation.GetDirtyMemoryState().TotalDirtyInBytes, SizeUnit.Bytes).GetValue(SizeUnit.Megabytes),
                IsHighDirty                = MemoryInformation.GetDirtyMemoryState().IsHighDirty,
                TestStage                  = testStage,
                Timestamp                  = timeStamp.ToString("o"),
                AssemblyName               = assemblyName,
                MachineCpuUsage            = (long)cpuUsage.MachineCpuUsage,
                ProcessCpuUsage            = (long)cpuUsage.ProcessCpuUsage,
                ProcessMemoryUsageInMb     = memoryInfo.WorkingSet.GetValue(SizeUnit.Megabytes),
                TotalMemoryInMb            = memoryInfo.TotalPhysicalMemory.GetValue(SizeUnit.Megabytes),
                TotalCommittableMemoryInMb = memoryInfo.TotalCommittableMemory.GetValue(SizeUnit.Megabytes),
                AvailableMemoryInMb        = memoryInfo.AvailableMemory.GetValue(SizeUnit.Megabytes),
                CurrentCommitChargeInMb    = memoryInfo.CurrentCommitCharge.GetValue(SizeUnit.Megabytes),
                SharedCleanMemoryInMb      = memoryInfo.SharedCleanMemory.GetValue(SizeUnit.Megabytes),
                TotalScratchDirtyMemory    = memoryInfo.TotalScratchDirtyMemory.GetValue(SizeUnit.Megabytes)
            };

            return(snapshot);
        }
 private void Write(TestResourceSnapshot snapshot)
 {
     lock (_syncObject)
     {
         _csvWriter.NextRecord();
         _csvWriter.WriteRecord(snapshot);
     }
 }