[m-rev.] for post-commit review: deep profiling action log

Zoltan Somogyi zs at csse.unimelb.edu.au
Tue Nov 7 14:39:13 AEDT 2006


For review by Julien.

Zoltan.

runtime/mercury_deep_call_port_body.h:
runtime/mercury_deep_leave_port_body.h:
runtime/mercury_deep_redo_port_body.h:
	Add conditionally compiled code that can be used to generate a machine
	processable log of the updates to the deep profiling tree.

	Convert to four-space indentation.

runtime/mercury_deep_profiling.[ch]:
	Add support for the new code in the port bodies, and add a mechanism
	for writing out proc statics and call sites statics at the start of the
	same machine processable log.

runtime/mercury_wrapper.c:
	Switch on the new debugging mechanism if the --deep-log-file
	or --deep-log-prog option is given in MERCURY_OPTIONS.

runtime/mercury_conf_param.h:
	Document the mecro controlling the new logging mechanism.

cvs diff: Diffing .
Index: mercury_conf_param.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.90
diff -u -b -r1.90 mercury_conf_param.h
--- mercury_conf_param.h	1 Nov 2006 02:31:12 -0000	1.90
+++ mercury_conf_param.h	7 Nov 2006 03:14:37 -0000
@@ -200,6 +200,10 @@
 **	(integers, strings, pointers, etc) of the deep profiling data
 **	structures.
 **
+** MR_DEEP_PROFILING_LOG
+**	Enables the code that writes out a log of the actions of the deep
+**	profiling code.
+**
 ** MR_DEBUG_DD_BACK_END
 **	Enables low-level debugging messages on the operation of the
 **	declarative debugging back end.
Index: mercury_deep_call_port_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_call_port_body.h,v
retrieving revision 1.7
diff -u -b -r1.7 mercury_deep_call_port_body.h
--- mercury_deep_call_port_body.h	11 Oct 2006 22:42:09 -0000	1.7
+++ mercury_deep_call_port_body.h	6 Nov 2006 06:55:52 -0000
@@ -1,4 +1,7 @@
 /*
+** vim: ts=4 sw=4 expandtab
+*/
+/*
 ** Copyright (C) 2001-2002, 2004, 2006 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
@@ -51,6 +54,16 @@
 	}
   #endif
 
+  #ifdef MR_DEEP_PROFILING_LOG
+    if (MR_deep_prof_log_file != NULL) {
+        fprintf(MR_deep_prof_log_file, "callport(%ld,%ld,%ld).\n",
+            (long) MR_current_call_site_dynamic,
+            (long) MR_next_call_site_dynamic,
+            (long) ((const MR_Proc_Layout *) ProcLayout)->MR_sle_proc_static);
+        fflush(MR_deep_prof_log_file);
+    }
+  #endif
+
 	TopCSD = (MR_Word) MR_current_call_site_dynamic;
 	MiddleCSD = (MR_Word) MR_next_call_site_dynamic;
 
@@ -83,8 +96,7 @@
 	ps = pl->MR_sle_proc_static;
 	MR_deep_assert(csd, pl, ps, ps != NULL);
   #ifdef MR_VERSION_SR
-	OldOutermostActivationPtr =
-		(MR_Word) ps->MR_ps_outermost_activation_ptr;
+    OldOutermostActivationPtr = (MR_Word) ps->MR_ps_outermost_activation_ptr;
   #endif
 
   #if defined(MR_VERSION_AC)
@@ -104,8 +116,7 @@
 
 	if (csd->MR_csd_callee_ptr != NULL) {
 		if (ps->MR_ps_activation_count == 0) {
-			ps->MR_ps_outermost_activation_ptr =
-				csd->MR_csd_callee_ptr;
+            ps->MR_ps_outermost_activation_ptr = csd->MR_csd_callee_ptr;
 		}
 	} else if (ps->MR_ps_activation_count > 0) {
 		csd->MR_csd_callee_ptr = ps->MR_ps_outermost_activation_ptr;
@@ -152,8 +163,7 @@
   #endif
 
   #ifdef MR_NEED_NEW_OUTERMOST
-	NewOutermostActivationPtr =
-		(MR_Word) ps->MR_ps_outermost_activation_ptr;
+    NewOutermostActivationPtr = (MR_Word) ps->MR_ps_outermost_activation_ptr;
   #endif
 
 	MR_leave_instrumentation();
Index: mercury_deep_leave_port_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_leave_port_body.h,v
retrieving revision 1.6
diff -u -b -r1.6 mercury_deep_leave_port_body.h
--- mercury_deep_leave_port_body.h	11 Oct 2006 22:42:09 -0000	1.6
+++ mercury_deep_leave_port_body.h	6 Nov 2006 06:56:13 -0000
@@ -1,4 +1,7 @@
 /*
+** vim: ts=4 sw=4 expandtab
+*/
+/*
 ** Copyright (C) 2001-2002, 2004, 2006 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
@@ -64,6 +67,24 @@
 	ps = pl->MR_sle_proc_static;
 	MR_deep_assert(csd, pl, ps, ps != NULL);
 
+  #ifdef MR_DEEP_PROFILING_LOG
+    if (MR_deep_prof_log_file != NULL) {
+        const char  *portname;
+
+    #if defined(MR_FAIL_PORT)
+        portname = "failport";
+    #elif defined(MR_EXIT_PORT)
+        portname = "exitport";
+    #else
+        portname = "otherleaveport";
+    #endif
+        fprintf(MR_deep_prof_log_file, "%s(%ld,%ld,%ld).\n",
+            portname, (long) MR_current_call_site_dynamic,
+            (long) (MR_CallSiteDynamic *) TopCSD, (long) ps);
+        fflush(MR_deep_prof_log_file);
+    }
+  #endif
+
   #if defined(MR_VERSION_AC)
     #ifdef MR_USE_ACTIVATION_COUNTS
 	/* decrement activation count */
