diff --git a/docs/yap.tex b/docs/yap.tex index 021a709f7..02948f03b 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -200,6 +200,7 @@ Subnodes of Library * Heaps:: Labelled binary tree where the key of each node is less than or equal to the keys of its children. * Lambda:: Ulrich Neumerkel's Lambda Library +* DBUsage:: Information bout data base usage. * LineUtilities:: Line Manipulation Utilities * Lists:: List Manipulation * MapList:: SWI-Compatible Apply library. @@ -8660,6 +8661,7 @@ Library, Extensions, Built-ins, Top than or equal to the keys of its children. * LAM:: LAM MPI * Lambda:: Ulrich Neumerkel's Lambda Library +* DBUsage:: Information bout data base usage. * Lists:: List Manipulation * LineUtilities:: Line Manipulation Utilities * MapList:: SWI-Compatible Apply library. @@ -12697,7 +12699,7 @@ The vertices @var{Vertices} have no outgoing edge in graph @end table -@node UnDGraphs, Lambda , DGraphs, Library +@node UnDGraphs, DBUsage , DGraphs, Library @section Undirected Graphs @cindex undirected graphs @@ -12793,7 +12795,50 @@ directed graph @var{DGraph}. @end table -@node Lambda, LAM, UnDGraphs, Library +@node DBUsage, Lambda, UnDGraphs, Library +@section Memory Usage in Prolog Data-Base +@cindex DBUsage + +This library provides a set of utilities for studying memory usage in YAP. +The following routines are available once included with the +@code{use_module(library(dbusage))} command. + +@table @code +@item db_usage +@findex db_usage/0 +@snindex db_usage/0 +@cnindex db_usage/0 +Give general overview of data-base usage in the system. + +@item db_static +@findex db_static/0 +@snindex db_static/0 +@cnindex db_static/0 +List memory usage for every static predicate. + +@item db_static(+@var{Threshold}) +@findex db_static/0 +@snindex db_static/0 +@cnindex db_static/0 +List memory usage for every static predicate. Predicate must use more +than @var{Threshold} bytes. + +@item db_dynamic +@findex db_dynamic/0 +@snindex db_dynamic/0 +@cnindex db_dynamic/0 +List memory usage for every dynamic predicate. + +@item db_dynamic(+@var{Threshold}) +@findex db_dynamic/0 +@snindex db_dynamic/0 +@cnindex db_dynamic/0 +List memory usage for every dynamic predicate. Predicate must use more +than @var{Threshold} bytes. + +@end table + +@node Lambda, LAM, DBUsage, Library @section Lambda Expressions @cindex Lambda Expressions diff --git a/library/dbusage.yap b/library/dbusage.yap index e525440fa..f67235ee8 100644 --- a/library/dbusage.yap +++ b/library/dbusage.yap @@ -2,7 +2,9 @@ :- module(dbusage, [ db_usage/0, db_static/0, - db_dynamic/0 + db_static/1, + db_dynamic/0, + db_dynamic/1 ]). db_usage :- @@ -13,8 +15,8 @@ db_usage :- HeapUsedK is HeapUsed//1024, HeapFreeK is HeapFree//1024, StackSpace is (GInU+SInU+FreeS+TInU+FreeT)//1024, - format(user_error, 'Heap Space = ~d KB (+ ~dKB free)~n',[HeapUsedK,HeapFreeK]), - format(user_error, 'Stack Space = ~d KB~n',[StackSpace]), + format(user_error, 'Heap Space = ~D KB (+ ~D KB free)~n',[HeapUsedK,HeapFreeK]), + format(user_error, 'Stack Space = ~D KB~n',[StackSpace]), findall(p(Cls,CSz,ISz), (current_module(M), current_predicate(_,M:P), @@ -22,12 +24,12 @@ db_usage :- sumall(LAll, TCls, TCSz, TISz), statistics(atoms,[AtomN,AtomS]), AtomSK is AtomS//1024, - format(user_error, '~d Atoms taking ~d KB~n',[AtomN,AtomSK]), + format(user_error, '~D Atoms taking ~D KB~n',[AtomN,AtomSK]), TSz is TCSz+TISz, TSzK is TSz//1024, TCSzK is TCSz//1024, TISzK is TISz//1024, - format(user_error, 'Total User Code~n ~d clauses taking ~d KB~n ~d KB in clauses + ~d KB in indices~n', + format(user_error, 'Total User Code~n ~D clauses taking ~D KB~n ~D KB in clauses + ~D KB in indices~n', [TCls,TSzK,TCSzK,TISzK]), statistics(static_code,[SCl,SI,SI1,SI2,SI3]), SClK is SCl//1024, @@ -37,7 +39,7 @@ db_usage :- SI3K is SI3//1024, ST is SCl+SI, STK is ST//1024, - format(user_error, 'Total Static code=~d KB~n ~dKB in clauses + ~dKB in indices (~d+~d+~d)~n', + format(user_error, 'Total Static code=~D KB~n ~D KB in clauses + ~D KB in indices (~D+~D+~D)~n', [STK,SClK,SIK,SI1K,SI2K,SI3K]), statistics(dynamic_code,[DCl,DI,DI1,DI2,DI3,DI4]), DClK is DCl//1024, @@ -48,20 +50,20 @@ db_usage :- DI4K is DI4//1024, DT is DCl+DI, DTK is DT//1024, - format(user_error, 'Total Dynamic code=~d KB~n ~dKB in clauses + ~dKB in indices (~d+~d+~d+~d)~n', + format(user_error, 'Total Dynamic code=~D KB~n ~D KB in clauses + ~D KB in indices (~D+~D+~D+~D)~n', [DTK,DClK,DIK,DI1K,DI2K,DI3K,DI4K]), total_erased(DCls,DSZ,ICls,ISZ), (DCls =:= 0 -> true ; DSZK is DSZ//1024, - format(user_error, ' ~d erased clauses not reclaimed (~dKB)~n',[DCls,DSZK]) + format(user_error, ' ~D erased clauses not reclaimed (~D KB)~n',[DCls,DSZK]) ), (ICls =:= 0 -> true ; ISZK is ISZ//1024, - format(user_error, ' ~d erased indices not reclaimed (~dKB)~n',[ICls,ISZK]) + format(user_error, ' ~D erased indices not reclaimed (~D KB)~n',[ICls,ISZK]) ), !. @@ -70,23 +72,31 @@ db_usage:- db_static :- + db_static(-1). + +db_static(Min) :- setof(p(Sz,M:P,Cls,CSz,ISz), PN^(current_module(M), current_predicate(PN,M:P), \+ predicate_property(M:P,dynamic), predicate_statistics(M:P,Cls,CSz,ISz), - Sz is (CSz+ISz)),All), + Sz is (CSz+ISz), + Sz > Min),All), format(user_error,' Static user code~n===========================~n',[]), display_preds(All). db_dynamic :- + db_dynamic(-1). + +db_dynamic(Min) :- setof(p(Sz,M:P,Cls,CSz,ISz,ECls,ECSz,EISz), PN^(current_module(M), current_predicate(PN,M:P), predicate_property(M:P,dynamic), predicate_statistics(M:P,Cls,CSz,ISz), predicate_erased_statistics(M:P,ECls,ECSz,EISz), - Sz is (CSz+ISz+ECSz+EISz)), + Sz is (CSz+ISz+ECSz+EISz), + Sz < Min), All), format(user_error,' Dynamic user code~n===========================~n',[]), display_dpreds(All). @@ -98,7 +108,7 @@ display_preds([p(Sz,M:P,Cls,CSz,ISz)|_]) :- KCSz is CSz//1024, KISz is ISz//1024, (M = user -> Name = A/N ; Name = M:A/N), - format(user_error,'~w~t~36+:~t~d~7+ clauses using~|~t~d~8+ KB (~d + ~d)~n',[Name,Cls,KSz,KCSz,KISz]), + format(user_error,'~w~t~36+:~t~D~7+ clauses using~|~t~D~8+ KB (~D + ~D)~n',[Name,Cls,KSz,KCSz,KISz]), fail. display_preds([_|All]) :- display_preds(All). @@ -111,20 +121,20 @@ display_dpreds([p(Sz,M:P,Cls,CSz,ISz,ECls,ECSz,EISz)|_]) :- KCSz is CSz//1024, KISz is ISz//1024, (M = user -> Name = A/N ; Name = M:A/N), - format(user_error,'~w~t~36+:~t~d~7+ clauses using~|~t~d~8+ KB (~d + ~d)~n',[Name,Cls,KSz,KCSz,KISz]), + format(user_error,'~w~t~36+:~t~D~7+ clauses using~|~t~D~8+ KB (~D + ~D)~n',[Name,Cls,KSz,KCSz,KISz]), (ECls =:= 0 -> true ; ECSzK is ECSz//1024, - format(user_error,' ~d erased clauses: ~d KB~n',[ECls,ECSzK]) + format(user_error,' ~D erased clauses: ~D KB~n',[ECls,ECSzK]) ), (EISz =:= 0 -> true ; EISzK is EISz//1024, - format(user_error,' ~d KB erased indices~n',[EISzK]) + format(user_error,' ~D KB erased indices~n',[EISzK]) ), fail. display_dpreds([_|All]) :-