Ejemplo n.º 1
0
        public void TheNumberOfStopEventsMustBeEqualToStartEvents()
        {
            var sut = new ProcessMetrics();

            sut.HandleIterationEvent(0, IterationMode.Overhead, 100); // start but no stop later on

            Assert.Throws <InvalidOperationException>(() => sut.CalculateMetrics(null, Array.Empty <PreciseMachineCounter>()));
        }
Ejemplo n.º 2
0
        public void TheNumberOfTotalOperationsPerIterationIsTheSameForAllIterations()
        {
            var sut = new ProcessMetrics();

            sut.HandleIterationEvent(0, IterationMode.Workload, 100); // start

            Assert.Throws <InvalidOperationException>(() => sut.HandleIterationEvent(0, IterationMode.Workload, 100 + 1));
        }
Ejemplo n.º 3
0
 public ProcessMetricsModel(ProcessMetrics metrics)
 {
     ProcessId    = metrics.ProcessId;
     Name         = metrics.Name;
     WorkingSet   = $"{metrics.WorkingSet / (1024.0 * 1024):F2} MB";
     PrivateBytes = $"{metrics.PrivateBytes / (1024.0 * 1024):F2} MB";
     ThreadsCount = metrics.ThreadsCount;
 }
Ejemplo n.º 4
0
        public void MetricsAreCorrectlyCalculatedPerIteration()
        {
            const int   profileSourceId = 123;
            const int   interval        = 100;
            const ulong ip = 12345;
            const long  totalOperations = 100;

            var sut = new ProcessMetrics();

            for (int relativeTimestamp = 0; relativeTimestamp < 20; relativeTimestamp++)
            {
                sut.HandleIterationEvent(relativeTimestamp, IterationMode.Overhead, totalOperations);       // Overhead iteration start at i

                sut.HandleNewSample(relativeTimestamp + 0.1, ip, profileSourceId);                          // Engine overhead produces one PMC event per iteration

                sut.HandleIterationEvent(relativeTimestamp + 0.5, IterationMode.Overhead, totalOperations); // Overhead iteration stop at i + 0.5
            }

            for (int relativeTimestamp = 20; relativeTimestamp < 40; relativeTimestamp++)
            {
                sut.HandleIterationEvent(relativeTimestamp, IterationMode.Workload, totalOperations);       // Workload iteration start at i

                sut.HandleNewSample(relativeTimestamp + 0.1, ip, profileSourceId);                          // Engine overhead produces one PMC event per iteration
                sut.HandleNewSample(relativeTimestamp + 0.2, ip, profileSourceId);                          // benchmarked code
                sut.HandleNewSample(relativeTimestamp + 0.3, ip, profileSourceId);                          // benchmarked code
                sut.HandleNewSample(relativeTimestamp + 0.4, ip, profileSourceId);                          // benchmarked code

                sut.HandleIterationEvent(relativeTimestamp + 0.5, IterationMode.Workload, totalOperations); // Workload iteration stop at i + 0.5
            }

            var metrics = sut.CalculateMetrics(
                new Dictionary <int, int> {
                { profileSourceId, interval }
            },
                new [] { new PreciseMachineCounter(profileSourceId, "test", HardwareCounter.InstructionRetired, interval), });

            const ulong expected = (4 * interval - interval) / totalOperations; // every workload was 4 events, the overhead was one and totalOperations times per iteration

            Assert.Equal(expected, metrics.Single().Value);
        }