/// <summary> /// Collects the memory profile on the device. /// </summary> /// <param name="memoryProfilerConfig"></param> /// <param name="snapshotLabel"></param> public void CollectDeviceMemoryProfile(DeviceMemoryProfilerConfig memoryProfilerConfig, string snapshotLabel) { bool collectMemory = false; try { if (DeviceInfo != null && !string.IsNullOrEmpty(DeviceInfo.Address) && memoryProfilerConfig != null && (memoryProfilerConfig.SampleAtCountIntervals || memoryProfilerConfig.SampleAtTimeIntervals)) //TODO: Move this to before calling CollectDeviceMemoryProfile { MemoryCaptureDeviceInfo dmc = GetMemoryCaptureDeviceInfo(DeviceInfo); if (dmc != null && dmc.EligibleForMemoryCapture) { dmc.CountSinceLastCapture++; // for debugging when memory collection should occur //UpdateStatus("Ticks = {0}, est. next sample time={1}".FormatWith( // (!dmc.DateOfLastCapture.HasValue ? 0 : (DateTime.Now - dmc.DateOfLastCapture.Value).Ticks), // (!dmc.DateOfLastCapture.HasValue ? DateTime.Now : dmc.DateOfLastCapture.Value.AddTicks(config.TargetSampleTime.Ticks)) // )); // flag to collect if sampling is enabled and it's either the first time or the target has been met/exceeded if ( (memoryProfilerConfig.SampleAtCountIntervals && (!dmc.DateOfLastCapture.HasValue || dmc.CountSinceLastCapture >= memoryProfilerConfig.TargetSampleCount)) || (memoryProfilerConfig.SampleAtTimeIntervals && (!dmc.DateOfLastCapture.HasValue || (DateTime.Now - dmc.DateOfLastCapture.Value).Ticks >= memoryProfilerConfig.TargetSampleTime.Ticks)) ) { collectMemory = true; } else { OnStatusUpdate($"-- DWA -- Not Collecting device memory"); } } if (collectMemory && dmc != null) { OnStatusUpdate($"Collecting device memory (last snapshot at {dmc.DateOfLastCapture}, count = {dmc.CountSinceLastCapture})..."); //Call into SessionProxyBackendConnection ExecutionServices.SessionRuntime.CollectDeviceMemoryProfile(DeviceInfo, snapshotLabel); dmc.DateOfLastCapture = DateTime.Now; dmc.CountSinceLastCapture = 0; OnStatusUpdate($"Device memory collected (last snapshot at {dmc.DateOfLastCapture}, count reset to {dmc.CountSinceLastCapture}.)"); } } } catch (Exception ex) { var msg = $"Unable to collect memory for device {DeviceInfo.Address}. ({ex.Message})"; OnStatusUpdate(msg); ExecutionServices.SystemTrace.LogError(msg, ex); } }
private MemoryCaptureDeviceInfo GetMemoryCaptureDeviceInfo(Framework.Assets.IDeviceInfo lookupDevice) { MemoryCaptureDeviceInfo result = null; if (lookupDevice != null) { result = _memoryDevices.FirstOrDefault(x => x.Address == lookupDevice.Address); if (result == null) { result = new MemoryCaptureDeviceInfo() { Address = lookupDevice.Address }; result.EligibleForMemoryCapture = (Device is JediDevice); _memoryDevices.Add(result); } } return(result); }