72:-
'$do_error'/2
use_system_module(
'$_errors', []).
78:-
user:prolog_predicate_name/2
multifile().
104:-
meta_predicate profile_data(:,+,-).
109 '$do_error'(instantiation_error,profile_data(
M:D,
Parm,
Data))
111 '$profile_data'(
D,
Parm,
Data,
M)
114 '$current_module'(
M),
115 '$profile_data'(
P,
Parm,
Data,
M).
117'$profile_data'(
P,
Parm,
Data,
M)
:- var(
P),
var,
118 '$profile_data_for_var'(
P,
Parm,
Data,
M).
119'$profile_data'(
M:P,
Parm,
Data,
_)
:- '$profile_data',
120 '$profile_data'(
P,
Parm,
Data,
M).
121'$profile_data'(
P,
Parm,
Data,
M)
:-
122 '$profile_data2'(
P,
Parm,
Data,
M).
124'$profile_data2'(
Na/Ar,
Parm,
Data,
M)
:-
126 '$profile_info'(
M,
P,
Stats),
127 '$profile_say'(
Stats,
Parm,
Data).
129'$profile_data_for_var'(
Name/Arity,
Parm,
Data,
M)
:-
131 '$current_predicate'(
Name,
M,
P,
_),
133 '$profile_info'(
M,
P,
Stats),
134 '$profile_say'(
Stats,
Parm,
Data).
136'$profile_say'(
'$profile'(
Entries,
_,
_), calls,
Entries).
137'$profile_say'(
'$profile'(
_,
_,
Backtracks), retries,
Backtracks).
141 '$current_predicate'(
_Na,
M,
P,
_),
142 '$profile_reset'(
M,
P),
167 '$offline_showprofres',
168 (
'$profison' -> profoff,
Stop = true
; Stop = false),
169 '$profglobs'(
Tot,
GCs,
HGrows,
SGrows,
Mallocs,
_Indexing,
ProfOns),
171 '$get_all_profinfo'(
0,[],
ProfInfo0,
0,
_TotCode),
172 msort(
ProfInfo0,
ProfInfo),
173 '$get_ppreds'(
ProfInfo,
Preds0),
174 '$add_extras_prof'(
GCs,
HGrows,
SGrows,
Mallocs,
Preds0,
PredsI),
176 '$sum_alls'(
Preds,
0,
Tot0),
179 format(user_error,
'~d ticks, ~d accounted for~n',[
Tot,
Accounted])
181 format(user_error,
'~d ticks, ~d accounted for (~d overhead)~n',[
Tot,
Accounted,
ProfOns])
185 '$display_preds'(
Preds,
Tot,
0,
1,
A1),
186 (
Stop = true
-> profon
; true).
198'$get_all_profinfo'([],
L,
L,
Tot,
Tot)
:- '$get_all_profinfo'.
199'$get_all_profinfo'(
Node,
L0,
Lf,
Tot0,
Totf)
:-
200 '$profnode'(
Node,
Clause,
PredId,
Count,
Left,
Right),
202 '$get_all_profinfo'(
Left,
L0,
Li,
Tot1,
Tot2),
203 '$get_all_profinfo'(
Right,[gprof(
PredId,
Clause,
Count)
|Li],
Lf,
Tot2,
Totf).
206'$get_ppreds'([gprof(
0,
_,
0)
|Cls],
Ps)
:- '$get_ppreds',
207 '$get_ppreds'(
Cls,
Ps).
208'$get_ppreds'([gprof(
0,
_,
Count)
|_],
_)
:- '$get_ppreds',
209 '$do_error'(
'SYSTEM_ERROR_INTERNAL',showprofres(gprof(
0,
_,
Count))).
210'$get_ppreds'([gprof(
PProfInfo,
_,
Count0)
|Cls],[
Sum-(
Mod:Name/Arity)
|Ps])
:-
211 '$get_more_ppreds'(
Cls,
PProfInfo,
Count0,
NCls,
Sum),
212 '$get_pred_pinfo'(
PProfInfo,
Mod,
Name,
Arity),
213 '$get_ppreds'(
NCls,
Ps).
215'$get_more_ppreds'([gprof(
PProfInfo,
_,
Count)
|Cls],
PProfInfo,
Count0,
NCls,
Sum)
216:- '$get_more_ppreds',
217 Count1 is Count+Count0,
218 '$get_more_ppreds'(
Cls,
PProfInfo,
Count1,
NCls,
Sum).
219'$get_more_ppreds'(
Cls,
_,
Sum,
Cls,
NSum)
:- NSum is -Sum.
221'$display_preds'(
_,
_,
_,
N,
N)
:- '$display_preds'.
222'$display_preds'([],
_,
_,
_,
_).
223'$display_preds'([
0-_|_],
_Tot,
_SoFar,
_I,
_N)
:- '$display_preds'.
224'$display_preds'([
NSum-P|Ps],
Tot,
SoFar,
I,
N)
:-
226 Perc is (
100*Sum)
/Tot,
228 NextP is (
100*Next)
/Tot,
235 functor
:prolog_predicate_name(
G,
PL)
->
236 prolog_predicate_name
239 format(user_error,
'~|~t~d.~7+ ~|~w:~t~d~50+ (~|~t~2f~6+%) |~|~t~2f~6+%|~n',[
I,
PL,
Sum,
Perc,
NextP]),
241 '$display_preds'(
Ps,
Tot,
Next,
I1,
N).
243'$sum_alls'([],
Tot,
Tot).
244'$sum_alls'([
C-_|Preds],
Tot0,
Tot)
:-
246 '$sum_alls'(
Preds,
TotI,
Tot).
249'$add_extras_prof'(
GCs,
HGrows,
SGrows,
Mallocs,
Preds0,
PredsI)
:-
250 '$add_extra_prof'(
GCs,
'Garbage Collections',
Preds0,
Preds1),
251 '$add_extra_prof'(
HGrows,
'Code Expansion',
Preds1,
Preds2),
252 '$add_extra_prof'(
SGrows,
'Stack Expansion',
Preds2,
Preds3),
253 '$add_extra_prof'(
Mallocs,
'Heap Allocation',
Preds3,
PredsI).
255'$add_extra_prof'(
0,
_,
Preds,
Preds)
:- '$add_extra_prof'.
256'$add_extra_prof'(
Ticks,
Name,
Preds, [
NTicks-Name|Preds])
:-
263
current_module( ? Mod:atom)
profile_data( ?Na/Ar, ?Parameter, -Data_)