Merge branch 'pu'
[jungerl.git] / lib / pan / src / prof_ts.erl
blob51010de2afcfd28a4d755166c1cbf8a5c0489de1
1 %%%-------------------------------------------------------------------
2 %%% File : prof_ts.erl
3 %%% Author : Mats Cronqvist <etxmacr@cbe2077>
4 %%% Description :
5 %%%
6 %%% Created : 28 Nov 2002 by Mats Cronqvist <etxmacr@cbe2077>
7 %%%-------------------------------------------------------------------
8 -module(prof_ts).
10 -export([go/0, go/1]).
12 -define(CB, cb_prof).
13 -define(PID(I), if integer(I) -> c:pid(0,127,I); true -> pid end).
14 -define(MSG(Tag, Pid, MFA, US),
15 [{Tag,{?PID(Pid),foo},MFA,{0,0,US}},1,standard_io]++stat()).
16 -define(FDEVENT(Tag, US), put(state, ?CB:go(?MSG(Tag, pid, 0, US)))).
17 -define(CEVENT(Tag, Pid,F, US), put(state, ?CB:go(?MSG(Tag, Pid,{m,F,0}, US)))).
18 -define(XEVENT(Tag, Pid,X, US), put(state, ?CB:go(?MSG(Tag, Pid,X, US)))).
19 -define(EVENT(Tag, Pid, US), put(state, ?CB:go(?MSG(Tag, Pid, info,US)))).
20 -define(END, ?CB:go([end_of_trace, 1, standard_io]++stat())).
22 go() -> do(1).
23 go(N) ->
24 pre(N),
25 tc(N).
27 do(N) ->
28 case go(N) of
29 not_yet_implemented -> the_end;
30 X -> do(N+1)
31 end.
33 pre(N) ->
34 io:fwrite("## ~p ######~n", [N]),
35 catch ets:delete(?MODULE),
36 ets:new(?MODULE, [named_table,public,ordered_set]),
37 erase(state).
39 stat() ->
40 case get(state) of
41 undefined -> [initial, ?MODULE];
42 S -> [S]
43 end.
45 post(Conds) ->
46 case post(Conds, [])--Conds of
47 [] -> io:fwrite("ok~n");
48 X -> io:fwrite("failed~n~p~n~p~n", [Conds, X])
49 end.
50 post([], O) -> O;
51 post([{Pid,Cs}|Conds], O) ->
52 Ds = ets:match(?MODULE,{{{stack,time},?PID(Pid),'$1'},'$2'}),
53 post(Conds, [{Pid,do_post(Ds, [])}|O]).
54 do_post([], O) -> lists:reverse(O);
55 do_post([[Stack,Time]|Ds], O) ->
56 do_post(Ds, [{st(Stack),Time}|O]).
57 st(St) -> [F||{m,F,0}<-St].
59 tc(1) ->
60 ?CEVENT(in, 1, f0, 0),
61 ?CEVENT(call, 1, f1, 3),
62 ?CEVENT(call, 1, f2, 4),
63 ?CEVENT(return_to, 1, f1, 5),
64 ?EVENT(out, 1, 7),
65 ?END,
66 post([{1, [{[f0],3},{[f0,f1],3},{[f0,f1,f2],1}]}]);
67 tc(2) ->
68 ?CEVENT(in, 1, f0, 0),
69 ?EVENT(gc_start, 1, 2),
70 ?EVENT(gc_end, 1, 3),
71 ?EVENT(out, 1, 7),
72 ?END,
73 post([{1, [{[f0],6}]}]);
74 tc(3) ->
75 ?CEVENT(in, 1, f0, 0),
76 ?EVENT(gc_start, 2, 3),
77 ?EVENT(gc_end, 2, 4),
78 ?EVENT(out, 1, 7),
79 ?END,
80 post([{1, [{[f0],6}]}]);
81 tc(4) ->
82 ?CEVENT(in, 1, f0, 0),
83 ?EVENT(out, 1, 7),
84 ?EVENT(gc_start, 2, 8),
85 ?EVENT(gc_end, 2, 10),
86 ?CEVENT(in, 3, f0, 12),
87 ?CEVENT(call, 3, f1, 14),
88 ?EVENT(out, 3, 17),
89 ?END,
90 post([{1, [{[f0],7}]},
91 {3, [{[f0],2},{[f0,f1],3}]}]);
92 tc(5) ->
93 ?CEVENT(in, 1, f0, 0),
94 ?CEVENT(call, 1, f1, 2),
95 ?EVENT(out, 1, 3),
96 ?EVENT(gc_start, 2, 5),
97 ?FDEVENT(out, 7),
98 ?FDEVENT(in, 8),
99 ?EVENT(gc_end, 2, 10),
100 ?CEVENT(in, 1, f1, 12),
101 ?CEVENT(return_to, 1, f0, 14),
102 ?EVENT(out, 1, 17),
103 ?END,
104 post([{1, [{[f0],5},{[f0,f1],3}]}]);
105 tc(6) ->
106 ?CEVENT(in, 1, f0, 0),
107 ?EVENT(gc_start, 2, 5),
108 ?FDEVENT(out, 7),
109 ?FDEVENT(in, 8),
110 ?EVENT(gc_end, 2, 10),
111 ?EVENT(out, 1, 17),
112 ?END,
113 post([{1, [{[f0],12}]}]);
114 tc(7) ->
115 ?CEVENT(in, 1, f0, 0),
116 ?FDEVENT(out, 7),
117 ?FDEVENT(in, 8),
118 ?EVENT(out, 1, 17),
119 ?END,
120 post([{1, [{[f0],16}]}]);
121 tc(8) ->
122 ?EVENT(gc_start, 2, 3),
123 ?EVENT(gc_end, 2, 4),
124 ?END,
125 post([]);
126 tc(9) ->
127 ?EVENT(gc_end, 2, 4),
128 ?END,
129 post([]);
130 tc(10) ->
131 ?FDEVENT(in, 8),
132 ?EVENT(gc_end, 2, 4),
133 ?EVENT(out, 1, 17),
134 ?END,
135 post([]);
136 tc(11) ->
137 ?FDEVENT(in, 2),
138 ?EVENT(gc_end, 2, 4),
139 ?EVENT(out, 1, 17),
140 ?CEVENT(in, 2, f0, 23),
141 ?EVENT(gc_start, 2, 25),
142 ?FDEVENT(out, 27),
143 ?END,
144 post([{2,[{[f0],2}]}]);
145 tc(12) ->
146 ?FDEVENT(in, 2),
147 ?EVENT(gc_end, 2, 4),
148 ?EVENT(out, 1, 17),
149 ?CEVENT(in, 3, f0, 18),
150 ?EVENT(out, 3, 21),
151 ?CEVENT(in, 2, f2, 23),
152 ?EVENT(gc_start, 2, 25),
153 ?FDEVENT(out, 27),
154 ?END,
155 post([{3,[{[f0],3}]},
156 {2,[{[f2],2}]}]);
157 tc(13) ->
158 ?CEVENT(in, 1, f0, 0),
159 ?EVENT(out, 1, 3),
160 ?EVENT(exit, 1, 6),
161 ?END,
162 post([{1, [{[f0],3}]}]);
163 tc(14) ->
164 ?CEVENT(in, 1, f0, 0),
165 ?EVENT(exit, 1, 6),
166 ?END,
167 post([{1, [{[f0],6}]}]);
168 tc(15) ->
169 ?CEVENT(in, 1, f0, 0),
170 ?EVENT(exit, 1, 6),
171 ?EVENT(gc_start, 3, 12),
172 ?EVENT(gc_end, 3, 14),
173 ?CEVENT(in, 2, f2, 18),
174 ?EVENT(out, 2, 25),
175 ?END,
176 post([{1, [{[f0],6}]},
177 {2, [{[f2],7}]}]);
178 tc(_) -> not_yet_implemented.