public void StopAndSubmitPerfData()
        {
            this.stopWatch.Stop();

            long elapsedTime = this.stopWatch.ElapsedMilliseconds;
            long privateMemorySizeDelta = 0;
            long pagedMemorySizeDelta = 0;
            long virtualMemorySizeDelta = 0;
            long workingSetDelta = 0;

            using (Process process = Process.GetCurrentProcess())
            {
                privateMemorySizeDelta = (process.PrivateMemorySize64 - this.privateMemorySizeStart) / 1024;
                pagedMemorySizeDelta = (process.PagedMemorySize64 - this.pagedMemorySizeStart) / 1024;
                virtualMemorySizeDelta = (process.VirtualMemorySize64 - this.virtualMemorySizeStart) / 1024;
                workingSetDelta = (process.WorkingSet64 - this.workingSetStart) / 1024;
            }

            if (!this.ShouldSubmitPerfData)
            {
                return;
            }

            var counterResults = new List<CounterResult>();

            PerfData data = new PerfData()
            {
                Name = Path.GetExtension(this.testContext.FullyQualifiedTestClassName).TrimStart('.') + "_" + this.testContext.TestName,
                ScenarioResult = new ScenarioResult()
                {
                    Name = this.testContext.TestName,
                    CounterResults = counterResults
                }
            };

            counterResults.Add(new CounterResult()
            {
                Name = "ExecutionTime",
                Default = true,
                Units = "MilliSeconds",
                Value = Convert.ToString(elapsedTime)
            });

            counterResults.Add(new CounterResult()
            {
                Name = "PrivateMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(privateMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name = "PagedMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(pagedMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name = "VirtualMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(virtualMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name = "WorkingSetDelta",
                Units = "KBytes",
                Value = Convert.ToString(workingSetDelta)
            });

            string dropPath = Path.Combine(this.prepDataPath, @"MetricsAggregations", DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss", CultureInfo.CurrentCulture));
            if (!Directory.Exists(dropPath))
            {
                Directory.CreateDirectory(dropPath);
            }

            data.WriteXml(dropPath);
        }
Пример #2
0
        public void StopAndSubmitPerfData()
        {
            this.stopWatch.Stop();

            long elapsedTime            = this.stopWatch.ElapsedMilliseconds;
            long privateMemorySizeDelta = 0;
            long pagedMemorySizeDelta   = 0;
            long virtualMemorySizeDelta = 0;
            long workingSetDelta        = 0;

            using (Process process = Process.GetCurrentProcess())
            {
                privateMemorySizeDelta = (process.PrivateMemorySize64 - this.privateMemorySizeStart) / 1024;
                pagedMemorySizeDelta   = (process.PagedMemorySize64 - this.pagedMemorySizeStart) / 1024;
                virtualMemorySizeDelta = (process.VirtualMemorySize64 - this.virtualMemorySizeStart) / 1024;
                workingSetDelta        = (process.WorkingSet64 - this.workingSetStart) / 1024;
            }

            if (!this.ShouldSubmitPerfData)
            {
                return;
            }

            var counterResults = new List <CounterResult>();

            PerfData data = new PerfData()
            {
                Name           = Path.GetExtension(this.testContext.FullyQualifiedTestClassName).TrimStart('.') + "_" + this.testContext.TestName,
                ScenarioResult = new ScenarioResult()
                {
                    Name           = this.testContext.TestName,
                    CounterResults = counterResults
                }
            };

            counterResults.Add(new CounterResult()
            {
                Name    = "ExecutionTime",
                Default = true,
                Units   = "MilliSeconds",
                Value   = Convert.ToString(elapsedTime)
            });

            counterResults.Add(new CounterResult()
            {
                Name  = "PrivateMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(privateMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name  = "PagedMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(pagedMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name  = "VirtualMemorySizeDelta",
                Units = "KBytes",
                Value = Convert.ToString(virtualMemorySizeDelta)
            });

            counterResults.Add(new CounterResult()
            {
                Name  = "WorkingSetDelta",
                Units = "KBytes",
                Value = Convert.ToString(workingSetDelta)
            });

            string dropPath = Path.Combine(this.prepDataPath, @"MetricsAggregations", DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss", CultureInfo.CurrentCulture));

            if (!Directory.Exists(dropPath))
            {
                Directory.CreateDirectory(dropPath);
            }

            data.WriteXml(dropPath);
        }