Index: mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.24
diff -u -b -r1.24 mercury_deep_profiling.c
--- mercury_deep_profiling.c	11 Oct 2006 22:42:09 -0000	1.24
+++ mercury_deep_profiling.c	6 Nov 2006 13:13:19 -0000
@@ -146,6 +146,10 @@
 
 #endif  /* MR_DEEP_PROFILING_STATISTICS */
 
+#ifdef MR_DEEP_PROFILING_LOG
+FILE    *MR_deep_prof_log_file = NULL;
+#endif
+
 void
 MR_deep_assert_failed(const MR_CallSiteDynamic *csd, const MR_Proc_Layout *pl,
     const MR_ProcStatic *ps, const char *cond,
@@ -666,6 +670,18 @@
     MR_write_out_proc_static(fp, (const MR_Proc_Layout *) proc_layout);
 }
 
+#ifdef  MR_DEEP_PROFILING_LOG
+MR_bool MR_deep_prof_doing_logging = MR_FALSE;
+
+void
+MR_deep_log_proc_statics(FILE *fp)
+{
+    MR_deep_prof_doing_logging = MR_TRUE;
+    (*MR_address_of_write_out_proc_statics)(fp);
+    MR_deep_prof_doing_logging = MR_FALSE;
+}
+#endif  /* MR_DEEP_PROFILING_LOG */
+
 void
 MR_write_out_proc_static(FILE *fp, const MR_Proc_Layout *proc_layout)
 {
@@ -685,6 +701,80 @@
     }
 
     ps = proc_layout->MR_sle_proc_static;
