Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
squeue-with-context-switches
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
squeue-with-context-switches
Commits
0377315a
Commit
0377315a
authored
7 months ago
by
William E Warriner
Browse files
Options
Downloads
Patches
Plain Diff
initial commit of script
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slurm-procs.sh
+42
-0
42 additions, 0 deletions
slurm-procs.sh
with
42 additions
and
0 deletions
slurm-procs.sh
0 → 100755
+
42
−
0
View file @
0377315a
#!/bin/bash
# Extract pid-job relationship
SCONTROL_PID_COL
=
1
SCONTROL_JOB_COL
=
2
SCONTROL_WIDTH
=
$(
scontrol listpids |
awk
'{print NF; exit}'
)
# Get pidstat -w output, extract headers and required columns
PIDSTAT_PID_COL
=
1
PIDSTAT_CTXTSW_COL
=
$((
2
+
$SCONTROL_WIDTH
-
1
))
# Extract headers and required columns from ps -aux
PS_PID_COL
=
1
PS_USER_COL
=
2
# Extract headers separately
ps_header
=
$(
ps
-eo
"pid,user,cp,drs,cmd"
--sort
pid |
head
-n
1
)
pidstat_header
=
$(
pidstat
-w
|
awk
'NR==3 {print $4, $5, $6}'
)
scontrol_header
=
$(
scontrol listpids |
head
-n
1
)
# Sort the outputs by PID, excluding headers
ps_sorted
=
$(
ps
-eo
"pid,user,cp,drs,cmd"
--sort
pid |
tail
-n
+2 |
sort
-k
$PS_PID_COL
,
$PS_PID_COL
)
pidstat_sorted
=
$(
pidstat
-w
|
awk
'NR>3 {print $4, $5, $6}'
|
sort
-k
$PIDSTAT_PID_COL
,
$PIDSTAT_PID_COL
)
scontrol_sorted
=
$(
scontrol listpids |
tail
-n
+2 |
sort
-k
$SCONTROL_PID_COL
,
$SCONTROL_PID_COL
)
# Join the two outputs on the PID column
scontrol_pidstat
=
$(
join
-1
$SCONTROL_PID_COL
-2
$PIDSTAT_PID_COL
<
(
echo
"
$scontrol_sorted
"
)
<
(
echo
"
$pidstat_sorted
"
)
)
scontrol_pidstat_ps
=
$(
join
-1
$SCONTROL_PID_COL
-2
$PS_PID_COL
<
(
echo
"
$scontrol_pidstat
"
)
<
(
echo
"
$ps_sorted
"
)
)
# Aggregate
agg
=
$(
echo
"
$scontrol_pidstat_ps
"
|
awk
-v
key_col
=
$SCONTROL_JOB_COL
-v
val_col
=
$PIDSTAT_CTXTSW_COL
\
'{
arr[$key_col]+=$val_col
}
END {
for (key in arr) printf("%s\t%s\n", key, arr[key])
}'
|
sort
-k1
,1
)
# Combine with squeue
squeue_header
=
$(
squeue
-w
$(
hostname
)
|
head
-n
1 |
sed
's/ \+/\t/g'
|
sed
's/^[ \t]*//'
)
printf
"%s
\t
context-switches/s
\n
"
"
$squeue_header
"
join
-1
1
-2
1 <
(
squeue
-w
$(
hostname
)
|
sort
-k1
,1
)
<
(
echo
"
$agg
"
)
|
sed
's/ \+/\t/g'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment