diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-11-13 21:23:54 +0800 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-11-13 21:23:54 +0800 |
commit | 05ba6fc7cb5a389737a238f312f4148e6b837d71 (patch) | |
tree | 7b0d8688095f94fd2010c63f0b0aadff301eccbf /bitbake/lib/bb/cooker.py | |
parent | 89929e1f283c8508c505c9731ad933880abf22a1 (diff) | |
download | poky-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>
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 73 |
1 files changed, 42 insertions, 31 deletions
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 | |||
927 | def 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 | |||
954 | class CookerExit(bb.event.Event): | 965 | class CookerExit(bb.event.Event): |
955 | """ | 966 | """ |
956 | Notify clients of the Cooker shutdown | 967 | Notify clients of the Cooker shutdown |