[m-dev.] For review: calling MR_collect_filter() in MR_trace_real()

Erwan Jahier Erwan.Jahier at irisa.fr
Tue Mar 6 04:46:42 AEDT 2001


Since this change simply fixes a performance bug, I don't mind too
much if I can't commit it before 0.10.1; it's up to you
Fergus. Incidentally, this change makes it easier to make collect
available from mdb one day. I can do that if someone emits such a
wish (certainly not before the release though).

--
Estimated hours taken: 10 
Branches: main and release.

Handling collect requests in MR_trace_real() rather than in
MR_trace_event_external() as it saves a few indirections and a few
function calls. It matters since this code is typically called
several million of times per seconds. 

trace/mercury_trace_external.c:
trace/mercury_trace.ch:
	Handling collect requests in MR_trace_real() rather than in
	MR_trace_event_external(). In particular, suppress the 
	external_debugger_mode `MR_collecting' in mercury_trace_external.c 
	and add the MR_trace_cmd mode `MR_CMD_COLLECT' in mercury_trace.c.

trace/mercury_trace_external.h:
	Make MR_collect_filter(), MR_send_collect_result and
	MR_send_message_to_socket() extern functions to be able to use them 
	from mercury_trace.c.

Index: trace/mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.39
diff -u -d -u -r1.39 mercury_trace.c
--- trace/mercury_trace.c	2001/03/05 03:52:29	1.39
+++ trace/mercury_trace.c	2001/03/05 17:30:14
@@ -166,6 +166,50 @@
 #endif	/* MR_TRACE_HISTOGRAM */
 
 	switch (MR_trace_ctrl.MR_trace_cmd) {
+		case MR_CMD_COLLECT:
+		  {
+		        MR_Event_Info	event_info;
+			Word		*saved_regs = event_info.MR_saved_regs;
+			int		max_r_num;
+			const char	*path;
+			bool    	stop_collecting = FALSE;
+
+
+			max_r_num = layout->MR_sll_entry->MR_sle_max_r_num;
+			if (max_r_num + MR_NUM_SPECIAL_REG > 
+					MR_MAX_SPECIAL_REG_MR) 
+			{
+				event_info.MR_max_mr_num = 
+					max_r_num + MR_NUM_SPECIAL_REG;
+			} else {
+				event_info.MR_max_mr_num = 
+					MR_MAX_SPECIAL_REG_MR;
+			}
+			
+			port = (MR_Trace_Port) layout->MR_sll_port;
+			path = layout->MR_sll_entry->MR_sle_module_layout
+				->MR_ml_string_table + layout->MR_sll_goal_path;
+			MR_copy_regs_to_saved_regs(event_info.MR_max_mr_num, 
+				saved_regs);
+			MR_trace_init_point_vars(layout, saved_regs, port);
+			MR_COLLECT_filter(seqno, depth, port, layout, 
+				path, &stop_collecting);
+			if (stop_collecting) {
+				MR_send_collect_result();
+				MR_send_message_to_socket(
+						"execution_continuing");
+				MR_trace_ctrl.MR_trace_cmd = MR_CMD_GOTO;
+				MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, 
+						saved_regs);
+				return MR_trace_event(&MR_trace_ctrl, TRUE,
+                                               layout, port, seqno, depth);
+			}
+			MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, 
+				saved_regs);
+
+			goto check_stop_print;
+		  }	
+
 		case MR_CMD_GOTO:
 			if (MR_trace_event_number >=
 					MR_trace_ctrl.MR_trace_stop_event)
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.21
diff -u -d -u -r1.21 mercury_trace.h
--- trace/mercury_trace.h	2001/02/13 08:28:27	1.21
+++ trace/mercury_trace.h	2001/03/05 17:30:14
@@ -129,6 +129,10 @@
 ** MR_trace_cmd says what mode the tracer is in, i.e. how events should be
 ** treated.
 **
+** If MR_trace_cmd == MR_CMD_COLLECT, the event handler calls MR_COLLECT_filter()
+** until the end of the execution is reached or until the `stop_collecting'
+** variable is set to TRUE. It is the tracer mode after a `collect' request.
+**
 ** If MR_trace_cmd == MR_CMD_GOTO, the event handler will stop at the next
 ** event whose event number is equal to or greater than MR_trace_stop_event.
 **
