summaryrefslogtreecommitdiffstats
path: root/src/seastar/scripts/seastar-cpu-map.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/seastar/scripts/seastar-cpu-map.sh
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/seastar/scripts/seastar-cpu-map.sh')
-rwxr-xr-xsrc/seastar/scripts/seastar-cpu-map.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/seastar/scripts/seastar-cpu-map.sh b/src/seastar/scripts/seastar-cpu-map.sh
new file mode 100755
index 00000000..ebc00009
--- /dev/null
+++ b/src/seastar/scripts/seastar-cpu-map.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+# !
+# ! Usage: ./seastar-cpu-map.sh -p <process_PID> -n <process_Name> -s (optional) <shard>
+# !
+# ! List CPU affinity for a particular running process
+# ! providing a map of threads -> shard, for any seastar apps.
+# ! Ex.: ./seastar-cpu-map.sh -n scylla
+# ! ./seastar-cpu-map.sh -n scylla -s 0
+# ! ./seastar-cpu-map.sh -p 34
+# ! ./seastar-cpu-map.sh -p 32 -s 12
+
+usage() {
+ cat $0 | grep ^"# !" | cut -d"!" -f2-
+}
+
+while getopts 'p:n:s:' option; do
+ case "$option" in
+ p) PID=$OPTARG
+ ;;
+ n) PID=`pidof $OPTARG`
+ ;;
+ s) SHARD=$OPTARG
+ ;;
+ :) printf "missing argument for -%s\n" "$OPTARG" >&2
+ usage >&2
+ exit 1
+ ;;
+ \?) printf "illegal option: -%s\n" "$OPTARG" >&2
+ usage >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ $# -eq 0 ]; then usage >&2; exit 1; fi
+
+if [ -e "/proc/$PID/task" ]; then
+ # get list of threads for given PID
+ THREADS=`ls /proc/$PID/task`
+ for i in $THREADS; do
+ # get shards from threads
+ # there were three options here to get the shard number:
+ # reactor-xx, syscall-xx and timer-xx
+ # syscall was preferred because reactor as a special case (reactor-0 is called scylla)
+ SYSCALL=`grep syscall /proc/$i/comm | cut -d"-" -f2`
+ if [ -n "$SYSCALL" ] && [ "$SYSCALL" = "$SHARD" ]; then
+ echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)"
+ elif [ -n "$SYSCALL" ] && [ -z "$SHARD" ]; then
+ echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)"
+ fi
+ done
+else
+ echo "Process does not exist"
+fi