25
25
base("diskload", 2, 10, 1000);
28
private string[] split(string val) {
29
string[] result = null;
32
for (; *current != '\0'; current = current + 1) {
33
if (*current == ' ' || *current == '\n') {
35
result += strndup(last, current - last);
44
result += strndup(last, current - last);
28
48
public override void update() {
29
49
uint64[] newdata = new uint64[3];
30
50
uint64 newtime = get_monotonic_time();
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);
39
for (uint i = 0; i < mountlist.number; ++i) {
41
GTop.get_fsusage(out fsusage, mountentries[i].mountdir);
42
newdata[0] += fsusage.read;
43
newdata[1] += fsusage.write;
53
// Accounts for io for everything that has an associated device
54
// TODO: will jump on unmount
55
Dir directory = Dir.open("/sys/block");
57
while ((entry = directory.read_name()) != null) {
58
if (!FileUtils.test(@"/sys/block/$entry/device", FileTest.EXISTS))
62
FileUtils.get_contents(@"/sys/block/$entry/stat", out stat);
66
string[] stats = this.split(stat);
69
newdata[0] += 512 * uint64.parse(stats[2]);
70
newdata[1] += 512 * uint64.parse(stats[6]);
73
// Fall back to libgtop if we have no /sys
74
GTop.MountEntry[] mountentries;
75
GTop.MountList mountlist;
76
mountentries = GTop.get_mountlist (out mountlist, false);
77
for (uint i = 0; i < mountlist.number; ++i) {
79
GTop.get_fsusage(out fsusage, mountentries[i].mountdir);
80
newdata[0] += fsusage.block_size * fsusage.read;
81
newdata[1] += fsusage.block_size * fsusage.write;
46
85
double read = 0, write = 0;