What is the best way to debug performance problems?

前端 未结 8 1448
夕颜
夕颜 2021-02-06 11:51

I\'m writing a plug-in for another program in C#.NET, and am having performance issues where commands take a lot longer then I would. The plug-in reacts to events in the host pr

相关标签:
8条回答
  • 2021-02-06 12:50

    In my experience, the best method is also the simplest. Get it running, and while it is being slow, hit the "pause" button in the IDE. Then make a record of the call stack. Repeat this several times. (Here's a more detailed example and explanation.)

    What you are looking for is any statement that appears on more than one stack sample that isn't strictly necessary. The more samples it appears on, the more time it takes. The way to tell if the statement is necessary is to look up the stack, because that tells you why it is being done.

    Anything that causes a significant amount of time to be consumed will be revealed by this method, and recursion does not bother it.

    People seem to tackle problems like this in one of two ways:

    1. Try to get good measurements before doing anything.

    2. Just find something big that you can get rid of, rip it out, and repeat.

    I prefer the latter, because it's fast, and because you don't have to know precisely how big a tumor is to know it's big enough to remove. What you do need to know is exactly where it is, and that's what this method tells you.

    0 讨论(0)
  • 2021-02-06 12:52

    You need to use profiler. Here link to good one: ANTS Performance Profiler.

    Update: You can also write messages in control points using Debug.Write. Then you need to load DebugView application that displays all your debug string with precise time stamp. It is freeware and very good for quick debugging and profiling.

    0 讨论(0)
提交回复
热议问题