[m-rev.] for review: add value-threshold of top procedures to deep profiler.

Paul Bone pbone at csse.unimelb.edu.au
Wed Sep 26 15:06:08 AEST 2007


Thanks Julien.

I've made the changes you've recomended.  I was unable to make the
change Peter recomended.  The new log and diff are below.  I would feel
better if it was reviewed once more before I commit it, if that's ok.

Thanks.

Estimated hours taken: 1.5 

Branches: main

Add the ability to select top procedures in the deep profiling tool based on a
raw threshold rather than a percentage.  This will be useful when selecting
procedures to be implicitly parallelized.  Add links to the top-level screen of
the deep profiler for accessing this feature.

deep_profiler/interface.m
    Added extra value for display_limit type, threshold_value to represent this
    new value-based threshold of procedures.
    Alter string conversion predicates for limits to include this new value and
    ensure it's distinct from existing values.

deep_profiler/query.m:
    Added links to main screen to access reports using this feature.  Default
    thresholds have been chosen.

deep_profiler/top_procs.m:
    Altered find_top_procs to accept this new display_limit and properly 
    exclude procedures below the value threshold.
    Added new predicate find_threshold_value_predicate which reference new 
    predicates to select rows above the threshold value.
    Renamed existing find_threshold_predicate to
    find_threshold_percent_predicate, as well as the predicates it looks up.


Index: deep_profiler/interface.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/interface.m,v
retrieving revision 1.17
diff -u -u -r1.17 interface.m
--- deep_profiler/interface.m	2 Apr 2007 02:42:32 -0000	1.17
+++ deep_profiler/interface.m	26 Sep 2007 05:00:49 -0000
@@ -167,9 +167,13 @@
             % rank_range(M, N): display procedures with rank M to N,
             % both inclusive.
 
-    ;       threshold(float).
+    ;       threshold_percent(float)
             % threshold(Percent): display procedures whose cost is at least
             % Percent% of the whole program's cost.
+    
+    ;       threshold_value(float).
+            % threshold_value(Value): display procedures whose cost is at least
+            % this value.
 
 :- type preferences_indication
     --->    given_pref(preferences)
@@ -969,8 +973,10 @@
 
 limit_to_string(rank_range(Lo, Hi)) =
     string.format("%d%c%d", [i(Lo), c(limit_separator_char), i(Hi)]).
-limit_to_string(threshold(Threshold)) =
-    string.format("%g", [f(Threshold)]).
+limit_to_string(threshold_percent(Threshold)) =
+    string.format("p%g", [f(Threshold)]).
+limit_to_string(threshold_value(Value)) =
+    string.format("v%g", [f(Value)]).
 
 :- pred string_to_limit(string::in, display_limit::out) is semidet.
 
@@ -983,9 +989,15 @@
     ->
         Limit = rank_range(First, Last)
     ;
-        string.to_float(LimitStr, Threshold)
+        string.append("p", PercentStr, LimitStr),
+        string.to_float(PercentStr, Threshold)
     ->
-        Limit = threshold(Threshold)
+        Limit = threshold_percent(Threshold)
+    ;
+        string.append("v", ValueStr, LimitStr),
+        string.to_float(ValueStr, Value)
+    ->
+        Limit = threshold_value(Value)
     ;
         fail
     ).
Index: deep_profiler/query.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/query.m,v
retrieving revision 1.16
diff -u -u -r1.16 query.m
--- deep_profiler/query.m	2 Apr 2007 06:10:43 -0000	1.16
+++ deep_profiler/query.m	26 Sep 2007 05:00:51 -0000
@@ -40,6 +40,7 @@
 :- import_module assoc_list.
 :- import_module bool.
 :- import_module exception.
+:- import_module float.
 :- import_module int.
 :- import_module list.
 :- import_module map.
