Changeset View
Changeset View
Standalone View
Standalone View
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, 2020 Yoshihiro Ota | * Copyright (c) 2017, 2020, 2021 Yoshihiro Ota | ||||
kib: I do not think that this changes deserve a copyright line, at least according to our typical… | |||||
Done Inline ActionsIs it 20% changes per commit or over a year? ota_j.email.ne.jp: Is it 20% changes per commit or over a year?
I'm just curious. | |||||
Not Done Inline ActionsTotal. I did not looked at the blame output. If you are the author of more than 1/5 of this file, then it is fine, of course. kib: Total. I did not looked at the blame output.
If you are the author of more than 1/5 of this… | |||||
* | * | ||||
* 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 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if (once) | ||||
return (1); | return (1); | ||||
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 (0); | return (0); | ||||
} | } | ||||
pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */; | pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */; | ||||
dsinit(12); | dsinit(12); | ||||
procinit(); | |||||
once = 1; | once = 1; | ||||
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; | ||||
} | } | ||||
struct devinfo *tmp_dinfo; | struct devinfo *tmp_dinfo; | ||||
tmp_dinfo = last_dev.dinfo; | tmp_dinfo = last_dev.dinfo; | ||||
last_dev.dinfo = cur_dev.dinfo; | last_dev.dinfo = cur_dev.dinfo; | ||||
cur_dev.dinfo = tmp_dinfo; | cur_dev.dinfo = tmp_dinfo; | ||||
last_dev.snap_time = cur_dev.snap_time; | last_dev.snap_time = cur_dev.snap_time; | ||||
dsgetinfo( &cur_dev ); | dsgetinfo(&cur_dev); | ||||
procgetinfo(); | |||||
} | } | ||||
void | void | ||||
labelswap(void) | labelswap(void) | ||||
{ | { | ||||
const char *name; | |||||
int i; | |||||
werase(wnd); | werase(wnd); | ||||
dslabel(12, 0, LINES - DISKHIGHT - 1); | dslabel(12, 0, LINES - DISKHIGHT - 1); | ||||
if (kvnsw <= 0) { | if (kvnsw <= 0) { | ||||
mvwprintw(wnd, 0, 0, "(swap not configured)"); | mvwprintw(wnd, 0, 0, "(swap not configured)"); | ||||
return; | return; | ||||
} | } | ||||
mvwprintw(wnd, 0, 0, "%*s%5s %5s %s", | mvwprintw(wnd, 0, 0, "%*s%5s %5s %s", | ||||
-pathlen, "Device/Path", "Size", "Used", | -pathlen, "Device/Path", "Size", "Used", | ||||
"|0% /10 /20 /30 /40 / 60\\ 70\\ 80\\ 90\\ 100|"); | "|0% /10 /20 /30 /40 / 60\\ 70\\ 80\\ 90\\ 100|"); | ||||
for (i = 0; i <= kvnsw; ++i) { | |||||
name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname; | |||||
mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name); | |||||
} | } | ||||
} | |||||
void | void | ||||
showswap(void) | showswap(void) | ||||
{ | { | ||||
int count; | const char *name; | ||||
int i; | int count, i; | ||||
if (kvnsw != okvnsw) | if (kvnsw != okvnsw) | ||||
labelswap(); | labelswap(); | ||||
dsshow(12, 0, LINES - DISKHIGHT - 1, &cur_dev, &last_dev); | dsshow(12, 0, LINES - DISKHIGHT - 1, &cur_dev, &last_dev); | ||||
if (kvnsw <= 0) | if (kvnsw <= 0) | ||||
return; | return; | ||||
for (i = 0; i <= kvnsw; ++i) { | for (i = (kvnsw == 1 ? 0 : kvnsw); i >= 0; i--) { | ||||
name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname; | |||||
mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name); | |||||
sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0); | sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0); | ||||
sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used, | sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used, | ||||
0); | 0); | ||||
if (kvmsw[i].ksw_used > 0) { | if (kvmsw[i].ksw_used > 0) { | ||||
count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total; | count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total; | ||||
sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count); | sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count); | ||||
} | } | ||||
wclrtoeol(wnd); | wclrtoeol(wnd); | ||||
} | } | ||||
if (kvnsw == 1) | |||||
count = 2; | |||||
else | |||||
count = 3; | |||||
Done Inline ActionsI would wrote this as count = kvnsw == 1 ? 2 : 3; kib: I would wrote this as `count = kvnsw == 1 ? 2 : 3;` | |||||
proclabel(kvnsw + count); | |||||
procshow(kvnsw + count, LINES - 5 - (kvnsw + 3) - (DISKHIGHT + 1), | |||||
Done Inline ActionsExcess (), two times kib: Excess (), two times | |||||
kvmsw[kvnsw].ksw_total); | |||||
} | } |
I do not think that this changes deserve a copyright line, at least according to our typical policy of 20% changes.