]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/scripts/seastar-cpu-map.sh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / scripts / seastar-cpu-map.sh
CommitLineData
11fdf7f2
TL
1#!/bin/bash
2# !
3# ! Usage: ./seastar-cpu-map.sh -p <process_PID> -n <process_Name> -s (optional) <shard>
4# !
5# ! List CPU affinity for a particular running process
6# ! providing a map of threads -> shard, for any seastar apps.
7# ! Ex.: ./seastar-cpu-map.sh -n scylla
8# ! ./seastar-cpu-map.sh -n scylla -s 0
9# ! ./seastar-cpu-map.sh -p 34
10# ! ./seastar-cpu-map.sh -p 32 -s 12
11
12usage() {
13 cat $0 | grep ^"# !" | cut -d"!" -f2-
14}
15
16while getopts 'p:n:s:' option; do
17 case "$option" in
18 p) PID=$OPTARG
19 ;;
1e59de90 20 n) PID=`pgrep --newest --exact $OPTARG`
11fdf7f2
TL
21 ;;
22 s) SHARD=$OPTARG
23 ;;
24 :) printf "missing argument for -%s\n" "$OPTARG" >&2
25 usage >&2
26 exit 1
27 ;;
28 \?) printf "illegal option: -%s\n" "$OPTARG" >&2
29 usage >&2
30 exit 1
31 ;;
32 esac
33done
34
35if [ $# -eq 0 ]; then usage >&2; exit 1; fi
36
37if [ -e "/proc/$PID/task" ]; then
38 # get list of threads for given PID
39 THREADS=`ls /proc/$PID/task`
40 for i in $THREADS; do
41 # get shards from threads
42 # there were three options here to get the shard number:
43 # reactor-xx, syscall-xx and timer-xx
44 # syscall was preferred because reactor as a special case (reactor-0 is called scylla)
45 SYSCALL=`grep syscall /proc/$i/comm | cut -d"-" -f2`
46 if [ -n "$SYSCALL" ] && [ "$SYSCALL" = "$SHARD" ]; then
47 echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)"
48 elif [ -n "$SYSCALL" ] && [ -z "$SHARD" ]; then
49 echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)"
50 fi
51 done
52else
53 echo "Process does not exist"
54fi