@@ -162,6 +166,7 @@
 */
 
 typedef enum {
+	MR_CMD_COLLECT,
 	MR_CMD_GOTO,
 	MR_CMD_NEXT,
 	MR_CMD_FINISH,
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.53
diff -u -d -u -r1.53 mercury_trace_external.c
--- trace/mercury_trace_external.c	2001/01/18 01:19:15	1.53
+++ trace/mercury_trace_external.c	2001/03/05 17:30:14
@@ -111,10 +111,9 @@
 ** (1) `MR_searching', it tries to find an event that matches a forward 
 **      move request,
 ** (2) `MR_reading_request', it reads a new request on the socket,
-** (3) `MR_collecting', it is collecting information (after a `collect' request).
 */
 typedef enum {
-	MR_searching, MR_reading_request, MR_collecting
+	MR_searching, MR_reading_request
 } MR_external_debugger_mode_type;
 
 static	MR_external_debugger_mode_type 
@@ -135,6 +134,15 @@
 static	void	(*send_collect_result_ptr)(MR_Word, MR_Word);
 
 /*
+** Function pointer which is applied to each event during collect requests.
+*/
+
+static void	(*filter_ptr)(MR_Integer, MR_Integer, MR_Integer, MR_Word,
+			MR_Word, MR_String, MR_String, MR_String, MR_Integer,
+			MR_Integer, MR_Word, MR_Integer, MR_String, MR_Word, 
+			MR_Word *, MR_Char *);
+
+/*
 ** Variable generated during the dynamic linking that is needed to close
 ** this linking properly.
 */
@@ -163,7 +171,6 @@
 static void MR_send_message_to_socket_format(const char *format, ...)
 	MR_LIKE_PRINTF(1, 2);
 
-static void	MR_send_message_to_socket(const char *message);
 static void	MR_read_request_from_socket(
 			MR_Word *debugger_request_ptr, 
 			MR_Integer *debugger_request_type_ptr);
@@ -203,15 +210,6 @@
 static void	MR_get_variable_name(MR_Word debugger_request,
 			MR_String *var_name_ptr);
 static void	MR_trace_browse_one_external(MR_Var_Spec which_var);
-static void	MR_COLLECT_filter(void (*filter_ptr)(MR_Integer, MR_Integer,
-			MR_Integer, MR_Word, MR_Word, MR_String, MR_String,
-			MR_String, MR_Integer, MR_Integer, MR_Word, MR_Integer,
-			MR_String, MR_Word, MR_Word *, MR_Char *),
-			MR_Unsigned seqno, MR_Unsigned depth,
-			MR_Trace_Port port, 
-			const MR_Label_Layout *layout, const char *path, 
-			bool *stop_collecting);
-static void	MR_send_collect_result(void);
 
 #if 0
 This pseudocode should go in the debugger process:
@@ -457,7 +455,7 @@
 			MR_send_message_to_socket("forward_move_match_not_found");
 			break;
 
-		case MR_collecting:
+		case MR_reading_request:
 			MR_send_collect_result();
 			MR_send_message_to_socket("execution_terminated");
 			break;
@@ -477,17 +475,11 @@
 MR_Code *
 MR_trace_event_external(MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info)
 {
-	static	MR_Word		search_data;
-	static	void		(*initialize_ptr)(MR_Word *);
-	static	void    	(*filter_ptr)(MR_Integer, MR_Integer,
-					MR_Integer, MR_Word, MR_Word,
-					MR_String, MR_String, MR_String,
-					MR_Integer, MR_Integer, MR_Word,
-					MR_Integer, MR_String, MR_Word,
-					MR_Word *, MR_Char *);
-	static	void		(*get_collect_var_type_ptr)(MR_Word *);
-	static	bool    	collect_linked = FALSE;
-	bool    		stop_collecting = FALSE;
+	static MR_Word	search_data;
+	static void	(*initialize_ptr)(MR_Word *);
+	static void	(*get_collect_var_type_ptr)(MR_Word *);
+	static bool    	collect_linked = FALSE;
+	bool    	stop_collecting = FALSE;
 	MR_Integer		debugger_request_type;
 	MR_Word			debugger_request;
 	MR_Word			var_list;
@@ -543,18 +535,6 @@
 			}
 			break;
 
-		case MR_collecting:
-		 
-			MR_COLLECT_filter(*filter_ptr, seqno, depth, port,
-				layout, path, &stop_collecting);
-
-			if (stop_collecting) {
-				MR_send_collect_result();
-				MR_send_message_to_socket("execution_continuing");
-				break;
-			} else {
-				goto done;
-			}
 		case MR_reading_request:
 			break;
 
@@ -816,9 +796,7 @@
 						"REQUEST_COLLECT\n");
 				}
 				if (collect_linked) {
-					MR_send_message_to_socket(
-						"collect_linked");
-					external_debugger_mode = MR_collecting;
+					MR_send_message_to_socket("collect_linked");
 					MR_TRACE_CALL_MERCURY(
 					  (*initialize_ptr)(&MR_collecting_variable));
 
@@ -827,7 +805,7 @@
 					** the current event, we need to call 
 					** filter once here.
 					*/
-					MR_COLLECT_filter(*filter_ptr, seqno, depth,
+					MR_COLLECT_filter(seqno, depth,
 						port, layout, path, &stop_collecting);
 					
 					if (stop_collecting) {
@@ -836,6 +814,16 @@
 							"execution_continuing");
 						break;
 					} else {
+					/*
+					** For efficiency, the remaining calls
+					** to MR_COLLECT_filter() are done in 
+					** MR_trace_real().
+					*/
+					        cmd->MR_trace_cmd = MR_CMD_COLLECT;
+						cmd->MR_trace_must_check = FALSE;
+						cmd->MR_trace_strict = TRUE;
+						cmd->MR_trace_print_level = 
+						 	MR_PRINT_LEVEL_NONE;
 						goto done;
 					}
 				} else {
@@ -1072,7 +1060,7 @@
 	MR_line_number(MR_debugger_socket_out)++;
 }
 
