Pygmy
Pygmy

Reputation: 1268

c# : runtime code profiling - any existing libraries?

I have an application where the user can connect nodes together to perform realtime calculations. I'd like to be able to show the user a CPU-usage percentage to show how much of available CPU-time is being used, and a per-node breakdown to be able to spot the problem-areas.

Are there any available open source implementations for a runtime profiler like this ? I can write my own using System.Diagnostics.Process.TotalProcessorTime, stopwatches / performancecounters, but I'd rather go with something tried & tested that could maybe offer me more detailed information later if possible.

Edit: I'm not looking for a stand-alone profiler since I want to show the realtime stats in the UI of my application.

Upvotes: 2

Views: 1146

Answers (2)

Mike Dunlavey
Mike Dunlavey

Reputation: 40649

I assume you are running off a timer, like say 10 calculations per second, because otherwise you are simply using 100% of the CPU (unless you're also doing I/O).

Can you set an alarm-clock interrupt to go off at some reasonable frequency, like 10 or 100 Hz, independent of whatever else the program is doing, and even especially during I/O or other blocked time?

Then for each block just keep a count of how many times out of the last 100 interrupts it was active. That's your percent, and the cost of acquiring it is minimal.

Do blocks call each other as subroutines? In that case, on each interrupt, you may want to capture the call stack among blocks, and a block is "active" if it is somewhere on the stack, and it is "crunching" if it is at the end of the stack (not in the process of calling another block, and not in I/O). Then you have a choice on each block of indicating the percent of time it is "crunching" (which will not exceed 100% when summed over blocks) or "active" (which probably will exceed 100% when summed over blocks).

The value of the latter number is it doesn't tell you so much "where" the time is spent, it tells you "why". That can answer questions like "I see that foo is taking a lot of time, but how did I get there?" Same for I/O. That's a process too, it just takes place on other hardware. You don't want to ignore it, because if you do you could end up saying "How come I'm only using a small fraction of the CPU? What's the holdup?"

Upvotes: 0

Evgeny Gavrin
Evgeny Gavrin

Reputation: 7825

You can try commercial GlowCode profiler that has such feature.

Or open source SlimTune, but it is still in beta.

Upvotes: 1

Related Questions