Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/systat/swap.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-3-Clause | * SPDX-License-Identifier: BSD-3-Clause | ||||
* | * | ||||
* Copyright (c) 1980, 1992, 1993 | * Copyright (c) 1980, 1992, 1993 | ||||
* The Regents of the University of California. All rights reserved. | * The Regents of the University of California. All rights reserved. | ||||
* Copyright (c) 2017 Yoshihiro Ota | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 36 Lines | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include "systat.h" | #include "systat.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
#include "devs.h" | |||||
kvm_t *kd; | kvm_t *kd; | ||||
static char *header; | static char *header; | ||||
static long blocksize; | static long blocksize; | ||||
static int dlen, odlen; | static int dlen, odlen; | ||||
static int hlen; | static int hlen; | ||||
static int ulen, oulen; | static int ulen, oulen; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | initswap(void) | ||||
} | } | ||||
okvnsw = kvnsw; | okvnsw = kvnsw; | ||||
calclens(); | calclens(); | ||||
odlen = dlen; | odlen = dlen; | ||||
oulen = ulen; | oulen = ulen; | ||||
once = 1; | once = 1; | ||||
dsinit(12); | |||||
return (1); | return (1); | ||||
} | } | ||||
void | void | ||||
fetchswap(void) | fetchswap(void) | ||||
{ | { | ||||
okvnsw = kvnsw; | okvnsw = kvnsw; | ||||
if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { | if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) { | ||||
error("systat: kvm_getswapinfo failed"); | error("systat: kvm_getswapinfo failed"); | ||||
return; | return; | ||||
} | } | ||||
odlen = dlen; | odlen = dlen; | ||||
oulen = ulen; | oulen = ulen; | ||||
calclens(); | calclens(); | ||||
struct devinfo *tmp_dinfo; | |||||
tmp_dinfo = last_dev.dinfo; | |||||
last_dev.dinfo = cur_dev.dinfo; | |||||
cur_dev.dinfo = tmp_dinfo; | |||||
last_dev.snap_time = cur_dev.snap_time; | |||||
dsgetinfo( &cur_dev ); | |||||
} | } | ||||
void | void | ||||
labelswap(void) | labelswap(void) | ||||
{ | { | ||||
const char *name; | const char *name; | ||||
int i; | int i; | ||||
Show All 9 Lines | for (i = 0; i <= kvnsw; ++i) { | ||||
if (i == kvnsw) { | if (i == kvnsw) { | ||||
if (kvnsw == 1) | if (kvnsw == 1) | ||||
break; | break; | ||||
name = "Total"; | name = "Total"; | ||||
} else | } else | ||||
name = kvmsw[i].ksw_devname; | name = kvmsw[i].ksw_devname; | ||||
mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name); | mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name); | ||||
} | } | ||||
dslabel(12, 0, 18); | |||||
} | } | ||||
void | void | ||||
showswap(void) | showswap(void) | ||||
{ | { | ||||
int count; | int count; | ||||
int i; | int i; | ||||
Show All 23 Lines | for (i = 0; i <= kvnsw; ++i) { | ||||
count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1; | count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1; | ||||
waddch(wnd, ' '); | waddch(wnd, ' '); | ||||
while (count--) | while (count--) | ||||
waddch(wnd, 'X'); | waddch(wnd, 'X'); | ||||
wclrtoeol(wnd); | wclrtoeol(wnd); | ||||
} | } | ||||
dsshow(12, 0, 18, &cur_dev, &last_dev); | |||||
} | } |