-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add PerformanceCounters Testing #24812
Add PerformanceCounters Testing #24812
Conversation
{ | ||
CounterCreationData[] ccds = { new CounterCreationData("Simple1", "Simple Help", PerformanceCounterType.RawBase), new CounterCreationData("Simple2", "Simple Help", PerformanceCounterType.RawBase) }; | ||
CounterCreationDataCollection ccdc = new CounterCreationDataCollection(ccds); | ||
|
There was a problem hiding this comment.
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") ) |
There was a problem hiding this comment.
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"]; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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))] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = ""; |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
There was a problem hiding this 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!
Looks like Windows 7 has some interesting quirks/limitations that your tests will need to work around --see test results. |
8e7a4b0
to
f640d6d
Compare
@dotnet-bot test Windows x64 Debug Build please |
@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? |
It's OK to poll so long as you check first. ie., it's OK to do 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. |
See if that pattern is possible (hopefully in a couple places not sprayed all over) |
Ah ok. I'll try it out. Thanks. |
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. |
f640d6d
to
7d9cf82
Compare
@dotnet-bot test OSX x64 Debug Build (access dnied) |
@dotnet-bot test Windows x86 Release Build please |
@dotnet-bot test this please |
@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); |
There was a problem hiding this comment.
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.
@dotnet-bot test Windows x64 Debug Build please |
LGTM Please remove Console.WriteLines before committing... |
7e7f26e
to
ffa2931
Compare
ffa2931
to
caa72fb
Compare
@dotnet-bot test Windows x86 Release Build please |
5b401fb
to
caa72fb
Compare
@adiaaida I think Helpers.cs is missing |
@dotnet/dnceng have you seen this?
|
@dotnet-bot test Windows x64 Debug Build please |
1 similar comment
@dotnet-bot test Windows x64 Debug Build please |
a98d9ef
to
80cd489
Compare
@dotnet-bot test Windows x64 Debug Build please |
I opened a core-eng issue for |
@dotnet-bot test Windows x64 Debug Build please |
@dotnet-bot test Windows x64 Debug Build please |
@dotnet-bot test Windows x64 Debug Build please |
1 similar comment
@dotnet-bot test Windows x64 Debug Build please |
@danmosemsft I've gotten the tests to pass in the lab 3 times now, so I am going to check this in now. |
Sounds good! |
Add PerformanceCounters Testing Commit migrated from dotnet/corefx@5617d39
No description provided.