开发者

How to plot how variables change in Visual Studio

开发者 https://www.devze.com 2023-02-09 15:40 出处:网络
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

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' 开发者_如何学Cin 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.


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:

How to plot how variables change in Visual Studio


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.


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.


Hopefully someone will come up with a better answer, but here is what I did in a similar situation...

I output the values, in CSV format, to the console. From there, I would copy and paste into Excel, and let Excel do some graphing for me. It worked quite well, but was a complete hassle during a caffeine-driven development session.


Can't you just define and array and write someVariable to array[i] inside the loop? Then you could reference it after you're done.

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


I've found SpPerfChart very easy to use and helpful. Simply add the user control and input your changing data to it. You'll get a graphical plot of whatever number you input realtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消