Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
clojure code observation tool.
Clojure
branch: master

This branch is 5 commits ahead of fatrow:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/hozumi
test/hozumi
.gitignore
README.textile
epl-v10.html
project.clj

README.textile

eyewrap

Tracing execution of Clojure code.
Code is completely macroexpanded.
Feel free to tell me problem or code which doesn’t work well.

Installation

leiningen

:dev-dependencies [[eyewrap "0.6.4"]]

Usage

user> (use 'hozumi.eyewrap)
nil

Tracing normal code

(cap code)
user> (cap (+ 1 2))
0 : + (+ 1 2)
0 :=> 3
3
user> (cap (* 2 (+ (- 3 8) 4)))
0 : + (* 2 (+ (- 3 8) 4))
1 : +   (+ (- 3 8) 4)
2 : +     (- 3 8)
2 :=>     -5
1 :->   (+ -5 4)
1 :=>   -1
0 :-> (* 2 -1)
0 :=> -2
-2

You can easily see the function which throw the exception.

user> (cap (+ 1 3 (- 2 3) (/ 2 0) (* 2 3)))
0 : + (+ 1 3 (- 2 3) (/ 2 0) (* 2 3))
1 : +   (- 2 3)
1 :=>   -1
0 :-> (+ 1 3 -1 (/ 2 0) (* 2 3))
1 : +   (/ 2 0)
1 :=>   #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
0 :-> (+ 1 3 -1 #<ArithmeticException java.lang.ArithmeticException: Divide by zero> (* 2 3))
0 :=> #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
#<ArithmeticException java.lang.ArithmeticException: Divide by zero>

Tracing defn

You can see the trace log after executing code by using special function which the cap generate.
(cap name (defn … code)
(cap name (fn … code)
(cap name (code…)

user> (cap ppp (defn touch [coll target-index]
		 (-> [(coll target-index)]
		     (into (subvec coll 0 target-index))
		     (into (subvec coll (inc target-index))))))
#'user/touch

ppp turn to be function.

user> ppp
#<user$eval__2153$ppp__2209 user$eval__2153$ppp__2209@4ce1e2b3>

still empty

user> (ppp)
nil

Once target code has been called, ppp will print trace log.

user> (touch [1 2 3 4] 2)
[3 1 2 4]
user> (ppp)
0 : + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 : +   (into [(coll target-index)] (subvec coll 0 target-index))
2 : +     [(coll target-index)]
3 : +       (coll target-index)
3 :->       ([1 2 3 4] target-index)
3 :->       ([1 2 3 4] 2)
3 :=>       3
2 :->     [3]
2 :=>     [3]
1 :->   (into [3] (subvec coll 0 target-index))
2 : +     (subvec coll 0 target-index)
2 :->     (subvec [1 2 3 4] 0 target-index)
2 :->     (subvec [1 2 3 4] 0 2)
2 :=>     [1 2]
1 :->   (into [3] [1 2])
1 :=>   [3 1 2]
0 :-> (into [3 1 2] (subvec coll (inc target-index)))
1 : +   (subvec coll (inc target-index))
1 :->   (subvec [1 2 3 4] (inc target-index))
2 : +     (inc target-index)
2 :->     (inc 2)
2 :=>     3
1 :->   (subvec [1 2 3 4] 3)
1 :=>   [4]
0 :-> (into [3 1 2] [4])
0 :=> [3 1 2 4]
nil
user>
user> (touch [:a :b :c] 2)
[:c :a :b]
user> (ppp)
0 : + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 : +   (into [(coll target-index)] (subvec coll 0 target-index))
2 : +     [(coll target-index)]
3 : +       (coll target-index)
3 :->       ([:a :b :c] target-index)
3 :->       ([:a :b :c] 2)
3 :=>       :c
2 :->     [:c]
2 :=>     [:c]
1 :->   (into [:c] (subvec coll 0 target-index))
2 : +     (subvec coll 0 target-index)
2 :->     (subvec [:a :b :c] 0 target-index)
2 :->     (subvec [:a :b :c] 0 2)
2 :=>     [:a :b]
1 :->   (into [:c] [:a :b])
1 :=>   [:c :a :b]
0 :-> (into [:c :a :b] (subvec coll (inc target-index)))
1 : +   (subvec coll (inc target-index))
1 :->   (subvec [:a :b :c] (inc target-index))
2 : +     (inc target-index)
2 :->     (inc 2)
2 :=>     3
1 :->   (subvec [:a :b :c] 3)
1 :=>   []
0 :-> (into [:c :a :b] [])
0 :=> [:c :a :b]
nil
user>

There are a few command line options that you may find interesting for if you want to change the looks of trace log,
or figure out where a problem is.

Using the :pp option, you can see the pprinted trace log.

user> (ppp :pp)
0 : + (into
       (into [(coll target-index)] (subvec coll 0 target-index))
       (subvec coll (inc target-index)))
1 : +   (into [(coll target-index)] (subvec coll 0 target-index))
2 : +     [(coll target-index)]
3 : +       (coll target-index)
3 :->       ([:a :b :c] target-index)
3 :->       ([:a :b :c] 2)
3 :=>       :c
2 :->     [:c]
2 :=>     [:c]
1 :->   (into [:c] (subvec coll 0 target-index))
2 : +     (subvec coll 0 target-index)
2 :->     (subvec [:a :b :c] 0 target-index)
2 :->     (subvec [:a :b :c] 0 2)
2 :=>     [:a :b]
1 :->   (into [:c] [:a :b])
1 :=>   [:c :a :b]
0 :-> (into [:c :a :b] (subvec coll (inc target-index)))
1 : +   (subvec coll (inc target-index))
1 :->   (subvec [:a :b :c] (inc target-index))
2 : +     (inc target-index)
2 :->     (inc 2)
2 :=>     3
1 :->   (subvec [:a :b :c] 3)
1 :=>   []
0 :-> (into [:c :a :b] [])
0 :=> [:c :a :b]
nil
user>

Using the :v option, you can print id number which the expression of same line correspond to.

user> (ppp :v)
0 : 20: + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 : 22: +   (into [(coll target-index)] (subvec coll 0 target-index))
2 : 24: +     [(coll target-index)]
3 : 25: +       (coll target-index)
3 : 25:->       ([:a :b :c] target-index)
3 : 25:->       ([:a :b :c] 2)
3 : 25:=>       :c
2 : 24:->     [:c]
2 : 24:=>     [:c]
1 : 22:->   (into [:c] (subvec coll 0 target-index))
2 : 28: +     (subvec coll 0 target-index)
2 : 28:->     (subvec [:a :b :c] 0 target-index)
2 : 28:->     (subvec [:a :b :c] 0 2)
2 : 28:=>     [:a :b]
1 : 22:->   (into [:c] [:a :b])
1 : 22:=>   [:c :a :b]
0 : 20:-> (into [:c :a :b] (subvec coll (inc target-index)))
1 : 33: +   (subvec coll (inc target-index))
1 : 33:->   (subvec [:a :b :c] (inc target-index))
2 : 36: +     (inc target-index)
2 : 36:->     (inc 2)
2 : 36:=>     3
1 : 33:->   (subvec [:a :b :c] 3)
1 : 33:=>   []
0 : 20:-> (into [:c :a :b] [])
0 : 20:=> [:c :a :b]
nil
user>

Using the :number option, you can see the preview trace log.

user> (ppp :v :1)
0 :  1: + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 :  3: +   (into [(coll target-index)] (subvec coll 0 target-index))
2 :  5: +     [(coll target-index)]
3 :  6: +       (coll target-index)
3 :  6:->       ([1 2 3 4] target-index)
3 :  6:->       ([1 2 3 4] 2)
3 :  6:=>       3
2 :  5:->     [3]
2 :  5:=>     [3]
1 :  3:->   (into [3] (subvec coll 0 target-index))
2 :  9: +     (subvec coll 0 target-index)
2 :  9:->     (subvec [1 2 3 4] 0 target-index)
2 :  9:->     (subvec [1 2 3 4] 0 2)
2 :  9:=>     [1 2]
1 :  3:->   (into [3] [1 2])
1 :  3:=>   [3 1 2]
0 :  1:-> (into [3 1 2] (subvec coll (inc target-index)))
1 : 14: +   (subvec coll (inc target-index))
1 : 14:->   (subvec [1 2 3 4] (inc target-index))
2 : 17: +     (inc target-index)
2 : 17:->     (inc 2)
2 : 17:=>     3
1 : 14:->   (subvec [1 2 3 4] 3)
1 : 14:=>   [4]
0 :  1:-> (into [3 1 2] [4])
0 :  1:=> [3 1 2 4]
nil
user> 

Using the :all option, you can see the all trace log.

user> (ppp :v :all)
----------------------------------------------------------------------------------------------------
0 :  1: + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 :  3: +   (into [(coll target-index)] (subvec coll 0 target-index))
2 :  5: +     [(coll target-index)]
3 :  6: +       (coll target-index)
3 :  6:->       ([1 2 3 4] target-index)
3 :  6:->       ([1 2 3 4] 2)
3 :  6:=>       3
2 :  5:->     [3]
2 :  5:=>     [3]
1 :  3:->   (into [3] (subvec coll 0 target-index))
2 :  9: +     (subvec coll 0 target-index)
2 :  9:->     (subvec [1 2 3 4] 0 target-index)
2 :  9:->     (subvec [1 2 3 4] 0 2)
2 :  9:=>     [1 2]
1 :  3:->   (into [3] [1 2])
1 :  3:=>   [3 1 2]
0 :  1:-> (into [3 1 2] (subvec coll (inc target-index)))
1 : 14: +   (subvec coll (inc target-index))
1 : 14:->   (subvec [1 2 3 4] (inc target-index))
2 : 17: +     (inc target-index)
2 : 17:->     (inc 2)
2 : 17:=>     3
1 : 14:->   (subvec [1 2 3 4] 3)
1 : 14:=>   [4]
0 :  1:-> (into [3 1 2] [4])
0 :  1:=> [3 1 2 4]
----------------------------------------------------------------------------------------------------
0 : 20: + (into (into [(coll target-index)] (subvec coll 0 target-index)) (subvec coll (inc target-index)))
1 : 22: +   (into [(coll target-index)] (subvec coll 0 target-index))
2 : 24: +     [(coll target-index)]
3 : 25: +       (coll target-index)
3 : 25:->       ([:a :b :c] target-index)
3 : 25:->       ([:a :b :c] 2)
3 : 25:=>       :c
2 : 24:->     [:c]
2 : 24:=>     [:c]
1 : 22:->   (into [:c] (subvec coll 0 target-index))
2 : 28: +     (subvec coll 0 target-index)
2 : 28:->     (subvec [:a :b :c] 0 target-index)
2 : 28:->     (subvec [:a :b :c] 0 2)
2 : 28:=>     [:a :b]
1 : 22:->   (into [:c] [:a :b])
1 : 22:=>   [:c :a :b]
0 : 20:-> (into [:c :a :b] (subvec coll (inc target-index)))
1 : 33: +   (subvec coll (inc target-index))
1 : 33:->   (subvec [:a :b :c] (inc target-index))
2 : 36: +     (inc target-index)
2 : 36:->     (inc 2)
2 : 36:=>     3
1 : 33:->   (subvec [:a :b :c] 3)
1 : 33:=>   []
0 : 20:-> (into [:c :a :b] [])
0 : 20:=> [:c :a :b]
nil
user> 

Using the ids option, you can print only the specific expression which id correspond to.
The ids can be multiple, but must be in a position anterior to other option.
This option is useful especially for tracing closure.

user> (ppp 9 22 :v)
====================================================================================================
0 :  9: + (subvec coll 0 target-index)
0 :  9:-> (subvec [1 2 3 4] 0 target-index)
0 :  9:-> (subvec [1 2 3 4] 0 2)
0 :  9:=> [1 2]
====================================================================================================
0 : 22: + (into [(coll target-index)] (subvec coll 0 target-index))
1 : 24: +   [(coll target-index)]
2 : 25: +     (coll target-index)
2 : 25:->     ([:a :b :c] target-index)
2 : 25:->     ([:a :b :c] 2)
2 : 25:=>     :c
1 : 24:->   [:c]
1 : 24:=>   [:c]
0 : 22:-> (into [:c] (subvec coll 0 target-index))
1 : 28: +   (subvec coll 0 target-index)
1 : 28:->   (subvec [:a :b :c] 0 target-index)
1 : 28:->   (subvec [:a :b :c] 0 2)
1 : 28:=>   [:a :b]
0 : 22:-> (into [:c] [:a :b])
0 : 22:=> [:c :a :b]
nil
user> 

If the corresponding expression is fn, ppp automatically print only previous executed trace log.
So if you want to print all trace log, the :all option can be used.

Using the :i option, you can print eyewrap’s internal data.
Using the :c option, you can clear the all trace cache.

Not support

recur

License

Eclipse Public License – v 1.0

Something went wrong with that request. Please try again.