-static void
+void
 MR_send_message_to_socket(const char *message)
 {
 	fprintf(MR_file(MR_debugger_socket_out), "%s.\n", message);
@@ -1477,11 +1465,8 @@
 ** This function calls the collect filtering predicate defined by the user
 ** and dynamically link with the execution.
 */
-static void
-MR_COLLECT_filter(void (*filter_ptr)(MR_Integer, MR_Integer, MR_Integer,
-	MR_Word, MR_Word, MR_String, MR_String, MR_String, MR_Integer,
-	MR_Integer, MR_Word, MR_Integer, MR_String, MR_Word, MR_Word *,
-	MR_Char *), MR_Unsigned seqno, MR_Unsigned depth, MR_Trace_Port port, 
+void
+MR_COLLECT_filter(MR_Unsigned seqno, MR_Unsigned depth, MR_Trace_Port port, 
 	const MR_Label_Layout *layout, const char *path, 
 	bool *stop_collecting)
 {
@@ -1504,7 +1489,7 @@
 			arguments = MR_list_empty()
 		);
 	}
-	MR_TRACE_CALL_MERCURY((*filter_ptr)(
+	(*filter_ptr)(
 		MR_trace_event_number,
 		seqno,
 		depth,
@@ -1520,11 +1505,11 @@
 		(MR_String) path,
 		MR_collecting_variable,
 		&MR_collecting_variable,
-		&result));
+		&result);
 	*stop_collecting = (result == 'y');
 }
 
-static void
+void
 MR_send_collect_result(void)
 {
 	MR_TRACE_CALL_MERCURY(
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.9
diff -u -d -u -r1.9 mercury_trace_external.h
--- trace/mercury_trace_external.h	2001/02/13 08:28:27	1.9
+++ trace/mercury_trace_external.h	2001/03/05 17:30:14
@@ -14,10 +14,16 @@
 
 #ifdef	MR_USE_EXTERNAL_DEBUGGER
 
+extern  void	MR_send_message_to_socket(const char *message);
 extern	void	MR_trace_init_external(void);
 extern	void	MR_trace_final_external(void);
 extern	MR_Code	*MR_trace_event_external(MR_Trace_Cmd_Info *cmd,
 			MR_Event_Info *event_info);
+extern void	MR_COLLECT_filter(MR_Unsigned seqno, 
+			MR_Unsigned depth, MR_Trace_Port port, 
+			const MR_Label_Layout *layout, const char *path, 
+			bool *stop_collecting);
+extern void	MR_send_collect_result(void);
 
 /*
 ** External debugger socket streams.

-- 
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