Opened 13 years ago

Closed 13 years ago

#634 closed defect (fixed)

Profiler does not work correctly on recursive procedures

Reported by: megane Owned by: felix winkelmann
Priority: minor Milestone:
Component: compiler Version: 4.7.x
Keywords: profiler Cc:
Estimated difficulty:

Description

The profiler seems to calculate the time spent on recursive funtion calls incorrectly.

Here is a simple example program:

(define (fib n)
    (if (or (equal? n 0) (equal? n 1))
        n
        (+ (fib (- n 1)) (fib ( - n 2)))))

(define (main)
  (let loop [(i 100)]
    (if (> i 0)
	(begin
	  (fib 15)
	  (loop (sub1 i))))))

(main)

And here is a sample output from chicken-profiler:

procedure   calls  seconds  average  percent
--------------------------------------------
fib        197300    4.695    0.000  100.000
main            1    0.092    0.092    1.959

Change History (4)

comment:1 Changed 13 years ago by felix winkelmann

The percentages are indeed wrong. I've changed this in commit 9663b2e (master). The other numbers seem to be correct - the average gives the average time of one execution of a procedure over the total time the procedure used during execution of the complete program.

comment:2 in reply to:  1 Changed 13 years ago by megane

Replying to felix:

The percentages are indeed wrong. I've changed this in commit 9663b2e (master). The other numbers seem to be correct - the average gives the average time of one execution of a procedure over the total time the procedure used during execution of the complete program.

The total seconds for fib is wrong, also. The program ran for a total of 0.092 seconds but the total time for fib is way bigger than that.

Sorry for not pointing this in the first post.

comment:3 Changed 13 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

comment:4 Changed 13 years ago by felix winkelmann

Resolution: fixed
Status: assignedclosed

This should work now. There have been a few fixes in the internal profiling timing code and the timings from your example look ok.

Note: See TracTickets for help on using tickets.