C# runtime application Diagnostics - c#

I am developing a c# GUI and was wondering if there were any (preferably free) runtime diagnostic programs available.
What Im looking for is a way to monitor user interactions with my GUI and what functions are called when. Preferably I do not want to add stacks of debug code as this has the potential to change the behaviour of the bug I am looking for.
Currently Im using Spy++ but am finding it a little heavy going as Im kinda new to this and its generating stacks of data.

EQATEC profiler is pretty simple to use. Free too. Started life targetting Compact Framework but since 2.00 is now geared more towards Desktop too.

I recommend ANTS profiler.
There is a trial available, first two weeks free.

In addition to ANTS profiler have a look at JetBrain's dotTrace

Related

C# profiler as a library, not application

Does anyone know about a profiler library in C# that I could embed in my source code that would do sample-based profiling? I.e. periodically get the instruction pointer location, store it in memory and allow to save it to a file and analyze later, presumably by some desktop application?
I know there are lots of traditional profiler applications (like JetBrains, Ants etc.), but I want to profile a C# program running on a non-desktop platform, where none of these profilers can be used. I want my application to sample itself, not an external profiler.
The Eqatec profiler might suit. I know at least in earlier versions the profiling got compiled into your binaries.
The user guide seems to provide a good overview of how to use it:
http://eqatec.zendesk.com/entries/20325613-user-guide#Intro
The ETW tracing infrastructure provides that capability. Try running the perfview tool by Microsoft. It uses ETW to show sampled stack traces.
You can use ETW yourself to build a sampling profiler. It might be a little work, though.

library/API recommendation for adding instrumentation in code

If I want to add some instrumentation in my code for getting metrics like how long a particular method took to execute, anyone has recommendation for either windows build-in or any 3rd party library?
I've seen this done with PostSharp AOP framework, hooked into Windows Performance Counters (System.Diagnostics.PerformanceCounter). One of their introductory pieces of sample code shows how to do this:
http://www.sharpcrafters.com/solutions/performance
This might be a good option if you want to deploy these measurements to production and measure performance in a live manner (to do diagnosis of a running system).
If you just want to locate bottlenecks in your code, and don't need to do live diagnosis, I suggest you simply use a profiler, such as the one built into VS or Ants Profiler (as Chris already suggested). Then run a redacted copy of your production data against your code so your performance measurements match production.
If you want this at runtime, you should probably use a profiler offline. I'd avoid doing any instrumentation where possible as it takes time and therefore causes more performance problems.
Google for RedGate ANTS Profiler or JetBrains dotTrace. If you have VS2010 Premium, it has one built in. That will give you a method-level breakdown of what is happening time-wise.
Generally a profiler will take care of measuring performance.
If you need to measure time yourself StopWatch with some sort of tracing is often enough.

Finding out what's slowing down ASP.NET pages

I have a rather 'heavy' ASP.NET page, and currently the speed is fairly unacceptable - there is a lot of database communication, and displaying large grids. But I effectively want to find out what's actually causing the most slowdown, and working from there.
Are there any tools built into Visual Studio 2008, or any third party tools, that'll allow me to do this?
You could use ASP.Net Trace to figure out what is slowing down in the page.
Another good tool and easy to use, https://addons.mozilla.org/en-US/firefox/addon/yslow/
Not aimed directly at code, but is very helpful with resources
Have you heard about profiling?
My favorite tool is RedGate's Ants Performance Profiler.
An easy approach is using Stopwatch. Something like this:
void SlowMethod()
{
Stopwatch timer = new Stopwatch();
timer.Start();
//a lot of DB operations
timer.Stop();
//record timer.Elapsed
//restart the timer and check another piece of code
//at last find the bottle neck of the method
}
What Muhammad said - add tracing to your code to identify the slowest bits.
Also if you think db activity could be responsible, you could run SQL profiler to identify any long running queries - this will also help you correct indexes.
Some ideas:
Visual Studio Team System has a built in profiler. In VS 2010 this is available in premium and above.
Otherwise red-gate has a good profiler available. (for a fee).
Try using the tracing functionality built into asp.net.
Try using client side developer tools like Yslow and Page Speed or fiddler to see the requests for a page and their size and timings.
If you haven't already done so, make sure your server is serving gzipped content. This is an easy win.
Use SQL Server Profiler to profile your database requests.
There are many profiling tools available, I personally like ANTS Profiler, it is quite good. Check out the following link for more information on out to use it: ANTS Profiler
And here is a link to the ANTS Profiler download: 14 Day Free Trial
But if there is a lot of database communication, it is most likely the cause. Try minimizing the number of database calls and improving the performance of your database queries.
Also make good use of cacheing!

