Convert systat(1) to use the new devstat interface.
Submitted by: "Sergey A. Osokin" <osa@freebsd.org.ru>
This commit is contained in:
parent
f9132cebdc
commit
8f29de8be3
@ -109,7 +109,7 @@ dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2,
|
||||
* devstat version. If not, exit and print a message informing
|
||||
* the user of his mistake.
|
||||
*/
|
||||
if (checkversion() < 0)
|
||||
if (devstat_checkversion(NULL) < 0)
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
|
||||
generation = 0;
|
||||
@ -119,7 +119,7 @@ dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2,
|
||||
select_generation = 0;
|
||||
last_type = DS_MATCHTYPE_NONE;
|
||||
|
||||
if (getdevs(s1) == -1)
|
||||
if (devstat_getdevs(NULL, s1) == -1)
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
|
||||
num_devices = s1->dinfo->numdevs;
|
||||
@ -132,10 +132,9 @@ dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2,
|
||||
* device list has changed, so we don't look for return values of 0
|
||||
* or 1. If we get back -1, though, there is an error.
|
||||
*/
|
||||
if (selectdevs(&dev_select, &num_selected, &num_selections,
|
||||
&select_generation, generation, s1->dinfo->devices,
|
||||
num_devices, NULL, 0, NULL, 0, DS_SELECT_ADD,
|
||||
maxshowdevs, 0) == -1)
|
||||
if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
|
||||
&select_generation, generation, s1->dinfo->devices, num_devices,
|
||||
NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1)
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
|
||||
return(1);
|
||||
@ -155,20 +154,15 @@ dscmd(char *cmd, char *args, int maxshowdevs, struct statinfo *s1)
|
||||
if (prefix(cmd, "type") || prefix(cmd, "match"))
|
||||
return(dsmatchselect(args, DS_SELECT_ONLY, maxshowdevs, s1));
|
||||
if (prefix(cmd, "refresh")) {
|
||||
retval = selectdevs(&dev_select, &num_selected, &num_selections,
|
||||
&select_generation, generation,
|
||||
s1->dinfo->devices, num_devices,
|
||||
(last_type == DS_MATCHTYPE_PATTERN) ?
|
||||
matches : NULL,
|
||||
(last_type == DS_MATCHTYPE_PATTERN) ?
|
||||
num_matches : 0,
|
||||
(last_type == DS_MATCHTYPE_SPEC) ?
|
||||
specified_devices : NULL,
|
||||
(last_type == DS_MATCHTYPE_SPEC) ?
|
||||
num_devices_specified : 0,
|
||||
(last_type == DS_MATCHTYPE_NONE) ?
|
||||
DS_SELECT_ADD : DS_SELECT_ADDONLY,
|
||||
maxshowdevs, 0);
|
||||
retval = devstat_selectdevs(&dev_select, &num_selected,
|
||||
&num_selections, &select_generation, generation,
|
||||
s1->dinfo->devices, num_devices,
|
||||
(last_type ==DS_MATCHTYPE_PATTERN) ? matches : NULL,
|
||||
(last_type ==DS_MATCHTYPE_PATTERN) ? num_matches : 0,
|
||||
(last_type == DS_MATCHTYPE_SPEC) ?specified_devices : NULL,
|
||||
(last_type == DS_MATCHTYPE_SPEC) ?num_devices_specified : 0,
|
||||
(last_type == DS_MATCHTYPE_NONE) ? DS_SELECT_ADD :
|
||||
DS_SELECT_ADDONLY, maxshowdevs, 0);
|
||||
if (retval == -1) {
|
||||
warnx("%s", devstat_errbuf);
|
||||
return(0);
|
||||
@ -225,7 +219,7 @@ dsmatchselect(char *args, devstat_select_mode select_mode, int maxshowdevs,
|
||||
}
|
||||
|
||||
for (i = 0; i < num_args; i++) {
|
||||
if (buildmatch(tstr[i], &matches, &num_matches) != 0) {
|
||||
if (devstat_buildmatch(tstr[i], &matches, &num_matches) != 0) {
|
||||
warnx("%s", devstat_errbuf);
|
||||
return(0);
|
||||
}
|
||||
@ -234,11 +228,10 @@ dsmatchselect(char *args, devstat_select_mode select_mode, int maxshowdevs,
|
||||
|
||||
last_type = DS_MATCHTYPE_PATTERN;
|
||||
|
||||
retval = selectdevs(&dev_select, &num_selected, &num_selections,
|
||||
&select_generation, generation,
|
||||
s1->dinfo->devices, num_devices, matches,
|
||||
num_matches, NULL, 0, select_mode,
|
||||
maxshowdevs, 0);
|
||||
retval = devstat_selectdevs(&dev_select, &num_selected,
|
||||
&num_selections, &select_generation, generation,
|
||||
s1->dinfo->devices, num_devices, matches, num_matches,
|
||||
NULL, 0, select_mode, maxshowdevs, 0);
|
||||
if (retval == -1)
|
||||
err(1, "device selection error");
|
||||
else if (retval == 1)
|
||||
@ -311,11 +304,11 @@ dsselect(char *args, devstat_select_mode select_mode, int maxshowdevs,
|
||||
if (num_devices_specified > 0) {
|
||||
last_type = DS_MATCHTYPE_SPEC;
|
||||
|
||||
retval = selectdevs(&dev_select, &num_selected, &num_selections,
|
||||
&select_generation, generation,
|
||||
s1->dinfo->devices, num_devices, NULL, 0,
|
||||
specified_devices, num_devices_specified,
|
||||
select_mode, maxshowdevs, 0);
|
||||
retval = devstat_selectdevs(&dev_select, &num_selected,
|
||||
&num_selections, &select_generation, generation,
|
||||
s1->dinfo->devices, num_devices, NULL, 0,
|
||||
specified_devices, num_devices_specified,
|
||||
select_mode, maxshowdevs, 0);
|
||||
if (retval == -1)
|
||||
err(1, "%s", devstat_errbuf);
|
||||
else if (retval == 1)
|
||||
|
@ -111,7 +111,7 @@ closeiostat(w)
|
||||
int
|
||||
initiostat()
|
||||
{
|
||||
if ((num_devices = getnumdevs()) < 0)
|
||||
if ((num_devices = devstat_getnumdevs(NULL)) < 0)
|
||||
return(0);
|
||||
|
||||
cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
||||
@ -155,7 +155,7 @@ fetchiostat()
|
||||
* the selection process again, in case a device that we
|
||||
* were previously displaying has gone away.
|
||||
*/
|
||||
switch (getdevs(&cur)) {
|
||||
switch (devstat_getdevs(NULL, &cur)) {
|
||||
case -1:
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
break;
|
||||
@ -320,12 +320,13 @@ devstats(row, col, dn)
|
||||
|
||||
di = dev_select[dn].position;
|
||||
|
||||
busy_seconds = compute_etime(cur.busy_time, last.busy_time);
|
||||
busy_seconds = devstat_compute_etime(cur.busy_time, last.busy_time);
|
||||
|
||||
if (compute_stats(&cur.dinfo->devices[di], &last.dinfo->devices[di],
|
||||
busy_seconds, NULL, NULL, NULL,
|
||||
&kb_per_transfer, &transfers_per_second,
|
||||
&mb_per_second, NULL, NULL) != 0)
|
||||
if (devstat_compute_statistics(&cur.dinfo->devices[di],
|
||||
&last.dinfo->devices[di], busy_seconds,
|
||||
DSM_KB_PER_TRANSFER, &kb_per_transfer,
|
||||
DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
|
||||
DSM_MB_PER_SECOND, &mb_per_second, DSM_NONE) != 0)
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
|
||||
if (numbers) {
|
||||
|
@ -211,7 +211,7 @@ initkre()
|
||||
int i;
|
||||
size_t sz;
|
||||
|
||||
if ((num_devices = getnumdevs()) < 0) {
|
||||
if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
|
||||
warnx("%s", devstat_errbuf);
|
||||
return(0);
|
||||
}
|
||||
@ -571,7 +571,7 @@ cmdkre(cmd, args)
|
||||
if (prefix(cmd, "run")) {
|
||||
retval = 1;
|
||||
copyinfo(&s2, &s1);
|
||||
switch (getdevs(&run)) {
|
||||
switch (devstat_getdevs(NULL, &run)) {
|
||||
case -1:
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
break;
|
||||
@ -601,7 +601,7 @@ cmdkre(cmd, args)
|
||||
retval = 1;
|
||||
if (state == RUN) {
|
||||
getinfo(&s1, RUN);
|
||||
switch (getdevs(&run)) {
|
||||
switch (devstat_getdevs(NULL, &run)) {
|
||||
case -1:
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
break;
|
||||
@ -792,7 +792,7 @@ getinfo(s, st)
|
||||
cur.dinfo = tmp_dinfo;
|
||||
|
||||
last.busy_time = cur.busy_time;
|
||||
switch (getdevs(&cur)) {
|
||||
switch (devstat_getdevs(NULL, &cur)) {
|
||||
case -1:
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
break;
|
||||
@ -845,19 +845,18 @@ dinfo(dn, c, now, then)
|
||||
|
||||
di = dev_select[dn].position;
|
||||
|
||||
elapsed_time = compute_etime(now->busy_time, then ?
|
||||
then->busy_time :
|
||||
now->dinfo->devices[di].dev_creation_time);
|
||||
elapsed_time = devstat_compute_etime(now->busy_time,
|
||||
then ? then->busy_time : now->dinfo->devices[di].dev_creation_time);
|
||||
|
||||
device_busy = compute_etime(now->dinfo->devices[di].busy_time, then ?
|
||||
then->dinfo->devices[di].busy_time :
|
||||
now->dinfo->devices[di].dev_creation_time);
|
||||
device_busy = devstat_compute_etime(now->dinfo->devices[di].busy_time,
|
||||
then ? then->dinfo->devices[di].busy_time :
|
||||
now->dinfo->devices[di].dev_creation_time);
|
||||
|
||||
if (compute_stats(&now->dinfo->devices[di], then ?
|
||||
&then->dinfo->devices[di] : NULL, elapsed_time,
|
||||
NULL, NULL, NULL,
|
||||
&kb_per_transfer, &transfers_per_second,
|
||||
&mb_per_second, NULL, NULL) != 0)
|
||||
if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
|
||||
&then->dinfo->devices[di] : NULL, elapsed_time,
|
||||
DSM_KB_PER_TRANSFER, &kb_per_transfer, DSM_TRANSFERS_PER_SECOND,
|
||||
&transfers_per_second, DSM_MB_PER_SECOND, &mb_per_second,
|
||||
DSM_NONE) != 0)
|
||||
errx(1, "%s", devstat_errbuf);
|
||||
|
||||
if ((device_busy == 0) && (transfers_per_second > 5))
|
||||
|
Loading…
Reference in New Issue
Block a user