Skip to content

Commit

Permalink
Switch from echo to printf
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Holguin <[email protected]>
  • Loading branch information
Nico Holguin committed Dec 2, 2024
1 parent 37bdf9d commit 75d8535
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,28 @@ nxf_mem_watch() {
done

## result struct: pid %mem vmem rss peak_vmem peak_rss
{
echo "%mem=${nxf_stat_ret[1]}"
echo "vmem=${nxf_stat_ret[2]}"
echo "rss=${nxf_stat_ret[3]}"
echo "peak_vmem=${nxf_stat_ret[4]}"
echo "peak_rss=${nxf_stat_ret[5]}"
echo "vol_ctxt=${nxf_stat_ret[6]}"
echo "inv_ctxt=${nxf_stat_ret[7]}"
} >> "$trace_file" || >&2 echo "Error: Failed to append to file: $trace_file"
printf "%s\n" \
"%mem=${nxf_stat_ret[1]}" \
"vmem=${nxf_stat_ret[2]}" \
"rss=${nxf_stat_ret[3]}" \
"peak_vmem=${nxf_stat_ret[4]}" \
"peak_rss=${nxf_stat_ret[5]}" \
"vol_ctxt=${nxf_stat_ret[6]}" \
"inv_ctxt=${nxf_stat_ret[7]}" >> "$trace_file" || >&2 echo "Error: Failed to append to file: $trace_file"
}

nxf_write_trace() {
{
echo "nextflow.trace/v2"
echo "realtime=$wall_time"
echo "%cpu=$ucpu"
echo "cpu_model=$cpu_model"
echo "rchar=${io_stat1[0]}"
echo "wchar=${io_stat1[1]}"
echo "syscr=${io_stat1[2]}"
echo "syscw=${io_stat1[3]}"
echo "read_bytes=${io_stat1[4]}"
echo "write_bytes=${io_stat1[5]}"
} > $trace_file || >&2 echo "Error: Failed to write to file: $trace_file"
printf "%s\n" \
"nextflow.trace/v2" \
"realtime=$wall_time" \
"%cpu=$ucpu" \
"cpu_model=$cpu_model" \
"rchar=${io_stat1[0]}" \
"wchar=${io_stat1[1]}" \
"syscr=${io_stat1[2]}" \
"syscw=${io_stat1[3]}" \
"read_bytes=${io_stat1[4]}" \
"write_bytes=${io_stat1[5]}" > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"
}

nxf_trace_mac() {
Expand Down Expand Up @@ -203,18 +201,17 @@ nxf_trace_linux() {
local wall_time=$((end_millis-start_millis))
[ $NXF_DEBUG = 1 ] && echo "+++ STATS %CPU=$ucpu TIME=$wall_time I/O=${io_stat1[*]}"

{
echo "nextflow.trace/v2"
echo "realtime=$wall_time"
echo "%cpu=$ucpu"
echo "cpu_model=$cpu_model"
echo "rchar=${io_stat1[0]}"
echo "wchar=${io_stat1[1]}"
echo "syscr=${io_stat1[2]}"
echo "syscw=${io_stat1[3]}"
echo "read_bytes=${io_stat1[4]}"
echo "write_bytes=${io_stat1[5]}"
} > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"
printf "%s\n" \
"nextflow.trace/v2" \
"realtime=$wall_time" \
"%cpu=$ucpu" \
"cpu_model=$cpu_model" \
"rchar=${io_stat1[0]}" \
"wchar=${io_stat1[1]}" \
"syscr=${io_stat1[2]}" \
"syscw=${io_stat1[3]}" \
"read_bytes=${io_stat1[4]}" \
"write_bytes=${io_stat1[5]}" > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"

## join nxf_mem_watch
[ -e /proc/$mem_proc ] && eval "echo 'DONE' >&$mem_fd" || true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,28 @@ nxf_mem_watch() {
count=$((count+1))
done

{
echo "%mem=${nxf_stat_ret[1]}"
echo "vmem=${nxf_stat_ret[2]}"
echo "rss=${nxf_stat_ret[3]}"
echo "peak_vmem=${nxf_stat_ret[4]}"
echo "peak_rss=${nxf_stat_ret[5]}"
echo "vol_ctxt=${nxf_stat_ret[6]}"
echo "inv_ctxt=${nxf_stat_ret[7]}"
} >> "$trace_file" || >&2 echo "Error: Failed to append to file: $trace_file"
printf "%s\n" \
"%mem=${nxf_stat_ret[1]}" \
"vmem=${nxf_stat_ret[2]}" \
"rss=${nxf_stat_ret[3]}" \
"peak_vmem=${nxf_stat_ret[4]}" \
"peak_rss=${nxf_stat_ret[5]}" \
"vol_ctxt=${nxf_stat_ret[6]}" \
"inv_ctxt=${nxf_stat_ret[7]}" >> "$trace_file" || >&2 echo "Error: Failed to append to file: $trace_file"
}

nxf_write_trace() {
{
echo "nextflow.trace/v2"
echo "realtime=$wall_time"
echo "%cpu=$ucpu"
echo "cpu_model=$cpu_model"
echo "rchar=${io_stat1[0]}"
echo "wchar=${io_stat1[1]}"
echo "syscr=${io_stat1[2]}"
echo "syscw=${io_stat1[3]}"
echo "read_bytes=${io_stat1[4]}"
echo "write_bytes=${io_stat1[5]}"
} > $trace_file || >&2 echo "Error: Failed to write to file: $trace_file"
printf "%s\n" \
"nextflow.trace/v2" \
"realtime=$wall_time" \
"%cpu=$ucpu" \
"cpu_model=$cpu_model" \
"rchar=${io_stat1[0]}" \
"wchar=${io_stat1[1]}" \
"syscr=${io_stat1[2]}" \
"syscw=${io_stat1[3]}" \
"read_bytes=${io_stat1[4]}" \
"write_bytes=${io_stat1[5]}" > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"
}

nxf_trace_mac() {
Expand Down Expand Up @@ -177,18 +175,17 @@ nxf_trace_linux() {
local wall_time=$((end_millis-start_millis))
[ $NXF_DEBUG = 1 ] && echo "+++ STATS %CPU=$ucpu TIME=$wall_time I/O=${io_stat1[*]}"

{
echo "nextflow.trace/v2"
echo "realtime=$wall_time"
echo "%cpu=$ucpu"
echo "cpu_model=$cpu_model"
echo "rchar=${io_stat1[0]}"
echo "wchar=${io_stat1[1]}"
echo "syscr=${io_stat1[2]}"
echo "syscw=${io_stat1[3]}"
echo "read_bytes=${io_stat1[4]}"
echo "write_bytes=${io_stat1[5]}"
} > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"
printf "%s\n" \
"nextflow.trace/v2" \
"realtime=$wall_time" \
"%cpu=$ucpu" \
"cpu_model=$cpu_model" \
"rchar=${io_stat1[0]}" \
"wchar=${io_stat1[1]}" \
"syscr=${io_stat1[2]}" \
"syscw=${io_stat1[3]}" \
"read_bytes=${io_stat1[4]}" \
"write_bytes=${io_stat1[5]}" > "$trace_file" || >&2 echo "Error: Failed to write to file: $trace_file"

[ -e /proc/$mem_proc ] && eval "echo 'DONE' >&$mem_fd" || true
wait $mem_proc 2>/dev/null || true
Expand Down

0 comments on commit 75d8535

Please sign in to comment.