2

I am using Delphi XE6. Often while stepping through code i'd like to trace where the CPU is being used, at least approximately.

I have AQtime but have been unable to get it running with my (large) application without getting lots of errors, and it seems overly complex for what i need.

My thought is that it would be very nice if the IDE ran a timer when executing my program , and could give me deltas whenever it pauses (whether by breakpoint, F4, F7 or F8). Through judicious use of this I should get a good idea of which functions etc in my code need speed improvement. I do this now approximately by judging where a slowdown is, but if its in a function called a zillion times taking a couple of ms my judgement fails me, eg:

   for i := 1 to 1000 do
    begin
      fastfunction1;  // takes 1ms
      fastfunction2;  // takes 1ms
      slowfunction;   // takes 20ms!!!  If I was able to see this while stepping over it...
      fastfunction3;  // takes 1ms
    end;

Has anyone seen a plugin for the IDE that might do this? Or would it be hard to write one?

Thanks, Chris

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
Chris Were
  • 131
  • 6
  • 1
    My technique is to run under debugger. With release options. Press pause. Switch to main thread. Look at call stack. Repeat a few times. The call stacks will give you a good idea of whether or not you have a bottleneck. AQ time is a disaster. Doesn't work at all in my experience. – David Heffernan Jan 14 '15 at 22:48
  • 1
    Mike Dunlavey's superb answer goes into the technique in more detail: http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024 and his video here is nice too http://m.youtube.com/watch?v=xPg3sRpdW1U – David Heffernan Jan 14 '15 at 22:54
  • Hmm, @David, it looks like what you do is a *sampling profiling* essentially. It could be automated but I cannot say "easily". – Free Consulting Jan 14 '15 at 23:52
  • @Free Yes it's sampling. No, it can't be automated. Does that matter? – David Heffernan Jan 15 '15 at 07:01
  • Do you use Unit Testing? if you do you can modify Unit Tests code so that at the same time it also time profiles your methods. Now this probablywon't give you exact mesuerments but it is still god enough for finding code botlenecks. – SilverWarior Jan 15 '15 at 07:31
  • I'm wondering whether the IDE's OTAPI would allow to intercept the F8 keypress, start a timer, do the Step Over action and then be notified when the debugger stops again. Might be possible. The difficult part is getting notified when the debugger stops again. – dummzeuch Jan 15 '15 at 08:12
  • @dummzeuch I am actually writing a plugin that I plan will do this (as well as many other things) right now. There are some tricky issues internally, even timing something as simple as a Step Over. But I've wanted to be able to do the same thing you have. Keep an eye on http://parnassus.co/delphi-tools/ for a new plugin in two or three months time, or send me an email on the contact form on that site. – David Jan 15 '15 at 08:54
  • @DavidHeffernan, why it can't be automated with all those computers and stuff? – Free Consulting Jan 15 '15 at 10:19
  • @FreeConsulting That would be a sampling profiler, and random breaking is probably not the ideal way to implement that. I like this method since it usually yields results in a few minutes. – David Heffernan Jan 15 '15 at 11:22
  • 2
    The Dunlavey technique is brilliant and you should definitely try it – Hugh Jones Jan 15 '15 at 13:51
  • @DavidHeffernan, thanks I will give this a try. Would still love to see the execution timings, might show up bottlenecks before i even know to look for them, so... – Chris Were Jan 18 '15 at 22:28
  • 1
    @DavidM, ...I will indeed followup on your site. Thanks all! – Chris Were Jan 18 '15 at 22:29
  • Very hard to get accurate and meaningful timings when stepping. You'll end up timing the debugger rather than your program. – David Heffernan Jan 18 '15 at 22:33
  • @Chris: Measurement, and finding speedups, are different goals. I think you want the latter. ("I should get a good idea of which functions etc. in my code need speed improvement.") Random pausing is sampling, but with a very different emphasis from sampling profilers. The emphasis is on *understanding* each of a small set, rather than *measuring* a large set. The number you need (from experience) is not large, because if a problem is worth fixing it will show up more than once on a reasonable number of samples (10 or 20). It finds anything a profiler will find, and more. – Mike Dunlavey Oct 04 '16 at 16:18

0 Answers0