Last active
August 7, 2017 15:21
-
-
Save kergoth/c0ed22a42b76972356bdd25971d157cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/lib/bb/build.py w/lib/bb/build.py | |
index 0d0100a0..63565fb6 100644 | |
--- i/lib/bb/build.py | |
+++ w/lib/bb/build.py | |
@@ -635,9 +635,13 @@ def exec_task(fn, task, d, profile = False): | |
except: | |
import profile | |
prof = profile.Profile() | |
- ret = profile.Profile.runcall(prof, _exec_task, fn, task, d, quieterr) | |
+ mprof = [] | |
+ from memory_profiler import memory_usage | |
+ ret = profile.Profile.runcall(prof, lambda *args: mprof.extend(memory_usage((_exec_task, args, {}), include_children=True)), fn, task, d, quieterr) | |
prof.dump_stats(profname) | |
bb.utils.process_profilelog(profname) | |
+ with open("memory-" + profname, "w") as f: | |
+ f.write("\t".join(str(m) for m in mprof) + "\n") | |
return ret | |
else: | |
diff --git i/lib/bb/cooker.py w/lib/bb/cooker.py | |
index 662a7ac0..1b5f8ada 100644 | |
--- i/lib/bb/cooker.py | |
+++ w/lib/bb/cooker.py | |
@@ -1799,11 +1799,15 @@ def server_main(cooker, func, *args): | |
except: | |
import profile | |
prof = profile.Profile() | |
+ mprof = [] | |
- ret = profile.Profile.runcall(prof, func, *args) | |
+ from memory_profiler import memory_usage | |
+ ret = profile.Profile.runcall(prof, lambda *args: mprof.extend(memory_usage((func, args, {}), include_children=True)), *args) | |
prof.dump_stats("profile.log") | |
bb.utils.process_profilelog("profile.log") | |
+ with open("memory-profile.log", "w") as f: | |
+ f.write("\t".join(str(m) for m in mprof) + "\n") | |
print("Raw profiling information saved to profile.log and processed statistics to profile.log.processed") | |
else: | |
@@ -2055,12 +2059,17 @@ class Parser(multiprocessing.Process): | |
import cProfile as profile | |
except: | |
import profile | |
+ from memory_profiler import memory_usage | |
prof = profile.Profile() | |
+ mprof = [] | |
+ | |
try: | |
- profile.Profile.runcall(prof, self.realrun) | |
+ profile.Profile.runcall(prof, lambda: mprof.extend(memory_usage((self.realrun, [], {}), include_children=True))) | |
finally: | |
logfile = "profile-parse-%s.log" % multiprocessing.current_process().name | |
prof.dump_stats(logfile) | |
+ with open("memory-" + logfile, "w") as f: | |
+ f.write("\t".join(str(m) for m in mprof) + "\n") | |
def realrun(self): | |
if self.init: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment