diff options
-rw-r--r-- | buildstream/_profile.py | 16 |
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() # |