views:

76

answers:

5

I am doing some tuning in a very large application. Is there a way to measure number of events fired in an application? For example using something in System.Diagnostics?

Adding code inside events is NOT an acceptable solution due to the size of the application.

There are profiling tools, but the fast and simple approach for me would be something found in .Net

A: 

Can you be a bit more specific? What kind of events do you want to trace?

No hay Problema
All events subscribed in my application. I want to get a summary on the amount of events fired in the application.
ToPa
A: 

This is a very interesting question.

There is really no easy way to trace events without any additional code. This doesn't mean that adding the code has to be hard or a performance hog.

If all your events use custom eventArgs you could add a simple logging statement to the constructor that would allow you to count every time that you create one of the custom eventArgs.

If you are not using custom eventArgs you could very easily extend eventArgs with a customEventArgs class that does exactly this counting. Just extend the constructor to update some static variable which you can write out to a log every so often. Then using a quick refactor you could rename all your default eventArgs to this new slightly different customEventArgs. This would take all of 10 minutes and would not break any existing code.

However, if you know that a profiler can do this, why not use it? If the application is this gigantic and you are trying to do very small optimizations whoever you are building this application for would probably not mind the added cost associated with you purchasing a license in exchange for the improvements to their software.

Mark
The size of the solution (8 MB *.cs files) makes this approach with custom event argument too tiresome.
ToPa
If you are using any IDE you can easily do a replace all after you create a customevent. It should not take more than 10 or 15 minutes. And if you already are using customevents all you need to do is add a new private field to do the counting.
Mark
Also how in the world are your ASCII text *.cs files 8MB?! If that is the case you need some SERIOUS refactoring of your program.
Mark
A: 

Are you talking about Windows 'event viewer' or subscriptions to events on your classes?

if it's the latter, who subscribes to your events? Maybe you can write some 'glue' code that sites between the events and the subscribers counting away!

n8wrl
+1  A: 

I'm not sure that knowing the number of events would help you in any way. It would be more helpful to know where your program is spending its time, or allocating its memory. A profiler will help with that.


For the record, a list of profilers:

John Saunders
The appication uses the command pattern where many (~80) commands sets up event listners at start up. The size of the solution causes a lot of events to be 'catched' and fired when not needed. I am trying out a solution instanciating commands when they are needed for the first time. It is to measure the effect of this i asked my question.(The sourcode *.cs of the solution is about 8 MB)
ToPa
A: 

I have come to the conclusion to try performance measuremet tools instead. Since there is no easy way to do thye measurement code wise. I will tr ANTS to se what it can do for me.

ToPa