1 | % (c) 2016-2024 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(performance_messages, | |
6 | [ | |
7 | performance_monitoring_on/0, | |
8 | perfmessage/1, perfmessage/2, perfmessage/3, perfmessage/4, | |
9 | perfmessage_bexpr/3, perfmessages_bexpr/3, perfmessages_bexpr_call/4, | |
10 | cond_perfmessage/2, | |
11 | perfmessagecall/3, perfmessagecall/4, | |
12 | perf_format/2, | |
13 | perf_format_wf/3, | |
14 | toggle_perfmessages/0 | |
15 | ]). | |
16 | ||
17 | :- meta_predicate perfmessagecall(*,0,*). | |
18 | :- meta_predicate perfmessagecall(*,*,0,*). | |
19 | :- meta_predicate perfmessages_bexpr_call(*,*,*,0). | |
20 | ||
21 | :- use_module(module_information,[module_info/2]). | |
22 | :- module_info(group,profiling). | |
23 | :- module_info(description,'This module allows to generate performance messages.'). | |
24 | ||
25 | :- use_module(preferences). | |
26 | :- use_module(error_manager). | |
27 | :- use_module(tools_printing,[format_with_colour/4]). | |
28 | :- use_module(tools_strings,[ajoin/2]). | |
29 | :- use_module(translate,[translate_bexpression_with_limit/3]). | |
30 | ||
31 | % ------------------------------------------- | |
32 | ||
33 | :- dynamic performance_monitoring_on/0. % should we use a preference | |
34 | %performance_monitoring_on. | |
35 | ||
36 | performance_monitoring_on :- get_preference(performance_monitoring_on,true). | |
37 | ||
38 | toggle_perfmessages :- print('TURNING PERF-MESSAGES '), | |
39 | (performance_monitoring_on | |
40 | -> set_preference(performance_monitoring_on,false), print('OFF') | |
41 | ; set_preference(performance_monitoring_on,true), print('ON')),nl. | |
42 | ||
43 | perf_format(M,Args) :- preference(performance_monitoring_on,true),!, | |
44 | format_with_colour(user_output,[blue],'==PERF-MESSAGE==> ',[]), | |
45 | format_with_colour(user_output,[blue],M,Args). | |
46 | perf_format(_,_). | |
47 | ||
48 | perf_format_wf(M,Args,WF) :- preference(performance_monitoring_on,true),!, | |
49 | format_with_colour(user_output,[blue],'==PERF-MESSAGE==> ',[]), | |
50 | format_with_colour(user_output,[blue],M,Args), | |
51 | kernel_waitflags:portray_call_stack(WF). | |
52 | perf_format_wf(_,_,_). | |
53 | ||
54 | perfmessage(M) :- preference(performance_monitoring_on,true),!, | |
55 | format_with_colour(user_output,[blue],'==PERF-MESSAGE==> ~w~n',[M]). | |
56 | perfmessage(_). | |
57 | ||
58 | :- use_module(library(lists),[maplist/2]). | |
59 | % conditional perfmessage | |
60 | cond_perfmessage(Prefs,M) :- preference(performance_monitoring_on,true), | |
61 | maplist(prefset,Prefs), | |
62 | !, | |
63 | format_with_colour(user_output,[blue],'==PERF-MESSAGE==> ~w~n',[M]). | |
64 | cond_perfmessage(_,_). | |
65 | ||
66 | prefset(P/V) :- get_preference(P,V). | |
67 | ||
68 | perfmessage(M,Location) :- preference(performance_monitoring_on,true),!, | |
69 | add_message(performance_message,'==PERF-MESSAGE==> ',M,Location). | |
70 | perfmessage(_,_). | |
71 | ||
72 | perfmessage(Category,M,Location) :- preference(performance_monitoring_on,true), | |
73 | show_message(Category), | |
74 | !, | |
75 | add_message(performance_message,'==PERF-MESSAGE==> ',M,Location). | |
76 | perfmessage(_,_,_). | |
77 | ||
78 | perfmessage(Category,Msg,Term,Location) :- preference(performance_monitoring_on,true), | |
79 | show_message(Category), | |
80 | !, | |
81 | ajoin(['==PERF-MESSAGE==> ',Msg],M), | |
82 | add_message(performance_message,M,Term,Location). | |
83 | perfmessage(_,_,_,_). | |
84 | ||
85 | % perfmessage where we provide a BExpr as location and part of message | |
86 | perfmessage_bexpr(Category,Msg,BExpr) :- | |
87 | (Msg = [_|_] -> List=Msg ; List=[Msg]), | |
88 | perfmessages_bexpr(Category,List,BExpr). | |
89 | ||
90 | ||
91 | % perfmessage where we provide a BExpr as location and messages to be joined | |
92 | perfmessages_bexpr(Category,Msgs,BExpr) :- preference(performance_monitoring_on,true), | |
93 | show_message(Category), | |
94 | !, | |
95 | translate_bexpression_with_limit(BExpr,100,TS), | |
96 | append(Msgs,[TS],List), | |
97 | ajoin(List,M), | |
98 | add_message(performance_message,'==PERF-MESSAGE==> ',M,BExpr). | |
99 | perfmessages_bexpr(_,_,_). | |
100 | ||
101 | % a version of the above performing a call before printing the message | |
102 | perfmessages_bexpr_call(Category,Msgs,BExpr,Call) :- preference(performance_monitoring_on,true), | |
103 | show_message(Category),!, | |
104 | call(Call), | |
105 | perfmessages_bexpr(Category,Msgs,BExpr). | |
106 | perfmessages_bexpr_call(_,_,_,_). | |
107 | ||
108 | perfmessagecall(M,Call,Location) :- preference(performance_monitoring_on,true),!, | |
109 | add_message(performance_message,'==PERF-MESSAGE==> ',M,Location), | |
110 | call(Call),nl(user_output). | |
111 | perfmessagecall(_,_,_). | |
112 | ||
113 | ||
114 | perfmessagecall(Category,M,Call,Location) :- preference(performance_monitoring_on,true), | |
115 | show_message(Category), | |
116 | !, | |
117 | add_message(performance_message,'==PERF-MESSAGE==> ',M,Location), | |
118 | call(Call),nl(user_output). | |
119 | perfmessagecall(_,_,_,_). | |
120 | ||
121 | % decide based upon category and current preferences whether to show the message or not | |
122 | show_message(reify) :- !, | |
123 | get_preference(data_validation_mode,false). | |
124 | show_message(good(_)) :- !, | |
125 | get_preference(provide_trace_information,true). | |
126 | show_message(_Category). |