summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-18 09:31:24 +0000
committerJames Ennis <james.ennis@codethink.com>2019-01-18 09:31:24 +0000
commit2cb37a7e8f8ba9e44ad0617fd0081b64755c9de0 (patch)
treeceb0e0d21eb6bf4e7baa54b9b237238f1fed3042
parentce91ce5d2eb73295d1862aa8514e631b6231300e (diff)
parentf64ee46f65cc68d9e5226c3f579be9cea97dd09e (diff)
downloadbuildstream-2cb37a7e8f8ba9e44ad0617fd0081b64755c9de0.tar.gz
Merge branch 'jennis/profiling_outputs_binaries' into 'master'
Make the profiler output binaries (which can be used to visualise the data) See merge request BuildStream/buildstream!1082
-rw-r--r--buildstream/_profile.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/buildstream/_profile.py b/buildstream/_profile.py
index 40cd2ab7e..6d8da9f66 100644
--- a/buildstream/_profile.py
+++ b/buildstream/_profile.py
@@ -62,15 +62,24 @@ class Profile():
def end(self):
self.profiler.disable()
+ dt = datetime.datetime.fromtimestamp(self.start)
+ timestamp = dt.strftime('%Y%m%dT%H%M%S')
+
filename = self.key.replace('/', '-')
filename = filename.replace('.', '-')
- filename = os.path.join(os.getcwd(), 'profile-' + filename + '.log')
+ filename = os.path.join(os.getcwd(), 'profile-' + timestamp + '-' + filename)
- with open(filename, "a", encoding="utf-8") as f:
+ time_ = dt.strftime('%Y-%m-%d %H:%M:%S') # Human friendly format
+ self.__write_log(filename + '.log', time_)
+
+ self.__write_binary(filename + '.cprofile')
- dt = datetime.datetime.fromtimestamp(self.start)
- time_ = dt.strftime('%Y-%m-%d %H:%M:%S')
+ ########################################
+ # Private Methods #
+ ########################################
+ def __write_log(self, filename, time_):
+ with open(filename, "a", encoding="utf-8") as f:
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()
#