Repository: dotnet/runtime
File: src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/JitInfoTests.cs (C#)

Code before:
                Assert.True(beforeCompiledILBytes >= 0, $"Compiled IL bytes not greater or equal to 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount >= 0, $"Compiled method count not greater or equal to 0! ({beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(beforeCompilationTime > TimeSpan.Zero, $"Compilation time not greater than 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes > 0, $"Compiled IL bytes not greater than 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount > 0, $"Compiled method count not greater than 0! ({beforeCompiledMethodCount})");
            }

            if (PlatformDetection.IsBrowser)
            {
                // Before and after will most likely be the same in browser because of low precision timers
                Assert.True(afterCompilationTime >= beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }
            else
            {
                Assert.True(afterCompilationTime > beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }

            if (PlatformDetection.IsMonoInterpreter)
            {
                Assert.True(afterCompiledILBytes >= beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount >= beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(afterCompiledILBytes > beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount > beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
        }


        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT), nameof(PlatformDetection.IsReflectionEmitSupported))] // JitInfo metrics will be 0 in full AOT scenarios
        public void JitInfoIsNotPopulated()
        {
            TimeSpan beforeCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long beforeCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long beforeCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            long square = MakeAndInvokeDynamicSquareMethod(100);
            Assert.True(square == 10000);

            TimeSpan afterCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long afterCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long afterCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            Assert.True(beforeCompilationTime == TimeSpan.Zero, $"Before Compilation time not equal to 0! ({beforeCompilationTime})");
            Assert.True(beforeCompiledILBytes == 0, $"Before Compiled IL bytes not equal to 0! ({beforeCompiledILBytes})");
            Assert.True(beforeCompiledMethodCount == 0, $"Before Compiled method count not equal to 0! ({beforeCompiledMethodCount})");


Review comment (bug):
Are the `CompiledILBytes` and `CompiledMethodCount` conditions really failing with Mono interpreter?

Code after:
                Assert.True(beforeCompiledILBytes >= 0, $"Compiled IL bytes not greater or equal to 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount >= 0, $"Compiled method count not greater or equal to 0! ({beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(beforeCompilationTime > TimeSpan.Zero, $"Compilation time not greater than 0! ({beforeCompilationTime})");
                Assert.True(beforeCompiledILBytes > 0, $"Compiled IL bytes not greater than 0! ({beforeCompiledILBytes})");
                Assert.True(beforeCompiledMethodCount > 0, $"Compiled method count not greater than 0! ({beforeCompiledMethodCount})");
            }

            //
            // Mono does not include compilation of IL into interpreter byte code in these counters
            //
            if (PlatformDetection.IsMonoInterpreter || PlatformDetection.IsBrowser)
            {
                // Before and after can be same in browser because of low precision timers
                Assert.True(afterCompilationTime >= beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }
            else
            {
                Assert.True(afterCompilationTime > beforeCompilationTime, $"CompilationTime: after not greater than before! (after: {afterCompilationTime}, before: {beforeCompilationTime})");
            }

            if (PlatformDetection.IsMonoInterpreter)
            {
                Assert.True(afterCompiledILBytes >= beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount >= beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
            else
            {
                Assert.True(afterCompiledILBytes > beforeCompiledILBytes, $"Compiled IL bytes: after not greater than before! (after: {afterCompiledILBytes}, before: {beforeCompiledILBytes})");
                Assert.True(afterCompiledMethodCount > beforeCompiledMethodCount, $"Compiled method count: after not greater than before! (after: {afterCompiledMethodCount}, before: {beforeCompiledMethodCount})");
            }
        }


        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT), nameof(PlatformDetection.IsReflectionEmitSupported))] // JitInfo metrics will be 0 in full AOT scenarios
        public void JitInfoIsNotPopulated()
        {
            TimeSpan beforeCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long beforeCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long beforeCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            long square = MakeAndInvokeDynamicSquareMethod(100);
            Assert.True(square == 10000);

            TimeSpan afterCompilationTime = System.Runtime.JitInfo.GetCompilationTime();
            long afterCompiledILBytes = System.Runtime.JitInfo.GetCompiledILBytes();
            long afterCompiledMethodCount = System.Runtime.JitInfo.GetCompiledMethodCount();

            Assert.True(beforeCompilationTime == TimeSpan.Zero, $"Before Compilation time not equal to 0! ({beforeCompilationTime})");