Skip to content

Commit

Permalink
[disk_io_stats_diff] Implement method
Browse files Browse the repository at this point in the history
  • Loading branch information
dag committed May 1, 2008
1 parent 900d8b7 commit 9c20dc0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Here is a list of all exceptions in the `Statgrab` namespace:
- `cpu_stats_diff`
- `cpu_percents`
- `disk_io_stats`
- `disk_io_stats_diff`

Somewhat relevant information is available for every method
supplied with libstatgrab as manual pages:
Expand Down
28 changes: 28 additions & 0 deletions statgrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ static VALUE statgrab_disk_io_stats(VALUE self) {
return arr;
}

static VALUE statgrab_disk_io_stats_diff(VALUE self) {
int entries, i;
sg_disk_io_stats *stats;
VALUE arr, info;

stats = sg_get_disk_io_stats_diff(&entries);
if(stats==NULL)
statgrab_handle_error();

arr = rb_ary_new();
for(i = 0; i < entries; i++) {
info = rb_hash_new();
rb_hash_aset(info, ID2SYM(rb_intern("disk_name")), rb_str_new2(stats[i].disk_name));
rb_hash_aset(info, ID2SYM(rb_intern("read_bytes")), INT2NUM(stats[i].read_bytes));
rb_hash_aset(info, ID2SYM(rb_intern("write_bytes")), INT2NUM(stats[i].write_bytes));
rb_hash_aset(info, ID2SYM(rb_intern("systime")), INT2NUM(stats[i].systime));

VALUE time_now;
time_now = rb_funcall(rb_cTime, rb_intern("now"), 0);
rb_hash_aset(info, ID2SYM(rb_intern("last_call")), rb_funcall(time_now, rb_intern("-"), 1, INT2NUM(stats[i].systime)));

rb_ary_push(arr, info);
}

return arr;
}

void Init_statgrab() {
cStatgrab = rb_define_class("Statgrab", rb_cObject);
eStatgrabException = rb_define_class_under(cStatgrab, "Exception", rb_eException);
Expand Down Expand Up @@ -306,4 +333,5 @@ void Init_statgrab() {
rb_define_method(cStatgrab, "cpu_stats_diff", statgrab_cpu_stats_diff, 0);
rb_define_method(cStatgrab, "cpu_percents", statgrab_cpu_percents, 0);
rb_define_method(cStatgrab, "disk_io_stats", statgrab_disk_io_stats, 0);
rb_define_method(cStatgrab, "disk_io_stats_diff", statgrab_disk_io_stats_diff, 0);
}

0 comments on commit 9c20dc0

Please sign in to comment.