Skip to content

Commit

Permalink
Add New Test to Track Number of Jitted Methods (dotnet#91235)
Browse files Browse the repository at this point in the history
* New beginning for the Jitted Methods Counting Test.

* EXPERIMENTAL CHANGE ONLY: Added a command to print the whole directory
tree after running the tests, and adjusted the pipelines
configuration to only run that one.

* experimental change only: Discovered the jobs have dependencies on
other jobs. Disabled the runtime pipeline entirely, and only kept the
relevant outerloop platforms for my change to save resources.

* EXPERIMENT-ONLY CHANGE: Added the 'ls -R' directly to the Helix Post
Commands, and disabled the dev-innerloop pipeline to further speed up
this testing and debugging process.

* Maybe it doesn't like me removing the innerloop...?

* More experimenting... So we can't do just musl...

* Changed the test's methodology to use the JitInfo API, instead of
logging all the jitted methods into a file.

* Added the `AlwaysUseCrossgen2` property to the HelloWorld test app.

* Now printing the Jitted Methods to compare with my local machine.

* REVIEW-READY: Reenabled all the pipelines to see if there are any
other broken ones.

* Changed the Jitted methods counter to consider the whole process,
instead of just the current thread.

* DEBUG-ONLY CHANGE: We're getting more Jitted methods on Arm64 for some
reason, so making the test always fail to see the full CI log to begin
investigating what in the world is going on.

* Enabled musl outerloop pipelines because we were observing different
results there.

* Will you stop complaining now?

* READY: Reenabled the pipelines and disabled the test for R2R_CG2
branches on Arm64. It will require more investigation and we need the
other platforms to be able to run this test.

* Changed the jits-number limit.

* Changed the test to not require an external app anymore, and fixed
some small bad merges in the CI files when rebasing.

* DEBUG-ONLY CHANGE: Printing some logging to try to figure out why
Windows is causing problems, yet again...

* ...

* ...

* Due to how some machines are set up, it is actually possible for a
dotnet app to be fully prejitted, and therefore show 0 jitted methods,
so added that case to the test.
  • Loading branch information
ivdiazsa authored Sep 25, 2023
1 parent eb4c875 commit dc5225d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ FCIMPLEND
FCIMPL1(INT64, GetCompiledMethodCount, CLR_BOOL currentThread)
{
FCALL_CONTRACT;

// WIP-DEBUG-ONLY change: Windows is causing problems in the CI, but can't
// be replicated locally. Using this for some logging there to try to figure
// it out.
printf("\nENTERING GETCOMPILEDMETHODCOUNT:");
printf("%d\n", currentThread ? 1 : 0);
printf("%ld\n", (long) t_cMethodsJittedForThread);
printf("%ld\n", (long) AtomicLoad64WithoutTearing(&g_cMethodsJitted));
printf(":EXITING GETCOMPILEDMETHODCOUNT\n");
return currentThread ? t_cMethodsJittedForThread : AtomicLoad64WithoutTearing(&g_cMethodsJitted);
}
FCIMPLEND
Expand Down
3 changes: 2 additions & 1 deletion src/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<Target Name="CheckForTestOutsideOfGroup" BeforeTargets="Build">
<Error Condition="'$(InMergedTestDirectory)' == 'true'
and '$(OutputType)' == 'Exe'
and '$(_CLRTestNeedsToRun)' == 'true'
and '$(RequiresProcessIsolation)' != 'true'
and '$(BuildAsStandalone)' != 'true'
and '$(IsMergedTestRunnerAssembly)' != 'true'"
Expand Down Expand Up @@ -510,7 +511,7 @@
</ItemGroup>
</Target>

<PropertyGroup Condition="'$(Language)' == 'C#' and ('$(BuildAsStandalone)' == 'true' or '$(RequiresProcessIsolation)' == 'true' or '$(InMergedTestDirectory)' == 'true' or '$(IsMergedTestRunnerAssembly)' == 'true')">
<PropertyGroup Condition="'$(Language)' == 'C#' and '$(_CLRTestNeedsToRun)' == 'true' and ('$(BuildAsStandalone)' == 'true' or '$(RequiresProcessIsolation)' == 'true' or '$(InMergedTestDirectory)' == 'true' or '$(IsMergedTestRunnerAssembly)' == 'true')">
<ReferenceXUnitWrapperGenerator Condition="'$(ReferenceXUnitWrapperGenerator)' == ''">true</ReferenceXUnitWrapperGenerator>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Xunit;

using InteropServices = System.Runtime.InteropServices;
using JitInfo = System.Runtime.JitInfo;

public class JittedMethodsCountingTest
{
private const int MAX_JITTED_METHODS_ACCEPTED = 70;

[Fact]
public static int TestEntryPoint()
{
// If DOTNET_ReadyToRun is disabled, then this test ought to be skipped.
if (!IsReadyToRunEnvSet())
{
Console.WriteLine("\nThis test is only supported in ReadyToRun scenarios."
+ " Skipping...\n");
return 100;
}

if (IsRunCrossgen2Set() && IsRunningOnARM64())
{
Console.WriteLine("\nThis test is currently unsupported on ARM64 when"
+ " RunCrossGen2 is enabled. Skipping...\n");
return 100;
}

Console.WriteLine("\nHello World from Jitted Methods Counting Test!");

long jits = JitInfo.GetCompiledMethodCount(false);
Console.WriteLine("Number of Jitted Methods in App: {0}\n", jits);

return (jits >= 0 && jits <= MAX_JITTED_METHODS_ACCEPTED) ? 100 : 101;
}

private static bool IsReadyToRunEnvSet()
{
string? dotnetR2R = Environment.GetEnvironmentVariable("DOTNET_ReadyToRun");
return (string.IsNullOrEmpty(dotnetR2R) || dotnetR2R == "1");
}

private static bool IsRunCrossgen2Set()
{
string? runCrossgen2 = Environment.GetEnvironmentVariable("RunCrossGen2");
return (runCrossgen2 == "1");
}

private static bool IsRunningOnARM64()
{
InteropServices.Architecture thisMachineArch = InteropServices
.RuntimeInformation
.OSArchitecture;

return (thisMachineArch == InteropServices.Architecture.Arm64);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<JitOptimizationSensitive>true</JitOptimizationSensitive>
</PropertyGroup>

<ItemGroup>
<Compile Include="JittedMethodsCountingTest.cs" />
</ItemGroup>

</Project>

0 comments on commit dc5225d

Please sign in to comment.