[m-dev.] For review: Add arguments in collect
Erwan Jahier
Erwan.Jahier at irisa.fr
Thu Nov 4 05:18:50 AEDT 1999
Estimated hours taken: 2
This change implements the possibility to use procedure arguments within
collect:filter/4.
browser/debugger_interface.m:
Add the new requests `collect_arg_on' and `collect_arg_off' which
respectively switch on and off the possibility to use arguments
within filter/4.
Opium-M/source/collect.in:
trace/mercury_trace_external.c:
Add an arguments slot to MR_COLLECT_filter(). This slot contains the
list of procedure arguments if the static variable
`MR_collect_arguments' is set to TRUE, the empty list otherwise.
Opium-M/source/collect.op:
Add a parameter collect_arg which tells whether to set
`MR_collect_arguments' to TRUE or FALSE before running run_collect/1.
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.14
diff -u -r1.14 debugger_interface.m
--- debugger_interface.m 1999/11/03 14:41:42 1.14
+++ debugger_interface.m 1999/11/03 18:04:20
@@ -183,6 +183,10 @@
% retrieve the grade the current execution has been
% compiled with
; current_grade
+ % switch the argument collecting on (for collect request)
+ ; collect_arg_on
+ % switch the argument collecting off (for collect request)
+ ; collect_arg_off
.
:- type event_number == int.
@@ -290,6 +294,10 @@
; execution_continuing
% sent if the execution is terminated after a collect request
; execution_terminated
+ % responses to collect_arg_on
+ ; collect_arg_on_ok
+ % responses to collect_arg_off
+ ; collect_arg_off_ok
.
@@ -685,6 +693,8 @@
classify_request(link_collect(_),18).
classify_request(collect,19).
classify_request(current_grade,20).
+classify_request(collect_arg_on,21).
+classify_request(collect_arg_off,22).
%-----------------------------------------------------------------------------%
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.29
diff -u -r1.29 mercury_trace_external.c
--- mercury_trace_external.c 1999/11/03 14:41:40 1.29
+++ mercury_trace_external.c 1999/11/03 18:04:27
@@ -86,8 +86,12 @@
MR_REQUEST_BROWSE = 17,/* call the term browser */
MR_REQUEST_LINK_COLLECT = 18,/* dynamically link the collect module */
MR_REQUEST_COLLECT = 19,/* collecting monitoring informations */
- MR_REQUEST_CURRENT_GRADE = 20 /* retrieving the grade of the current
+ MR_REQUEST_CURRENT_GRADE = 20,/* retrieving the grade of the current
program has been compiled with */
+ MR_REQUEST_COLLECT_ARG_ON
+ = 21,/* switch the arguments collecting on */
+ MR_REQUEST_COLLECT_ARG_OFF
+ = 22 /* switch the arguments collecting off */
} MR_debugger_request_type;
@@ -133,6 +137,13 @@
static Word collect_lib_maybe_handle;
/*
+** Static variable that tells whether the list of arguments is available
+** within a collect module.
+*/
+
+static bool MR_collect_arguments = FALSE;
+
+/*
** Use a GNU C extension to enforce static type checking
** for printf-style functions.
** (See the "Function attributes" section of "C extensions"
@@ -183,7 +194,7 @@
static void MR_trace_browse_one_external(MR_Var_Spec which_var);
static void MR_COLLECT_filter(void (*filter_ptr)(Integer, Integer, Integer,
Word, Word, String, String, String, Integer, Integer,
- Integer, String, Word, Word *, Char *), Unsigned seqno,
+ Word, Integer, String, Word, Word *, Char *), Unsigned seqno,
Unsigned depth, MR_Trace_Port port,
const MR_Stack_Layout_Label *layout, const char *path,
bool *stop_collecting);
@@ -460,7 +471,7 @@
static void (*initialize_ptr)(Word *);
static void (*filter_ptr)(Integer, Integer, Integer, Word,
Word, String, String, String, Integer,
- Integer, Integer, String, Word, Word *, Char *);
+ Integer, Word, Integer, String, Word, Word *, Char *);
static void (*get_collect_var_type_ptr)(Word *);
static bool collect_linked = FALSE;
bool stop_collecting = FALSE;
@@ -521,15 +532,7 @@
break;
case MR_collecting:
- /*
- ** XXX Add a another request that takes
- ** arguments into account. We need two kinds
- ** of request in order to not penalize the
- ** performance of collect in the cases where
- ** arguments are not used.
- **
- ** arguments = MR_make_var_list(layout, saved_regs);
- */
+
MR_COLLECT_filter(*filter_ptr, seqno, depth, port,
layout, path, &stop_collecting);
@@ -842,6 +845,27 @@
MR_GRADE_OPT);
break;
}
+
+ case MR_REQUEST_COLLECT_ARG_ON:
+ {
+ if (MR_debug_socket) {
+ fprintf(stderr, "\nMercury runtime: "
+ "REQUEST_COLLECT_ARG_ON\n");
+ }
+ MR_collect_arguments = TRUE;
+ MR_send_message_to_socket("collect_arg_on_ok");
+ break;
+ }
+ case MR_REQUEST_COLLECT_ARG_OFF:
+ {
+ if (MR_debug_socket) {
+ fprintf(stderr, "\nMercury runtime: "
+ "REQUEST_COLLECT_ARG_OFF\n");
+ }
+ MR_collect_arguments = FALSE;
+ MR_send_message_to_socket("collect_arg_off_ok");
+ break;
+ }
default:
fatal_error("unexpected request read from "
"debugger socket");
@@ -1438,13 +1462,28 @@
*/
static void
MR_COLLECT_filter(void (*filter_ptr)(Integer, Integer, Integer, Word, Word,
- String, String, String, Integer, Integer, Integer, String, Word, Word *,
- Char *), Unsigned seqno, Unsigned depth, MR_Trace_Port port,
+ String, String, String, Integer, Integer, Word, Integer, String, Word,
+ Word *, Char *), Unsigned seqno, Unsigned depth, MR_Trace_Port port,
const MR_Stack_Layout_Label *layout, const char *path,
bool *stop_collecting)
{
Char result;
+ Word arguments;
+ /*
+ ** Only pass the arguments list down filter
+ ** if required, i.e. if MR_collect_arguments
+ ** is set to TRUE. We need to do that in
+ ** order to not penalize the performance
+ ** of collect in the cases where the argument
+ ** list (which might be very big) is not used.
+ **
+ */
+ if (MR_collect_arguments) {
+ arguments = MR_trace_make_var_list();
+ } else {
+ arguments = MR_list_empty();
+ }
MR_TRACE_CALL_MERCURY((*filter_ptr)(
MR_trace_event_number,
seqno,
@@ -1456,6 +1495,7 @@
(String) layout->MR_sll_entry->MR_sle_user.MR_user_name,
layout->MR_sll_entry->MR_sle_user.MR_user_arity,
layout->MR_sll_entry->MR_sle_user.MR_user_mode,
+ arguments,
layout->MR_sll_entry->MR_sle_detism,
(String) path,
MR_collecting_variable,
Index: 0.9/collect.in
--- 0.9/collect.in Wed, 03 Nov 1999 17:18:07 +0100 jahier (collect/5_collect.in 1.2 640)
+++ 0.9(w)/collect.in Wed, 03 Nov 1999 17:23:51 +0100 jahier (collect/5_collect.in 1.2 640)
@@ -11,10 +11,10 @@
:- pred filter(event_number, call_number, depth_number, trace_port_type,
pred_or_func, declared_module_name, defined_module_name, proc_name,
- arity, mode_number, determinism, goal_path_string, collected_type,
- collected_type, char).
+ arity, mode_number, arguments, determinism, goal_path_string,
+ collected_type, collected_type, char).
-:- mode filter(in, in, in, in, in, in, in, in, in, in, in, in, acc_in, acc_out, out)
+:- mode filter(in, in, in, in, in, in, in, in, in, in, in, in, in, acc_in, acc_out, out)
is det.
:- pred send_collect_result(collected_type, io__output_stream, io__state,
@@ -27,7 +27,7 @@
:- implementation.
:- pragma export(initialize(out), "ML_COLLECT_initialize").
-:- pragma export(filter(in, in, in, in, in, in, in, in, in, in, in, in,
+:- pragma export(filter(in, in, in, in, in, in, in, in, in, in, in, in, in,
acc_in, acc_out, out), "ML_COLLECT_filter").
:- pragma export(send_collect_result(in, in, di, uo),
"ML_COLLECT_send_collect_result").
@@ -86,6 +86,8 @@
:- type procedure --->
proc(pred_or_func, declared_module_name, proc_name, arity, mode_number).
+:- type arguments == list(univ).
+
:- type event --->
event(
event_number,
@@ -98,6 +100,7 @@
proc_name,
arity,
mode_number,
+ arguments,
determinism,
goal_path_string).
@@ -114,6 +117,7 @@
:- func proc(event::in) = (procedure::out) is det.
:- func determinism(event::in) = (determinism::out) is det.
:- func goal_path(event::in) = (goal_path_string::out) is det.
+:- func arguments(event::in) = (arguments::out) is det.
:- pragma inline(chrono/1).
:- pragma inline(call/1).
@@ -127,46 +131,50 @@
:- pragma inline(proc_mode_number/1).
:- pragma inline(determinism/1).
:- pragma inline(goal_path/1).
+:- pragma inline(arguments/1).
chrono(Event) = Chrono :-
- Event = event(Chrono, _, _, _, _, _, _, _, _, _, _, _).
+ Event = event(Chrono, _, _, _, _, _, _, _, _, _, _, _, _).
call(Event) = Call :-
- Event = event(_, Call, _, _, _, _, _, _, _, _, _, _).
+ Event = event(_, Call, _, _, _, _, _, _, _, _, _, _, _).
depth(Event) = Depth :-
- Event = event(_, _, Depth, _, _, _, _, _, _, _, _, _).
+ Event = event(_, _, Depth, _, _, _, _, _, _, _, _, _, _).
port(Event) = Port :-
- Event = event(_, _, _, Port, _, _, _, _, _, _, _, _).
+ Event = event(_, _, _, Port, _, _, _, _, _, _, _, _, _).
proc_type(Event) = ProcType :-
- Event = event(_, _, _, _, ProcType, _, _, _, _, _, _, _).
+ Event = event(_, _, _, _, ProcType, _, _, _, _, _, _, _, _).
decl_module(Event) = DeclModule :-
- Event = event(_, _, _, _, _, DeclModule, _, _, _, _, _, _).
+ Event = event(_, _, _, _, _, DeclModule, _, _, _, _, _, _, _).
def_module(Event) = DefModule :-
- Event = event(_, _, _, _, _, _, DefModule, _, _, _, _, _).
+ Event = event(_, _, _, _, _, _, DefModule, _, _, _, _, _, _).
proc_name(Event) = ProcName :-
- Event = event(_, _, _, _, _, _, _, ProcName, _, _, _, _).
+ Event = event(_, _, _, _, _, _, _, ProcName, _, _, _, _, _).
proc_arity(Event) = ProcArity :-
- Event = event(_, _, _, _, _, _, _, _, ProcArity, _, _, _).
+ Event = event(_, _, _, _, _, _, _, _, ProcArity, _, _, _, _).
proc_mode_number(Event) = ModeNumber :-
- Event = event(_, _, _, _, _, _, _, _, _, ModeNumber, _, _).
+ Event = event(_, _, _, _, _, _, _, _, _, ModeNumber, _, _, _).
proc(Event) = (proc(ProcType, DeclModule, Name, Arity, ModeNum)) :-
Event = event(_, _, _, _, ProcType, DeclModule, _, Name, Arity,
- ModeNum, _, _).
+ ModeNum, _, _, _).
+
+arguments(Event) = ListArg :-
+ Event = event(_, _, _, _, _, _, _, _, _, _, ListArg, _, _).
determinism(Event) = Determinism :-
- Event = event(_, _, _, _, _, _, _, _, _, _, Determinism, _).
+ Event = event(_, _, _, _, _, _, _, _, _, _, _, Determinism, _).
goal_path(Event) = GoalPath :-
- Event = event(_, _, _, _, _, _, _, _, _, _, _, GoalPath).
+ Event = event(_, _, _, _, _, _, _, _, _, _, _, _, GoalPath).
% Type of the fourth argument of filter/4 which tells whether to stop collecting
@@ -176,11 +184,11 @@
; continue.
filter(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc, DeclModuleName,
- DefModuleName, PredName, Arity, ModeNum, Determinism, Path,
- AccIn, AccOut, Char) :-
+ DefModuleName, PredName, Arity, ModeNum, Arguments, Determinism,
+ Path, AccIn, AccOut, Char) :-
filter(event(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc,
DeclModuleName, DefModuleName, PredName, Arity, ModeNum,
- Determinism, Path), AccIn, AccOut, StopOrContinue),
+ Arguments, Determinism, Path), AccIn, AccOut, StopOrContinue),
(
StopOrContinue = continue,
Char = 'n'
--- collect.op.save Wed Nov 3 17:53:09 1999
+++ collect.op Wed Nov 3 18:05:37 1999
@@ -102,6 +102,7 @@
proc_name, \n\
arity, \n\
mode_number).\n\
+:- type arguments == list(univ).\n\
\n\
Here are functions that eases the access of the event attributes:\n\
\n\
@@ -118,7 +119,10 @@
:- func proc(event::in) = (procedure::out) is det.\n\
:- func determinism(event::in) = (determinism::out) is det.\n\
:- func goal_path(event::in) = (goal_path_string::out) is det.\n\
+:- func arguments(event::in) = (arguments::out) is det. (*)\n\
\n\
+(*) To be able to retrieve arguments, you to need to have the opium parameter \n\
+`collect_arg' set to yes (`man collect_arg.' for more details).\n\
\n\
Then, this file is used to generate the Mercury module `collect.m', \
which is compiled and dynamically linked with the current execution. \
@@ -144,7 +148,7 @@
interface : button,
command_type : opium,
implementation : collect_Op,
- parameters : [],
+ parameters : [collect_arg],
message :
"If File contains the implementation of the Mercury predicates initialize/1 \
and filter/4, collect(File, Result) calls filter/4 with each event of the \
@@ -201,6 +205,22 @@
dyn_link_collect,
run_collect(Result).
+%------------------------------------------------------------------------------%
+
+opium_parameter(
+ name : collect_arg,
+ arg_list : [YesOrNo],
+ arg_type_list : [member([yes, no])],
+ parameter_type : single,
+ default : [no],
+ commands : [collect],
+ message :
+"Parameter which tells whether it is possible to use arguments/1 within \
+collect:filter/4. If you do not use arguments, it is better to set this \
+parameter to `no' since when arguments are very big, it migth slow down \
+the execution of collect a lot."
+ ).
+
%------------------------------------------------------------------------------%
opium_primitive(
@@ -379,6 +399,20 @@
run_collect_Op(Result) :-
check_a_program_is_running("run_collect/1"),
+ (
+ collect_arg(yes),
+ send_message_to_socket(collect_arg_on),
+ read_message_from_socket(collect_arg_on_ok),
+ !
+ ;
+ collect_arg(no),
+ send_message_to_socket(collect_arg_off),
+ read_message_from_socket(collect_arg_off_ok),
+ !
+ ;
+ print("Error in run_collect_Op.\n"),
+ abort
+ ),
send_message_to_socket(collect),
read_message_from_socket(CollectLinked),
(
--
R1.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list