Beispiel #1
0
        static TestResourcesAnalyzer()
        {
            _enabled = bool.TryParse(Environment.GetEnvironmentVariable("TEST_RESOURCE_ANALYZER_ENABLE"), out var value) && value;
            if (_enabled == false)
            {
                return;
            }

            _cpuUsageCalculator = CpuHelper.GetOSCpuUsageCalculator();
            _metricCacher       = new TestResourcesAnalyzerMetricCacher(_cpuUsageCalculator);
            _timer = new Timer(ProcessQueue, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
        }
        public TestResourceSnapshotWriter(string filename = null)
        {
            lock (_syncObject)
            {
                _cpuUsageCalculator = CpuHelper.GetOSCpuUsageCalculator();
                _metricCacher       = new TestResourcesAnalyzerMetricCacher(_cpuUsageCalculator);

                filename ??= $"TestResources_{DateTime.UtcNow:dd_MM_yyyy_HH_mm_ss}.csv";

                var file = File.OpenWrite(filename);

                file.Position = 0;
                file.SetLength(0);

                _csvWriter = new CsvWriter(new StreamWriter(file), CultureInfo.InvariantCulture);
                _csvWriter.WriteHeader(typeof(TestResourceSnapshot));
            }
        }