[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/06: statprof: 'statprof' and 'with-statprof' return t
From: |
Ludovic Courtès |
Subject: |
[Guile-commits] 01/06: statprof: 'statprof' and 'with-statprof' return the code's return values. |
Date: |
Sun, 11 Jan 2015 21:54:24 +0000 |
civodul pushed a commit to branch stable-2.0
in repository guile.
commit cdcba5b2f6270de808e51b3b933374170611b91d
Author: Ludovic Courtès <address@hidden>
Date: Sun Jan 11 20:44:36 2015 +0100
statprof: 'statprof' and 'with-statprof' return the code's return values.
* module/statprof.scm (statprof): Return the return values of THUNK.
(with-statprof): Adjust docstring accordingly.
* test-suite/tests/statprof.test ("return values"): New test.
* doc/ref/statprof.texi (Statprof): Adjust accordingly.
---
doc/ref/statprof.texi | 7 ++++---
module/statprof.scm | 23 ++++++++++++-----------
test-suite/tests/statprof.test | 13 +++++++++++++
3 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/doc/ref/statprof.texi b/doc/ref/statprof.texi
index c481ac7..5b99fb6 100644
--- a/doc/ref/statprof.texi
+++ b/doc/ref/statprof.texi
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
address@hidden Copyright (C) 2013 Free Software Foundation, Inc.
address@hidden Copyright (C) 2013, 2015 Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@node Statprof
@@ -220,7 +220,7 @@ The return value is a list of nodes, each of which is of
the type:
@end defun
@anchor{statprof address@hidden statprof thunk [#:loop] [#:hz]
[#:count-calls?] [#:full-stacks?]
-Profiles the execution of @var{thunk}.
+Profile the execution of @var{thunk}, and return its return values.
The stack will be sampled @var{hz} times per second, and the thunk
itself will be called @var{loop} times.
@@ -236,7 +236,8 @@ retrieve the last-stored stacks.
@end defun
@anchor{statprof address@hidden with-statprof args
-Profiles the expressions in its body.
+Profile the expressions in the body, and return the body's return
+value.
Keyword arguments:
diff --git a/module/statprof.scm b/module/statprof.scm
index 33246e5..cb88340 100644
--- a/module/statprof.scm
+++ b/module/statprof.scm
@@ -1,7 +1,7 @@
;;;; (statprof) -- a statistical profiler for Guile
;;;; -*-scheme-*-
;;;;
-;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
;;;; Copyright (C) 2004, 2009 Andy Wingo <wingo at pobox dot com>
;;;; Copyright (C) 2001 Rob Browning <rlb at defaultvalue dot org>
;;;;
@@ -632,10 +632,10 @@ The return value is a list of nodes, each of which is of
the type:
(define* (statprof thunk #:key (loop 1) (hz 100) (count-calls? #f)
(full-stacks? #f))
- "Profiles the execution of @var{thunk}.
+ "Profile the execution of @var{thunk}, and return its return values.
-The stack will be sampled @var{hz} times per second, and the thunk itself will
-be called @var{loop} times.
+The stack will be sampled @var{hz} times per second, and the thunk
+itself will be called @var{loop} times.
If @var{count-calls?} is true, all procedure calls will be recorded. This
operation is somewhat expensive.
@@ -643,7 +643,6 @@ operation is somewhat expensive.
If @var{full-stacks?} is true, at each sample, statprof will store away the
whole call tree, for later analysis. Use @code{statprof-fetch-stacks} or
@code{statprof-fetch-call-tree} to retrieve the last-stored stacks."
-
(dynamic-wind
(lambda ()
(statprof-reset (inexact->exact (floor (/ 1 hz)))
@@ -653,18 +652,20 @@ whole call tree, for later analysis. Use
@code{statprof-fetch-stacks} or
full-stacks?)
(statprof-start))
(lambda ()
- (let lp ((i loop))
- (if (not (zero? i))
- (begin
- (thunk)
- (lp (1- i))))))
+ (let lp ((i loop)
+ (result '()))
+ (if (zero? i)
+ (apply values result)
+ (call-with-values thunk
+ (lambda result
+ (lp (1- i) result))))))
(lambda ()
(statprof-stop)
(statprof-display)
(set! procedure-data #f))))
(define-macro (with-statprof . args)
- "Profiles the expressions in its body.
+ "Profile the expressions in the body, and return the body's return values.
Keyword arguments:
diff --git a/test-suite/tests/statprof.test b/test-suite/tests/statprof.test
index 1fec617..482709f 100644
--- a/test-suite/tests/statprof.test
+++ b/test-suite/tests/statprof.test
@@ -45,6 +45,19 @@
(throw 'unresolved)
(apply throw args))))))
+(pass-if-equal "return values"
+ '(42 77)
+ (call-with-values
+ (lambda ()
+ (with-output-to-port (%make-void-port "w")
+ (lambda ()
+ (with-statprof
+ (let loop ((i 10000))
+ (if (zero? i)
+ (values 42 77)
+ (loop (1- i))))))))
+ list))
+
(pass-if "statistical sample counts within expected range"
(when-implemented
;; test to see that if we call 3 identical functions equally, they
- [Guile-commits] branch stable-2.0 updated (5d971db -> 01a301d), Ludovic Courtès, 2015/01/11
- [Guile-commits] 01/06: statprof: 'statprof' and 'with-statprof' return the code's return values.,
Ludovic Courtès <=
- [Guile-commits] 04/06: Deprecate 'scm_string_hash'., Ludovic Courtès, 2015/01/11
- [Guile-commits] 03/06: Optimize 'write' for strings., Ludovic Courtès, 2015/01/11
- [Guile-commits] 02/06: Avoid converting the 'mode' argument of 'open-file'., Ludovic Courtès, 2015/01/11
- [Guile-commits] 05/06: Add 'string-hash' benchmarks., Ludovic Courtès, 2015/01/11
- [Guile-commits] 06/06: Optimize 'string-hash'., Ludovic Courtès, 2015/01/11