diff --git a/psrecord/main.py b/psrecord/main.py index 9beccec..a17d116 100644 --- a/psrecord/main.py +++ b/psrecord/main.py @@ -90,6 +90,10 @@ def main(): 'in a slower maximum sampling rate).', action='store_true') + parser.add_argument('--use-unix-ts', + help='When used, time would be logged in unix timestamp', + action='store_true') + args = parser.parse_args() # Attach to process @@ -106,14 +110,15 @@ def main(): pid = sprocess.pid monitor(pid, logfile=args.log, plot=args.plot, duration=args.duration, - interval=args.interval, include_children=args.include_children) + interval=args.interval, include_children=args.include_children, + use_unix_ts=args.use_unix_ts) if sprocess is not None: sprocess.kill() def monitor(pid, logfile=None, plot=None, duration=None, interval=None, - include_children=False): + include_children=False, use_unix_ts=False): pr = psutil.Process(pid) @@ -142,6 +147,8 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None, # Find current time current_time = time.time() + logged_time = (current_time - start_time) if not use_unix_ts \ + else current_time try: pr_status = pr.status() @@ -153,7 +160,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 @@ -182,7 +189,7 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None, if logfile: f.write("{0:12.3f} {1:12.3f} {2:12.3f} {3:12.3f}\n".format( - current_time - start_time, + logged_time, current_cpu, current_mem_real, current_mem_virtual)) @@ -193,7 +200,7 @@ 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['times'].append(logged_time) log['cpu'].append(current_cpu) log['mem_real'].append(current_mem_real) log['mem_virtual'].append(current_mem_virtual)