From be326e580cb7a34634242e7408a99607231d9aa7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 5 Feb 2022 11:09:25 -0500 Subject: almost --- fireslay | 26 +++++++++++++------ ioslay-firefox | 79 ---------------------------------------------------------- ioslay-mgr.sh | 21 +++++++++++++--- 3 files changed, 37 insertions(+), 89 deletions(-) diff --git a/fireslay b/fireslay index a63a709..3e52a84 100755 --- a/fireslay +++ b/fireslay @@ -65,17 +65,29 @@ main() exit $r } +is_web_content() +{ + local comm state + read comm < /proc/"$1"/comm && [ "$comm" = 'Web Content' ] && + read _ _ state _ < /proc/"$1"/stat && [ "$state" != Z ] || return +} + web_content_pids() { - while read pids + while read pid do - for pid in $pids - do - read comm < /proc/$pid/comm && [ "$comm" = 'Web Content' ] || continue - read _ _ state _ < /proc/$pid/stat && [ "$state" != Z ] && echo $pid - done - done < "$(get_current_group)"/cgroup.procs + if is_web_content $pid + then + echo $pid + fi + done < $FIREFOX_GROUP/cgroup.procs } +CURRENT_GROUP=$(get_current_group) +FIREFOX_GROUP=${CURRENT_GROUP%/*}/firefox +FIREFOX_GROUP_PROCS=$FIREFOX_GROUP/cgroup.procs + +[ -e "$FIREFOX_GROUP_PROCS" ] + main "$@" diff --git a/ioslay-firefox b/ioslay-firefox index bebcd11..0fae790 100755 --- a/ioslay-firefox +++ b/ioslay-firefox @@ -1,31 +1,4 @@ #!/bin/bash -web_content_pids() -{ - top -w512 -b -o '%MEM' | { - unset PIDS - while read line - do - case "$line" in - top*) - if [ "${PIDS+is_set}" ] - then - echo $PIDS - fi - while [ "$line" ] - do read line - done - PIDS= - ;; - *) - set -- $line - [ "${12} ${13}" = "Web Content" ] || continue - PIDS="$PIDS $1" - ;; - esac - done - } -} - sum() { local total=0 n @@ -48,59 +21,7 @@ last() printf '%s\n' "$*" } -new_pids() -{ - # This is not correct because the correct code is not implemented yet. - # But this is OK for testing the other parts. Fixing this is only an - # optimization. - [ "$1" != "$2" ] -} - enable -f /usr/lib/bash/sleep sleep 2>/dev/null || true -unset IOTOP_PID -relaunch_iotop() -{ - if [ "$IOTOP_PID" ] - then - kill "$IOTOP_PID" - fi - - web_content_pids | ( - while read pids - do - set -- $pids - if [ $# = 0 ] - then - kill_iotop - elif new_pids "$pids" "$oldpids" - then - kill_iotop - IOTOP_PID=$(launch_iotop "$@") - fi - sleep 1 - oldpids=$pids - done - ) -} - -kill_iotop() -{ - if [ "$IOTOP_PID" ] - then - ( - set -x - kill "$IOTOP_PID" - ) - fi -} - -launch_iotop() -{ - set -- $(printf '\55\55pid=%s\n' "$@" | tac) - (set -x - iotop -qq -b "$@") | iotop_reader & - echo $! -} iotop_reader() { diff --git a/ioslay-mgr.sh b/ioslay-mgr.sh index 6765d83..1b8cf73 100755 --- a/ioslay-mgr.sh +++ b/ioslay-mgr.sh @@ -54,12 +54,26 @@ get_uid() # Really, could just check for any/first cgroup with processes and basename # 'firefox'. Fork for each one. +vkill() +{ + if [ $# = 0 ] + then + return + fi + ( + set -x + ps u "$@" + sudo kill "$@" + ) +} + uid=1000 group=user.slice/user-$uid.slice/firefox wantcomm='Web Content' ioslay= lastprocs= -while true +trap 'RECEIVED_SIGINT=y' SIGINT +while [ -z "$RECEIVED_SIGINT" ] do read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs if [ "$procs" ] @@ -77,9 +91,9 @@ do # echo "pids: ($*|$(echo $procs))" >&2 if [ "$lastargs" != "$*" ] then - [ -z "$ioslay" ] || kill $ioslay $(pgrep -P $ioslay) + [ -z "$ioslay" ] || vkill $ioslay $(pgrep -P $ioslay) wait $ioslay - ioslay-firefox "$@" & + sudo ioslay-firefox "$@" & ioslay=$! fi lastargs=$* @@ -87,3 +101,4 @@ do sleep 1 done + -- cgit v1.2.3