From f64ee46f65cc68d9e5226c3f579be9cea97dd09e Mon Sep 17 00:00:00 2001 From: James Ennis Date: Thu, 17 Jan 2019 16:06:05 +0000 Subject: _profile.py: Write binaries as well as logs 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. --- buildstream/_profile.py | 16 ++++++++++++++-- 1 file 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() # -- cgit v1.2.1