在clojure中自定义跟踪

时间:2014-02-01 10:36:41

标签: clojure

如何将自定义代码注入clojure跟踪库? (https://github.com/clojure/tools.trace

该库正在产生这样的痕迹: (见Debugging in Clojure?

TRACE t4328: (fib 3)
TRACE t4329: | (fib 2)
TRACE t4330: | | (fib 1)
TRACE t4330: | | => 1
TRACE t4331: | | (fib 0)
TRACE t4331: | | => 0
TRACE t4329: | => 1
TRACE t4332: | (fib 1)
TRACE t4332: | => 1
TRACE t4328: => 2

我特别感兴趣:

  • 测量调用时间
  • 渲染输入/输出数据。
  • 重定向输出

我想要制作的例子:

Measure time:
TRACE t4328: (fib 3) (100 ms)
TRACE t4329: | (fib 2) (200 ms)
TRACE t4330: | | (fib 1) (150 ms)
.....

Rendering: Custom rendering per arg/return value
TRACE t4328: (fib number) (a small number was given)
TRACE t4329: | (fib number) (an even number was returned)
TRACE t4330: | | (fib number) (attention: number is too big)

Stacktrace:
(fib number) (fib.clj line 1)
| (fib number) (fib.clj line 2)
| | (fib number) (fib.clj line ...)

output to disk:
(fib 3)
| (fib 2)
| | (fib 1)
| | => 1

我不确定该库是否设计为允许此类自定义,但由于整个lib只是一个文件(https://github.com/clojure/tools.trace/blob/master/src/main/clojure/clojure/tools/trace.clj),我不介意直接修补它。

2010年的问题(clojure: adding a debug trace to every function in a namespace?)类似,但建议的答案使用trace-ns的自定义版本。 在那里手动注入自定义代码:

(clojure.contrib.trace/trace (str "entering: " s))

简而言之:今天是否有更通用的方法来注入我的自定义代码?

0 个答案:

没有答案