Commit f64ee46f authored by James Ennis's avatar James Ennis
Browse files

_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.
parent 63b02f7c
Loading
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -67,10 +67,19 @@ class Profile():


        filename = self.key.replace('/', '-')
        filename = self.key.replace('/', '-')
        filename = filename.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:
        with open(filename, "a", encoding="utf-8") as f:
            time_ = dt.strftime('%Y-%m-%d %H:%M:%S')
            heading = '================================================================\n'
            heading = '================================================================\n'
            heading += 'Profile for key: {}\n'.format(self.key)
            heading += 'Profile for key: {}\n'.format(self.key)
            heading += 'Started at: {}\n'.format(time_)
            heading += 'Started at: {}\n'.format(time_)
@@ -81,6 +90,9 @@ class Profile():
            ps = pstats.Stats(self.profiler, stream=f).sort_stats('cumulative')
            ps = pstats.Stats(self.profiler, stream=f).sort_stats('cumulative')
            ps.print_stats()
            ps.print_stats()


    def __write_binary(self, filename):
        self.profiler.dump_stats(filename)



# profile_start()
# profile_start()
#
#