| 1 |
< |
Diskio Statistics |
| 1 |
> |
DiskIO Statistics |
| 2 |
> |
================= |
| 3 |
|
|
| 4 |
< |
All diskio statistics return a diskio_stat_t structure. |
| 4 |
> |
Data Structure |
| 5 |
> |
-------------- |
| 6 |
|
|
| 7 |
+ |
All diskio statistics return a structure of type diskio_stat_t that |
| 8 |
+ |
looks like this: |
| 9 |
+ |
|
| 10 |
|
typedef struct{ |
| 11 |
|
char *disk_name; |
| 12 |
|
long long read_bytes; |
| 14 |
|
time_t systime; |
| 15 |
|
}diskio_stat_t; |
| 16 |
|
|
| 17 |
< |
disk_name is the name know to the OS. E.g. hda on linux. |
| 18 |
< |
read_bytes is the number of bytes that disk has read. |
| 19 |
< |
write_bytes is the number of bytes that disk has written. |
| 20 |
< |
sysname is time_t covering the time the amount of data in rx/tx was |
| 21 |
< |
generated. |
| 17 |
> |
disk_name is the name known to the operating system. |
| 18 |
> |
(eg. on linux it might be hda) |
| 19 |
> |
read_bytes is the number of bytes that disk has read. |
| 20 |
> |
write_bytes is the number of bytes that disk has written. |
| 21 |
> |
sysname is the time period over which read_bytes and |
| 22 |
> |
write_bytes were transferred. |
| 23 |
|
|
| 24 |
+ |
Functions |
| 25 |
+ |
--------- |
| 26 |
+ |
|
| 27 |
|
diskio_stat_t *get_diskio_stats(int *entries); |
| 28 |
|
|
| 29 |
|
diskio_stat_t *get_diskio_stats_diff(int *entries); |
| 30 |
|
|
| 31 |
< |
Both calls take a pointer to an int, "entries". This is filled with the number |
| 32 |
< |
of disks the machine has. You need to know this to know how many diskio_stat_t |
| 33 |
< |
have been returned. |
| 31 |
> |
Both calls take a pointer to an int, "entries", which is filled with |
| 32 |
> |
the number of disks the machine has. This is needed to know how many |
| 33 |
> |
diskio_stat_t structures have been returned. A pointer is returned to |
| 34 |
> |
the first diskio_stat_t. |
| 35 |
|
|
| 36 |
< |
get_diskio_stats returns the disk io stored in the kernel. E.g. |
| 37 |
< |
since bootup as long as the way it is stored in the kernel can store a large |
| 38 |
< |
enough number. Solaris 7 can not, it only stores it in a 32bit int, so it |
| 39 |
< |
can only store upto 4gb before it will wrap around. Solaris 8 upwards stores |
| 40 |
< |
it in a 64bit int and so is a very large number :) |
| 36 |
> |
get_diskio_stats returns the disk IO stored in the kernel which holds |
| 37 |
> |
the amount of data transferred since bootup. On some platforms, such as |
| 38 |
> |
Solaris 7, this value is stored in a 32bit int, so wraps around when it |
| 39 |
> |
reaches 4GB. Other platforms, such as Solaris 8, hold the value in a |
| 40 |
> |
64bit int, which wraps somewhere near 17 million terabytes. |
| 41 |
|
|
| 42 |
|
get_diskio_stats_diff is the same as get_diskio_stats except it will |
| 43 |
|
return the difference since the last call. So, for instance a call to |
| 44 |
< |
get_diskio_stats_diff is made, and called again 5 seconds later. Over that |
| 45 |
< |
time, 2000 bytes of traffic was written and 10000 bytes read. write_bytes will |
| 46 |
< |
store 2000 bytes, read_bytes will store 10000 and systime will store 5. This |
| 47 |
< |
function copes with wrap arounds by the O/S so should be seemless to use. |
| 44 |
> |
get_diskio_stats_diff is made, and called again 5 seconds later. Over |
| 45 |
> |
that time, 2000 bytes of traffic were written and 10000 bytes read. |
| 46 |
> |
write_bytes will store 2000 bytes, read_bytes will store 10000, and |
| 47 |
> |
systime will store 5. This function copes with wrap arounds by the O/S |
| 48 |
> |
so should be seemless to use. |
| 49 |
|
|
| 50 |
< |
Bugs: |
| 51 |
< |
get_diskio_stats_diff on very first call will return the same as |
| 41 |
< |
get_diskio_stats. After first call it will always return the difference. |
| 42 |
< |
On machines that hold only 32bits of information, if the call is made 2x |
| 43 |
< |
wrap around (eg sol7 9gb has been transferred, and it wraps at 4gb) it will |
| 44 |
< |
return incorrect results (case above, it would say 5gb transferred). |
| 50 |
> |
Bugs |
| 51 |
> |
---- |
| 52 |
|
|
| 53 |
< |
Very basic example in examples/disk_traffic.c |
| 53 |
> |
On the very first call get_diskio_stats_diff will return the same as |
| 54 |
> |
get_diskio_stats. After the first call it will always return the |
| 55 |
> |
difference. |
| 56 |
> |
|
| 57 |
> |
On operating systems that hold only 32bits of data there is a problem |
| 58 |
> |
if the values wrap twice. For example, on Solaris 7 if 9GB is |
| 59 |
> |
transferred and the operating system wraps at 4GB, the |
| 60 |
> |
get_diskio_stats_diff function will return 5GB. |
| 61 |
> |
|
| 62 |
> |
Example |
| 63 |
> |
------- |
| 64 |
> |
|
| 65 |
> |
A very basic example can be found in examples/disk_traffic.c |