~indicator-multiload/indicator-multiload/trunk

1 by Michael Hofmann
Initial public version.
1
/******************************************************************************
2
 * Copyright (C) 2011  Michael Hofmann <mh21@piware.de>                       *
3
 *                                                                            *
4
 * This program is free software; you can redistribute it and/or modify       *
5
 * it under the terms of the GNU General Public License as published by       *
6
 * the Free Software Foundation; either version 3 of the License, or          *
7
 * (at your option) any later version.                                        *
8
 *                                                                            *
9
 * This program is distributed in the hope that it will be useful,            *
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
12
 * GNU General Public License for more details.                               *
13
 *                                                                            *
14
 * You should have received a copy of the GNU General Public License along    *
15
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                *
17
 ******************************************************************************/
18
19
public class DiskIconData : IconData {
20
    private uint64[] lastdata;
21
    private uint64 lasttime;
22
23
    public DiskIconData() {
24
        // minimum of 1 kb/s
25
        base("diskload", 2, 10, 1000);
26
    }
27
28
    public override void update_traces() {
29
        uint64[] newdata = new uint64[3];
30
        uint64 newtime = get_monotonic_time();
31
32
        // TODO: This does not work for LVM or virtual fs
33
        // may give weird results anyway if there are two partitions on the same drive?
34
        // on Linux, maybe copy the code from iotop?
35
        GTop.MountEntry[] mountentries;
36
        GTop.MountList mountlist;
37
        mountentries = GTop.get_mountlist (out mountlist, false);
38
39
        for (uint i = 0; i < mountlist.number; ++i) {
40
            GTop.FSUsage fsusage;
41
            GTop.get_fsusage(out fsusage, mountentries[i].mountdir);
42
            newdata[0] += fsusage.read;
43
            newdata[1] += fsusage.write;
44
        }
45
46
        if (this.lastdata.length == 0) {
47
            foreach (unowned IconTraceData trace in this.traces)
48
                trace.add_value(0);
49
        } else {
50
            double delta = (newtime - this.lasttime) / 1e6;
51
            for (uint i = 0, isize = this.traces.length; i < isize; ++i)
52
                this.traces[i].add_value((newdata[i] - this.lastdata[i]) / delta);
53
        }
54
        this.lastdata = newdata;
55
        this.lasttime = newtime;
56
    }
57
}