[gnome-games/sudoku-tube] Make profile work
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Make profile work
- Date: Sun, 21 Jun 2009 11:24:01 -0400 (EDT)
commit a1a974ab6a0d28ad7137fb23b7809b5a2cc7b654
Author: Zhang Sen <zh jesse gmail com>
Date: Sun Jun 21 23:22:42 2009 +0800
Make profile work
gnome-sudoku/src/lib/gnome_sudoku.py | 34 ++++++++++++++++++++++++++++++++--
gnome-sudoku/src/lib/main.py | 33 ++-------------------------------
2 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gnome_sudoku.py b/gnome-sudoku/src/lib/gnome_sudoku.py
index 1271ed1..57d16fe 100644
--- a/gnome-sudoku/src/lib/gnome_sudoku.py
+++ b/gnome-sudoku/src/lib/gnome_sudoku.py
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
+import optparse
import sys
+import main
+import defaults
+
# Ignore any exceptions writing to stdout using print statements
class SafeStdout:
def __init__(self):
@@ -17,6 +21,32 @@ class SafeStdout:
sys.stdout = SafeStdout()
+
+def profile_me(func):
+ import tempfile, hotshot, hotshot.stats, os.path
+ pname = os.path.join(tempfile.gettempdir(), 'GNOME_SUDOKU_HOTSHOT_PROFILE')
+ prof = hotshot.Profile(pname)
+ prof.runcall(func)
+ stats = hotshot.stats.load(pname)
+ stats.strip_dirs()
+ stats.sort_stats('time', 'calls').print_stats()
+
+
def start_game ():
- import main
- main.start_game()
+ parser = optparse.OptionParser(
+ version = defaults.VERSION,
+ option_list = [
+ optparse.make_option("-v", const=True, action="store_const",
+ dest="debug", help="Print debug information",
+ default=False),
+ optparse.make_option("-p", const=True, action="store_const",
+ dest="profile", help="Profile gnome-sudoku",
+ default=False)])
+
+ options, args = parser.parse_args()
+
+ if options.profile:
+ print 'Profiling GNOME Sudoku'
+ profile_me(lambda: main.start_game(options.debug))
+ else:
+ main.start_game(options.debug)
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index b26a9a6..3b845f5 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -7,7 +7,6 @@ except ImportError, err:
import os.path
import threading
-import optparse
import gobject
import gtk
@@ -857,45 +856,17 @@ class TrackerBox (gtk.VBox):
clearer.perform()
-def start_game ():
- parser = optparse.OptionParser(
- version = VERSION,
- option_list = [
- optparse.make_option("-v", const=True, action="store_const",
- dest="debug", help="Print debug information",
- default=False),
- optparse.make_option("-p", const=True, action="store_const",
- dest="profile", help="Profile gnome-sudoku",
- default=False)])
-
- options, args = parser.parse_args()
-
- if options.debug:
+def start_game(debug=False):
+ if debug:
print 'Starting GNOME Sudoku in debug mode'
## You must call g_thread_init() before executing any other GLib
## functions in a threaded GLib program.
gobject.threads_init()
- if options.profile:
- options.profile = False
- profile_me()
- return
-
u = UI()
try:
gtk.main()
except KeyboardInterrupt:
# properly quit on a keyboard interrupt...
u.quit_cb()
-
-def profile_me ():
- print 'Profiling GNOME Sudoku'
- import tempfile, hotshot, hotshot.stats
- pname = os.path.join(tempfile.gettempdir(), 'GNOME_SUDOKU_HOTSHOT_PROFILE')
- prof = hotshot.Profile(pname)
- prof.runcall(start_game)
- stats = hotshot.stats.load(pname)
- stats.strip_dirs()
- stats.sort_stats('time', 'calls').print_stats()
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]