PerformanceCounter & PerformanceCounterCategory on Windows 2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We are trying to create a custom performance counter and category in .Net 1.1 with Windows 2003 and XP as our operating systems. We use the following code to do this

if (PerformanceCounterCategory.Exists(categoryName)

PerformanceCounterCategory.Delete(categoryName)

CounterCreationData ccd = new CounterCreationData(counterName, counterHelp, PerformanceCounterType.RateOfCountsPerSecond32)
CounterCreationDataCollection ccdc = new CounterCreationDataCollection()
ccdc.Add(ccd)

PerformanceCounterCategory perfCategory = PerformanceCounterCategory.Create(categoryName, categoryHelp, ccdc)
OurLibrary.Error.AssertThrow(perfCategory.CounterExists(counterName), String.Format("Expected \"{0}\" counter to exist.", counterName))

PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, false)

We get a "Category does not exist" InvalidOperationException when we assert that the counter exists. perfCategory != null at this time. The PerformanceCounterCategory.Create does NOT throw. We have tried many permutations of calls to try to get this to work, but it always throws. The odd thing is that the category and counter are actually created in the perfmon utility. We can see them from .net too, but not in the process that created them. We have tried this same code on Windows 2000 boxes and it works correctly. What is the problem with the Windows 2003 and XP operating systems that cause this to fail? We have searched the newsgroups and have not seen any explanations and very few instances of this problem. Are we the only ones using the .net performance counters

Thanks
Frank
 
Hi Frank,

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Hi Frank,

Based on my understanding, when you use PerformanceCounterCategory to
create categroy, you got "Category does not exist"
InvalidOperationException.

Is your application winform/console application? Or does it run under
Asp.net account?

If it is a winform/console application, what account does it run under? Is
the account administrator?

There is a useful information relate this by "Ryan Byington [MS]", please
refer to:
http://groups.google.com/groups?q="Category+does+not+exist"+PerformanceC
ounter&hl=zh-CN&lr=&ie=UTF-8&selm=po%23jTWyGEHA.3800%40cpmsftngxa06.phx.gbl&
rnum=4

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
This application is being run in NUnit, so it is effectively under the logged in user accounts security context. I am logged in as a local administrator, so it is not a security issue. I have run the test with registry and NTFS security auditing turned on and get no security errors there

No, we don't get a "Category does not exist" exception when creating the category. Only when trying to do something with it. The Create() call works fine. It's the assertion that the counter exists in the category that throws the exception

The most odd thing about this is that the category and counter (which is created through the CounterCreationData) really are created. It's just that in code at runtime, we cannot access the counter or category directly after it's been created. The test fails, then upon next run, it succeeds because the counter and category are both there

Fran


----- "Jeffrey Tan[MSFT]" wrote: ----

Hi Frank

Based on my understanding, when you use PerformanceCounterCategory to
create categroy, you got "Category does not exist"
InvalidOperationException.

Is your application winform/console application? Or does it run under
Asp.net account

If it is a winform/console application, what account does it run under? Is
the account administrator

There is a useful information relate this by "Ryan Byington [MS]", please
refer to
http://groups.google.com/groups?q="Category+does+not+exist"+Performance
ounter&hl=zh-CN&lr=&ie=UTF-8&selm=po%23jTWyGEHA.3800%40cpmsftngxa06.phx.gbl
rnum=

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance

Best regards
Jeffrey Ta
Microsoft Online Partner Suppor
Get Secure! - www.microsoft.com/securit
This posting is provided "as is" with no warranties and confers no rights
 
Hi Frank,

Thanks very much for your feedback.

Yes, I have reproduced out your issue on my WindowXP and Windows 2003
machines.

After do some research, I found that this is a know issue of our product.
It looks like after creating the performance counter category we keep
around some shared information that is stale so we think that the Category
does not exist. The workaround is call
PerformanceCounter.CloseSharedResources() static method to refresh the
stale data and it should fix this issue.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Frank,

Thanks for your feedback.

After some research, I found that the following problem of Win32Exception
"The device is not ready" is a bug.

We cannot reliably create or delete categories at runtime more than one
times.

So this code will generate exception:
public static void Main()
{
string categoryName = "Create_Delete_Test";
string categoryHelp = "Create_Delete_Test Help";
string counterName = "Counter1";
string counterHelp = "Counter1 Help";
PerformanceCounter pc;
int i = 0;

for(i=0; i<2; ++i)
{
try
{
PerformanceCounterCategory.Create(categoryName + i.ToString(),
categoryHelp + i.ToString(), counterName, counterHelp);
PerformanceCounter.CloseSharedResources();
pc = new PerformanceCounter(categoryName + i.ToString(), counterName,
false);
pc.RawValue = 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

try
{
PerformanceCounterCategory.Delete(categoryName + i.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Console.WriteLine("Press to exit");
Console.Read();
}

While this code snippet will not generate exception:
public static void Main()
{
string categoryName = "Create_Delete_Test";
string categoryHelp = "Create_Delete_Test Help";
string counterName = "Counter1";
string counterHelp = "Counter1 Help";
PerformanceCounter pc;
int i = 0;

try
{
PerformanceCounterCategory.Create(categoryName + i.ToString(),
categoryHelp + i.ToString(), counterName, counterHelp);
PerformanceCounter.CloseSharedResources();
pc = new PerformanceCounter(categoryName + i.ToString(), counterName,
false);
pc.RawValue = 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

try
{
PerformanceCounterCategory.Delete(categoryName + i.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Console.WriteLine("Press to exit");
Console.Read();
}

The workaround is removing PerformanceCounter.CloseSharedResources(),
however this sentence is tracked by our previous bug. Unfortunately,
currently I can not find a good workaround for your issue.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Frank,

Thanks for your feedback.

Currently, our product group is pending for this issue, and there is no
existed hot fix for this issue. But if you feel this issue is a critical
one for you, you may contact our PSS and require a hot fix for it. Because
it is a known issue, the requiring is free.

I hope my reply makes sense to you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top