From 6bdc0c76319dc6a67b056d0c8e92808262c90d06 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 5 Jan 2007 02:36:51 +0100 Subject: [PATCH] use a single function for asking profile info. --- input/regression/profile-property-access.ly | 24 +++++++++++------- lily/include/profile.hh | 2 ++ lily/include/program-option.hh | 1 - lily/prob.cc | 6 +++++ lily/profile.cc | 27 ++++++++++++--------- lily/program-option.cc | 1 + 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/input/regression/profile-property-access.ly b/input/regression/profile-property-access.ly index c46bbf58dc..641c24fe70 100644 --- a/input/regression/profile-property-access.ly +++ b/input/regression/profile-property-access.ly @@ -7,27 +7,33 @@ \version "2.10.8" -\include "../../input/typography-demo.ly" -%\book { \score { {c4 } } } +%\include "../../input/typography-demo.ly" +\book { \score { {c4 } } } #(define (prop-stats>? x y) (> (cdr x) (cdr y))) -#(define (display-stats what hash) +#(define (display-stats what) (let* ((count 50) - (rnd 10)) - (ly:progress "\n~A properties, top ~a rounded to ~a\n~a" + (rnd 10) + (alist (hash-table->alist (ly:property-lookup-stats what))) + (total (apply + (map cdr alist))) + ) + + (set! alist (acons 'TOTAL total alist)) + + (ly:progress "\n\n~A properties, top ~a rounded to ~a\n\n~a" what count rnd (string-join (map (lambda (x) (format "~30a: ~6@a" (car x) (* rnd (inexact->exact (round (/ (cdr x) rnd)))))) (take - (sort (hash-table->alist hash) prop-stats>?) count)) + (sort alist prop-stats>?) count)) "\n")))) -#(display-stats "Context" (ly:context-property-lookup-stats)) - -#(display-stats "Grob" (ly:grob-property-lookup-stats)) +#(display-stats 'prob) +#(display-stats 'context) +#(display-stats 'grob) diff --git a/lily/include/profile.hh b/lily/include/profile.hh index fff7fa225c..d8d4eff957 100644 --- a/lily/include/profile.hh +++ b/lily/include/profile.hh @@ -14,5 +14,7 @@ void note_property_access (SCM *table, SCM sym); extern SCM context_property_lookup_table; extern SCM grob_property_lookup_table; +extern SCM prob_property_lookup_table; +extern bool profile_property_accesses; #endif /* PROFILE_HH */ diff --git a/lily/include/program-option.hh b/lily/include/program-option.hh index 55971a1fa1..bf5e253d59 100644 --- a/lily/include/program-option.hh +++ b/lily/include/program-option.hh @@ -15,7 +15,6 @@ extern bool do_midi_debugging_global; extern int testing_level_global; extern bool lily_1_8_relative; extern bool lily_1_8_compatibility_used; -extern bool profile_property_accesses; SCM ly_get_option (SCM); SCM ly_set_option (SCM, SCM); diff --git a/lily/prob.cc b/lily/prob.cc index a45e089a08..9c3b40d712 100644 --- a/lily/prob.cc +++ b/lily/prob.cc @@ -10,6 +10,7 @@ #include "main.hh" #include "item.hh" #include "input.hh" +#include "profile.hh" #include "ly-smobs.icc" @@ -140,6 +141,11 @@ Prob::print_smob (SCM smob, SCM port, scm_print_state*) SCM Prob::internal_get_property (SCM sym) const { +#ifndef NDEBUG + if (profile_property_accesses) + note_property_access (&prob_property_lookup_table, sym); +#endif + /* TODO: type checking */ diff --git a/lily/profile.cc b/lily/profile.cc index 6531a3f330..e1862c7236 100644 --- a/lily/profile.cc +++ b/lily/profile.cc @@ -12,22 +12,25 @@ void note_property_access (SCM *table, SCM sym); SCM context_property_lookup_table; SCM grob_property_lookup_table; +SCM prob_property_lookup_table; -LY_DEFINE (ly_context_property_lookup_stats, "ly:context-property-lookup-stats", - 0, 0, 0, (), - "") +LY_DEFINE (ly_property_lookup_stats, "ly:property-lookup-stats", + 1, 0, 0, (SCM sym), + "Return hash table with a property access corresponding to @var{sym}. " + "Choices are prob, grob and context.") { - return context_property_lookup_table ? context_property_lookup_table - : scm_c_make_hash_table (1); + if (sym == ly_symbol2scm ("context")) + return context_property_lookup_table ? context_property_lookup_table + : scm_c_make_hash_table (1); + if (sym == ly_symbol2scm ("prob")) + return prob_property_lookup_table ? prob_property_lookup_table + : scm_c_make_hash_table (1); + if (sym == ly_symbol2scm ("grob")) + return grob_property_lookup_table ? grob_property_lookup_table + : scm_c_make_hash_table (1); + return scm_c_make_hash_table (1); } -LY_DEFINE (ly_property_lookup_stats, "ly:grob-property-lookup-stats", - 0, 0, 0, (), - "") -{ - return grob_property_lookup_table ? grob_property_lookup_table - : scm_c_make_hash_table (1); -} void note_property_access (SCM *table, SCM sym) diff --git a/lily/program-option.cc b/lily/program-option.cc index 8399cef9d5..0c87be9dc8 100644 --- a/lily/program-option.cc +++ b/lily/program-option.cc @@ -7,6 +7,7 @@ */ #include "program-option.hh" +#include "profile.hh" #include #include -- 2.39.2