summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-02-05 11:09:25 -0500
committerAndrew Cady <d@cryptonomic.net>2022-02-05 11:09:25 -0500
commitbe326e580cb7a34634242e7408a99607231d9aa7 (patch)
tree0735a6e5894a962b01b1b314bb5e9d7f818fdd36
parente0783c80d3d6f6f6efdbe2fddde4ff1ec00a5558 (diff)
almost
-rwxr-xr-xfireslay26
-rwxr-xr-xioslay-firefox79
-rwxr-xr-xioslay-mgr.sh21
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()
65 exit $r 65 exit $r
66} 66}
67 67
68is_web_content()
69{
70 local comm state
71 read comm < /proc/"$1"/comm && [ "$comm" = 'Web Content' ] &&
72 read _ _ state _ < /proc/"$1"/stat && [ "$state" != Z ] || return
73}
74
68web_content_pids() 75web_content_pids()
69{ 76{
70 while read pids 77 while read pid
71 do 78 do
72 for pid in $pids 79 if is_web_content $pid
73 do 80 then
74 read comm < /proc/$pid/comm && [ "$comm" = 'Web Content' ] || continue 81 echo $pid
75 read _ _ state _ < /proc/$pid/stat && [ "$state" != Z ] && echo $pid 82 fi
76 done 83 done < $FIREFOX_GROUP/cgroup.procs
77 done < "$(get_current_group)"/cgroup.procs
78} 84}
79 85
86CURRENT_GROUP=$(get_current_group)
87FIREFOX_GROUP=${CURRENT_GROUP%/*}/firefox
88FIREFOX_GROUP_PROCS=$FIREFOX_GROUP/cgroup.procs
89
90[ -e "$FIREFOX_GROUP_PROCS" ]
91
80main "$@" 92main "$@"
81 93
diff --git a/ioslay-firefox b/ioslay-firefox
index bebcd11..0fae790 100755
--- a/ioslay-firefox
+++ b/ioslay-firefox
@@ -1,31 +1,4 @@
1#!/bin/bash 1#!/bin/bash
2web_content_pids()
3{
4 top -w512 -b -o '%MEM' | {
5 unset PIDS
6 while read line
7 do
8 case "$line" in
9 top*)
10 if [ "${PIDS+is_set}" ]
11 then
12 echo $PIDS
13 fi
14 while [ "$line" ]
15 do read line
16 done
17 PIDS=
18 ;;
19 *)
20 set -- $line
21 [ "${12} ${13}" = "Web Content" ] || continue
22 PIDS="$PIDS $1"
23 ;;
24 esac
25 done
26 }
27}
28
29sum() 2sum()
30{ 3{
31 local total=0 n 4 local total=0 n
@@ -48,59 +21,7 @@ last()
48 printf '%s\n' "$*" 21 printf '%s\n' "$*"
49} 22}
50 23
51new_pids()
52{
53 # This is not correct because the correct code is not implemented yet.
54 # But this is OK for testing the other parts. Fixing this is only an
55 # optimization.
56 [ "$1" != "$2" ]
57}
58
59enable -f /usr/lib/bash/sleep sleep 2>/dev/null || true 24enable -f /usr/lib/bash/sleep sleep 2>/dev/null || true
60unset IOTOP_PID
61relaunch_iotop()
62{
63 if [ "$IOTOP_PID" ]
64 then
65 kill "$IOTOP_PID"
66 fi
67
68 web_content_pids | (
69 while read pids
70 do
71 set -- $pids
72 if [ $# = 0 ]
73 then
74 kill_iotop
75 elif new_pids "$pids" "$oldpids"
76 then
77 kill_iotop
78 IOTOP_PID=$(launch_iotop "$@")
79 fi
80 sleep 1
81 oldpids=$pids
82 done
83 )
84}
85
86kill_iotop()
87{
88 if [ "$IOTOP_PID" ]
89 then
90 (
91 set -x
92 kill "$IOTOP_PID"
93 )
94 fi
95}
96
97launch_iotop()
98{
99 set -- $(printf '\55\55pid=%s\n' "$@" | tac)
100 (set -x
101 iotop -qq -b "$@") | iotop_reader &
102 echo $!
103}
104 25
105iotop_reader() 26iotop_reader()
106{ 27{
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()
54# Really, could just check for any/first cgroup with processes and basename 54# Really, could just check for any/first cgroup with processes and basename
55# 'firefox'. Fork for each one. 55# 'firefox'. Fork for each one.
56 56
57vkill()
58{
59 if [ $# = 0 ]
60 then
61 return
62 fi
63 (
64 set -x
65 ps u "$@"
66 sudo kill "$@"
67 )
68}
69
57uid=1000 70uid=1000
58group=user.slice/user-$uid.slice/firefox 71group=user.slice/user-$uid.slice/firefox
59wantcomm='Web Content' 72wantcomm='Web Content'
60ioslay= 73ioslay=
61lastprocs= 74lastprocs=
62while true 75trap 'RECEIVED_SIGINT=y' SIGINT
76while [ -z "$RECEIVED_SIGINT" ]
63do 77do
64 read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs 78 read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs
65 if [ "$procs" ] 79 if [ "$procs" ]
@@ -77,9 +91,9 @@ do
77 # echo "pids: ($*|$(echo $procs))" >&2 91 # echo "pids: ($*|$(echo $procs))" >&2
78 if [ "$lastargs" != "$*" ] 92 if [ "$lastargs" != "$*" ]
79 then 93 then
80 [ -z "$ioslay" ] || kill $ioslay $(pgrep -P $ioslay) 94 [ -z "$ioslay" ] || vkill $ioslay $(pgrep -P $ioslay)
81 wait $ioslay 95 wait $ioslay
82 ioslay-firefox "$@" & 96 sudo ioslay-firefox "$@" &
83 ioslay=$! 97 ioslay=$!
84 fi 98 fi
85 lastargs=$* 99 lastargs=$*
@@ -87,3 +101,4 @@ do
87 sleep 1 101 sleep 1
88done 102done
89 103
104