summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-11-13 21:23:54 +0800
committerRichard Purdie <rpurdie@linux.intel.com>2010-11-13 21:23:54 +0800
commit05ba6fc7cb5a389737a238f312f4148e6b837d71 (patch)
tree7b0d8688095f94fd2010c63f0b0aadff301eccbf
parent89929e1f283c8508c505c9731ad933880abf22a1 (diff)
downloadpoky-05ba6fc7cb5a389737a238f312f4148e6b837d71.tar.gz
bitbake: Rewrite profiling code so its functional for both none and xmlrpc backends
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rwxr-xr-xbitbake/bin/bitbake4
-rw-r--r--bitbake/lib/bb/cooker.py73
-rw-r--r--bitbake/lib/bb/server/none.py16
-rw-r--r--bitbake/lib/bb/server/xmlrpc.py19
4 files changed, 73 insertions, 39 deletions
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
index b046156b49..797b5a8d60 100755
--- a/bitbake/bin/bitbake
+++ b/bitbake/bin/bitbake
@@ -180,7 +180,7 @@ Default BBFILES are the .bb files in the current directory.""")
180 180
181 serverinfo = server.BitbakeServerInfo(cooker.server) 181 serverinfo = server.BitbakeServerInfo(cooker.server)
182 182
183 server.BitBakeServerFork(serverinfo, cooker.serve, cooker_logfile) 183 server.BitBakeServerFork(cooker, cooker.server, serverinfo, cooker_logfile)
184 del cooker 184 del cooker
185 185
186 # Setup a connection to the server (cooker) 186 # Setup a connection to the server (cooker)
@@ -203,7 +203,7 @@ Default BBFILES are the .bb files in the current directory.""")
203 print("Valid interfaces are 'ncurses', 'depexp' or the default, 'knotty'.") 203 print("Valid interfaces are 'ncurses', 'depexp' or the default, 'knotty'.")
204 else: 204 else:
205 try: 205 try:
206 return_value = ui_init(serverConnection.connection, serverConnection.events) 206 return_value = server.BitbakeUILauch().launch(serverinfo, ui_init, serverConnection.connection, serverConnection.events)
207 except Exception as e: 207 except Exception as e:
208 print("FATAL: Unable to start to '%s' UI: %s" % (ui, e)) 208 print("FATAL: Unable to start to '%s' UI: %s" % (ui, e))
209 raise 209 raise
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 44b9b2c31a..33eb65e2f3 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -1,4 +1,3 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et 1# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- 2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4# 3#
@@ -71,7 +70,7 @@ class BBCooker:
71 self.bb_cache = None 70 self.bb_cache = None
72 71
73 if server: 72 if server:
74 self.server = server.BitBakeServer(self) 73 self.server = server.BitBakeServer(self, self.pre_serve, self.post_serve)
75 74
76 self.configuration = configuration 75 self.configuration = configuration
77 76
@@ -916,41 +915,53 @@ class BBCooker:
916 return self.appendlist[f] 915 return self.appendlist[f]
917 return [] 916 return []
918 917
919 def serve(self): 918 def pre_serve(self):
920
921 # Empty the environment. The environment will be populated as 919 # Empty the environment. The environment will be populated as
922 # necessary from the data store. 920 # necessary from the data store.
923 bb.utils.empty_environment() 921 bb.utils.empty_environment()
924 922
925 if self.configuration.profile: 923 def post_serve(self):
926 try:
927 import cProfile as profile
928 except:
929 import profile
930
931 profile.runctx("self.server.serve_forever()", globals(), locals(), "profile.log")
932
933 # Redirect stdout to capture profile information
934 pout = open('profile.log.processed', 'w')
935 so = sys.stdout.fileno()
936 os.dup2(pout.fileno(), so)
937
938 import pstats
939 p = pstats.Stats('profile.log')
940 p.sort_stats('time')
941 p.print_stats()
942 p.print_callers()
943 p.sort_stats('cumulative')
944 p.print_stats()
945
946 os.dup2(so, pout.fileno())
947 pout.flush()
948 pout.close()
949 else:
950 self.server.serve_forever()
951
952 bb.event.fire(CookerExit(), self.configuration.event_data) 924 bb.event.fire(CookerExit(), self.configuration.event_data)
953 925
926
927def server_main(cooker, func, *args):
928 if cooker.configuration.profile:
929 try:
930 import cProfile as profile
931 except:
932 import profile
933 prof = profile.Profile()
934
935 ret = profile.Profile.runcall(prof, func, *args)
936
937 prof.dump_stats("profile.log")
938
939 # Redirect stdout to capture profile information
940 pout = open('profile.log.processed', 'w')
941 so = sys.stdout.fileno()
942 orig_so = os.dup(sys.stdout.fileno())
943 os.dup2(pout.fileno(), so)
944
945 import pstats
946 p = pstats.Stats('profile.log')
947 p.sort_stats('time')
948 p.print_stats()
949 p.print_callers()
950 p.sort_stats('cumulative')
951 p.print_stats()
952
953 os.dup2(orig_so, so)
954 pout.flush()
955 pout.close()
956
957 print("Raw profiling information saved to profile.log and processed statistics to profile.log.processed")
958
959 return ret
960 else:
961 return func(*args)
962
963
964
954class CookerExit(bb.event.Event): 965class CookerExit(bb.event.Event):
955 """ 966 """
956 Notify clients of the Cooker shutdown 967 Notify clients of the Cooker shutdown
diff --git a/bitbake/lib/bb/server/none.py b/bitbake/lib/bb/server/none.py
index 14915d9737..38f713c519 100644
--- a/bitbake/lib/bb/server/none.py
+++ b/bitbake/lib/bb/server/none.py
@@ -109,9 +109,11 @@ class BitBakeServer():
109 # remove this when you're done with debugging 109 # remove this when you're done with debugging
110 # allow_reuse_address = True 110 # allow_reuse_address = True
111 111
112 def __init__(self, cooker): 112 def __init__(self, cooker, pre_serve, post_serve):
113 self._idlefuns = {} 113 self._idlefuns = {}
114 self.commands = BitBakeServerCommands(self, cooker) 114 self.commands = BitBakeServerCommands(self, cooker)
115 self.pre_serve = pre_serve
116 self.post_serve = post_serve
115 117
116 def register_idle_function(self, function, data): 118 def register_idle_function(self, function, data):
117 """Register a function to be called while the server is idle""" 119 """Register a function to be called while the server is idle"""
@@ -160,9 +162,17 @@ class BitbakeServerInfo():
160 self.commands = server.commands 162 self.commands = server.commands
161 163
162class BitBakeServerFork(): 164class BitBakeServerFork():
163 def __init__(self, serverinfo, command, logfile): 165 def __init__(self, cooker, server, serverinfo, logfile):
164 serverinfo.forkCommand = command
165 serverinfo.logfile = logfile 166 serverinfo.logfile = logfile
167 serverinfo.cooker = cooker
168 serverinfo.server = server
169
170class BitbakeUILauch():
171 def launch(self, serverinfo, uifunc, *args):
172 serverinfo.server.pre_serve()
173 ret = bb.cooker.server_main(serverinfo.cooker, uifunc, *args)
174 serverinfo.server.post_serve()
175 return ret
166 176
167class BitBakeServerConnection(): 177class BitBakeServerConnection():
168 def __init__(self, serverinfo): 178 def __init__(self, serverinfo):
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index cb2949fb9f..30b83d2b13 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -87,7 +87,7 @@ class BitBakeServer(SimpleXMLRPCServer):
87 # remove this when you're done with debugging 87 # remove this when you're done with debugging
88 # allow_reuse_address = True 88 # allow_reuse_address = True
89 89
90 def __init__(self, cooker, interface = ("localhost", 0)): 90 def __init__(self, cooker, pre_serve, post_serve, interface = ("localhost", 0)):
91 """ 91 """
92 Constructor 92 Constructor
93 """ 93 """
@@ -99,6 +99,9 @@ class BitBakeServer(SimpleXMLRPCServer):
99 #self.register_introspection_functions() 99 #self.register_introspection_functions()
100 commands = BitBakeServerCommands(self, cooker) 100 commands = BitBakeServerCommands(self, cooker)
101 self.autoregister_all_functions(commands, "") 101 self.autoregister_all_functions(commands, "")
102 self.cooker = cooker
103 self.pre_serve = pre_serve
104 self.post_serve = post_serve
102 105
103 def autoregister_all_functions(self, context, prefix): 106 def autoregister_all_functions(self, context, prefix):
104 """ 107 """
@@ -116,9 +119,14 @@ class BitBakeServer(SimpleXMLRPCServer):
116 self._idlefuns[function] = data 119 self._idlefuns[function] = data
117 120
118 def serve_forever(self): 121 def serve_forever(self):
122 bb.cooker.server_main(self.cooker, self._serve_forever)
123
124 def _serve_forever(self):
119 """ 125 """
120 Serve Requests. Overloaded to honor a quit command 126 Serve Requests. Overloaded to honor a quit command
121 """ 127 """
128 self.pre_serve()
129
122 self.quit = False 130 self.quit = False
123 self.timeout = 0 # Run Idle calls for our first callback 131 self.timeout = 0 # Run Idle calls for our first callback
124 while not self.quit: 132 while not self.quit:
@@ -155,6 +163,7 @@ class BitBakeServer(SimpleXMLRPCServer):
155 except: 163 except:
156 pass 164 pass
157 165
166 self.post_serve()
158 self.server_close() 167 self.server_close()
159 return 168 return
160 169
@@ -164,8 +173,12 @@ class BitbakeServerInfo():
164 self.port = server.port 173 self.port = server.port
165 174
166class BitBakeServerFork(): 175class BitBakeServerFork():
167 def __init__(self, serverinfo, command, logfile): 176 def __init__(self, cooker, server, serverinfo, logfile):
168 daemonize.createDaemon(command, logfile) 177 daemonize.createDaemon(server.serve_forever, logfile)
178
179class BitbakeUILauch():
180 def launch(self, serverinfo, uifunc, *args):
181 return uifunc(*args)
169 182
170class BitBakeServerConnection(): 183class BitBakeServerConnection():
171 def __init__(self, serverinfo): 184 def __init__(self, serverinfo):