summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-02-15 16:59:56 -0700
committerChris Larson <chris_larson@mentor.com>2011-02-15 17:02:14 -0700
commitdbc0cf970140cfb18c58d8110eef5cef10ea33cb (patch)
tree7e8ad70139f3beb86d42088ddbb21ac6d7ae0b55
parent67a55a6b45fec300bea42c18be41cf0a2f931072 (diff)
downloadbitbake-dbc0cf970140cfb18c58d8110eef5cef10ea33cb.tar.gz
server: add profiling support to ProcessServer
Based on poky's support, particularly the format of the processed log file and the log message shown to the user regarding the files written. Signed-off-by: Chris Larson <chris_larson@mentor.com>
-rw-r--r--lib/bb/server/process.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 279934849..51a99182b 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -22,6 +22,7 @@
import logging
import signal
+import sys
import time
import bb
import bb.event
@@ -65,6 +66,9 @@ class EventAdapter():
class ProcessServer(Process):
+ profile_filename = "profile.log"
+ profile_processed_filename = "profile.log.processed"
+
def __init__(self, command_channel, event_queue, configuration):
Process.__init__(self)
self.command_channel = command_channel
@@ -88,6 +92,36 @@ class ProcessServer(Process):
self._idlefunctions[function] = data
def run(self):
+ if self.configuration.profile:
+ return self.profile_main()
+ else:
+ return self.main()
+
+ def profile_main(self):
+ import cProfile
+ profiler = cProfile.Profile()
+ try:
+ return profiler.runcall(self.main)
+ finally:
+ profiler.dump_stats(self.profile_filename)
+ self.write_profile_stats(self.profile_filename,
+ self.profile_processed_filename)
+ sys.__stderr__.write("Raw profiling information saved to %s and "
+ "processed statistics to %s\n" %
+ (self.profile_filename,
+ self.profile_processed_filename))
+
+ def write_profile_stats(self, infn, outfn):
+ import pstats
+ with open(outfn, 'w') as outfile:
+ stats = pstats.Stats(infn, stream=outfile)
+ stats.sort_stats('time')
+ stats.print_stats()
+ stats.print_callers()
+ stats.sort_stats('cumulative')
+ stats.print_stats()
+
+ def main(self):
# Ignore SIGINT within the server, as all SIGINT handling is done by
# the UI and communicated to us
signal.signal(signal.SIGINT, signal.SIG_IGN)