@@ -384,36 +385,59 @@
         ( ShouldDisplayTimes = yes ->
             "<li>\n" ++
             menu_item(Deep, Pref,
-                deep_cmd_top_procs(threshold(0.1), cost_time, self, overall),
+                deep_cmd_top_procs(threshold_percent(0.1), cost_time, self, 
+                    overall),
                 "Procedures above 0.1% threshold: time, self.") ++
             "<li>\n" ++
             menu_item(Deep, Pref,
-                deep_cmd_top_procs(threshold(1.0), cost_time, self_and_desc,
-                    overall),
-                "Procedures above 1% threshold: time, self+descendants.")
+                deep_cmd_top_procs(threshold_percent(1.0), cost_time, 
+                    self_and_desc, overall),
+                "Procedures above 1% threshold: time, self+descendants.") ++
+            "<li>\n" ++
+            menu_item(Deep, Pref,
+                deep_cmd_top_procs(threshold_value(100.0), cost_time, 
+                    self_and_desc, overall),
+                "Procedures above 1 second threshold: " ++ 
+                    "time, self+descendants.")
         ;
             ""
         ) ++
         "<li>\n" ++
         menu_item(Deep, Pref,
-            deep_cmd_top_procs(threshold(0.1), cost_callseqs, self, overall),
+            deep_cmd_top_procs(threshold_percent(0.1), cost_callseqs, self, 
+                overall),
             "Procedures above 0.1% threshold: callseqs, self.") ++
         "<li>\n" ++
         menu_item(Deep, Pref,
-            deep_cmd_top_procs(threshold(1.0), cost_callseqs, self_and_desc,
-                overall),
+            deep_cmd_top_procs(threshold_percent(1.0), cost_callseqs, 
+                self_and_desc, overall),
             "Procedures above 1% threshold: callseqs, self+descendants.")
             ++
         "<li>\n" ++
         menu_item(Deep, Pref,
-            deep_cmd_top_procs(threshold(0.1), cost_words, self, overall),
-            "Procedures above 0.1% threshold: words, self.") ++
+            deep_cmd_top_procs(threshold_value(1000000.0), cost_callseqs, 
+                self_and_desc, overall),
+            "Procedures above 1,000,000 callseqs threshold: callseqs, " ++
+                "self+descendants.")
+            ++
         "<li>\n" ++
         menu_item(Deep, Pref,
-            deep_cmd_top_procs(threshold(1.0), cost_words, self_and_desc,
+            deep_cmd_top_procs(threshold_percent(0.1), cost_words, self, 
                 overall),
+            "Procedures above 0.1% threshold: words, self.") ++
+        "<li>\n" ++
+        menu_item(Deep, Pref,
+            deep_cmd_top_procs(threshold_percent(1.0), cost_words, 
+                self_and_desc, overall),
             "Procedures above 1% threshold: words, self+descendants.")
             ++
+        "<li>\n" ++
+        % 2M words is chosen arbitrary because it is 8MB on ia32
+        menu_item(Deep, Pref,
+            deep_cmd_top_procs(threshold_value(float(1024 * 1024 * 2)), 
+                cost_words, self_and_desc, overall),
+            "Procedures above 2M words threshold: words, self+descendants.")
+            ++
         "</ul>\n" ++
         "<p>\n" ++
         present_stats(Deep) ++
Index: deep_profiler/top_procs.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/top_procs.m,v
retrieving revision 1.10
diff -u -u -r1.10 top_procs.m
--- deep_profiler/top_procs.m	1 Dec 2006 15:03:47 -0000	1.10
+++ deep_profiler/top_procs.m	26 Sep 2007 05:00:51 -0000
@@ -93,8 +93,23 @@
                 MaybeTopPSIs = ok([])
             )
         ;
