Skip to contentSkip to conversation

utils: Improve profile log processing

PATCH New Richard Purdie 1 participant 1 message Aug 27, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Improve profile log processing

This stream redirection of stdout is horrible. pstats takes a stream argument so lets use that instead.

bitbake/lib/bb/utils.py +1 -6
index 7d37a74..670e592 100644
@@ -862,21 +862,16 @@ def nonblockingfd(fd):
     fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
 def process_profilelog(fn):
-    # Redirect stdout to capture profile information
     pout = open(fn + '.processed', 'w')
-    so = sys.stdout.fileno()
-    orig_so = os.dup(sys.stdout.fileno())
-    os.dup2(pout.fileno(), so)
    
     import pstats
-    p = pstats.Stats(fn)
+    p = pstats.Stats(fn, stream=pout)
     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()