Skip to content

Commit

Permalink
Remove unnecessary bottlenecks
Browse files Browse the repository at this point in the history
1. No need to wait on join() the monitoring thread, it is safely killed
   when duct process exits.
2. pass when ps fails (because inner process has finished)
3. Collect the first sample immediately rather than waiting for
   <sample-interval>

Fixes #36
  • Loading branch information
asmacdo committed Jun 6, 2024
1 parent b00e404 commit 0b4b4f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def collect_sample(self):
"timestamp": datetime.now().astimezone().isoformat(),
}
except subprocess.CalledProcessError:
process_data["error"] = "Failed to query process data"
pass
return process_data

def write_pid_samples(self):
Expand Down Expand Up @@ -199,7 +199,7 @@ def monitor_process(report, process, report_interval, sample_interval):
totals = report.calculate_total_usage(sample)
report.update_max_resources(sample, totals)
report.update_max_resources(report._sample, sample)
if report.elapsed_time >= (report.number + 1) * report_interval:
if report.elapsed_time >= report.number * report_interval:
report.write_pid_samples()
report.update_max_resources(report.max_values, report._sample)
report._sample = defaultdict(dict) # Reset sample
Expand Down Expand Up @@ -406,7 +406,6 @@ def main():
target=monitor_process, args=monitoring_args
)
monitoring_thread.start()
monitoring_thread.join()

if args.record_types in ["all", "system-summary"]:
report.collect_environment()
Expand Down
2 changes: 1 addition & 1 deletion test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def consume_memory(size):


def main(duration, cpu_load, memory_size):
consume_memory(memory_size)
print("this is of test of STDERR: ERRRRRRRRRRRRRRR", file=sys.stderr)
consume_memory(memory_size)
consume_cpu(duration, cpu_load)
print(
f"Test completed. Consumed {memory_size} MB for {duration} seconds with CPU load factor {cpu_load}."
Expand Down

0 comments on commit 0b4b4f6

Please sign in to comment.