[m-rev.] for review: display progress while in implicit subtrees
Ian MacLarty
maclarty at cs.mu.OZ.AU
Thu Aug 18 20:01:07 AEST 2005
This diff fixes a problem with showing progress in my recent speed
improvement to the declarative debugger. This diff will be committed together
with that diff, so I've included an interdiff of the CVS log message
and code.
I also rearranged the if statement inside MR_trace_real_decl_implicit_subtree
to be slightly more efficient.
Zoltan, I used this version for the paper benchmarks.
Ian.
For review by anyone.
--- CVSLOG.old 2005-08-13 23:45:57.000000000 +1000
+++ CVSLOG 2005-08-18 19:49:02.000000000 +1000
@@ -1,4 +1,4 @@
-Estimated hours taken: 5
+Estimated hours taken: 7
Branches: main
Speed up the declarative debugger by factoring out the code responsible for
@@ -42,3 +42,13 @@
Delete MR_trace_count_event_in_implicit_subtree since
MR_trace_real_decl_implicit_subtree now does this job.
+
+ Split the function which prints progress into two: one for printing
+ progress when generating a subtree and one for printing progress
+ when generating a supertree.
+
+ Define two macros which call the above functions. One macro
+ is called when inside and implicit subtree and one is called when
+ constructing nodes.
+
+ Print different messages when generating a subtree or a supertree.
diff -bu trace/mercury_trace.c trace/mercury_trace.c
--- trace/mercury_trace.c 14 Aug 2005 03:36:49 -0000
+++ trace/mercury_trace.c 14 Aug 2005 15:23:22 -0000
@@ -591,9 +591,10 @@
*/
MR_DD_CALC_NODE_DEPTH(port, node_depth, MR_edt_implicit_subtree_depth);
- if ((node_depth == 0) && MR_port_is_final(port)) {
+ if (node_depth < MR_edt_implicit_subtree_num_counters) {
MR_edt_implicit_subtree_counters[node_depth]++;
+ if ((node_depth == 0) && MR_port_is_final(port)) {
MR_selected_trace_func_ptr = MR_trace_real_decl;
{
@@ -602,11 +603,11 @@
/* MR_TRACE_EVENT_TEARDOWN returns jumpaddr */
MR_TRACE_EVENT_TEARDOWN
}
- } else {
- if (node_depth < MR_edt_implicit_subtree_num_counters) {
- MR_edt_implicit_subtree_counters[node_depth]++;
}
}
+
+ MR_DECL_MAYBE_UPDATE_PROGRESS_IMPLICIT_SUBTREE(MR_trace_event_number);
+
return NULL;
}
diff -bu trace/mercury_trace_declarative.c trace/mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c 14 Aug 2005 03:30:34 -0000
+++ trace/mercury_trace_declarative.c 14 Aug 2005 15:37:24 -0000
@@ -243,13 +243,6 @@
static MR_Unsigned MR_edt_initial_event;
/*
-** This variable indicates whether we are building a supertree above a
-** given event or a subtree rooted at a given event.
-*/
-
-static MR_bool MR_edt_building_supertree;
-
-/*
** The node returned to the front end once a subtree or supertree has been
** generated. If a supertree is generated then the implicit root in the
** new supertree that represents the existing tree is returned, otherwise
@@ -432,8 +425,6 @@
MR_Event_Info *event_info, MR_Unsigned depth);
static void MR_trace_maybe_update_implicit_tree_ideal_depth(
MR_Unsigned depth, MR_Trace_Node call);
-static void MR_trace_maybe_show_progress(
- MR_Unsigned event_number);
static void MR_trace_finish_progress(void);
static void MR_trace_init_implicit_subtree_counters(
MR_Unsigned size);
@@ -456,4 +447,6 @@
MR_Unsigned MR_edt_implicit_subtree_num_counters;
+MR_bool MR_edt_building_supertree;
+
/*
** This function is called for every traced event when building the
@@ -479,7 +472,7 @@
MR_trace_edt_build_sanity_check(event_info, entry);
- MR_trace_maybe_show_progress(event_info->MR_event_number);
+ MR_DECL_MAYBE_UPDATE_PROGRESS(MR_trace_event_number);
if (! MR_trace_include_event(entry, event_info, &jumpaddr)) {
return jumpaddr;
@@ -2217,21 +2210,17 @@
}
}
-static void
-MR_trace_maybe_show_progress(MR_Unsigned event_number)
+void
+MR_trace_show_progress_subtree(MR_Unsigned event_number)
{
MR_Unsigned current_tick;
- if (MR_mdb_decl_print_progress) {
- if (! MR_edt_building_supertree) {
- if (event_number % MR_DECL_PROGRESS_CHECK_INTERVAL == 0
- || event_number == MR_edt_last_event)
- {
- if (MR_edt_progress_last_tick == 0 &&
+ if (event_number != MR_edt_last_event &&
+ MR_edt_progress_last_tick == 0 &&
(MR_edt_start_time + MR_DECL_DISPLAY_PROGRESS_DELAY
< MR_get_user_cpu_miliseconds()))
{
- fprintf(MR_mdb_out, MR_DECL_PROGRESS_MESSAGE);
+ fprintf(MR_mdb_out, MR_DECL_PROGRESS_MESSAGE_SUBTREE);
fflush(MR_mdb_out);
/*
** We count the initial progress message as the first
@@ -2252,9 +2241,11 @@
}
}
}
- }
- } else {
- if (event_number % MR_DECL_PROGRESS_CHECK_INTERVAL == 0) {
+}
+
+void
+MR_trace_show_progress_supertree(MR_Unsigned event_number)
+{
/*
** If we are building a supertree we don't know what the
** final event will be, so we just show a tick every
@@ -2265,7 +2256,7 @@
(MR_edt_start_time + MR_DECL_DISPLAY_PROGRESS_DELAY
< MR_get_user_cpu_miliseconds()))
{
- fprintf(MR_mdb_out, MR_DECL_PROGRESS_MESSAGE);
+ fprintf(MR_mdb_out, MR_DECL_PROGRESS_MESSAGE_SUPERTREE);
fflush(MR_mdb_out);
MR_edt_progress_last_tick = 1;
} else if ((MR_edt_start_time
@@ -2277,9 +2268,6 @@
fprintf(MR_mdb_out, MR_DECL_PROGRESS_TICK_STRING);
fflush(MR_mdb_out);
}
- }
- }
- }
}
static void
diff -bu trace/mercury_trace_declarative.h trace/mercury_trace_declarative.h
--- trace/mercury_trace_declarative.h 14 Aug 2005 03:44:15 -0000
+++ trace/mercury_trace_declarative.h 14 Aug 2005 15:36:06 -0000
@@ -1,4 +1,7 @@
/*
+** vim: ts=4 sw=4 expandtab
+*/
+/*
** Copyright (C) 1998-2002, 2004-2005 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.
@@ -21,2 +24,10 @@
/*
+** The following functions update the progress indicator when building a
+** subtree or a supertree.
+*/
+
+extern void MR_trace_show_progress_subtree(MR_Unsigned event_number);
+extern void MR_trace_show_progress_supertree(MR_Unsigned event_number);
+
+/*
** The internal (interactive) debugger calls this function to enter
@@ -27,7 +38,8 @@
typedef enum { MR_DECL_NODUMP, MR_DECL_DUMP } MR_Decl_Mode;
-extern MR_bool MR_trace_start_decl_debug(MR_Decl_Mode mode, const char *out,
+extern MR_bool MR_trace_start_decl_debug(MR_Decl_Mode mode,
+ const char *out,
MR_bool new_session, MR_Trace_Cmd_Info *cmd,
MR_Event_Info *event_info,
MR_Event_Details *event_details, MR_Code **jumpaddr);
@@ -58,7 +70,8 @@
*/
extern void MR_decl_add_trusted_module(const char *module_name);
-extern void MR_decl_add_trusted_pred_or_func(const MR_Proc_Layout *entry);
+extern void MR_decl_add_trusted_pred_or_func(
+ const MR_Proc_Layout *entry);
extern void MR_decl_trust_standard_library(void);
extern MR_bool MR_decl_remove_trusted(int n);
@@ -148,6 +161,38 @@
extern MR_Unsigned MR_edt_implicit_subtree_num_counters;
/*
+** When building a new explicit tree we build it to the maximum depth such
+** that the number of nodes in the explicit tree is less than or equal to
+** MR_edt_desired_nodes_in_subtree.
+*/
+
+extern MR_Unsigned MR_edt_desired_nodes_in_subtree;
+
+/*
+** In the event that the ideal depth to build a tree to cannot be calculated,
+** either because it is the initial build of the annotated trace or a supertree
+** is being built, use the value of the following global as the depth limit.
+*/
+
+extern MR_Unsigned MR_edt_default_depth_limit;
+
+/*
+** The following variable indicates whether the declarative debugger was
+** invoked with the --debug option. It is needed so that the declarative
+** debugger can continue to be debugged after a new portion of the
+** annotated trace has been generated.
+*/
+
+extern MR_bool MR_trace_decl_debug_debugger_mode;
+
+/*
+** This variable indicates whether we are building a supertree above a
+** given event or a subtree rooted at a given event.
+*/
+
+extern MR_bool MR_edt_building_supertree;
+
+/*
** The following macros are provided to help C code manipulate the
** Mercury data structure. The values here must match the corresponding
** values in the definitions in browser/declarative_execution.m.
@@ -187,10 +232,13 @@
/*
** How often to update the progress message, expressed in terms of number of
-** events.
+** events. We define seperate intervals for when we are materializing
+** nodes and when we are in an implicit subtree, since execution is much
+** faster in implicit subtrees.
*/
#define MR_DECL_PROGRESS_CHECK_INTERVAL 100000
+#define MR_DECL_PROGRESS_CHECK_INTERVAL_IMPLICIT_SUBTREE 1000000
/*
** The total number of progress ticks that should be displayed when building of
@@ -204,7 +252,8 @@
** after the initial progress message.
*/
-#define MR_DECL_PROGRESS_MESSAGE "Generating execution trace.."
+#define MR_DECL_PROGRESS_MESSAGE_SUBTREE "Generating subtree.."
+#define MR_DECL_PROGRESS_MESSAGE_SUPERTREE "Generating supertree.."
#define MR_DECL_PROGRESS_TICK_STRING "."
/*
@@ -214,6 +263,52 @@
#define MR_DECL_DISPLAY_PROGRESS_DELAY 1000
/*
+** The following two macros decide when to display progress.
+** We define two version: one for when we are materializing nodes and one
+** for when we are in an implicit subtree, since execution is much faster in
+** implicit subtrees.
+** In the implicit tree version we don't need to check if the event is the
+** last event, since the last event will not be in an implicit subtree.
+** This means we can reorder the if-then-elses to be more efficient in
+** implicit subtrees. We also check to see if we should update the progress
+** less often when in an implicit subtree.
+** By defining these checks as macros we only incur the cost of a function call
+** when we need to update the progress.
+*/
+
+#define MR_DECL_MAYBE_UPDATE_PROGRESS(event_number) \
+ do { \
+ if (MR_mdb_decl_print_progress) { \
+ if(MR_edt_building_supertree) { \
+ if (event_number % MR_DECL_PROGRESS_CHECK_INTERVAL == 0) { \
+ MR_trace_show_progress_supertree(event_number); \
+ } \
+ } else { \
+ if (event_number % MR_DECL_PROGRESS_CHECK_INTERVAL == 0 \
+ || event_number == MR_edt_last_event) \
+ { \
+ MR_trace_show_progress_subtree(event_number); \
+ } \
+ } \
+ } \
+ } while(0)
+
+#define MR_DECL_MAYBE_UPDATE_PROGRESS_IMPLICIT_SUBTREE(event_number) \
+ do { \
+ if (event_number % MR_DECL_PROGRESS_CHECK_INTERVAL_IMPLICIT_SUBTREE \
+ == 0) \
+ { \
+ if (MR_mdb_decl_print_progress) { \
+ if (MR_edt_building_supertree) { \
+ MR_trace_show_progress_supertree(event_number); \
+ } else { \
+ MR_trace_show_progress_subtree(event_number); \
+ } \
+ } \
+ } \
+ } while (0)
+
+/*
** The following macro works out the depth of a node in the EDT.
** It also updates next_depth to the depth of the next node if that node is
** a final or internal event.
@@ -240,27 +335,2 @@
-/*
-** When building a new explicit tree we build it to the maximum depth such
-** that the number of nodes in the explicit tree is less than or equal to
-** MR_edt_desired_nodes_in_subtree.
-*/
-
-extern MR_Unsigned MR_edt_desired_nodes_in_subtree;
-
-/*
-** In the event that the ideal depth to build a tree to cannot be calculated,
-** either because it is the initial build of the annotated trace or a supertree
-** is being built, use the value of the following global as the depth limit.
-*/
-
-extern MR_Unsigned MR_edt_default_depth_limit;
-
-/*
-** The following variable indicates whether the declarative debugger was
-** invoked with the --debug option. It is needed so that the declarative
-** debugger can continue to be debugged after a new portion of the
-** annotated trace has been generated.
-*/
-
-extern MR_bool MR_trace_decl_debug_debugger_mode;
-
#endif /* MERCURY_TRACE_DECLARATIVE_H */
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list