Start on debug categories
@@ -22,10 +22,10 @@ namespace eval turbine {
namespace export init start finalize spawn_rule rule
-
# Import adlb commands
namespace import ::adlb::put ::adlb::get ::adlb::RANK_ANY \
- ::adlb::get_priority ::adlb::reset_priority ::adlb::set_priority
+ ::adlb::get_priority ::adlb::reset_priority \
+ ::adlb::set_priority
# Re-export adlb commands
namespace export put get RANK_ANY \
get_priority reset_priority set_priority
@@ -73,6 +73,9 @@ namespace eval turbine {
variable error_code
set error_code 10
+ # The list of enabled debug categories
+ variable debug_categories
+
# User function
# rank_config: If an empty string, configure ranks based on environment.
# If an integer, interpret as a server count and do old-style
@@ -81,8 +84,13 @@ namespace eval turbine {
# the rank_allocation function
# lang: language to use in error messages
proc init { rank_config {lang ""} } {
- # Initialise debugging in case other functions want to debug
+
+ # Initialize debugging in case other functions want to debug
+ variable debug_categories
c::init_debug
+ set debug_categories [ list ]
+
+ debug_set SHUTDOWN true
# Setup communicator so we can get size later
if { [ info exists ::TURBINE_ADLB_COMM ] } {
@@ -492,9 +500,60 @@ namespace eval turbine {
adlb::enable_read_refcount
}
- proc debug { msg } {
+ # Basic debugging function
+ # If #args == 1, then just print that as a message
+ # If #args == 2, the first argument is the category,
+ # the second argument is the message,
+ # and only print the message if the category
+ # has been enabled with debug_set
+ proc debug { args } {
+ variable debug_categories
+ set argc [ llength $args ]
+ if { $argc == 1 } {
+ c::debug $args
+ } elseif { $argc == 2 } {
+ lassign $args category msg
+ if { [ lsearch $debug_categories $category ] >= 0 } {
c::debug $msg
}
+ } else {
+ error "Bad arguments to debug (count=$argc) : $args"
+ }
+ }
+
+ # Enable debugging on the given category
+ # category: any string
+ # enabled: true to enable, false to disable
+ proc debug_set { category enabled } {
+ variable debug_categories
+ if $enabled {
+ if { [ lsearch $debug_categories $category ] == -1 } {
+ lappend debug_categories $category
+ } else {
+ debug [ cat "debug: warning: " \
+ "duplicate enable of debug category: $category" ]
+ }
+ } else {
+ set index [ lsearch $debug_categories $category ]
+ if { $index == -1 } {
+ debug [ cat "debug: warning: " \
+ "attempted removal of non-existent category: " \
+ $category ]
+ } else {
+ set debug_categories \
+ [ lreplace debug_categories $index $index ]
+ }
+ }
+ }
+
+ proc debug_enabled { category } {
+ variable debug_categories
+ if { [ lsearch $debug_categories $category ] == -1 } {
+ return false
+ } else {
+ return true
+ }
+ }
proc finalize { } {
log "turbine finalizing"
@@ -505,6 +564,9 @@ namespace eval turbine {
} else {
adlb::finalize 1
}
+ if [ debug_enabled SHUTDOWN ] {
+ printf "adlb finalized at: %0.4f" [ c::log_time ]
+ }
}
# DEPRECATED
@@ -613,5 +675,5 @@ namespace eval turbine {
# Local Variables:
# mode: tcl
-# tcl-indent-level: 4
+# tcl-indent-level: 2
# End:
