[Notes] [Git][BuildStream/buildstream][master] 3 commits: _profile.py: Add timestamp to the logs



Title: GitLab

James Ennis pushed to branch master at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • buildstream/_profile.py
    ... ... @@ -62,15 +62,24 @@ class Profile():
    62 62
         def end(self):
    
    63 63
             self.profiler.disable()
    
    64 64
     
    
    65
    +        dt = datetime.datetime.fromtimestamp(self.start)
    
    66
    +        timestamp = dt.strftime('%Y%m%dT%H%M%S')
    
    67
    +
    
    65 68
             filename = self.key.replace('/', '-')
    
    66 69
             filename = filename.replace('.', '-')
    
    67
    -        filename = os.path.join(os.getcwd(), 'profile-' + filename + '.log')
    
    70
    +        filename = os.path.join(os.getcwd(), 'profile-' + timestamp + '-' + filename)
    
    68 71
     
    
    69
    -        with open(filename, "a", encoding="utf-8") as f:
    
    72
    +        time_ = dt.strftime('%Y-%m-%d %H:%M:%S')  # Human friendly format
    
    73
    +        self.__write_log(filename + '.log', time_)
    
    74
    +
    
    75
    +        self.__write_binary(filename + '.cprofile')
    
    70 76
     
    
    71
    -            dt = datetime.datetime.fromtimestamp(self.start)
    
    72
    -            time_ = dt.strftime('%Y-%m-%d %H:%M:%S')
    
    77
    +    ########################################
    
    78
    +    #            Private Methods           #
    
    79
    +    ########################################
    
    73 80
     
    
    81
    +    def __write_log(self, filename, time_):
    
    82
    +        with open(filename, "a", encoding="utf-8") as f:
    
    74 83
                 heading = '================================================================\n'
    
    75 84
                 heading += 'Profile for key: {}\n'.format(self.key)
    
    76 85
                 heading += 'Started at: {}\n'.format(time_)
    
    ... ... @@ -81,6 +90,9 @@ class Profile():
    81 90
                 ps = pstats.Stats(self.profiler, stream=f).sort_stats('cumulative')
    
    82 91
                 ps.print_stats()
    
    83 92
     
    
    93
    +    def __write_binary(self, filename):
    
    94
    +        self.profiler.dump_stats(filename)
    
    95
    +
    
    84 96
     
    
    85 97
     # profile_start()
    
    86 98
     #
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]