Skip to content
Snippets Groups Projects
Commit f42cd543 authored by Gregory Szorc's avatar Gregory Szorc
Browse files

statprof: require paths to save or load profile data

Upstream appears to aggressively save statprof data in a well-defined
home directory path. Change the code to not do that.

We also change file saving to fail if an error has occurred
instead of silently failing. Callers can catch the exception.

This behavior is more suitable for a generic "library" module.
parent ad4c0236
No related branches found
No related tags found
No related merge requests found
......@@ -311,5 +311,6 @@
state.accumulate_time(clock())
state.last_start_time = None
statprofpath = os.environ.get('STATPROF_DEST')
save_data(statprofpath)
if statprofpath:
save_data(statprofpath)
......@@ -315,9 +316,6 @@
def save_data(path=None):
try:
path = path or (os.environ['HOME'] + '/statprof.data')
file = open(path, "w+")
def save_data(path):
with open(path, 'w+') as file:
file.write(str(state.accumulated_time) + '\n')
for sample in state.samples:
time = str(sample.time)
......@@ -326,13 +324,7 @@
for s in stack]
file.write(time + '\0' + '\0'.join(sites) + '\n')
file.close()
except (IOError, OSError):
# The home directory probably didn't exist, or wasn't writable. Oh well.
pass
def load_data(path=None):
path = path or (os.environ['HOME'] + '/statprof.data')
def load_data(path):
lines = open(path, 'r').read().splitlines()
state.accumulated_time = float(lines[0])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment