Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add PerformanceCounters Testing #24812

Merged

Conversation

michellemcdaniel
Copy link
Contributor

No description provided.

{
CounterCreationData[] ccds = { new CounterCreationData("Simple1", "Simple Help", PerformanceCounterType.RawBase), new CounterCreationData("Simple2", "Simple Help", PerformanceCounterType.RawBase) };
CounterCreationDataCollection ccdc = new CounterCreationDataCollection(ccds);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, newlines .. you can search and replace \s*\n\s*\n with \n

[ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
public static void PerformanceCounterCategory_CreateCategory()
{
if ( !PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, spaces inside parens

public static InstanceDataCollection GetInstanceDataCollection()
{
InstanceDataCollectionCollection idcc = GetInstanceDataCollectionCollection();
return idcc["% User Time"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to try changing your Windows locale to non English (then log in/out) and verify your tests still pass, that will verify that strings like this are not localized.

Our tests must pass on the machines of contributors who aren't using English.

@@ -0,0 +1,368 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I noticed lingering use of CAS (code access security) in performancecountercategory.cs:

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, categoryName);
            permission.Demand();

any stuff that looks like this can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove any of these
RuntimeHelpers.PrepareConstrainedRegions();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I also remove RegistryPermission, EnvironmentPermission and FileIOPermission, etc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, anything in S.S.Permissions -- remove all the using System.Security.Permissions; and you will find them

Assert.Equal("Processor", pcc.CategoryName);
}

[ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal, but many of these tests don't need this attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW you could replace it with
[ConditionalFact(typeof(Helpers), nameof(Helpers.CanWriteToPerfCounters))]
or similar, akin to what event logs did with [ConditionalFact(typeof(Helpers), nameof(Helpers.SupportsEventLogs))]

Nice thing about this is it makes a single place you can tune when the tests run later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it appears you need to -- your tests are failing on Windows Nano. So once you centralize as I usggest, you'll need to add && !PlatformDetection.IsWindowsNanoServer to the check.

Assert.Throws<ArgumentNullException>(() => PerformanceCounterCategory.Create("category name", "Category help", PerformanceCounterCategoryType.SingleInstance, null));
Assert.Throws<InvalidOperationException>(() => PerformanceCounterCategory.Create("Processor", "Category help", PerformanceCounterCategoryType.MultiInstance, "Interrupts/sec", "counter help"));

string maxCounter = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace this with just new string('a', 32768)

var name = nameof(PerformanceCounterCategory_GetCounterHelp) + "_Counter";
var category = name + "_Category";

if (PerformanceCounterCategory.Exists(category))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This category exists/delete pattern you are using all over, you could make it into a private helper function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you have one: DeleteCategory()

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! nearly done with perf counters!

@danmoseley
Copy link
Member

Looks like Windows 7 has some interesting quirks/limitations that your tests will need to work around --see test results.

@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from 8e7a4b0 to f640d6d Compare October 25, 2017 16:36
@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please

@michellemcdaniel
Copy link
Contributor Author

@danmosemsft The PerfCounter tests tend to be a little flakey, even locally. I don't know if it's because it takes a little while for the system to actually register the PerfCounter, outside of the code, or what else is going on. I changed the if(!PerfCounterCounter.Exists) statement to be a while, and that seems to have addressed some of the issue, because it makes sure that we actually have created the category before trying to create the counter, but I'm not sure if that's the right way to address the issue. It's also not the best track for the PerformanceCounterCategory tests, which also have this issue. I wonder if putting a short sleep in the tests would give the system time, but I don't want to add unnecessary time to the tests. Thoughts?

@danmoseley
Copy link
Member

danmoseley commented Oct 25, 2017

It's OK to poll so long as you check first. ie., it's OK to do

success = doBlah()
while (!success && tries < 3)
{
tries++
Thread.Sleep(100)
success = doBlah()
}

and hopefully it rarely actually needs to sleep.

@Anipik found he had to do this for some of his event log tests. MSDN even said there was a 6 second delay in some cases.

@danmoseley
Copy link
Member

See if that pattern is possible (hopefully in a couple places not sprayed all over)

@michellemcdaniel
Copy link
Contributor Author

Ah ok. I'll try it out. Thanks.

@danmoseley
Copy link
Member

If the tests are then slow we can just make them outer loop, so they don't bother most people. But they must be 100% reliable.

@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from f640d6d to 7d9cf82 Compare October 25, 2017 22:39
@danmoseley
Copy link
Member

@dotnet-bot test OSX x64 Debug Build (access dnied)

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test this please

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please

@@ -99,15 +99,17 @@ public static PerformanceCounter CreateCounter(string name, PerformanceCounterTy
}

DeleteCategory(name);
PerformanceCounterCategory.Create(category, "description", PerformanceCounterCategoryType.SingleInstance, ccdc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize you're experimenting at this point but I hope when you're done any sleep/retries are abstracted from the tests either by having methods like "CreateCategory" that they call that guarantee it's visible when they complete, or worst case by having a "PollUntilTrue" method they call that takes a delegate to check for the case they want and it will poll or timeout then return. Timeout should cause assert failure.

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@danmoseley
Copy link
Member

LGTM Please remove Console.WriteLines before committing...

@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from 7e7f26e to ffa2931 Compare October 31, 2017 20:41
@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from ffa2931 to caa72fb Compare November 1, 2017 14:30
@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from 5b401fb to caa72fb Compare November 2, 2017 20:35
@danmoseley
Copy link
Member

@adiaaida I think Helpers.cs is missing using Xunit; ..

@danmoseley
Copy link
Member

@dotnet/dnceng have you seen this?

  Restoring packages for /Users/dotnet-bot/j/workspace/dotnet_corefx/master/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/init-tools.msbuild...
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-buildtools/nuget/v3/flatcontainer/microsoft.dotnet.build.tasks.feed/index.json'.
  Access to the path '/tmp/NuGet/TempCache/2f3f9dbe-352f-4004-ae7d-1c899166cb67' is denied.
    Permission denied
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-buildtools/nuget/v3/flatcontainer/microsoft.dotnet.buildtools/index.json'.
  Access to the path '/tmp/NuGet/TempCache/2f3f9dbe-352f-4004-ae7d-1c899166cb67' is denied.
    Permission denied
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-buildtools/nuget/v3/flatcontainer/microsoft.dotnet.build.tasks.feed/index.json'.
  Access to the path '/tmp/NuGet/TempCache/2f3f9dbe-352f-4004-ae7d-1c899166cb67' is denied.
    Permission denied
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-buildtools/nuget/v3/flatcontainer/microsoft.dotnet.buildtools/index.json'.
  Access to the path '/tmp/NuGet/TempCache/2f3f9dbe-352f-4004-ae7d-1c899166cb67' is denied.
    Permission denied

https://ci3.dot.net/job/dotnet_corefx/job/master/job/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/5011/consoleText

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

1 similar comment
@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel michellemcdaniel force-pushed the addPerformanceCounterTests branch from a98d9ef to 80cd489 Compare November 6, 2017 23:06
@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@danmoseley
Copy link
Member

I opened a core-eng issue for Caused by: com.fasterxml.jackson.databind.JsonMappingException: Numeric value (4302832145) out of range of int

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

1 similar comment
@michellemcdaniel
Copy link
Contributor Author

@dotnet-bot test Windows x64 Debug Build please
@dotnet-bot test Windows x86 Release Build please

@michellemcdaniel
Copy link
Contributor Author

@danmosemsft I've gotten the tests to pass in the lab 3 times now, so I am going to check this in now.

@danmoseley
Copy link
Member

Sounds good!

@michellemcdaniel michellemcdaniel merged commit 5617d39 into dotnet:master Nov 8, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Add PerformanceCounters Testing

Commit migrated from dotnet/corefx@5617d39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants