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

Add CPU model name to trace files and traceRecord #3946

Merged
merged 8 commits into from
Jul 5, 2023
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
5 changes: 5 additions & 0 deletions docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ The following table shows the fields that can be included in the execution repor
:::
: The host on which the task was executed. Supported only for the Kubernetes executor yet. Activate with `k8s.fetchNodeName = true` in the Nextflow config file.

`cpu_model`
: :::{versionadded} 22.07.0-edge
:::
: The name of the CPU model used to execute the task. This data is read from file `/proc/cpuinfo`.

:::{note}
These metrics provide an estimation of the resources used by running tasks. They are not an alternative to low-level performance analysis tools, and they may not be completely accurate, especially for very short-lived tasks (running for less than a few seconds).
:::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class TraceRecord implements Serializable {
error_action:'str',
vol_ctxt: 'num',
inv_ctxt: 'num',
hostname: 'str'
hostname: 'str',
cpu_model: 'str'
]

static public Map<String,Closure<String>> FORMATTER = [
Expand Down Expand Up @@ -448,6 +449,10 @@ class TraceRecord implements Serializable {
this.put(name, val)
break

case 'cpu_model':
this.put(name, value)
break

default:
def val = parseLong(value, file, name)
this.put(name, val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ nxf_write_trace() {
echo "nextflow.trace/v2" > $trace_file
echo "realtime=$wall_time" >> $trace_file
echo "%cpu=$ucpu" >> $trace_file
echo "cpu_model=$cpu_model" >> $trace_file
echo "rchar=${io_stat1[0]}" >> $trace_file
echo "wchar=${io_stat1[1]}" >> $trace_file
echo "syscr=${io_stat1[2]}" >> $trace_file
Expand All @@ -144,6 +145,7 @@ nxf_trace_mac() {
local end_millis=$(nxf_date)
local wall_time=$((end_millis-start_millis))
local ucpu=''
local cpu_model=''
local io_stat1=('' '' '' '' '' '')
nxf_write_trace
}
Expand All @@ -163,6 +165,7 @@ nxf_trace_linux() {
## https://stackoverflow.com/questions/27508531/calculate-cpu-per-process/27514562##27514562
## https://stackoverflow.com/questions/16726779/how-do-i-get-the-total-cpu-usage-of-an-application-from-proc-pid-stat
local num_cpus=$(< /proc/cpuinfo grep '^processor' -c)
local cpu_model=$(< /proc/cpuinfo grep '^model name' | head -n 1 | awk 'BEGIN{FS="\t: "} { print $2 }')
local tot_time0=$(grep '^cpu ' /proc/stat | awk '{sum=$2+$3+$4+$5+$6+$7+$8+$9; printf "%.0f",sum}')
local cpu_time0=$(2> /dev/null < /proc/$pid/stat awk '{printf "%.0f", ($16+$17)*10 }' || echo -n 'X')
local io_stat0=($(2> /dev/null < /proc/$pid/io sed 's/^.*:\s*//' | head -n 6 | tr '\n' ' ' || echo -n '0 0 0 0 0 0'))
Expand Down Expand Up @@ -199,6 +202,7 @@ nxf_trace_linux() {
echo "nextflow.trace/v2" > $trace_file
echo "realtime=$wall_time" >> $trace_file
echo "%cpu=$ucpu" >> $trace_file
echo "cpu_model=$cpu_model" >> $trace_file
echo "rchar=${io_stat1[0]}" >> $trace_file
echo "wchar=${io_stat1[1]}" >> $trace_file
echo "syscr=${io_stat1[2]}" >> $trace_file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ nxf_write_trace() {
echo "nextflow.trace/v2" > $trace_file
echo "realtime=$wall_time" >> $trace_file
echo "%cpu=$ucpu" >> $trace_file
echo "cpu_model=$cpu_model" >> $trace_file
echo "rchar=${io_stat1[0]}" >> $trace_file
echo "wchar=${io_stat1[1]}" >> $trace_file
echo "syscr=${io_stat1[2]}" >> $trace_file
Expand All @@ -125,6 +126,7 @@ nxf_trace_mac() {
local end_millis=$(nxf_date)
local wall_time=$((end_millis-start_millis))
local ucpu=''
local cpu_model=''
local io_stat1=('' '' '' '' '' '')
nxf_write_trace
}
Expand All @@ -139,6 +141,7 @@ nxf_trace_linux() {
local pid=$$
command -v ps &>/dev/null || { >&2 echo "Command 'ps' required by nextflow to collect task metrics cannot be found"; exit 1; }
local num_cpus=$(< /proc/cpuinfo grep '^processor' -c)
local cpu_model=$(< /proc/cpuinfo grep '^model name' | head -n 1 | awk 'BEGIN{FS="\t: "} { print $2 }')
local tot_time0=$(grep '^cpu ' /proc/stat | awk '{sum=$2+$3+$4+$5+$6+$7+$8+$9; printf "%.0f",sum}')
local cpu_time0=$(2> /dev/null < /proc/$pid/stat awk '{printf "%.0f", ($16+$17)*10 }' || echo -n 'X')
local io_stat0=($(2> /dev/null < /proc/$pid/io sed 's/^.*:\s*//' | head -n 6 | tr '\n' ' ' || echo -n '0 0 0 0 0 0'))
Expand Down Expand Up @@ -171,6 +174,7 @@ nxf_trace_linux() {
echo "nextflow.trace/v2" > $trace_file
echo "realtime=$wall_time" >> $trace_file
echo "%cpu=$ucpu" >> $trace_file
echo "cpu_model=$cpu_model" >> $trace_file
echo "rchar=${io_stat1[0]}" >> $trace_file
echo "wchar=${io_stat1[1]}" >> $trace_file
echo "syscr=${io_stat1[2]}" >> $trace_file
Expand Down