From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: frames / stacks / source? was Re: coverage/profiling Date: Sun, 14 Jan 2007 00:36:22 +0000 Message-ID: <87odp2jvg9.fsf@ossau.uklinux.net> References: <45A2D83D.3060700@xs4all.nl> <87wt3vhmon.fsf@ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1168735014 28619 80.91.229.12 (14 Jan 2007 00:36:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 14 Jan 2007 00:36:54 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 14 01:36:51 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1H5tMZ-0006Ix-00 for guile-devel@m.gmane.org; Sun, 14 Jan 2007 01:36:43 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H5tMY-0001bm-Iz for guile-devel@m.gmane.org; Sat, 13 Jan 2007 19:36:42 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H5tMS-0001a8-OY for guile-devel@gnu.org; Sat, 13 Jan 2007 19:36:36 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H5tMP-0001Ya-6R for guile-devel@gnu.org; Sat, 13 Jan 2007 19:36:34 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H5tMO-0001YN-Ui for guile-devel@gnu.org; Sat, 13 Jan 2007 19:36:33 -0500 Original-Received: from [80.84.72.33] (helo=mail3.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1H5tMO-0005Gb-E2 for guile-devel@gnu.org; Sat, 13 Jan 2007 19:36:32 -0500 Original-Received: from laruns (host86-145-157-83.range86-145.btcentralplus.com [86.145.157.83]) by mail3.uklinux.net (Postfix) with ESMTP id B19C340A03E for ; Sun, 14 Jan 2007 00:36:31 +0000 (UTC) Original-Received: from laruns (laruns [127.0.0.1]) by laruns (Postfix) with ESMTP id 631466F70B for ; Sun, 14 Jan 2007 00:36:22 +0000 (GMT) Original-To: guile-devel@gnu.org In-Reply-To: <87wt3vhmon.fsf@ossau.uklinux.net> (Neil Jerram's message of "Tue, 09 Jan 2007 22:15:04 +0000") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6425 Archived-At: Neil Jerram writes: > guile-debugging should be able to accumulate coverage of all source > expressions - say in a particular file - but it might incur a big > performance cost in so doing. I'll try this out and let you know what > I find. For the record, here is how one can do code coverage using guile-debugging. I appreciate this may in practice be too slow for complex programs, but it seems to work reasonably for small amounts of code. First we implement a basic code coverage trap: (use-modules (ice-9 debugging traps)) (define covered-file-names '()) (define coverage-hash (make-hash-table 31)) (define (cover-entry trap-context) (let ((source-pos (frame->source-position (tc:frame trap-context)))) (if (and source-pos (member (car source-pos) covered-file-names)) (hash-set! coverage-hash source-pos (+ (or (hash-ref coverage-hash source-pos) 0) 1))))) (define coverage-trap (make #:behaviour cover-entry)) Then here's an example of how to use this trap: (use-modules (ice-9 debugging example-fns)) (set! covered-file-names '("/usr/share/guile/ice-9/debugging/example-fns.scm ")) (install-trap coverage-trap) (fact2 5) (uninstall-trap coverage-trap) ;; The trap does hit performance a ;; bit while it is installed, so this uninstall is just to get back to ;; normal performance. And here are the results that I get from this, which look correct to me: (hash-fold (lambda (key value acc) (format #t "~S: ~S\n" key value)) #f coverage-hash) |= ("/usr/share/guile/ice-9/debugging/example-fns.scm" 11 21): 5 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 3 0): 1 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 8 0): 1 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 9 2): 6 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 13 0): 1 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 9 6): 6 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 14 2): 1 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 11 6): 5 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 11 13): 5 ("/usr/share/guile/ice-9/debugging/example-fns.scm" 0 0): 3 For profiling, this could be extended to record the time when evaluation of each source expression begins, and to subtract this from the time when the frame for each source expression is exited. The guile-debugging "at-exit" procedure allows you to do something when a frame is exited, so `cover-entry' would be extended as follows. (use-modules (ice-9 debugging steps)) ; for at-exit (define (cover-entry trap-context) (let ((source-pos (frame->source-position (tc:frame trap-context))) (entry-time #f)) (if (and source-pos (member (car source-pos) covered-file-names)) (begin (hash-set! coverage-hash source-pos (+ (or (hash-ref coverage-hash source-pos) 0) 1)) (at-exit (tc:depth trap-context) (lambda (ignored) (hash-set! accumulated-time-hash source-pos (+ (or (hash-ref accumulated-time-hash source-pos) 0) (- (get-time-now) entry-time))))) (set! entry-time (get-time-now)))))) I've glossed over details of how to get the current time, and time arithmetic, so this probably won't work as is, but the intent should be clear. It will also be slow, and will incorrectly increase the time of non-"leaf" code by the time taken by the coverage/profiling code itself. guile-statprof does a better job of trying to mitigate the latter factor, so is in fact a better current bet for profiling Guile code. Regards, Neil _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel