summaryrefslogtreecommitdiff
path: root/ioslay-firefox
blob: eac3184033d3b54505cc8378fb1274a0e675ad65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh

if [ "$1" = -q ]
then
    exec 2>/dev/null
    shift
fi

web_content_pids()
{
    top -w512 -bn1 -o '%MEM' | sed -e '1,/^$/d' | {
        while read line
        do set -- $line
           [ "${12} ${13}" = "Web Content" ] || continue
           echo $1
        done
    }
}

set -- $(web_content_pids | tac)

set -- $(printf "\055\055pid=%s " $*)

over_count=0
sudo -- iotop -qq -b "$@" |
    while read line
    do
        case "$line" in
            "Total DISK"*)
                if [ "$OVER" ]
                then
                    over_count=$((over_count + 1))
                    if [ "$over_count" -gt 3 ]
                    then
                        fireslay
                    fi
                    over=
                else
                    over_count=0
                fi
            ;;
            "Current DISK"*) continue ;;
            *)
                set -- $line
                pct=${10%.*}
                if [ $pct -gt 90 ]
                then
                    printf '[%d] %s%% %s\n' "$over_count" "${10}" "${12}" >&2
                    over=y
                fi
                ;;
        esac
    done