OSDN Git Service

Added shogi-server-profile to take profile of shogi-server.
authorDaigo Moriwaki <daigo@debian.org>
Sun, 18 Dec 2011 14:26:18 +0000 (23:26 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sun, 18 Dec 2011 14:26:18 +0000 (23:26 +0900)
changelog
shogi-server-profile [new file with mode: 0755]

index a84c552..430ca72 100644 (file)
--- a/changelog
+++ b/changelog
@@ -4,6 +4,7 @@
          - shogi_server/board.rb, piece.rb: Refactoring to cache OU pieces,
            which was inspired by 81SquareShogi-server's change
            (74b24b88c843f1dd767412475b117481d1d5e8eb).
+         - Added shogi-server-profile to take profile of shogi-server.
        * [mk_rate] [mk_game_results]
          - Supports Ruby 1.9.3.
 
diff --git a/shogi-server-profile b/shogi-server-profile
new file mode 100755 (executable)
index 0000000..e9829c3
--- /dev/null
@@ -0,0 +1,74 @@
+#! /usr/bin/ruby1.9.1
+# $Id$
+#
+# Author:: Daigo Moriwaki
+# Homepage:: http://sourceforge.jp/projects/shogi-server/
+#
+#--
+# Copyright (C) 2011 Daigo Moriwaki (daigo at debian dot org)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#++
+#
+# == Synopsis
+#
+# shogi-server-profile is a wrapper of shogi-server to take profile, which
+# is only used by Shogi-server developers.
+# 
+#
+# == Usage
+#
+# Same as shogi-server.
+# 
+# == PREREQUIRE
+#
+# Sample Command lines that isntall prerequires will work on Debian.
+#
+# * {ruby-prof}[http://rubyforge.org/projects/ruby-prof/]
+#
+#   $ sudo gem1.9.1 install ruby-prof
+#
+# == Run
+#
+# Same as shogi-server. It will result in a profile log file (calltree.log),
+# which can be read by KCacheGrind.
+#
+
+require 'ruby-prof'
+load 'shogi-server'
+
+
+if ($0 == __FILE__)
+  STDOUT.sync = true
+  STDERR.sync = true
+  TCPSocket.do_not_reverse_lookup = true
+  Thread.abort_on_exception = $DEBUG ? true : false
+
+  begin
+    result = RubyProf.profile do
+      main
+    end
+    printer = RubyProf::CallTreePrinter.new(result)
+    f = File.open("calltree.log", "w")
+    printer.print(f, {})
+  rescue Exception => ex
+    if $logger
+      log_error("main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}")
+    else
+      $stderr.puts "main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
+    end
+  end
+end
+