Visualising Program Behaviour Program visualisation tools in ECLi
Visualising Program Behaviour
Program visualisation tools in ECLi. PSe ¡ ¡ ¡ Debugger Profiler Coverage Display matrix Visualisation 2
Profiler - sample based code profiling ¡ ¡ Any goal can be profiled Does not require special compilation 0. 01 s sample interval Not available on MS Window (currently) queen(Data, Out) : qperm(Data, Out), safe(Out). qperm([], []). qperm([X|Y], [U|V]) : qdelete(U, X, Y, Z), qperm(Z, V). qdelete(A, A, L, L). qdelete(X, A, [H|T], [A|R]) : qdelete(X, H, T, R). safe([]). safe([N|L]) : nodiag(L, N, 1), safe(L). nodiag([], _, _). nodiag([N|L], B, D) : D == N - B, D == B - N, D 1 is D + 1, nodiag(L, B, D 1). 3
Profiler - the profile predicate ¡ profile(+Goal) : - profile(queen([1, 2, 3, 4, 5, 6, 7, 8, 9], Out)). ¡ profile(+Goal, +Option. List) : - profile( queen([1, 2, 3, 4, 5, 6, 7, 8, 9], Out), [simple, keep_file] ). ¡ When the goal runs quickly, use an auxiliary queen_100 : for(_X, 1, 100) do queen([1, 2, 3, 4, 5, 6, 7, 8, 9], _Out). : - profile(queen_100). 4
Profiler - sample based code profiling goal succeeded PROFILING STATISTICS ----------Goal: Total user time: queen_100 3. 19 s Predicate Module %Time %Cum ----------------------------nodiag /3 eclipse 52. 2% 1. 67 s 52. 2% qdelete /4 eclipse 27. 4% 0. 87 s 79. 6% qperm /2 eclipse 17. 0% 0. 54 s 96. 5% safe /1 eclipse 2. 8% 0. 09 s 99. 4% queen /2 eclipse 0. 6% 0. 02 s 100. 0% Yes (3. 33 s cpu) 5
Coverage - source line coverage library queen(Data, Out) : 1 qperm(Data, Out), 7686 safe(Out) 1. ¡ ¡ Requires special qperm([], []) 7686. compilation qperm([X|Y], [U|V]) : 13211 qdelete(U, X, Y, Z), Inserts coverage counters 20896 qperm(Z, V) 69174. into the code qdelete(A, A, L, L) 20896. Entry to code blocks qdelete(X, A, [H|T], [A|R]) : Between predicate calls within a 7685 qdelete(X, H, T, R) 10434. block safe([]) 1. At the end of code blocks ¡ Pretty prints source annotated with counter values safe([N|L]) : 9023 nodiag(L, N, 1), 1338 safe(L) 9. nodiag([], _5917, _5918) nodiag([N|L], B, D) : 25683 D == N 18296 D == B 17998 D 1 is D + 17998 nodiag(L, 1338. B, N, 1, B, D 1) 10314. 6
Coverage - source line coverage library The ccompile predicate compiles and loads a file adding coverage counters as it does so ccompile(+File) : - ccompile(’foo. ecl’). ccompile(+File, +Option. List) : - ccompile(’foo. ecl’, [exit_counters: off, macro_expansion: off]). 7
Coverage - source line coverage library All coverage counters are reset by calling ¡ reset_counters/0 The result predicate outputs source code annotated with coverage counter values ¡ result/0 ¡ result(+File) : - result(‘foo. ecl’). ¡ result(+File, +Option. List) : - result(‘foo. ecl’, [outdir: coverage, format: html]). 8
Coverage - source line coverage library : -lib(coverage). : -ccompile(“foo. ecl”). : -queen( [1, 2, 3, 4, 5, 6, 7, 8, 9], Out ). : -result(“foo. ecl”). queen(Data, Out) : 1 qperm(Data, Out), 7686 safe(Out) 1. qperm([], []) 7686. qperm([X|Y], [U|V]) : 13211 qdelete(U, X, Y, Z), 20896 qperm(Z, V) 69174. qdelete(A, A, L, L) 20896. qdelete(X, A, [H|T], [A|R]) : 7685 qdelete(X, H, T, R) 10434. safe([]) 1. safe([N|L]) : 9023 nodiag(L, N, 1), 1338 safe(L) 9. nodiag([], _5917, _5918) nodiag([N|L], B, D) : 25683 D == N 18296 D == B 17998 D 1 is D + 17998 nodiag(L, 1338. B, N, 1, B, D 1) 10314. 9
Visualisation - control flow Annotated source code Visualisation Client Debugger 10
More Details. . . ¡ See ECLi. PSe User Manual Profiling Prolog Execution chapter ¡ See ECLi. PSe Library Manual Coverage library ¡ See ECLi. PSe Visualisation Tutorial 11
SEND + MORE = MONEY : -lib(ic). lab([]). lab([X|Xs]): indomain(X), lab(Xs). sendmore(Digits) : Digits = [S, E, N, D, M, O, R, Y], Digits : : [0. . 9], Carries = [C 1, C 2, C 3, C 4], Carries : : [0. . 1], alldifferent(Digits), S #= 0, M #= 0, C 1 #= M, C 2 + S + M #= O + 10*C 1, C 3 + E + O #= N + 10*C 2, C 4 + N + R #= E + 10*C 3, D + E #= Y + 10*C 4, lab(Carries), lab(Digits). 12
SEND + MORE = MONEY (annotated) : -lib(ic). : -lib(viewable). lab([]). lab([X|Xs]): indomain(X), lab(Xs). sendmore 1(Digits) : Digits = [S, E, N, D, M, O, R, Y], Digits : : [0. . 9], viewable_create(equation, Digits), Carries = [C 1, C 2, C 3, C 4], Carries : : [0. . 1], alldifferent(Digits), S #= 0, M #= 0, C 1 #= M, C 2 + S + M #= O + 10*C 1, C 3 + E + O #= N + 10*C 2, C 4 + N + R #= E + 10*C 3, D + E #= Y + 10*C 4, lab(Carries), lab(Digits). 13
SEND + MORE = MONEY (annotated II) : -lib(ic). : -lib(viewable). lab([]). lab([X|Xs]): indomain(X), lab(Xs). sendmore 2(Digits) : Digits = [S, E, N, D, M, O, R, Y], Digits : : [0. . 9], viewable_create(equation, Digits, array([flexible], numeric_bounds)), Carries = [C 1, C 2, C 3, C 4], . . lab(Digits), viewable_expand(equation, 1, C 1), viewable_expand(equation, 1, C 2), viewable_expand(equation, 1, C 3), viewable_expand(equation, 1, C 4). 14
SEND + MORE = MONEY (annotated III) : -lib(ic). : -lib(viewable). lab([]). lab([X|Xs]): indomain(X), lab(Xs). sendmore 3(Digits) : Digits = [S, E, N, D, M, O, R, Y], Digits : : [0. . 9], viewable_create(equation, []([](0, S, E, N, D), [](0, M, O, R, E), [](M, O, N, E, Y)), array([flexible, fixed], numeric_bounds)), Carries = [C 1, C 2, C 3, C 4], . . lab(Carries), lab(Digits), viewable_expand(equation, 1, [C 1, C 2, C 3, C 4, 0]). 15
SEND + MORE = MONEY (annotated IV) : -lib(ic). : -lib(viewable). . . . sendmore 4(Digits) : Digits = [S, E, N, D, M, O, R, Y], Digits : : [0. . 9], viewable_create(equation, []([](0, S, E, N, D), [](0, M, O, R, E), [](M, O, N, E, Y)), array([flexible, fixed], numeric_bounds), [["send", "more", "money"], ["ten thousands", "hundreds", "tens", "units"]]), Carries = [C 1, C 2, C 3, C 4], . . lab(Carries), lab(Digits), viewable_expand(equation, 1, [C 1, C 2, C 3, C 4, 0], "carries"). 16
- Slides: 16