Commit 2cb37a7e authored by James Ennis's avatar James Ennis

Merge branch 'jennis/profiling_outputs_binaries' into 'master'

Make the profiler output binaries (which can be used to visualise the data)

See merge request !1082
parents ce91ce5d f64ee46f
Pipeline #43848981 passed with stages
in 35 minutes and 34 seconds
......@@ -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()
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment