New Tracing Library

8 views
Skip to first unread message

Craig McDaniel

unread,
Dec 5, 2008, 3:09:21 PM12/5/08
to Clojure
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

Craig McDaniel

unread,
Dec 5, 2008, 3:38:11 PM12/5/08
to Clojure
Reply all
Reply to author
Forward
0 new messages