Mehdi
Mehdi

Reputation: 211

How can I understand visual studio profiler report?

I am trying to understand profiler report and use it for optimise my code. The problem I have is I do not see any problem with the case software highlighted !

For instance:

14.2%    public int vbar.X {get{return vbar.x;} set {vbar.x = value;}}

// time

for (int t = 2; t < 1000000; t++)
{

// main calculations
    for (int i = 2; i < 800; i++)
                    {
0.5%                 for (int j = 2; j < 800; j++)
                        {                              
                                vbar.X = 0.0;
34%                             vbar.Y = 0.0;
                              // some culculations for vbar.X and vbar.Y  
lap.X = ((((theSpace.TheCells[i + 1, j, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i - 1, j, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
                                            + (((theSpace.TheCells[i, j + 1, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i, j - 1, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
                                        vbar.X = theSpace.TheCells[i, j, 0].Velocity.X - theSpace.Dt * (adv.X - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.X);

lap.Y = ((((theSpace.TheCells[i + 1, j, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i - 1, j, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
                                            + (((theSpace.TheCells[i, j + 1, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i, j - 1, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
                                        vbar.Y = theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.Dt * (adv.Y - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.Y - theSpace.TheCells[i, j, 0].Temperature);


                        }
                   }
}

... Based on this sample, my code has problem with the following lines : all these variables are integers: vbar.X = 0.0, int j = 2 and j++ . As you can see in the second picture.

How should I fix these problems? or what part of these loops has problem ? What is the other way of coding this part of code (vbar.X = 0.0) which have 39% inclusive time? Interestingly, the time needed for getting result by profiler is half of amount that code need to run !

enter image description here enter image description here

//////////////////////////////////////////////////////////////////////////////////////////////////////

I found the answer for part of my question. Regarding this part (vbar.X = 0.0) it was incorrect because I can put it out side of my loops and avoid repeating it in every iteration.

//////////////////////////////////////////////////////////////////////////////////////////////////////

Upvotes: 2

Views: 270

Answers (1)

mandaleeka
mandaleeka

Reputation: 6667

This is likely a manifestation of inaccuracy in the source line highlighting functionality of the profiler. If possible, I'd try it in the Visual Studio "14" preview to see if it's been fixed since we made some improvements in this area recently.

That said, when in release mode, source line mappings are not 100% accurate because of optimizations that can occur, especially for .NET code. As a general rule, in cases where the highlighted lines disagree with what's the call tree view says, favor the call tree.

Upvotes: 1

Related Questions