OSDN Git Service

[shogi-server] - Implemented conversion of move representation between CSA format...
[shogi-server/shogi-server.git] / shogi-server-profile
1 #! /usr/bin/ruby1.9.1
2 # $Id$
3 #
4 # Author:: Daigo Moriwaki
5 # Homepage:: http://sourceforge.jp/projects/shogi-server/
6 #
7 #--
8 # Copyright (C) 2011-2012 Daigo Moriwaki (daigo at debian dot org)
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 #++
24 #
25 # == Synopsis
26 #
27 # shogi-server-profile is a wrapper of shogi-server to take profile, which
28 # is only used by Shogi-server developers.
29
30 #
31 # == Usage
32 #
33 # Same as shogi-server.
34
35 # == PREREQUIRE
36 #
37 # Sample Command lines that isntall prerequires will work on Debian.
38 #
39 # * {ruby-prof}[http://rubyforge.org/projects/ruby-prof/]
40 #
41 #   $ sudo gem1.9.1 install ruby-prof
42 #
43 # == Run
44 #
45 # Same as shogi-server. It will result in a profile log file (calltree.log),
46 # which can be read by KCacheGrind.
47 #
48
49 require 'ruby-prof'
50 load 'shogi-server'
51
52
53 if ($0 == __FILE__)
54   STDOUT.sync = true
55   STDERR.sync = true
56   TCPSocket.do_not_reverse_lookup = true
57   Thread.abort_on_exception = $DEBUG ? true : false
58
59   begin
60     result = RubyProf.profile do
61       main
62     end
63     printer = RubyProf::CallTreePrinter.new(result)
64     f = File.open("calltree.log", "w")
65     printer.print(f, {})
66   rescue Exception => ex
67     if $logger
68       log_error("main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}")
69     else
70       $stderr.puts "main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
71     end
72   end
73 end
74