]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/debugger.rb
markov: refactor triplet learning
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / debugger.rb
index f0ff0c03fdb61b9bfa512a4256372a47c7125d41..2895cd0beadf678c3ec01ba3aec2c35e9d22d9c7 100644 (file)
@@ -1,25 +1,33 @@
-# Debugging/profiling for rbot
+#-- vim:sw=2:et
+#++
 #
-# (c) 2006 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
-# Licensed under GPL V2.
+# :title: Debugging/profiling for rbot
+#
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
+# Copyright:: (C) 2006-2007 Giuseppe Bilotta
+# License:: GPL v2
 
 class DebugPlugin < Plugin
-  BotConfig.register BotConfigIntegerValue.new('debug.interval',
+  Config.register Config::IntegerValue.new('debug.interval',
     :default => 10, :validate => Proc.new{|v| v > 0},
     :desc => "Number of seconds between memory profile dumps")
-  BotConfig.register BotConfigBooleanValue.new('debug.dump_strings',
+  Config.register Config::BooleanValue.new('debug.dump_strings',
     :default => false,
     :desc => "Set to true if you want the profiler to dump strings, false otherwise")
-  BotConfig.register BotConfigStringValue.new('debug.logdir',
+  Config.register Config::StringValue.new('debug.logdir',
     :default => "",
     :desc => "Directory where profile/string dumps are to be stored")
 
+  def dirname
+    @bot.config['debug.logdir']
+  end
+
   def initialize
     super
     @prev = Hash.new(0)
     @curr = Hash.new(0)
     @delta = Hash.new(0)
-    @file = File.open("#{@bot.botclass}/#{@bot.config['debug.logdir']}/memory_profiler.log",'w')
+    @file = File.open(datafile("memory_profiler.log"), 'w')
     @thread = @bot.timer.add(@bot.config['debug.interval']) {
         begin
           GC.start
@@ -35,7 +43,7 @@ class DebugPlugin < Plugin
           end
 
           if @bot.config['debug.dump_strings']
-            File.open("#{@bot.botclass}/#{@bot.config['debug.logdir']}/memory_profiler_strings.log.#{Time.now.to_i}",'w') do |f|
+            File.open(datafile("memory_profiler_strings.log.#{Time.now.to_i}"), 'w') do |f|
               curr_strings.sort.each do |s|
                 f.puts s
               end
@@ -44,7 +52,7 @@ class DebugPlugin < Plugin
           end
 
           @delta.clear
-          (@curr.keys + @delta.keys).uniq.each do |k,v|
+          (@curr.keys + @prev.keys).uniq.each do |k,v|
             @delta[k] = @curr[k]-@prev[k]
           end
 
@@ -103,7 +111,7 @@ class DebugPlugin < Plugin
         end
       end
 
-      File.open("#{@bot.botclass}/#{@bot.config['debug.logdir']}/memory_profiler_strings.log.#{Time.now.to_i}",'w') do |f|
+      File.open(datafile("memory_profiler_strings.log.#{Time.now.to_i}"), 'w') do |f|
         curr_strings.sort.each do |s|
           f.puts s
         end
@@ -120,7 +128,7 @@ end
 
 
 plugin = DebugPlugin.new
-plugin.register( "debug" )
+
 plugin.default_auth( 'start', false )
 plugin.default_auth( 'stop', false )
 plugin.default_auth( 'dumpstrings', false )