I'm debugging into the .NET Framework source code to look for a bug in my application. I have two similar inputs for the code where one exhibits the bug and the other doesn't. However to follow the code path into the .NET source is quite complex.
What I'd like is a tool that can be executed for both inputs and compare the results to see what code paths are taken, how the internal values differ, etc...
Is this available for .NET?
You could try nCover. It can show you code coverage information which might help you work out which branches are taken when the bug occurs.
You could try JetBrains DotTrace and just ignore the timings. They offer a free 30 day trial download.
As Mitch suggests, check out a profiler, perhaps ANTS. It will give you all the method calls so you can see everything that is going on.
The SD C# Test Coverage Tool will show you what code is executed if you run your test cases separately.
It will also compute the difference between the covered code for each case if you ask it to do so. This difference will be the code that one tests executes, that the other does not. Likely that's where your problem is.
It won't help you obtain source for the .NET framework.
Try using a profiler:
EqaTec (free)
ANTS Performance Profiler (14-day Trial)
dotTrace (10-day Trial)
If you have the Enterprise version of Visual Studio 2008 (or other version)
Visual Studio Profiler
Try the free EQATEC Tracer - it does pretty much exactly what you're looking for.
It injects "tracing-code" into your application which will at runtime tell you exactly what methods are executed and what the parameters are. There are sophisticated ways of fine-tuning what methods to trace, since "all" is usually too much, but you can turn on tracing for all methods with just one single click if you really want to.
Take a look at the key features here: http://www.eqatec.com/tools/tracer/features
-and get it here: http://www.eqatec.com/tools/tracer
Edit: Sorry, I missed the part about having to dig into the actual .NET framework code. The tracer can't do that in an easy manner.
Related
After searching the stackoverflow plus googling alot, the solutions offered for debugging code that gets emitted for DynamicMethods seems outdated and very unwieldy.
Surely in the intervening 4 years or more since LCG (light-weight code generation) was released, someone must have found a better way.
What do you find is the easiest way to verify the dynamic IL that you write and debug it?
Do you use peverify or ILDasm or something else? Those 2 tools require writing the assembly to disk but DynamicMethod doesn't offer any direct way to do that.
Apparently WinDbg aso offers a way to see the IL but that's very awkward to deal with that.
Something like a plugin to VisualStudio 2010 will be ideal.
Any ideas?
You can use ILGenerator.MarkSequencePoint to allow debugging step by step your emitted code.
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
I'm looking for extensions that can show code metrics (especially cyclomatic complexity) beside method bodies or in a tool window as I type (without additional interactions).
So far I know:
Code Metrices by Elisha: free and simple. I don't know what metric it calculates, but read somewhere that it's not cyclomatic complexity. It doesn't support any other metrics.
CodeMetricAdornment by Carpslayer: only supports lines of code, comments, and whitespaces within a code file.
CodeRush: Not free. Exactly what I want (metric is selectable), unfortunately I'm already using ReSharper, and I'm thinking that it would be an overkill to have / buy both.
Are there others? What metrics do they provide?
Installing CodeRush (and turning off all the options you don't need) is certainly the easiest. It is possible to get CodeRush and Resharper to work together, see some of the answers here. There's a free trial if you just want to give it a go.
(There is also a free lite version of CodeRush called CodeRush Xpress, but I just checked and it does NOT include code metrics.)
If you're really opposed to installing the whole of CodeRush, DevExpress also provides its Visual Studio plugin technology on which it's built, DXCore, for free. So, you could create your own plugin (without installing CodeRush). There is a tutorial here which continues here and there are some (work in progress) docs here and another tutorial here.
Those tutorials are about creating your own metric, but you should be able to just replace the custom code with:
public partial class PlugIn1 : StandardPlugIn
{
private void codeMetricProvider1_GetMetricValue(object sender, GetMetricValueEventArgs e)
{
e.Value = e.LanguageElement.GetCyclomaticComplexity();
}
}
However, I don't think the display of the resulting value (e.g., next to the method) is covered by the tutorial so you might have to dig further (but DXCore can handle that too).
Here is the tool which can meets your requirements i.e. implementing code metrics using api while coding an application. This helps you generate or suggest the code metrics programmatically and instantly. And it generates the metrics far more than you have specified here.
Here is the link for the tool.
http://www.ndepend.com/ConstraintsExtractedFromCode.aspx
I have a feeling this is going to be really simple. I don't know if I'm just missing a trick here, or searching for the wrong phrases.
I'm looking for a profiling or code coverage (don't really know which category this falls in) that can monitor an application (preferably let me start and stop the monitoring) and count the number of times a method has been called. I've been tasked with optimising some old code and whilst doing so, I've found a few methods that are being called twice or even 3 times, where they only need to be called once.
I have a feeling there could be more of these..
On a side note: I'm actually a big fan of the JetBrains .NET tools. I'm using ReSharper, dotPeek and dotTrace at the moment (but can't find a way to do this). Is it worth looking into dotCover?
Visual Studio 2010 Premium and above have performance profiling tools built in that can do exactly what you're asking.
Here's a blog about the performance tools available in VS2010 Premium/Ultimate.
You're right to consider using 'dotCover'. That's if you want more in-depth code coverage analysis and are willing to invest, then this will be more than suitable. Another alternative is 'NDepend' (http://www.ndepend.com) which I have greater experience with and outputs a large array of metrics.
SmartBear's AQTime Standard (free version) and Pro (pay version) can both track hit counts of methods. I've used AQTime for years and have found it quite useful.
http://smartbear.com/products/free-tools/aqtime-standard/
Not only will it tell you how many times a method is called, but it also can display call trees.
The free version (Standard) really is free - no strings. It is just like the pay version but some of the more advanced features are disabled. But it has enough functionality that it stands on its own as very useful tool.
I don't have any touch or knowledge of dotcover that you are talking about. But regarding number of times a method called, a dumb method to calculate this is create a static integer and increment it in the method. I am not sure what "profiling or code coverage" means. This may sound really stupid if you are asking something else.
It occurs pretty often that I start debugging a class by logging every function call to console and looking for differences in the bugged cases.
Is there some attribute that I can apply to a class to enable such a tracing? It's pretty exhausting to have to enter these
Console.WriteLine("classname: methodname")
to every method and to remove them afterwards (removing can be done by conditional compilation, but it is not very nice to look at the code when you have all this redundance)
There was an add-on tool someone mentioned to me, using Attributes. Let's see if I can find it.
I think it was PostSharp:
Article
http://www.postsharp.org/
You can use PostSharp to intercept all method calls and print them even with all arguments and it does not require source code changes. This CodeProject article shows how to do logging with PostSharp.
Just to note, PostSharp is an aspect-oriented programming (AOP) framework and there are some more.
If log4net is as good as log4j, then you are all set
http://logging.apache.org/log4net//index.html
In the dim dark ages of software engineering, one often used a profiling tool to achieve that since profiling injected extra code at entry and exit of all functions, although I must say that this is a pretty dismal approach to debugging and when I used it, it was a desperation move not front line. Debugging by print statement is fairly slow and ineffective.
AOP is supported also by http://www.springframework.net/
I am using JetBrains dotTrace, I've profiled my app which is entirely CPU bound. But the results as you walk down the tree don't sum to the level above in the tree, I only see method calls not the body lines of the node in questions method.
Is it possible to profile the source code line by line.
i.e for one node:
SimulatePair() 99.04%
--nextUniform() 30.12%
--IDCF() 24.08%
So the method calls nextUniform + IDCF use 54% of the time in SimulatePair (or 54% total execution time I'm not sure how to read this) regardless what is happening the other 46% of SimulatePair I need some detail on a line by line basis.
Any help or alternative tools is much appreciated.
Thanks
Check out ANTS ...
Line-level code timing – drill down to
the specific lines of code responsible
for performance inefficiencies
dotTrace 6 supports line by line profiling. Also, with the use of the Profiler API you can set via code which parts of the application you want to profile via PerformanceProfiler.Start and PerformanceProfiler.Stop.
Really easy to use and powerful.
For the benefit of future searchers, dotTRACE 4.0 BETA supports line-by-line profiling. It helped me find an endless loop.
Here's the method I use. It's simple, free, gives you line by line info, and suffers no such confusions.