summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-17 16:06:05 +0000
committerJames Ennis <james.ennis@codethink.com>2019-01-17 17:02:28 +0000
commitf64ee46f65cc68d9e5226c3f579be9cea97dd09e (patch)
treeceb0e0d21eb6bf4e7baa54b9b237238f1fed3042
parent63b02f7c810e55360126cb725952d6043ed7caa0 (diff)
downloadbuildstream-jennis/profiling_outputs_binaries.tar.gz
_profile.py: Write binaries as well as logsjennis/profiling_outputs_binaries
Private class methods which write the logs and write the binaries have been added to Profile. The binaries are able to be used by various visualisation tools.
-rw-r--r--buildstream/_profile.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/buildstream/_profile.py b/buildstream/_profile.py
index f197b608c..6d8da9f66 100644
--- a/buildstream/_profile.py
+++ b/buildstream/_profile.py
@@ -67,10 +67,19 @@ class Profile():
filename = self.key.replace('/', '-')
filename = filename.replace('.', '-')
- filename = os.path.join(os.getcwd(), 'profile-' + timestamp + '-' + filename + '.log')
+ filename = os.path.join(os.getcwd(), 'profile-' + timestamp + '-' + filename)
+ time_ = dt.strftime('%Y-%m-%d %H:%M:%S') # Human friendly format
+ self.__write_log(filename + '.log', time_)
+
+ self.__write_binary(filename + '.cprofile')
+
+ ########################################
+ # Private Methods #
+ ########################################
+
+ def __write_log(self, filename, time_):
with open(filename, "a", encoding="utf-8") as f:
- time_ = dt.strftime('%Y-%m-%d %H:%M:%S')
heading = '================================================================\n'
heading += 'Profile for key: {}\n'.format(self.key)
heading += 'Started at: {}\n'.format(time_)
@@ -81,6 +90,9 @@ class Profile():
ps = pstats.Stats(self.profiler, stream=f).sort_stats('cumulative')
ps.print_stats()
+ def __write_binary(self, filename):
+ self.profiler.dump_stats(filename)
+
# profile_start()
#