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

FIx CSV output (missing comma) and include number of processes in CSV output #76

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
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
Loading