Reputation: 7525
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.
Upvotes: 7
Views: 2602
Reputation: 616
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.
Upvotes: 0
Reputation: 20360
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
If you find a solution or this works for you please let us know.
Upvotes: 1
Reputation: 5256
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:
Upvotes: 7
Reputation: 2839
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;
}
Upvotes: 0
Reputation: 163262
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.
Upvotes: 0
Reputation: 12849
Easy way? None.
But you can code it yourself..
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.
Upvotes: 1