Add `comment` and the profiling functions
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 15 Nov 2016 17:30:45 +0000 |
parents |
71fe6a16fcef
|
children |
21296e2bf834
|
branches/tags |
(none) |
files |
DOCUMENTATION.markdown losh.asd losh.lisp package.lisp |
Changes
--- a/DOCUMENTATION.markdown Sat Nov 12 12:51:05 2016 +0000
+++ b/DOCUMENTATION.markdown Tue Nov 15 17:30:45 2016 +0000
@@ -240,6 +240,18 @@
+### `COMMENT` (macro)
+
+ (COMMENT
+ &BODY
+ BODY)
+
+Do nothing with a bunch of forms.
+
+ Handy for block-commenting multiple expressions.
+
+
+
### `DIS` (macro)
(DIS ARGLIST
@@ -300,6 +312,24 @@
Run `body` with stdout and stderr redirected to the void.
+### `START-PROFILING` (function)
+
+ (START-PROFILING &OPTIONAL CALL-COUNT-PACKAGES)
+
+Start profiling performance. SBCL only.
+
+ `call-count-packages` should be a list of package designators. Functions in
+ these packages will have their call counts recorded via
+ `sb-sprof::profile-call-counts`.
+
+
+
+### `STOP-PROFILING` (function)
+
+ (STOP-PROFILING &OPTIONAL (FILENAME lisp.prof))
+
+Stop profiling performance and dump a report to `filename`. SBCL only.
+
### `STRUCTURAL-STRING` (function)
(STRUCTURAL-STRING THING)
--- a/losh.asd Sat Nov 12 12:51:05 2016 +0000
+++ b/losh.asd Tue Nov 15 17:30:45 2016 +0000
@@ -7,7 +7,9 @@
:license "MIT/X11"
:version "0.0.1"
- :depends-on (:iterate)
+ :depends-on (:iterate
+ #+sbcl :sb-sprof
+ )
:serial t
:components
--- a/losh.lisp Sat Nov 12 12:51:05 2016 +0000
+++ b/losh.lisp Tue Nov 15 17:30:45 2016 +0000
@@ -1340,6 +1340,14 @@
(declare (optimize speed))
,@body)))))
+(defmacro comment (&body body)
+ "Do nothing with a bunch of forms.
+
+ Handy for block-commenting multiple expressions.
+
+ "
+ nil)
+
(defun aesthetic-string (thing)
"Return the string used to represent `thing` when printing aesthetically."
@@ -1408,6 +1416,45 @@
(values))
+
+#+sbcl
+(defun dump-profile (filename)
+ (with-open-file (*standard-output* filename
+ :direction :output
+ :if-exists :supersede)
+ (sb-sprof:report :type :graph
+ :sort-by :cumulative-samples
+ :sort-order :ascending)
+ (sb-sprof:report :type :flat
+ :min-percent 0.5)))
+
+#+sbcl
+(defun start-profiling (&optional call-count-packages)
+ "Start profiling performance. SBCL only.
+
+ `call-count-packages` should be a list of package designators. Functions in
+ these packages will have their call counts recorded via
+ `sb-sprof::profile-call-counts`.
+
+ "
+ (sb-sprof::reset)
+ (-<> call-count-packages
+ (mapcar #'mkstr <>)
+ (mapcar #'string-upcase <>)
+ (mapc #'sb-sprof::profile-call-counts <>))
+ (sb-sprof::start-profiling :max-samples 50000
+ ; :mode :cpu
+ :mode :time
+ :sample-interval 0.01
+ :threads :all))
+
+#+sbcl
+(defun stop-profiling (&optional (filename "lisp.prof"))
+ "Stop profiling performance and dump a report to `filename`. SBCL only."
+ (sb-sprof::stop-profiling)
+ (dump-profile))
+
+
;;;; Weightlists --------------------------------------------------------------
(defstruct (weightlist (:constructor %make-weightlist))
weights sums items total)
--- a/package.lisp Sat Nov 12 12:51:05 2016 +0000
+++ b/package.lisp Tue Nov 15 17:30:45 2016 +0000
@@ -161,8 +161,11 @@
:bits
:shut-up
:dis
+ :comment
:aesthetic-string
:structural-string
+ #+sbcl :start-profiling
+ #+sbcl :stop-profiling
:print-table
:print-hash-table))