summaryrefslogtreecommitdiff
path: root/ioslay-firefox
blob: d56553f685121d469b046fd6c78abd74a057c908 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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 " $*)

log=
over_count=0
sudo -- iotop -qq -b "$@" |
    while read line
    do
        case "$line" in
            "Total DISK"*)
                if [ "$over" ]
                then
                    log="$log 1"
                    over=
                else
                    log="$log 0"
                fi
                set -- $log
                while [ $# -gt 10 ]
                do
                    shift
                done
                log=$*

                total=0
                echo "log=$log" >&2
                for n in $log
                do
                    total=$((total+n))
                done
                if [ "$total" -gt 5 ]
                then
                    fireslay
                fi
            ;;
            "Current DISK"*) continue ;;
            *)
                set -- $line
                pct=${10%.*}
                if [ $pct -gt 90 ]
                then
                    printf '[%d] %s%% %s\n' "$total" "${10}" "${12}" >&2
                    over=y
                fi
                ;;
        esac
    done