-            Limit = threshold(Threshold),
-            find_threshold_predicate(Sort, InclDesc,
+            Limit = threshold_percent(Threshold),
+            find_threshold_percent_predicate(Sort, InclDesc,
+                ThresholdCompatible, RawThresholdPred),
+            (
+                ThresholdCompatible = no,
+                MaybeTopPSIs = error("bad threshold specification")
+            ;
+                ThresholdCompatible = yes,
+                ThresholdPred = (pred(PSI::in) is semidet :-
+                    RawThresholdPred(Deep, Threshold, PSI)
+                ),
+                list.takewhile(ThresholdPred, DescendingPSIs, TopPSIs, _),
+                MaybeTopPSIs = ok(TopPSIs)
+            )
+        ;
+            Limit = threshold_value(Threshold),
+            find_threshold_value_predicate(Sort, InclDesc,
                 ThresholdCompatible, RawThresholdPred),
             (
                 ThresholdCompatible = no,
@@ -198,39 +213,73 @@
 find_top_sort_predicate(cost_words,  self_and_desc, per_call, yes,
     compare_ps_words_both_percall,  filter_ps_words_both).
 
-:- pred find_threshold_predicate(cost_kind::in, include_descendants::in,
+:- pred find_threshold_percent_predicate(cost_kind::in, include_descendants::in,
     bool::out, pred(deep, float, int)::out(pred(in, in, in) is semidet))
     is det.
 
-find_threshold_predicate(cost_calls,  self,          no,
-    threshold_ps_time_self).
-find_threshold_predicate(cost_calls,  self_and_desc, no,
-    threshold_ps_time_self).
-
-find_threshold_predicate(cost_redos,  self,          no,
-    threshold_ps_time_self).
-find_threshold_predicate(cost_redos,  self_and_desc, no,
-    threshold_ps_time_self).
-
-find_threshold_predicate(cost_time,   self,          yes,
-    threshold_ps_time_self).
-find_threshold_predicate(cost_time,   self_and_desc, yes,
-    threshold_ps_time_both).
-
-find_threshold_predicate(cost_callseqs, self,          yes,
-    threshold_ps_callseqs_self).
-find_threshold_predicate(cost_callseqs, self_and_desc, yes,
-    threshold_ps_callseqs_both).
-
-find_threshold_predicate(cost_allocs, self,          yes,
-    threshold_ps_allocs_self).
-find_threshold_predicate(cost_allocs, self_and_desc, yes,
-    threshold_ps_allocs_both).
-
-find_threshold_predicate(cost_words,  self,          yes,
-    threshold_ps_words_self).
-find_threshold_predicate(cost_words,  self_and_desc, yes,
-    threshold_ps_words_both).
+find_threshold_percent_predicate(cost_calls,  self,          no,
+    threshold_percent_ps_time_self).
+find_threshold_percent_predicate(cost_calls,  self_and_desc, no,
+    threshold_percent_ps_time_self).
+
+find_threshold_percent_predicate(cost_redos,  self,          no,
+    threshold_percent_ps_time_self).
+find_threshold_percent_predicate(cost_redos,  self_and_desc, no,
+    threshold_percent_ps_time_self).
+
+find_threshold_percent_predicate(cost_time,   self,          yes,
+    threshold_percent_ps_time_self).
+find_threshold_percent_predicate(cost_time,   self_and_desc, yes,
+    threshold_percent_ps_time_both).
+
+find_threshold_percent_predicate(cost_callseqs, self,          yes,
+    threshold_percent_ps_callseqs_self).
+find_threshold_percent_predicate(cost_callseqs, self_and_desc, yes,
+    threshold_percent_ps_callseqs_both).
+
+find_threshold_percent_predicate(cost_allocs, self,          yes,
+    threshold_percent_ps_allocs_self).
+find_threshold_percent_predicate(cost_allocs, self_and_desc, yes,
+    threshold_percent_ps_allocs_both).
+
+find_threshold_percent_predicate(cost_words,  self,          yes,
+    threshold_percent_ps_words_self).
+find_threshold_percent_predicate(cost_words,  self_and_desc, yes,
+    threshold_percent_ps_words_both).
+
+:- pred find_threshold_value_predicate(cost_kind::in, include_descendants::in,
+    bool::out, pred(deep, float, int)::out(pred(in, in, in) is semidet))
+    is det.
+
+find_threshold_value_predicate(cost_calls,  self,          no,
+    threshold_value_ps_time_self).
+find_threshold_value_predicate(cost_calls,  self_and_desc, no,
+    threshold_value_ps_time_self).
+
+find_threshold_value_predicate(cost_redos,  self,          no,
+    threshold_value_ps_time_self).
+find_threshold_value_predicate(cost_redos,  self_and_desc, no,
+    threshold_value_ps_time_self).
+
+find_threshold_value_predicate(cost_time,   self,          yes,
+    threshold_value_ps_time_self).
+find_threshold_value_predicate(cost_time,   self_and_desc, yes,
+    threshold_value_ps_time_both).
+
+find_threshold_value_predicate(cost_callseqs, self,          yes,
+    threshold_value_ps_callseqs_self).
+find_threshold_value_predicate(cost_callseqs, self_and_desc, yes,
+    threshold_value_ps_callseqs_both).
+
+find_threshold_value_predicate(cost_allocs, self,          yes,
+    threshold_value_ps_allocs_self).
+find_threshold_value_predicate(cost_allocs, self_and_desc, yes,
+    threshold_value_ps_allocs_both).
+
+find_threshold_value_predicate(cost_words,  self,          yes,
+    threshold_value_ps_words_self).
+find_threshold_value_predicate(cost_words,  self_and_desc, yes,
+    threshold_value_ps_words_both).
 
 %-----------------------------------------------------------------------------%
 
@@ -602,9 +651,93 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred threshold_ps_time_self(deep::in, float::in, int::in) is semidet.
+:- pred threshold_value_ps_time_self(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_time_self(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    array.lookup(PSOwn, PSI, Own),
+    OwnQuanta = quanta(Own),
+    float(OwnQuanta) > Threshold.
+
+:- pred threshold_value_ps_time_both(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_time_both(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    PSDesc = Deep ^ ps_desc,
+    array.lookup(PSOwn, PSI, Own),
+    array.lookup(PSDesc, PSI, Desc),
+    OwnQuanta = quanta(Own),
+    DescQuanta = inherit_quanta(Desc),
+    TotalQuanta = OwnQuanta + DescQuanta,
+    float(TotalQuanta) > Threshold.
+
+:- pred threshold_value_ps_callseqs_self(deep::in, float::in, int::in) 
+    is semidet.
+
+threshold_value_ps_callseqs_self(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    array.lookup(PSOwn, PSI, Own),
+    OwnCallSeqs = callseqs(Own),
+    float(OwnCallSeqs) > Threshold.
+
+:- pred threshold_value_ps_callseqs_both(deep::in, float::in, int::in) 
+    is semidet.
+
+threshold_value_ps_callseqs_both(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    PSDesc = Deep ^ ps_desc,
+    array.lookup(PSOwn, PSI, Own),
+    array.lookup(PSDesc, PSI, Desc),
+    OwnCallSeqs = callseqs(Own),
+    DescCallSeqs = inherit_callseqs(Desc),
+    TotalCallSeqs = OwnCallSeqs + DescCallSeqs,
+    float(TotalCallSeqs) > Threshold.
+
+:- pred threshold_value_ps_allocs_self(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_allocs_self(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    array.lookup(PSOwn, PSI, Own),
+    OwnAlloc = allocs(Own),
+    float(OwnAlloc) > Threshold.
+
+:- pred threshold_value_ps_allocs_both(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_allocs_both(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    PSDesc = Deep ^ ps_desc,
+    array.lookup(PSOwn, PSI, Own),
+    array.lookup(PSDesc, PSI, Desc),
+    OwnAlloc = allocs(Own),
+    DescAlloc = inherit_allocs(Desc),
+    TotalAlloc = OwnAlloc + DescAlloc,
+    float(TotalAlloc) > Threshold.
+
+:- pred threshold_value_ps_words_self(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_words_self(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    array.lookup(PSOwn, PSI, Own),
+    OwnWords = words(Own),
+    float(OwnWords) > Threshold.
+
+:- pred threshold_value_ps_words_both(deep::in, float::in, int::in) is semidet.
+
+threshold_value_ps_words_both(Deep, Threshold, PSI) :-
+    PSOwn = Deep ^ ps_own,
+    PSDesc = Deep ^ ps_desc,
+    array.lookup(PSOwn, PSI, Own),
+    array.lookup(PSDesc, PSI, Desc),
+    OwnWords = words(Own),
+    DescWords = inherit_words(Desc),
+    TotalWords = OwnWords + DescWords,
+    float(TotalWords) > Threshold.
+
+%-----------------------------------------------------------------------------%
+
+:- pred threshold_percent_ps_time_self(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_time_self(Deep, Threshold, PSI) :-
+threshold_percent_ps_time_self(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     array.lookup(PSOwn, PSI, Own),
     RootOwn = root_own_info(Deep),
@@ -615,9 +748,9 @@
     RootTotalQuanta = RootOwnQuanta + RootDescQuanta,
     100.0 * float(OwnQuanta) > Threshold * float(RootTotalQuanta).
 
-:- pred threshold_ps_time_both(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_time_both(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_time_both(Deep, Threshold, PSI) :-
+threshold_percent_ps_time_both(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     PSDesc = Deep ^ ps_desc,
     array.lookup(PSOwn, PSI, Own),
@@ -632,9 +765,9 @@
     RootTotalQuanta = RootOwnQuanta + RootDescQuanta,
     100.0 * float(TotalQuanta) > Threshold * float(RootTotalQuanta).
 
-:- pred threshold_ps_callseqs_self(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_callseqs_self(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_callseqs_self(Deep, Threshold, PSI) :-
+threshold_percent_ps_callseqs_self(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     array.lookup(PSOwn, PSI, Own),
     RootOwn = root_own_info(Deep),
@@ -645,9 +778,9 @@
     RootTotalCallSeqs = RootOwnCallSeqs + RootDescCallSeqs,
     100.0 * float(OwnCallSeqs) > Threshold * float(RootTotalCallSeqs).
 
-:- pred threshold_ps_callseqs_both(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_callseqs_both(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_callseqs_both(Deep, Threshold, PSI) :-
+threshold_percent_ps_callseqs_both(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     PSDesc = Deep ^ ps_desc,
     array.lookup(PSOwn, PSI, Own),
@@ -662,9 +795,9 @@
     RootTotalCallSeqs = RootOwnCallSeqs + RootDescCallSeqs,
     100.0 * float(TotalCallSeqs) > Threshold * float(RootTotalCallSeqs).
 
-:- pred threshold_ps_allocs_self(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_allocs_self(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_allocs_self(Deep, Threshold, PSI) :-
+threshold_percent_ps_allocs_self(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     array.lookup(PSOwn, PSI, Own),
     RootOwn = root_own_info(Deep),
@@ -675,9 +808,9 @@
     RootTotalAlloc = RootOwnAlloc + RootDescAlloc,
     100.0 * float(OwnAlloc) > Threshold * float(RootTotalAlloc).
 
-:- pred threshold_ps_allocs_both(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_allocs_both(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_allocs_both(Deep, Threshold, PSI) :-
+threshold_percent_ps_allocs_both(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     PSDesc = Deep ^ ps_desc,
     array.lookup(PSOwn, PSI, Own),
@@ -692,9 +825,9 @@
     RootTotalAlloc = RootOwnAlloc + RootDescAlloc,
     100.0 * float(TotalAlloc) > Threshold * float(RootTotalAlloc).
 
-:- pred threshold_ps_words_self(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_words_self(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_words_self(Deep, Threshold, PSI) :-
+threshold_percent_ps_words_self(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     array.lookup(PSOwn, PSI, Own),
     RootOwn = root_own_info(Deep),
@@ -705,9 +838,9 @@
     RootTotalWords = RootOwnWords + RootDescWords,
     100.0 * float(OwnWords) > Threshold * float(RootTotalWords).
 
-:- pred threshold_ps_words_both(deep::in, float::in, int::in) is semidet.
+:- pred threshold_percent_ps_words_both(deep::in, float::in, int::in) is semidet.
 
-threshold_ps_words_both(Deep, Threshold, PSI) :-
+threshold_percent_ps_words_both(Deep, Threshold, PSI) :-
     PSOwn = Deep ^ ps_own,
     PSDesc = Deep ^ ps_desc,
     array.lookup(PSOwn, PSI, Own),
--------------------------------------------------------------------------
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