+
+#ifdef  MR_DEEP_PROFILING_LOG
+    if (MR_deep_prof_doing_logging) {
+        procid = &proc_layout->MR_sle_proc_id;
+        if (MR_PROC_ID_IS_UCI(*procid)) {
+            fprintf(fp,
+                "proc_static_uci(%ld,\"%s\",\"%s\",\"%s\",\"%s\",%d,%d,[",
+                (long) proc_layout->MR_sle_proc_static,
+                procid->MR_proc_uci.MR_uci_type_name,
+                procid->MR_proc_uci.MR_uci_type_module,
+                procid->MR_proc_uci.MR_uci_def_module,
+                procid->MR_proc_uci.MR_uci_pred_name,
+                procid->MR_proc_uci.MR_uci_type_arity,
+                procid->MR_proc_uci.MR_uci_mode);
+        } else {
+            fprintf(fp,
+                "proc_static_user(%ld,%s,\"%s\",\"%s\",\"%s\",%d,%d,[",
+                (long) proc_layout->MR_sle_proc_static,
+                procid->MR_proc_user.MR_user_pred_or_func == MR_PREDICATE ?
+                    "p" : "f",
+                procid->MR_proc_user.MR_user_decl_module,
+                procid->MR_proc_user.MR_user_def_module,
+                procid->MR_proc_user.MR_user_name,
+                procid->MR_proc_user.MR_user_arity,
+                procid->MR_proc_user.MR_user_mode);
+        }
+
+        for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+            if (i == 0) {
+                fputs("\n\t", fp);
+            } else {
+                fputs(",\n\t", fp);
+            }
+
+            switch (ps->MR_ps_call_sites[i].MR_css_kind) {
+                case MR_normal_call:
+                    fprintf(fp, "css_normal(%ld, %ld)",
+                        (long) &ps->MR_ps_call_sites[i],
+                        (long) &ps->MR_ps_call_sites[i].
+                            MR_css_callee_ptr_if_known->MR_sle_proc_static);
+                    break;
+
+                case MR_special_call:
+                    fprintf(fp, "css_special(%ld)",
+                        (long) &ps->MR_ps_call_sites[i]);
+                    break;
+
+                case MR_higher_order_call:
+                    fprintf(fp, "css_higher_order(%ld)",
+                        (long) &ps->MR_ps_call_sites[i]);
+                    break;
+
+                case MR_method_call:
+                    fprintf(fp, "css_method(%ld)",
+                        (long) &ps->MR_ps_call_sites[i]);
+                    break;
+
+                case MR_callback:
+                    fprintf(fp, "css_callback(%ld)",
+                        (long) &ps->MR_ps_call_sites[i]);
+                    break;
+
+                default:
+                    fprintf(fp, "css_unknown(%ld)",
+                        (long) &ps->MR_ps_call_sites[i]);
+                    break;
+            }
+        }
+
+        fprintf(fp, "]).\n");
+        return;
+    }
+#endif
+
     if (ps == NULL) {
         procid = &proc_layout->MR_sle_proc_id;
         if (MR_PROC_ID_IS_UCI(*procid)) {
Index: mercury_deep_profiling.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_profiling.h,v
retrieving revision 1.15
diff -u -b -r1.15 mercury_deep_profiling.h
--- mercury_deep_profiling.h	4 Oct 2006 06:59:23 -0000	1.15
+++ mercury_deep_profiling.h	6 Nov 2006 11:46:15 -0000
@@ -352,6 +352,12 @@
 
 #endif	/* MR_DEEP_PROFILING_STATISTICS */
 
+#ifdef MR_DEEP_PROFILING_LOG
+extern	FILE	*MR_deep_prof_log_file;
+
+extern	void	MR_deep_log_proc_statics(FILE *fp);
+#endif
+
 extern	void	MR_deep_assert_failed(const MR_CallSiteDynamic *csd,
 			const MR_Proc_Layout *pl, const MR_ProcStatic *ps,
 			const char *cond, const char *filename,
Index: mercury_deep_redo_port_body.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_redo_port_body.h,v
retrieving revision 1.6
diff -u -b -r1.6 mercury_deep_redo_port_body.h
--- mercury_deep_redo_port_body.h	11 Oct 2006 22:42:09 -0000	1.6
+++ mercury_deep_redo_port_body.h	6 Nov 2006 06:56:32 -0000
@@ -1,4 +1,7 @@
 /*
+** vim: ts=4 sw=4 expandtab
+*/
+/*
 ** Copyright (C) 2001-2002, 2004, 2006 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
@@ -35,6 +38,19 @@
 	/* The matching parenthesis is at the end of the file */
   #endif
 
+  #ifdef MR_DEEP_PROFILING_LOG
+    if (MR_deep_prof_log_file != NULL) {
+        MR_CallSiteDynamic  *midcsd;
+
+        midcsd = (MR_CallSiteDynamic *) MiddleCSD;
+        fprintf(MR_deep_prof_log_file, "redoport(%ld,%ld,%ld).\n",
+            (long) MR_current_call_site_dynamic, (long) midcsd,
+            (long) midcsd->MR_csd_callee_ptr->MR_pd_proc_layout->
+                MR_sle_proc_static);
+        fflush(MR_deep_prof_log_file);
+    }
+  #endif
+
 	MR_enter_instrumentation();
 	csd = (MR_CallSiteDynamic *) MiddleCSD;
 	MR_current_call_site_dynamic = csd;
Index: mercury_wrapper.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.171
diff -u -b -r1.171 mercury_wrapper.c
--- mercury_wrapper.c	1 Nov 2006 02:31:15 -0000	1.171
+++ mercury_wrapper.c	6 Nov 2006 13:19:51 -0000
@@ -620,6 +620,12 @@
         MR_deep_prof_init();
         MR_deep_prof_turn_on_time_profiling();
     }
+
+  #ifdef  MR_DEEP_PROFILING_LOG
+    if (MR_deep_prof_log_file != NULL) {
+        MR_deep_log_proc_statics(MR_deep_prof_log_file);
+    }
+  #endif
 #endif
 
 #ifdef  MR_RECORD_TERM_SIZES
@@ -1070,6 +1076,8 @@
     MR_NUM_OUTPUT_ARGS,
     MR_DEBUG_THREADS_OPT,
     MR_DEEP_PROF_DEBUG_FILE_OPT,
+    MR_DEEP_PROF_LOG_FILE_OPT,
+    MR_DEEP_PROF_LOG_PROG_OPT,
     MR_TABLING_STATISTICS_OPT,
     MR_TRACE_COUNT_OPT,
     MR_TRACE_COUNT_IF_EXEC_OPT,
@@ -1156,6 +1164,8 @@
     { "num-output-args",                1, 0, MR_NUM_OUTPUT_ARGS },
     { "debug-threads",                  0, 0, MR_DEBUG_THREADS_OPT },
     { "deep-debug-file",                0, 0, MR_DEEP_PROF_DEBUG_FILE_OPT },
+    { "deep-log-file",                  1, 0, MR_DEEP_PROF_LOG_FILE_OPT },
+    { "deep-log-prog",                  1, 0, MR_DEEP_PROF_LOG_PROG_OPT },
     { "tabling-statistics",             0, 0, MR_TABLING_STATISTICS_OPT },
     { "trace-count",                    0, 0, MR_TRACE_COUNT_OPT },
     { "trace-count-if-exec",            1, 0, MR_TRACE_COUNT_IF_EXEC_OPT },
@@ -1586,6 +1596,38 @@
                 MR_deep_prof_debug_file_flag = MR_TRUE;
                 break;
 
+            case MR_DEEP_PROF_LOG_FILE_OPT:
+#if defined(MR_DEEP_PROFILING) && defined(MR_DEEP_PROFILING_LOG)
+                MR_deep_prof_log_file = fopen(MR_optarg, "w");
+                if (MR_deep_prof_log_file == NULL) {
+                    perror(MR_optarg);
+                    exit(1);
+                }
+#else
+                printf("Mercury runtime: `--deep-log-file' is specified "
+                    "in MERCURY_OPTIONS\n");
+                printf("but support for it is not enabled.\n");  
+                fflush(stdout);
+                exit(1);
+#endif
+                break;
+
+            case MR_DEEP_PROF_LOG_PROG_OPT:
+#if defined(MR_DEEP_PROFILING) && defined(MR_DEEP_PROFILING_LOG)
+                MR_deep_prof_log_file = popen(MR_optarg, "w");
+                if (MR_deep_prof_log_file == NULL) {
+                    perror(MR_optarg);
+                    exit(1);
+                }
+#else
+                printf("Mercury runtime: `--deep-log-prog' is specified "
+                    "in MERCURY_OPTIONS\n");
+                printf("but support for it is not enabled.\n");  
+                fflush(stdout);
+                exit(1);
+#endif
+                break;
+
             case MR_TABLING_STATISTICS_OPT:
                 MR_print_table_statistics = MR_TRUE;
                 break;
@@ -2473,6 +2515,9 @@
     if (MR_deep_profiling_save_results) {
         MR_write_out_profiling_tree();
     }
+  #ifdef MR_DEEP_PROFILING_LOG
+    (void) fclose(MR_deep_prof_log_file);
+  #endif
 #endif
 
 #ifdef MR_RECORD_TERM_SIZES
cvs diff: Diffing GETOPT
cvs diff: Diffing machdeps
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list