Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot how variables change in Visual Studio

oes anyone know a way to plot how a watched variable changes over time in Visual Studio 2010? I.e. if you had the following code

double someVariable;
for ( int i = 0; i < 20; i++)
{
    someVariable = Math.Pi() * i;
}

and you watched 'someVariable' in the ide you could step through the code and watch how it grows with each step. I would like to be able to run through the loop and plot what that variable did with out having to manually step through it. I am doing a lot of math and sometimes watching how variables change is really useful and insightful.

More info: I have a bunch of slightly different solvers and depending on the problem I am troubleshooting I would like to watch different variables to see where the problems are occurring. I currently put log these variables to a log file but it slows down the solver significantly and I have to spend a decent amount of time changing debug code to track down problems. I am looking for a slicker way to do this that is IDE centric. Sort of a Visualizer on steroids.

like image 369
PlTaylor Avatar asked Feb 07 '11 15:02

PlTaylor


3 Answers

How about using Tracepoints? In VS 2008 (it's somewhat different in VS 2010) you just add a normal breakpoint, then right-click on it, then select "When Hit...".

In the subsequent dialog box, check "Print a message" and enter something like

someVariable = {someVariable}

This will just output its value to the output window in the IDE.

Screenshot:

tracepoint dialog

like image 153
Guido Domenici Avatar answered Oct 28 '22 19:10

Guido Domenici


Easy way? None.

But you can code it yourself..

  1. Use property.
  2. In setter put code, that will log change in some collection. Possibly save time too.
  3. Use some plotting control to plot this collection

Edit: If you dont want to create property, you can create some kind of generic class, that will have this property and has some kind of internal logging logic.

like image 28
Euphoric Avatar answered Oct 28 '22 20:10

Euphoric


Use Perfmon and publish that value to a counter that perfmon can read. Perfmon does all the plotting etc. You just need to publish to perfmon. Unfrotunately it is not very well documented and is not trivial. (well, at least it wasn't trivial for unmanaged c++ when I was looking into it)

I did this a while back and used some classes published in an old MSJ article. (ca 1998 or so)

I will try to find some online docs.

See this question for some links

This may also be useful

If you find a solution or this works for you please let us know.

like image 28
Tim Avatar answered Oct 28 '22 18:10

Tim