Performance and monitoring .NET Apps

We've build a Web Application which is performing horrible even with alot of resources available. My boss doesn't believe me that the application is consuming alot of Hardware IO, so I have to prove that the hardware is ok, but the web app is really crap.
The app is using:
SQL Server 2000 with SP4
The main web application (.NET 3.5)
Two Web Services (.NET 1.1)
Biztalk 2004
There are 30 people using this apps.
How can I prove I am right?
You can hook up a profiler like ANTS profiler or JetBrains DotTrace and see where the application's performance bottlenecks are.
One place you could start is getting a performance profiler like Red-Gate ANTS profiler. I've used this tool and it's very useful is weeding out performance bottlenecks.
Randy
You could start by using SQL Server Profiler to get an impression of the amount of database traffic that is going on.
I'm not saying that database interaction is the bottleneck, but it often is, and the tool is already there if you are using SQL Server, so it may be a good idea to take a look at that before you go out and buy a lot of profiling tools.
Visual Studio 2008 also have built-in performance analysis tools.
Windows performance counters are a good way to get some basic information about general system performance. Proper counters will show you if it's really the IO that's doing lots of stuff. If you take out the numbers from the counters and compare those to the specs, you should be able to tell if the system is maxing out or not.
If the system is maxing out, it's a problem with the web application, and it should be profiled to find out where to start optimizing.
You could use the system performance monitor built into windows since at least XP. You can get almost any information you could possibly need. This includes CPU time, .NET memory usage (include gen0 gen1 and gen2), native memory usage, amount of time spent garbage collection, disk access time, etc. If you just search codeproject or just the web there are many examples of using these counter to test for just about anything you want.
One of the benefits of this is you don't have to change your code and can be used with existing system.
I find this is the best starting point to point you to where you should look for bottle necks and issues.

c# vs2005 .net 2.0: code optimization

What is the best way to see memory leaks or areas to optimize code in your .net source code?
I am using vs2005, c# , .net 2.0
Any good free tools out there that I can safely install on my work desktop?
I don't know of any good C# memory profilers, besides the functionality built into Visual Studios. But a great commercial memory profiler is ANTS Memory Profiler($495)
I've been extensively using the dotTrace profiler from JetBrains (the makers of another invaluable tool, ReSharper). Its fairly lightweight and works well for tracking both memory utilization and standard application profiling.
CLR Profiler can help you troubleshoot memory issues. Beware, though, the learning curve is pretty steep.
http://msdn.microsoft.com/en-us/library/ms979205.aspx
I never had to worry about memory leaks in my .net applications. You have to worry about system resources such as timers, file handles, comm port handles, database connections etc but again if you stick with right pattern (using?), they are not a problem either.
When it comes to optimization, you need to profile your application to see the performance bottlenecks. Don't even rely on your instincts when you are hunting a slow code because you might be looking at the wrong place.
AQTime, Ants profiler are good options but they are not free. They come with a trial period though so if you need them for a short period, you might get away with using them for trial period only. But if you really like them, you can consider buying them.
Or you can consider a free alternative EQATEC Profiler which seems pretty good but I haven't personally used it.

Categories