Skip to content

Commit b76d59f

Browse files
authored
Merge pull request #76 from astrofrog/csv-fix
FIx CSV output (missing comma) and include number of processes in CSV output
2 parents 34ef8d6 + 7ac8cd9 commit b76d59f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

psrecord/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def monitor(
176176
)
177177
)
178178
elif log_format == "csv":
179-
f.write("elapsed_time,cpu,mem_real,mem_virtual")
179+
f.write("elapsed_time,nproc,cpu,mem_real,mem_virtual")
180180
if include_io:
181181
f.write(",read_count,write_count,read_bytes,write_bytes")
182182
else:
@@ -236,6 +236,8 @@ def monitor(
236236
read_bytes = counters.read_bytes
237237
write_bytes = counters.write_bytes
238238

239+
n_proc = 1
240+
239241
# Get information for children
240242
if include_children:
241243
for child in all_children(pr):
@@ -250,6 +252,7 @@ def monitor(
250252
write_count += counters.write_count
251253
read_bytes += counters.read_bytes
252254
write_bytes += counters.write_bytes
255+
n_proc += 1
253256
except Exception:
254257
continue
255258

@@ -266,10 +269,10 @@ def monitor(
266269
)
267270
elif log_format == "csv":
268271
f.write(
269-
f"{elapsed_time},{current_cpu},{current_mem_real},{current_mem_virtual}"
272+
f"{elapsed_time},{n_proc},{current_cpu},{current_mem_real},{current_mem_virtual}"
270273
)
271274
if include_io:
272-
f.write(f"{read_count},{write_count},{read_bytes},{write_bytes}")
275+
f.write(f",{read_count},{write_count},{read_bytes},{write_bytes}")
273276
f.write("\n")
274277
f.flush()
275278

psrecord/tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_logfile_csv(self, tmpdir):
6363
assert len(open(filename).readlines()) > 0
6464
with open(filename) as csvfile:
6565
data = csv.reader(csvfile)
66-
assert next(data) == ["elapsed_time", "cpu", "mem_real", "mem_virtual"]
66+
assert next(data) == ["elapsed_time", "nproc", "cpu", "mem_real", "mem_virtual"]
6767

6868
def test_plot(self, tmpdir):
6969
pytest.importorskip("matplotlib")

0 commit comments

Comments
 (0)