private void WriteAggregatedFileAsync(bool[] outlierFlags)
        {
            // write aggregated file
            Task.Run(() =>
            {
                string process = string.Empty;
                var filteredFileRecordInfoList = _fileRecordInfoList.Where((x, i) => !outlierFlags[i]);

                var runs = new List <ISessionRun>();

                foreach (var recordInfo in filteredFileRecordInfoList)
                {
                    var otherSession = _recordManager.LoadData(recordInfo.FullPath);
                    process          = otherSession.Info.ProcessName;
                    runs.AddRange(otherSession.Runs);
                }

                _recordManager.SaveSessionRunsToFile(runs, process);
            });
        }
Beispiel #2
0
        public void AddRunToHistory(ISessionRun sessionRun, string process, string recordDirectory)
        {
            var frametimes = sessionRun.CaptureData.MsBetweenPresents;

            if (RunHistoryCount == _numberOfRuns)
            {
                if (!_runHistoryOutlierFlags.All(x => x == false) &&
                    _appConfiguration.OutlierHandling == EOutlierHandling.Replace.ConvertToString())
                {
                    var historyDefault = Enumerable.Repeat("N/A", _numberOfRuns).ToList();
                    var validRuns      = _runHistory.Where((run, i) => _runHistoryOutlierFlags[i] == false).ToList();

                    for (int i = 0; i < validRuns.Count; i++)
                    {
                        historyDefault[i] = validRuns[i];
                    }

                    var validCaptureData    = _captureDataHistory.Where((run, i) => _runHistoryOutlierFlags[i] == false);
                    var validFrametimes     = _frametimeHistory.Where((run, i) => _runHistoryOutlierFlags[i] == false);
                    var validMetricAnalysis = _metricAnalysis.Where((run, i) => _runHistoryOutlierFlags[i] == false);

                    _runHistory         = historyDefault.ToList();
                    _captureDataHistory = validCaptureData.ToList();
                    _frametimeHistory   = validFrametimes.ToList();
                    _metricAnalysis     = validMetricAnalysis.ToList();

                    // local reset
                    _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray();
                    _rTSSService.SetRunHistory(_runHistory.ToArray());
                    _rTSSService.SetRunHistoryAggregation(string.Empty);
                    _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);
                }
                else
                {
                    ResetHistory();
                }
            }

            if (RunHistoryCount < _numberOfRuns)
            {
                // metric history
                var currentAnalysis = _statisticProvider.GetMetricAnalysis(frametimes, SecondMetric, ThirdMetric);
                _metricAnalysis.Add(currentAnalysis);
                _runHistory[RunHistoryCount] = currentAnalysis.ResultString;
                _rTSSService.SetRunHistory(_runHistory.ToArray());

                // capture data history
                _captureDataHistory.Add(sessionRun);

                // frametime history
                _frametimeHistory.Add(frametimes);

                if (_appConfiguration.UseAggregation &&
                    RunHistoryCount == _numberOfRuns)
                {
                    _runHistoryOutlierFlags = _statisticProvider
                                              .GetOutlierAnalysis(_metricAnalysis,
                                                                  _appConfiguration.RelatedMetricOverlay,
                                                                  _appConfiguration.OutlierPercentageOverlay);
                    _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags);

                    if ((_runHistoryOutlierFlags.All(x => x == false) &&
                         _appConfiguration.OutlierHandling == EOutlierHandling.Replace.ConvertToString()) ||
                        _appConfiguration.OutlierHandling == EOutlierHandling.Ignore.ConvertToString())
                    {
                        _rTSSService.SetRunHistoryAggregation(GetAggregation());

                        // write aggregated file
                        Task.Run(async() =>
                        {
                            await Task.Delay(1000);
                            await _recordManager.SaveSessionRunsToFile(_captureDataHistory, process, recordDirectory);
                        });
                    }
                }
            }
        }
Beispiel #3
0
        private async Task WriteExtractedCaptureDataToFileAsync()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(_currentCaptureOptions.ProcessName))
                {
                    PrepareForNextCapture();
                    return;
                }

                var adjustedCaptureData = GetAdjustedCaptureData();

                PrepareForNextCapture();

                if (!adjustedCaptureData.Any())
                {
                    AddLoggerEntry("Error while extracting capture data. No file will be written.");
                    return;
                }

                // Skip first line to compensate the first frametime being one frame before original capture start point.
                var normalizedAdjustedCaptureData = NormalizeTimes(adjustedCaptureData.Skip(1));
                var sessionRun = _recordManager.ConvertPresentDataLinesToSessionRun(normalizedAdjustedCaptureData);
                sessionRun.SensorData = _sensorService.GetSessionSensorData();


                if (_appConfiguration.UseRunHistory)
                {
                    await Task.Factory.StartNew(() => _overlayService.AddRunToHistory(sessionRun, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory));
                }


                // if aggregation mode is active and "Save aggregated result only" is checked, don't save single history items
                if (_appConfiguration.UseAggregation && _appConfiguration.SaveAggregationOnly)
                {
                    return;
                }

                if (_currentCaptureOptions.CaptureFileMode == Enum.GetName(typeof(ECaptureFileMode), ECaptureFileMode.JsonCsv))
                {
                    await _recordManager.SavePresentmonRawToFile(normalizedAdjustedCaptureData, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory);
                }

                bool checkSave = await _recordManager.SaveSessionRunsToFile(new ISessionRun[] { sessionRun }, _currentCaptureOptions.ProcessName, _currentCaptureOptions.RecordDirectory);


                if (!checkSave)
                {
                    AddLoggerEntry("Error while saving capture data.");
                }
                else
                {
                    AddLoggerEntry("Capture file is successfully written into directory.");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error writing capture data");
                PrepareForNextCapture();
            }
        }