# HG changeset patch # User Steve Losh # Date 1479231045 0 # Node ID 0e60bff933178864de5e0279b33fb871e56ff09a # Parent 71fe6a16fcef350dec88244244d3a937e1ef6112 Add `comment` and the profiling functions diff -r 71fe6a16fcef -r 0e60bff93317 DOCUMENTATION.markdown --- 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) diff -r 71fe6a16fcef -r 0e60bff93317 losh.asd --- 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 diff -r 71fe6a16fcef -r 0e60bff93317 losh.lisp --- 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) diff -r 71fe6a16fcef -r 0e60bff93317 package.lisp --- 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))