Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions psrecord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,

if logfile:
f = open(logfile, 'w')
f.write("# {0:12s} {1:12s} {2:12s} {3:12s}\n".format(
'Elapsed time'.center(12),
f.write("{0:12s} {1:12s} {2:12s} {3:12s} {4:12s}\n".format(
'Current Time'.center(12),
'Elapsed Time'.center(12),
'CPU (%)'.center(12),
'Real (MB)'.center(12),
'Virtual (MB)'.center(12))
)

log = {}
log['current_time'] = []
log['times'] = []
log['cpu'] = []
log['mem_real'] = []
Expand All @@ -142,6 +144,7 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,

# Find current time
current_time = time.time()
logged_time = (current_time - start_time)

try:
pr_status = pr.status()
Expand All @@ -153,7 +156,7 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,
# Check if process status indicates we should exit
if pr_status in [psutil.STATUS_ZOMBIE, psutil.STATUS_DEAD]:
print("Process finished ({0:.2f} seconds)"
.format(current_time - start_time))
.format(logged_time))
break

# Check if we have reached the maximum time
Expand Down Expand Up @@ -181,8 +184,9 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,
current_mem_virtual += current_mem.vms / 1024. ** 2

if logfile:
f.write("{0:12.3f} {1:12.3f} {2:12.3f} {3:12.3f}\n".format(
current_time - start_time,
f.write("{0:12.3f} {1:12.3f} {2:12.3f} {3:12.3f} {4:12.3f}\n".format(
current_time,
logged_time,
current_cpu,
current_mem_real,
current_mem_virtual))
Expand All @@ -193,7 +197,8 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,

# If plotting, record the values
if plot:
log['times'].append(current_time - start_time)
log['current_time'].append(current_time)
log['times'].append(logged_time)
log['cpu'].append(current_cpu)
log['mem_real'].append(current_mem_real)
log['mem_virtual'].append(current_mem_virtual)
Expand Down