I'd like to submit a new tracing library to clojure.contrib. Please
try it out and let me know if it is suitable.
The existing clojure.contrib.trace macros allow you to explicitly
trace any expression or redefine a function with deftrace so that it
is traced. But deftrace doesn't work with functions with multiple
arity or comment string. To trace many functions, you'd have to do a
mass change of your defns to deftrace.
This new library keeps track of functions you're tracing, allows you
to toggle trace on/off on on functions, and trace every function in a
namespace. If you reload a function, tracing is disabled for that
function. The toggle trace and untrace all functions could be used to
fill some missing pieces in emacs/slime/swank-clojure. It shouldn't be
too difficult to make a simple profiler from it.
The user interface is:
(defmacro toggle-trace
"Toggles tracing of function f"
[f]
(defmacro trace-on
"Turn trace on for function f"
[f]
(defmacro trace-off
"Turn trace off for function f"
[f]
(defn trace-ns
"trace everything in the namespace ns. Don't try to trace
clojure.core."
[ns]
(defn untrace-ns
"untrace everything in the namespace ns"
[ns]
(defn untrace-all
"untrace everything and clean out traced-map"
[]
I'm pasting the code to
http://paste.lisp.org/display/71652.
-Craig