]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Debug.scl
7ccad037e2ad9629528a6339096d494b633044cf
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Debug.scl
1 import "Prelude"
2 import "JavaBuiltin" as Java
3
4 import "Logging" as LOGGER
5
6 importJava "java.lang.System" where
7     nanoTime :: () -> <Proc> Long
8
9 """
10 Executes the expression and returns the result
11 together with execution time in seconds.
12 """
13 time :: (<e> a) -> <Proc,e> (a,Double)
14 time f = do
15     beginTime = nanoTime ()
16     result = f
17     endTime = nanoTime ()
18     (result, Java.l2d (endTime-beginTime) * 1e-9)
19
20 reportTime :: (<e> a) -> <e> a
21 reportTime f = runProc do
22     beginTime = nanoTime ()
23     result = f
24     endTime = nanoTime ()
25     time = Java.l2d (endTime-beginTime) * 1e-9
26     LOGGER.info "time \(time) s"
27     result
28     
29 reportTimeM :: String -> (<e> a) -> <e> a
30 reportTimeM task f = runProc do
31     beginTime = nanoTime ()
32     result = f
33     endTime = nanoTime ()
34     time = Java.l2d (endTime-beginTime) * 1e-9
35     LOGGER.info "\(task): \(time) s"
36     result
37
38 """
39 Prints the given text and returns
40 the second parameter.
41 """
42 trace :: String -> a -> a
43 trace text value = runProc do
44     printString text
45     value
46
47 """
48 Prints the given value and returns
49 the second parameter.
50 """
51 traceShow :: Show a => a -> b -> b
52 traceShow p v = trace (show p) v
53