Skip to content

Commit

Permalink
Merge pull request #76 from astrofrog/csv-fix
Browse files Browse the repository at this point in the history
FIx CSV output (missing comma) and include number of processes in CSV output
  • Loading branch information
astrofrog authored Apr 26, 2024
2 parents 34ef8d6 + 7ac8cd9 commit b76d59f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions psrecord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def monitor(
)
)
elif log_format == "csv":
f.write("elapsed_time,cpu,mem_real,mem_virtual")
f.write("elapsed_time,nproc,cpu,mem_real,mem_virtual")
if include_io:
f.write(",read_count,write_count,read_bytes,write_bytes")
else:
Expand Down Expand Up @@ -236,6 +236,8 @@ def monitor(
read_bytes = counters.read_bytes
write_bytes = counters.write_bytes

n_proc = 1

# Get information for children
if include_children:
for child in all_children(pr):
Expand All @@ -250,6 +252,7 @@ def monitor(
write_count += counters.write_count
read_bytes += counters.read_bytes
write_bytes += counters.write_bytes
n_proc += 1
except Exception:
continue

Expand All @@ -266,10 +269,10 @@ def monitor(
)
elif log_format == "csv":
f.write(
f"{elapsed_time},{current_cpu},{current_mem_real},{current_mem_virtual}"
f"{elapsed_time},{n_proc},{current_cpu},{current_mem_real},{current_mem_virtual}"
)
if include_io:
f.write(f"{read_count},{write_count},{read_bytes},{write_bytes}")
f.write(f",{read_count},{write_count},{read_bytes},{write_bytes}")
f.write("\n")
f.flush()

Expand Down
2 changes: 1 addition & 1 deletion psrecord/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_logfile_csv(self, tmpdir):
assert len(open(filename).readlines()) > 0
with open(filename) as csvfile:
data = csv.reader(csvfile)
assert next(data) == ["elapsed_time", "cpu", "mem_real", "mem_virtual"]
assert next(data) == ["elapsed_time", "nproc", "cpu", "mem_real", "mem_virtual"]

def test_plot(self, tmpdir):
pytest.importorskip("matplotlib")
Expand Down

0 comments on commit b76d59f

Please sign in to comment.