diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-06-08 11:44:50 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-06-08 11:44:54 +0100 |
commit | 61080391726d3e4798faeb8d35df9f32a0653491 (patch) | |
tree | f6bab1f1b38e04b0e5a44e75e80fc0e7af8b9284 /lib/bb/cooker.py | |
parent | 077657e50ad032c0fa876bf54e9802af2686e0fb (diff) | |
download | bitbake-61080391726d3e4798faeb8d35df9f32a0653491.tar.gz |
cooker/process.py: Move profiling code to a place it can be reused by different server mechanisms
The cooker profiling code isn't server specific so move it to a place
where different server backends can use it.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/cooker.py')
-rw-r--r-- | lib/bb/cooker.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py index 622227393..6096e54b0 100644 --- a/lib/bb/cooker.py +++ b/lib/bb/cooker.py @@ -1058,12 +1058,62 @@ class BBCooker: return self.appendlist[f] return [] + def pre_serve(self): + # Empty the environment. The environment will be populated as + # necessary from the data store. + #bb.utils.empty_environment() + return + + def post_serve(self): + bb.event.fire(CookerExit(), self.configuration.event_data) + def shutdown(self): self.state = state.shutdown def stop(self): self.state = state.stop +def server_main(cooker, func, *args): + cooker.pre_serve() + + if cooker.configuration.profile: + try: + import cProfile as profile + except: + import profile + prof = profile.Profile() + + ret = profile.Profile.runcall(prof, func, *args) + + prof.dump_stats("profile.log") + + # Redirect stdout to capture profile information + pout = open('profile.log.processed', 'w') + so = sys.stdout.fileno() + orig_so = os.dup(sys.stdout.fileno()) + os.dup2(pout.fileno(), so) + + import pstats + p = pstats.Stats('profile.log') + p.sort_stats('time') + p.print_stats() + p.print_callers() + p.sort_stats('cumulative') + p.print_stats() + + os.dup2(orig_so, so) + pout.flush() + pout.close() + + print("Raw profiling information saved to profile.log and processed statistics to profile.log.processed") + + else: + ret = func(*args) + + cooker.post_serve() + + return ret + class CookerExit(bb.event.Event): """ Notify clients of the Cooker shutdown |