1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
|
/*
** ATOP - System & Process Monitor
**
** The program 'atop' offers the possibility to view the activity of
** the system on system-level as well as process-level.
**
** This source-file contains the Linux-specific functions to calculate
** figures to be visualized.
** ==========================================================================
** Author: Gerlof Langeveld - AT Computing, Nijmegen, Holland
** E-mail: gerlof@ATComputing.nl
** Date: July 2002
** --------------------------------------------------------------------------
** Copyright (C) 2000-2007 Gerlof Langeveld
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 2, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** --------------------------------------------------------------------------
**
** $Log: showlinux.c,v $
** Revision 1.49 2008/03/06 08:38:28 gerlof
** Register/show ppid of a process.
**
** Revision 1.48 2008/01/18 07:37:05 gerlof
** Show information about the state of the individual threads
** in the scheduling report shown with keystroke 's'.
**
** Revision 1.47 2008/01/07 11:34:18 gerlof
** Correct the sort-order of network-interfaces (on busy-percentage).
**
** Revision 1.46 2007/11/07 09:23:29 gerlof
** Modified format for avg1, avg5 and avg15 (CPL) when counters too large.
**
** Revision 1.45 2007/11/05 11:43:25 gerlof
** Bug-solution for new-process indicator on 64-bits machines.
**
** Revision 1.44 2007/11/05 10:57:56 gerlof
** Bug-solution for huge exit code on 64-bits machines.
**
** Revision 1.43 2007/08/17 09:45:57 gerlof
** Experimental: gather info about HTTP statistics.
**
** Revision 1.42 2007/08/16 12:02:04 gerlof
** Add support for atopsar reporting.
** Concerns modification of networking-counters.
**
** Revision 1.41 2007/07/04 10:18:16 gerlof
** Bug-solution for division by zero.
**
** Revision 1.40 2007/07/03 09:02:29 gerlof
** Support Apache-statistics.
**
** Revision 1.39 2007/03/22 10:12:54 gerlof
** Support for io counters (>= kernel 2.6.20).
**
** Revision 1.38 2007/03/21 14:22:24 gerlof
** Handle io counters maintained from 2.6.20
**
** Revision 1.37 2007/02/13 10:36:09 gerlof
** Removal of external declarations.
** Use of hertz variable instead of HZ.
**
** Revision 1.36 2007/01/26 12:11:07 gerlof
** Add configuration-value 'swoutcritsec'.
**
** Revision 1.35 2007/01/26 10:25:42 gerlof
** Introduce steal percentage for virtual machines.
** Correct bug: when one interface is colored all subsequent interfaces
** are colored.
**
** Revision 1.34 2007/01/18 10:58:45 gerlof
** Only check for committed limit if it is not zero.
**
** Revision 1.33 2007/01/18 10:37:09 gerlof
** Add support for colors.
** Add support for automatic determination of most critical resource.
** Add support for parsing of new arguments in ~/.atoprc
**
** Revision 1.32 2006/11/13 13:48:46 gerlof
** Implement load-average counters, context-switches and interrupts.
**
** Revision 1.31 2006/02/07 08:38:49 gerlof
** Swapped the zombie counter and exit counter in the PRC-line.
**
** Revision 1.30 2006/02/07 08:30:07 gerlof
** Add possibility to show counters per second.
** Ease parsing of output-lines by fixed number of columns per line.
**
** Revision 1.29 2006/01/30 09:24:12 gerlof
** PRC-line: 'exits' modified to 'exit' to save space.
**
** Revision 1.28 2006/01/30 09:14:26 gerlof
** Extend memory counters (a.o. page scans).
**
** Revision 1.27 2005/11/04 14:16:45 gerlof
** Minor bug-solutions.
**
** Revision 1.26 2005/10/28 09:51:29 gerlof
** All flags/subcommands are defined as macro's.
** Subcommand 'p' has been changed to 'z' (pause).
**
** Revision 1.25 2005/10/21 09:51:11 gerlof
** Per-user accumulation of resource consumption.
**
** Revision 1.24 2004/12/14 15:06:48 gerlof
** Implementation of patch-recognition for disk and network-statistics.
**
** Revision 1.23 2004/10/28 08:31:41 gerlof
** New counter: vm committed space
**
** Revision 1.22 2004/09/24 10:02:46 gerlof
** Wrong cpu-numbers for system level statistics.
**
** Revision 1.21 2004/09/23 08:21:10 gerlof
** Added wait-percentage per cpu.
**
** Revision 1.20 2004/09/23 07:37:34 gerlof
** Consistent handling of CPU percentages on system-level and process-level.
**
** Revision 1.19 2004/09/13 09:20:21 gerlof
** Modify subcommands (former 's' -> 'v', 'v' -> 'V', new 's').
**
** Revision 1.18 2004/09/02 10:55:21 root
** Added sleep-average to process-info.
**
** Revision 1.17 2004/08/31 09:53:31 gerlof
** Show information about underlying threads.
**
** Revision 1.16 2004/06/01 11:58:34 gerlof
** Regular expressions for selections on process-name and user-name.
**
** Revision 1.15 2004/05/06 09:47:59 gerlof
** Ported to kernel-version 2.6.
**
** Revision 1.14 2003/07/07 09:27:34 gerlof
** Cleanup code (-Wall proof).
**
** Revision 1.13 2003/07/03 12:04:25 gerlof
** Minor bug fixes.
**
** Revision 1.12 2003/06/30 11:29:57 gerlof
** Enlarge counters to 'long long'.
**
** Revision 1.11 2003/06/24 06:22:10 gerlof
** Limit number of system resource lines.
**
** Revision 1.10 2003/02/07 10:43:22 gerlof
** Solved a division-by-zero bug for process-percentage.
**
** Revision 1.9 2003/01/24 14:20:57 gerlof
** If possible, also show commandline when process has exited.
**
** Revision 1.8 2003/01/17 07:32:49 gerlof
** Show the full command-line per process (option 'c').
**
** Revision 1.7 2002/10/04 10:05:54 gerlof
** Bug-solution: New process indicator in static output set when needed.
**
** Revision 1.6 2002/10/03 11:14:42 gerlof
** Modify (effective) uid/gid to real uid/gid.
**
** Revision 1.5 2002/09/26 13:52:51 gerlof
** Limit header lines by not showing disks.
** Limit header lines by not showing disks.
**
** Revision 1.4 2002/09/16 08:59:13 gerlof
** Change field EXCODE to STATUS for support of indicator of newly created
** processes.
**
** Revision 1.3 2002/09/02 08:42:44 gerlof
** Bug-solution: blank line after header when more than 999 screens of
** process-list information.
**
** Revision 1.2 2002/08/30 07:11:20 gerlof
** Minor changes in the header-line of the process list.
**
** Revision 1.1 2002/07/24 11:14:16 gerlof
** Initial revision
**
**
** Initial
**
*/
static const char rcsid[] = "$Id: showlinux.c,v 1.49 2008/03/06 08:38:28 gerlof Exp $";
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <termio.h>
#include <unistd.h>
#include <stdarg.h>
#include <curses.h>
#include <pwd.h>
#include <grp.h>
#include <regex.h>
#include "atop.h"
#include "photoproc.h"
#include "photosyst.h"
#include "showgeneric.h"
/*
** critical percentages for occupation-percentage;
** these defaults can be overruled via the config-file
*/
int cpubadness = 90; /* percentage */
int membadness = 90; /* percentage */
int swpbadness = 80; /* percentage */
int dskbadness = 70; /* percentage */
int netbadness = 90; /* percentage */
int pagbadness = 10; /* number per second */
int almostcrit = 80; /* percentage */
/*
** table with column headers for sorted process list
*/
static char *columnhead[] = {
[MSORTCPU]= "CPU", [MSORTMEM]= "MEM",
[MSORTDSK]= "DSK", [MSORTNET]= "NET",
};
/*
** function protoypes
*/
static int syscolorlabel(char *, int, unsigned int);
static void syscoloroff (char);
/*
** format-lines for printing
*/
char *prcline = "PRC | sys %s | user %s | #proc %s | #zombie %s |"
" #exit %s |\n";
/***************************************************************************/
char *genprochdr1 = "\n PID SYSCPU USRCPU VGROW RGROW RDDSK WRDSK "
"RNET SNET S %c%s CMD %4d/%-4d\n";
char *genproclina1 = "%5d %s %s %s %s %s %s %s %s %c %3.0lf%% %.14s\n";
char *genprocline1 = "%s %s 0K 0K (r&w %s) - "
"- E %3.0lf%% <%.12s>\n";
char *genprocline1p = "%s %s %s %s %s %s %s %s E %3.0lf%% <%.12s>\n";
char *genprochdr2 = "\n PID SYSCPU USRCPU VGROW RGROW RDDSK WRDSK "
" ST EXC S %c%s CMD %4d/%-4d\n";
char *genproclina2 = "%5d %s %s %s %s %s %s %c%c - %c %3.0lf%% "
"%.14s\n";
char *genprocline2 = "%s %s 0K 0K - - %c%c %3d "
"E %3.0lf%% <%.12s>\n";
char *genprochdr3 = "\n PID SYSCPU USRCPU VGROW RGROW USERNAME THR "
"ST EXC S %c%s CMD %4d/%-4d\n";
char *genproclina3 = "%5d %s %s %s %s %-8.8s %3d %c%c - %c %3.0lf%% "
"%.14s\n";
char *genprocline3 = "%s %s 0K 0K %-8.8s 0 %c%c %3d "
"E %3.0lf%% <%.12s>\n";
/***************************************************************************/
char *memprochdr = "\n PID MINFLT MAJFLT VSTEXT "
" VSIZE RSIZE VGROW RGROW %c%s CMD %4d/%-4d\n";
char *memproclina = "%5d %s %s %s %s %s %s %s %3.0lf%% %.14s\n";
char *memprocline = "%s %s 0K 0K 0K 0K 0K"
" %3.0lf%% <%.12s>\n";
char *memproclinep = "%5d %s %s 0K %s %s %s %s %3.0lf%% "
"<%.12s>\n";
/***************************************************************************/
char *dskprochdr1 = "\n PID READDISK AVGSIZE TOTSIZE WRITEDISK "
"AVGSIZE TOTSIZE %c%s CMD %4d/%-4d\n";
char *dskproclina1 = "%5d %s %s %s %s %s %s %3.0lf%% %.14s\n";
char *dskprocline1 = " (reads&writes %s) "
" %3.0lf%% <%.12s>\n";
char *dskprocline1p = "%5d %s %s %s %s %s %s %3.0lf%% <%.12s>\n";
char *dskprochdr2 = "\n PID RDDSK WRDSK WRDSK_CANCEL "
" %c%s CMD %4d/%-4d\n";
char *dskproclina2 = "%5d %s %s %s "
"%3.0lf%% %.14s\n";
char *dskprocline2 = " - - - "
" %3.0lf%% <%.12s>\n";
/***************************************************************************/
char *netprochdr = "\n PID TCPRCV AVSZ|TCPSND AVSZ|UDPRCV AVSZ"
"|UDPSND AVSZ|RAWRS|%c%s CMD %4d/%-4d\n";
char *netproclina = "%5d %s %s|%s %s|%s %s|%s %s|%2llu %2llu|"
"%3.0lf%% %.14s\n";
char *netprocline = " "
" %3.0lf%% <%.12s>\n";
char *netproclinep = "%5d %s %s|%s %s|%s %s|%s %s|%2llu %2llu|"
"%3.0lf%% <%.12s>\n";
/***************************************************************************/
char *varprochdr = "\n PID PPID USERNAME GROUP "
"STDATE STTIME ST EXC S %c%s CMD %4d/%-4d\n";
char *varproclina = "%5d %5d %-8.8s %-8.8s %s %s %c%c - %c %3.0lf%% "
"%.14s\n";
char *varprocline = "%5d %-8.8s %-8.8s %s %s %c%c %3d E %3.0lf%% "
"<%.12s>\n";
/***************************************************************************/
char *cmdprochdr = "\n PID %c%s COMMAND-LINE "
" %4d/%-4d\n";
char *cmdproclina = "%5d %3.0lf%% %s\n";
char *cmdprocline = "%3.0lf%% <%.66s>\n";
/***************************************************************************/
char *schprochdr = "\n PID TRUN TSLPI TSLPU POLI NICE PRI RTPR "
"CURCPU ST EXC S %c%s CMD %4d/%-4d\n";
char *schproclina = "%5d %4d %5d %5d %-4s %4d %3d %4d %6d %-2s - "
"%c %3.0lf%% %.14s\n";
char *schprocline = " 0 0 0 - - - - - "
"%c%c %3d E %3.0lf%% <%.12s>\n";
/***************************************************************************/
char *totuserhdr = "\nNPROCS SYSCPU USRCPU VSIZE RSIZE RDDSK "
"WRDSK RNET SNET %c%s USER %4d/%-4d\n";
char *totuserlin = "%s %s %s %s %s %s %s %s %s "
"%3.0lf%% %.14s\n";
/***************************************************************************/
char *totprochdr = "\nNPROCS SYSCPU USRCPU VSIZE RSIZE RDDSK "
"WRDSK RNET SNET %c%s CMD %4d/%-4d\n";
char *totproclin = "%s %s %s %s %s %s %s %s %s "
"%3.0lf%% %.14s\n";
/***************************************************************************/
/*
** calculate the total consumption on system-level for the
** four main resources
*/
void
totalcap(struct syscap *psc, struct sstat *sstat, struct pstat *pstat, int nact)
{
register int i;
psc->nrcpu = sstat->cpu.nrcpu;
psc->availcpu = sstat->cpu.all.stime +
sstat->cpu.all.utime +
sstat->cpu.all.ntime +
sstat->cpu.all.itime +
sstat->cpu.all.wtime +
sstat->cpu.all.Itime +
sstat->cpu.all.Stime +
sstat->cpu.all.steal;
psc->availmem = sstat->mem.physmem * pagesize/1024;
if (supportflags & PATCHSTAT)
{
/*
** calculate total number of accesses which have been
** issued by the active processes for disk and for network
*/
for (psc->availnet=psc->availdsk=0, i=0; i < nact; i++)
{
psc->availnet += (pstat+i)->net.tcpsnd;
psc->availnet += (pstat+i)->net.tcprcv;
psc->availnet += (pstat+i)->net.udpsnd;
psc->availnet += (pstat+i)->net.udprcv;
psc->availnet += (pstat+i)->net.rawsnd;
psc->availnet += (pstat+i)->net.rawrcv;
psc->availdsk += (pstat+i)->dsk.rio;
psc->availdsk += (pstat+i)->dsk.wio;
}
}
else
{
for (psc->availnet=psc->availdsk=0, i=0; i < nact; i++)
{
psc->availdsk += (pstat+i)->dsk.rsz;
psc->availdsk += (pstat+i)->dsk.wsz;
}
}
}
/*
** calculate cumulative system- and user-time for all active processes
*/
void
pricumproc(struct pstat *pstat, int nact, int nproc, int nzomb, int nexit,
int avgval, int nsecs)
{
int i;
count_t totut, totst;
char format1[16], format2[16], format3[16];
char format4[16], format5[16];
for (i=totut=totst=0; i < nact; i++)
{
totut += (pstat+i)->cpu.utime;
totst += (pstat+i)->cpu.stime;
}
printg(prcline, val2cpustr(totst * 1000/hertz, format1),
val2cpustr(totut * 1000/hertz, format2),
val2valstr(nproc, format3, 6, 0, 0),
val2valstr(nzomb, format4, 4, 0, 0),
supportflags & ACCTACTIVE ?
val2valstr(nexit, format5, 6, avgval, nsecs):
" ?");
}
/*
** print a line of general figures about one process
*/
void
showgenproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
struct passwd *pwd;
char *username, usname[16], exittype;
char format1[16], format2[16];
char format3[16], format4[16];
char format5[16], format6[16];
char format7[16], format8[16];
if (curstat->gen.state != 'E')
{
if (supportflags & PATCHSTAT)
{
/*
** show active processes for patched kernel
*/
printg(genproclina1,
curstat->gen.pid,
val2cpustr(curstat->cpu.stime*1000/hertz, format1),
val2cpustr(curstat->cpu.utime*1000/hertz, format2),
val2memstr(curstat->mem.vgrow*1024,
format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow*1024,
format4, KBFORMAT, 0, 0),
val2valstr(curstat->dsk.rio, format5, 5,
avgval, nsecs),
val2valstr(curstat->dsk.wio, format6, 5,
avgval, nsecs),
val2valstr(curstat->net.tcprcv +
curstat->net.udprcv +
curstat->net.rawrcv, format7, 4,
avgval, nsecs),
val2valstr(curstat->net.tcpsnd +
curstat->net.udpsnd +
curstat->net.rawsnd, format8, 4,
avgval, nsecs),
curstat->gen.state,
perc, curstat->gen.name);
}
else
{
if (supportflags & IOSTAT)
{
/*
** show active processes for kernel with iostats
*/
printg(genproclina2,
curstat->gen.pid,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
val2memstr(curstat->mem.vgrow*1024,
format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow*1024,
format4, KBFORMAT, 0, 0),
val2memstr(curstat->dsk.rsz*512,
format5, KBFORMAT, 0, 0),
val2memstr(curstat->dsk.wsz*512,
format6, KBFORMAT, 0, 0),
curstat->gen.excode & ~(INT_MAX) ?
'N' : '-',
'-',
curstat->gen.state,
perc, curstat->gen.name);
}
else
{
/*
** show active processes for conventional kernel
**
** determine the user-name of process
*/
if ( (pwd = getpwuid(curstat->gen.ruid)) )
{
username = pwd->pw_name;
}
else
{
snprintf(usname, sizeof usname, "%d",
curstat->gen.ruid);
username = usname;
}
printg(genproclina3,
curstat->gen.pid,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
val2memstr(curstat->mem.vgrow*1024,
format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow*1024,
format4, KBFORMAT, 0, 0),
username,
curstat->gen.nthr,
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
'-',
curstat->gen.state,
perc, curstat->gen.name);
}
}
}
else
{
/*
** show exited processes
*/
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
if (supportflags & PATCHSTAT)
{
/*
** show exited processes for patched kernel
*/
if (supportflags & PATCHACCT)
{
/*
** show exited processes for patched kernel
** including patches for accounting
*/
printg(genprocline1p,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
val2memstr(curstat->mem.vgrow*1024,
format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow*1024,
format4, KBFORMAT, 0, 0),
val2valstr(curstat->dsk.rio,
format5, 5, avgval, nsecs),
val2valstr(curstat->dsk.wio,
format6, 5, avgval, nsecs),
val2valstr(curstat->net.tcprcv +
curstat->net.udprcv +
curstat->net.rawrcv,
format7, 4, avgval, nsecs),
val2valstr(curstat->net.tcpsnd +
curstat->net.udpsnd +
curstat->net.rawsnd,
format8, 4, avgval, nsecs),
perc, curstat->gen.name);
}
else
{
/*
** show exited processes for patched kernel
** without patches for accounting
*/
printg(genprocline1,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
val2valstr(curstat->dsk.rio,
format3, 6, avgval, nsecs),
perc, curstat->gen.name);
}
}
else
{
if (curstat->gen.excode & 0xff)
{
if (curstat->gen.excode & 0x80)
exittype = 'C';
else
exittype = 'S';
}
else
{
exittype = 'E';
}
if (supportflags & IOSTAT)
{
/*
** show exited processes for kernel with iostats
*/
printg(genprocline2,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
exittype,
curstat->gen.excode & 0xff ?
curstat->gen.excode & 0x7f :
(curstat->gen.excode>>8) & 0xff,
perc, curstat->gen.name);
}
else
{
/*
** show active processes for conventional kernel
**
** determine the user-name of process
*/
if ( (pwd = getpwuid(curstat->gen.ruid)) )
{
username = pwd->pw_name;
}
else
{
snprintf(usname, sizeof usname, "%d",
curstat->gen.ruid);
username = usname;
}
printg(genprocline3,
val2cpustr(curstat->cpu.stime*1000/hertz,
format1),
val2cpustr(curstat->cpu.utime*1000/hertz,
format2),
username,
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
exittype,
curstat->gen.excode & 0xff ?
curstat->gen.excode & 0x7f :
(curstat->gen.excode>>8) & 0xff,
perc, curstat->gen.name);
}
}
}
}
/*
** print a line of memory-figures about one process
*/
void
showmemproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char format1[16], format2[16];
char format3[16], format4[16];
char format5[16], format6[16];
char format7[16];
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(memproclina,
curstat->gen.pid,
val2valstr(curstat->mem.minflt, format1, 6,
avgval, nsecs),
val2valstr(curstat->mem.majflt, format2, 6,
avgval, nsecs),
val2memstr(curstat->mem.shtext*1024, format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.vmem *1024, format4, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rmem *1024, format5, KBFORMAT, 0, 0),
val2memstr(curstat->mem.vgrow *1024, format6, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow *1024, format7, KBFORMAT, 0, 0),
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (supportflags & PATCHACCT)
{
printg(memproclinep,
curstat->gen.pid,
val2valstr(curstat->mem.minflt, format1, 6,
avgval, nsecs),
val2valstr(curstat->mem.majflt, format2, 6,
avgval, nsecs),
val2memstr(curstat->mem.vmem *1024, format3, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rmem *1024, format4, KBFORMAT, 0, 0),
val2memstr(curstat->mem.vgrow *1024, format5, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rgrow *1024, format6, KBFORMAT, 0, 0),
perc, curstat->gen.name);
}
else
{
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
printg(memprocline,
val2valstr(curstat->mem.minflt, format1, 6,
avgval, nsecs),
val2valstr(curstat->mem.majflt, format2, 6,
avgval, nsecs),
perc, curstat->gen.name);
}
}
}
/*
** print a line of disk-figures about one process
*/
void
showdskproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char format1[16], format2[16], format3[16];
char format4[16], format5[16], format6[16];
unsigned int avgrsz, avgwsz;
if (supportflags & PATCHSTAT)
{
avgrsz = curstat->dsk.rio ?
curstat->dsk.rsz * 512LL / curstat->dsk.rio : 0;
avgwsz = curstat->dsk.wio ?
curstat->dsk.wsz * 512LL / curstat->dsk.wio : 0;
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(dskproclina1,
curstat->gen.pid,
val2valstr(curstat->dsk.rio,
format1, 9, avgval, nsecs),
val2valstr(avgrsz, format2, 7, 0, 0),
val2memstr(curstat->dsk.rsz*512LL,
format3, KBFORMAT, avgval, nsecs),
val2valstr(curstat->dsk.wio,
format4, 9, avgval, nsecs),
val2valstr(avgwsz, format5, 7, 0, 0),
val2memstr(curstat->dsk.wsz*512LL,
format6, KBFORMAT, avgval, nsecs),
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (supportflags & PATCHACCT)
{
printg(dskprocline1p,
curstat->gen.pid,
val2valstr(curstat->dsk.rio,
format1, 9, avgval, nsecs),
val2valstr(avgrsz, format2, 7, 0, 0),
val2memstr(curstat->dsk.rsz * 512LL,
format3, KBFORMAT, avgval, nsecs),
val2valstr(curstat->dsk.wio,
format4, 9, avgval, nsecs),
val2valstr(avgwsz, format5, 7, 0, 0),
val2memstr(curstat->dsk.wsz * 512LL,
format6, KBFORMAT, avgval, nsecs),
perc, curstat->gen.name);
}
else
{
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
printg(dskprocline1,
val2valstr(curstat->dsk.rio,
format1, 9, avgval, nsecs),
perc, curstat->gen.name);
}
}
}
else
{
if (supportflags & IOSTAT)
{
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(dskproclina2,
curstat->gen.pid,
val2memstr(curstat->dsk.rsz*512LL,
format1, KBFORMAT, avgval, nsecs),
val2memstr(curstat->dsk.wsz*512LL,
format2, KBFORMAT, avgval, nsecs),
val2memstr(curstat->dsk.cwsz*512LL,
format3, KBFORMAT, avgval, nsecs),
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
printg(dskprocline2,
perc, curstat->gen.name);
}
}
}
}
/*
** print a line of network-figures about one process
*/
void
shownetproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char format1[16], format2[16], format3[16], format4[16];
char format5[16], format6[16], format7[16], format8[16];
int avgtcpr, avgtcps, avgudpr, avgudps;
avgtcpr = curstat->net.tcprcv ?
curstat->net.tcprsz / curstat->net.tcprcv : 0;
avgtcps = curstat->net.tcpsnd ?
curstat->net.tcpssz / curstat->net.tcpsnd : 0;
avgudpr = curstat->net.udprcv ?
curstat->net.udprsz / curstat->net.udprcv : 0;
avgudps = curstat->net.udpsnd ?
curstat->net.udpssz / curstat->net.udpsnd : 0;
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(netproclina,
curstat->gen.pid,
val2valstr(curstat->net.tcprcv, format1, 6,
avgval, nsecs),
val2valstr(avgtcpr, format2, 4, 0, 0),
val2valstr(curstat->net.tcpsnd, format3, 6,
avgval, nsecs),
val2valstr(avgtcps, format4, 4, 0, 0),
val2valstr(curstat->net.udprcv, format5, 6,
avgval, nsecs),
val2valstr(avgudpr, format6, 4, 0, 0),
val2valstr(curstat->net.udpsnd, format7, 6,
avgval, nsecs),
val2valstr(avgudps, format8, 4, 0, 0),
curstat->net.rawrcv,
curstat->net.rawsnd,
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (supportflags & PATCHACCT)
{
printg(netproclinep,
curstat->gen.pid,
val2valstr(curstat->net.tcprcv, format1, 6,
avgval, nsecs),
val2valstr(avgtcpr, format2, 4, 0, 0),
val2valstr(curstat->net.tcpsnd, format3, 6,
avgval, nsecs),
val2valstr(avgtcps, format4, 4, 0, 0),
val2valstr(curstat->net.udprcv, format5, 6,
avgval, nsecs),
val2valstr(avgudpr, format6, 4, 0, 0),
val2valstr(curstat->net.udpsnd, format7, 6,
avgval, nsecs),
val2valstr(avgudps, format8, 4, 0, 0),
curstat->net.rawrcv,
curstat->net.rawsnd,
perc, curstat->gen.name);
}
else
{
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
printg(netprocline, perc, curstat->gen.name);
}
}
}
/*
** print a line of total resource consumption per user
*/
void
showtotuser(struct pstat *curstat, double perc, int nsecs, int avgval)
{
struct passwd *pwd;
char numuser[16], *username;
char format1[16], format2[16];
char format3[16], format4[16];
char format5[16], format6[16];
char format7[16], format8[16];
char format9[16];
/*
** determine the user-name of process
*/
if ( (pwd = getpwuid(curstat->gen.ruid)) == NULL)
{
snprintf(numuser, sizeof numuser, "%u", curstat->gen.ruid);
username = numuser;
}
else
{
username = pwd->pw_name;
}
printg(totuserlin,
val2valstr(curstat->gen.pid, format1, 6, 0, 0),
val2cpustr(curstat->cpu.stime*1000/hertz, format2),
val2cpustr(curstat->cpu.utime*1000/hertz, format3),
val2memstr(curstat->mem.vmem *1024, format4, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rmem *1024, format5, KBFORMAT, 0, 0),
val2valstr(curstat->dsk.rio, format6, 5,
avgval, nsecs),
val2valstr(curstat->dsk.wio, format7, 5,
avgval, nsecs),
val2valstr(curstat->net.tcprcv +
curstat->net.udprcv +
curstat->net.rawrcv, format8, 4,
avgval, nsecs),
val2valstr(curstat->net.tcpsnd +
curstat->net.udpsnd +
curstat->net.rawsnd, format9, 4,
avgval, nsecs),
perc, username);
}
/*
** print a line of total resource consumption per program (process name)
*/
void
showtotproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char format1[16], format2[16];
char format3[16], format4[16];
char format5[16], format6[16];
char format7[16], format8[16];
char format9[16];
printg(totproclin,
val2valstr(curstat->gen.pid, format1, 6, 0, 0),
val2cpustr(curstat->cpu.stime*1000/hertz, format2),
val2cpustr(curstat->cpu.utime*1000/hertz, format3),
val2memstr(curstat->mem.vmem *1024, format4, KBFORMAT, 0, 0),
val2memstr(curstat->mem.rmem *1024, format5, KBFORMAT, 0, 0),
val2valstr(curstat->dsk.rio, format6, 5,
avgval, nsecs),
val2valstr(curstat->dsk.wio, format7, 5,
avgval, nsecs),
val2valstr(curstat->net.tcprcv +
curstat->net.udprcv +
curstat->net.rawrcv, format8, 4,
avgval, nsecs),
val2valstr(curstat->net.tcpsnd +
curstat->net.udpsnd +
curstat->net.rawsnd, format9, 4,
avgval, nsecs),
perc, curstat->gen.name);
}
/*
** print a line of (more or less) static info about one process
*/
void
showvarproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char format1[16], format2[16];
struct passwd *pwd;
struct group *grp;
char *username, *groupname;
char usname[16], grname[16];
char exittype;
/*
** determine the user- and group-name of the process
*/
if ( (pwd = getpwuid(curstat->gen.ruid)) )
{
username = pwd->pw_name;
}
else
{
snprintf(usname, sizeof usname, "%d", curstat->gen.ruid);
username = usname;
}
if ( (grp = getgrgid(curstat->gen.rgid)) )
{
groupname = grp->gr_name;
}
else
{
snprintf(grname, sizeof grname, "%d", curstat->gen.rgid);
groupname = grname;
}
/*
** show process-info
*/
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(varproclina,
curstat->gen.pid,
curstat->gen.ppid,
username,
groupname,
convdate(curstat->gen.btime, format1),
convtime(curstat->gen.btime, format2),
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
'-',
curstat->gen.state,
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
if (curstat->gen.excode & 0xff)
{
if (curstat->gen.excode & 0x80)
exittype = 'C';
else
exittype = 'S';
}
else
{
exittype = 'E';
}
printg(varprocline,
curstat->gen.ppid,
username,
groupname,
convdate(curstat->gen.btime, format1),
convtime(curstat->gen.btime, format2),
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
exittype,
curstat->gen.excode & 0xff ?
curstat->gen.excode & 0x7f :
(curstat->gen.excode>>8) & 0xff,
perc, curstat->gen.name);
}
}
/*
** print a line containing the (almost) full command line
*/
void
showcmdproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
/*
** show process-info
*/
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(cmdproclina,
curstat->gen.pid,
perc,
curstat->gen.cmdline[0] ?
curstat->gen.cmdline : curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (curstat->gen.pid == 0)
printg(" ? ");
else
printg("%5d ", curstat->gen.pid);
printg(cmdprocline,
perc,
curstat->gen.cmdline[0] ?
curstat->gen.cmdline : curstat->gen.name);
}
}
/*
** print a line of scheduling info about one process
*/
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
void
showschproc(struct pstat *curstat, double perc, int nsecs, int avgval)
{
char *pol, exittype;
switch (curstat->cpu.policy)
{
case SCHED_NORMAL:
pol = "norm";
break;
case SCHED_RR:
pol = "rr ";
break;
case SCHED_FIFO:
pol = "fifo";
break;
default:
pol = "?";
}
/*
** show process-info
*/
if (curstat->gen.state != 'E')
{
/*
** show process-info of active process
*/
printg(schproclina,
curstat->gen.pid,
curstat->gen.nthrrun,
curstat->gen.nthrslpi,
curstat->gen.nthrslpu,
pol,
curstat->cpu.nice,
curstat->cpu.prio,
curstat->cpu.rtprio,
curstat->cpu.curcpu,
curstat->gen.excode & ~(INT_MAX) ? "N-" : "--",
curstat->gen.state,
perc, curstat->gen.name);
}
else
{
/*
** show process-info of exited process
*/
if (curstat->gen.pid == 0)
printg(" ?");
else
printg("%5d", curstat->gen.pid);
if (curstat->gen.excode & 0xff)
{
if (curstat->gen.excode & 0x80)
exittype = 'C';
else
exittype = 'S';
}
else
{
exittype = 'E';
}
printg(schprocline,
curstat->gen.excode & ~(INT_MAX) ? 'N' : '-',
exittype,
curstat->gen.excode & 0xff ?
curstat->gen.excode & 0x7f :
(curstat->gen.excode>>8) & 0xff,
perc, curstat->gen.name);
}
}
/*
** print the header for the process-list
*/
void
priphead(int curlist, int totlist, char showtype, char showorder, char autosort)
{
char columnprefix;
int order = showorder;
/*
** determine the prefix for the sorting-column
** to indicate automatic mode
*/
if (autosort)
columnprefix = 'A';
else
columnprefix = ' ';
/*
** print the header line
*/
switch (showtype)
{
case MPROCGEN:
if (supportflags & PATCHSTAT)
{
printg(genprochdr1, columnprefix,
columnhead[order], curlist, totlist);
}
else
{
if (supportflags & IOSTAT)
printg(genprochdr2, columnprefix,
columnhead[order], curlist, totlist);
else
printg(genprochdr3, columnprefix,
columnhead[order], curlist, totlist);
}
break;
case MPROCMEM:
printg(memprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MPROCDSK:
if (supportflags & PATCHSTAT)
{
printg(dskprochdr1, columnprefix, columnhead[order],
curlist, totlist);
}
else
{
if (supportflags & IOSTAT)
printg(dskprochdr2, columnprefix,
columnhead[order], curlist, totlist);
}
break;
case MPROCNET:
printg(netprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MPROCVAR:
printg(varprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MPROCARG:
printg(cmdprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MPROCSCH:
printg(schprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MCUMUSER:
printg(totuserhdr, columnprefix, columnhead[order],
curlist, totlist);
break;
case MCUMPROC:
printg(totprochdr, columnprefix, columnhead[order],
curlist, totlist);
break;
}
}
/*
** print the list of processes from the deviation-list
*/
int
priproc(struct pstat *pstat, int firstproc, int lastproc, int curline,
int curlist, int totlist, char showtype, char showorder,
struct syscap *sb, struct selection *sel, int nsecs, int avgval)
{
register int i;
register struct pstat *curstat;
double perc;
/*
** print info per actual process and maintain totals
*/
for (i=firstproc; i < lastproc; i++)
{
if (screen && curline >= LINES) /* screen filled entirely ? */
break;
curstat = pstat+i;
/*
** calculate occupation-percentage of this process
** depending on selected resource
*/
switch (showorder)
{
case MSORTCPU:
perc = 0.0;
if (sb->availcpu)
{
perc = (double)(curstat->cpu.stime +
curstat->cpu.utime ) *
100.0 /
(sb->availcpu / sb->nrcpu);
if (perc > 100.0 * sb->nrcpu)
perc = 100.0 * sb->nrcpu;
if (perc > 100.0 * curstat->gen.nthr)
perc = 100.0 * curstat->gen.nthr;
}
break;
case MSORTMEM:
perc = 0.0;
if (sb->availmem)
{
perc = (double)curstat->mem.rmem *
100.0 / sb->availmem;
if (perc > 100.0)
perc = 100.0;
}
break;
case MSORTDSK:
perc = 0.0;
if (supportflags & PATCHSTAT)
{
if (sb->availdsk)
{
perc = (double)(curstat->dsk.rio +
curstat->dsk.wio ) *
100.0 / sb->availdsk;
if (perc > 100.0)
perc = 100.0;
}
}
else
{
if (sb->availdsk)
{
perc = (double)(curstat->dsk.rsz +
curstat->dsk.wsz ) *
100.0 / sb->availdsk;
if (perc > 100.0)
perc = 100.0;
}
}
break;
case MSORTNET:
perc = 0.0;
if (sb->availnet)
{
perc = (double)(curstat->net.tcpsnd +
curstat->net.tcprcv +
curstat->net.udpsnd +
curstat->net.udprcv +
curstat->net.rawsnd +
curstat->net.rawrcv ) *
100.0 / sb->availnet;
if (perc > 100.0)
perc = 100.0;
}
break;
default:
perc = 0.0;
}
/*
** check if only processes of a particular user
** should be shown
*/
if (sel->userid[0] != USERSTUB)
{
int u = 0;
while (sel->userid[u] != USERSTUB)
{
if (sel->userid[u] == curstat->gen.ruid)
break;
u++;
}
if (sel->userid[u] != curstat->gen.ruid)
continue;
}
/*
** check if only processes with a particular name
** should be shown
*/
if (sel->procnamesz &&
regexec(&(sel->procregex), curstat->gen.name, 0, NULL, 0))
continue;
/*
** now do the formatting of output
*/
switch (showtype)
{
case MPROCGEN:
showgenproc(curstat, perc, nsecs, avgval);
break;
case MPROCMEM:
showmemproc(curstat, perc, nsecs, avgval);
break;
case MPROCDSK:
showdskproc(curstat, perc, nsecs, avgval);
break;
case MPROCNET:
shownetproc(curstat, perc, nsecs, avgval);
break;
case MPROCVAR:
showvarproc(curstat, perc, nsecs, avgval);
break;
case MPROCARG:
showcmdproc(curstat, perc, nsecs, avgval);
break;
case MPROCSCH:
showschproc(curstat, perc, nsecs, avgval);
break;
case MCUMUSER:
showtotuser(curstat, perc, nsecs, avgval);
break;
case MCUMPROC:
showtotproc(curstat, perc, nsecs, avgval);
break;
}
curline++;
}
return curline;
}
/*
** print the system-wide statistics
*/
int
prisyst(struct sstat *sstat, int curline, int nsecs, int avgval,
int fixedhead, int usecolors, char *highorderp,
int maxcpulines, int maxdsklines, int maxintlines)
{
register int i, lin;
count_t cputot, percputot, mstot, busy;
count_t udpin, udpout, ipin, ipout, ipfrw, ipindel;
unsigned int badness, highbadness=0;
char format1[16], format2[16], format3[16];
char format4[16], format5[16];
char busyval[5], coloron=0;
/*
** CPU statistics
*/
cputot = sstat->cpu.all.stime + sstat->cpu.all.utime +
sstat->cpu.all.ntime + sstat->cpu.all.itime +
sstat->cpu.all.wtime + sstat->cpu.all.Itime +
sstat->cpu.all.Stime + sstat->cpu.all.steal;
busy = (cputot - sstat->cpu.all.itime - sstat->cpu.all.wtime)
* 100.0 / cputot;
if (cpubadness)
badness = busy * 100 / cpubadness;
else
badness = 0;
if (highbadness < badness)
{
highbadness = badness;
*highorderp = MSORTCPU;
}
if (cputot == 0)
cputot = 1; /* avoid divide-by-zero */
percputot = cputot / sstat->cpu.nrcpu;
if (percputot == 0)
percputot = 1; /* avoid divide-by-zero */
coloron = syscolorlabel("CPU", usecolors, badness);
printg(" | sys %6.0f%% | user %6.0f%% | "
"irq %6.0f%% | idle %6.0f%% | wait %6.0f%% |\n",
(double) (sstat->cpu.all.stime * 100.0) / percputot,
(double)((sstat->cpu.all.utime + sstat->cpu.all.ntime)
* 100.0) / percputot,
(double)((sstat->cpu.all.Itime + sstat->cpu.all.Stime)
* 100.0) / percputot,
(double) (sstat->cpu.all.itime * 100.0) / percputot,
(double) (sstat->cpu.all.wtime * 100.0) / percputot);
if (coloron)
syscoloroff(coloron);
curline++;
if (sstat->cpu.all.steal) /* only for virtual machines ... */
{
coloron = syscolorlabel("CPU", usecolors, badness);
printg(" | steal %4.0f%% | stl/cpu %3.0f%% | "
" | | |\n",
(double) (sstat->cpu.all.steal * 100.0) / percputot,
(double) (sstat->cpu.all.steal * 100.0) / cputot);
if (coloron)
syscoloroff(coloron);
curline++;
}
if (sstat->cpu.nrcpu > 1)
{
for (i=lin=0; i < sstat->cpu.nrcpu && lin < maxcpulines; i++)
{
percputot = sstat->cpu.cpu[i].stime +
sstat->cpu.cpu[i].utime +
sstat->cpu.cpu[i].ntime +
sstat->cpu.cpu[i].itime +
sstat->cpu.cpu[i].wtime +
sstat->cpu.cpu[i].Itime +
sstat->cpu.cpu[i].Stime +
sstat->cpu.cpu[i].steal;
if (percputot == (sstat->cpu.cpu[i].itime +
sstat->cpu.cpu[i].wtime ) &&
!fixedhead )
continue; /* inactive cpu */
busy = (percputot - sstat->cpu.cpu[i].itime
- sstat->cpu.cpu[i].wtime)
* 100.0 / percputot;
if (cpubadness)
badness = busy * 100 / cpubadness;
else
badness = 0;
if (highbadness < badness)
{
highbadness = badness;
*highorderp = MSORTCPU;
}
if (percputot == 0)
percputot = 1; /* avoid divide-by-zero */
coloron = syscolorlabel("cpu", usecolors, badness);
printg(" | sys %6.0f%% | "
"user %6.0f%% | irq %6.0f%% | "
"idle %6.0f%% | cpu%03d w%3.0f%% |\n",
(double) (sstat->cpu.cpu[i].stime
* 100.0) / percputot,
(double)((sstat->cpu.cpu[i].utime +
sstat->cpu.cpu[i].ntime)
* 100.0) / percputot,
(double)((sstat->cpu.cpu[i].Itime +
sstat->cpu.cpu[i].Stime)
* 100.0) / percputot,
(double) (sstat->cpu.cpu[i].itime
* 100.0) / percputot,
sstat->cpu.cpu[i].cpunr,
(double) (sstat->cpu.cpu[i].wtime
* 100.0) / percputot);
if (coloron)
syscoloroff(coloron);
curline++;
lin++;
}
}
/*
** other CPU-related statistics
*/
if (sstat->cpu.lavg1 > 999.0 ||
sstat->cpu.lavg5 > 9999.0 ||
sstat->cpu.lavg15 > 999.0 )
{
printg("CPL | avg1 %6.0f | avg5 %7.0f | avg15 %6.0f | csw %s"
" | intr %s |\n",
sstat->cpu.lavg1,
sstat->cpu.lavg5,
sstat->cpu.lavg15,
val2valstr(sstat->cpu.csw, format1, 8,avgval,nsecs),
val2valstr(sstat->cpu.devint, format2, 7,avgval,nsecs));
}
else
{
printg("CPL | avg1 %6.2f | avg5 %7.2f | avg15 %6.2f | csw %s"
" | intr %s |\n",
sstat->cpu.lavg1,
sstat->cpu.lavg5,
sstat->cpu.lavg15,
val2valstr(sstat->cpu.csw, format1, 8,avgval,nsecs),
val2valstr(sstat->cpu.devint, format2, 7,avgval,nsecs));
}
curline++;
/*
** MEMORY statistics
*/
busy = (sstat->mem.physmem - sstat->mem.freemem
- sstat->mem.cachemem
- sstat->mem.buffermem)
* 100.0 / sstat->mem.physmem;
if (membadness)
badness = busy * 100 / membadness;
else
badness = 0;
if (highbadness < badness)
{
highbadness = badness;
*highorderp = MSORTMEM;
}
coloron = syscolorlabel("MEM", usecolors, badness);
printg(" | tot %s | free %s | cache %s | buff %s | slab %s |\n",
val2memstr(sstat->mem.physmem * pagesize, format1,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.freemem * pagesize, format2,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.cachemem * pagesize, format3,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.buffermem * pagesize, format4,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.slabmem * pagesize, format5,
MBFORMAT, 0, 0));
if (coloron)
syscoloroff(coloron);
curline++;
/*
** SWAP statistics
*/
busy = (sstat->mem.totswap - sstat->mem.freeswap)
* 100.0 / sstat->mem.totswap;
if (swpbadness)
badness = busy * 100 / swpbadness;
else
badness = 0;
if (highbadness < badness)
{
highbadness = badness;
*highorderp = MSORTMEM;
}
if (sstat->mem.commitlim && sstat->mem.committed > sstat->mem.commitlim)
badness = 100; /* force colored output */
coloron = syscolorlabel("SWP", usecolors, badness);
printg(" | tot %s | free %s | "
"| vmcom %s | vmlim %s |\n",
val2memstr(sstat->mem.totswap * pagesize, format1,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.freeswap * pagesize, format2,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.committed * pagesize, format3,
MBFORMAT, 0, 0),
val2memstr(sstat->mem.commitlim * pagesize, format4,
MBFORMAT, 0, 0));
if (coloron)
syscoloroff(coloron);
curline++;
/*
** PAGING statistics
*/
if (fixedhead ||
sstat->mem.pgscans ||
sstat->mem.allocstall ||
sstat->mem.swins ||
sstat->mem.swouts )
{
busy = sstat->mem.swouts / nsecs * pagbadness;
if (busy > 100)
busy = 100;
if (membadness)
badness = busy * 100 / membadness;
else
badness = 0;
if (highbadness < badness)
{
highbadness = badness;
*highorderp = MSORTMEM;
}
/*
** take care that this line is anyhow colored for
** 'almost critical' in case of swapouts > 1 per second
*/
if (sstat->mem.swouts / nsecs > 0 &&
pagbadness && almostcrit && badness < almostcrit)
badness = almostcrit;
coloron = syscolorlabel("PAG", usecolors, badness);
printg(" | scan %s | stall %s | "
" | swin %s | swout %s |\n",
val2valstr(sstat->mem.pgscans, format1, 6,
avgval, nsecs),
val2valstr(sstat->mem.allocstall, format2, 6,
avgval, nsecs),
val2valstr(sstat->mem.swins, format3, 7,
avgval, nsecs),
val2valstr(sstat->mem.swouts, format4, 6,
avgval, nsecs));
if (coloron)
syscoloroff(coloron);
curline++;
}
/*
** DISK statistics
**
** If extended disk-stats's are supported, take them
*/
mstot = cputot * 1000 / hertz / sstat->cpu.nrcpu;
for (i=0, lin=0; sstat->xdsk.xdsk[i].name[0] && lin < maxdsklines; i++)
{
count_t iotot;
iotot = sstat->xdsk.xdsk[i].nread + sstat->xdsk.xdsk[i].nwrite;
busy = (double)(sstat->xdsk.xdsk[i].io_ms * 100.0 / mstot);
if (dskbadness)
badness = busy * 100 / dskbadness;
else
badness = 0;
if (highbadness < badness &&
(supportflags & (PATCHSTAT|IOSTAT)) )
{
highbadness = badness;
*highorderp = MSORTDSK;
}
if (iotot || fixedhead)
{
coloron = syscolorlabel("DSK", usecolors, badness);
printg(" | %11.11s | busy %6.0lf%% | read %s |"
" write %s | avio %4.0lf ms |\n",
sstat->xdsk.xdsk[i].name,
(double)(sstat->xdsk.xdsk[i].io_ms * 100.0 / mstot),
val2valstr(sstat->xdsk.xdsk[i].nread, format1, 7,
avgval, nsecs),
val2valstr(sstat->xdsk.xdsk[i].nwrite, format2, 6,
avgval, nsecs),
iotot?(double)(sstat->xdsk.xdsk[i].io_ms/iotot):0.0);
if (coloron)
syscoloroff(coloron);
curline++;
lin++;
}
}
/*
** NET statistics
*/
udpin = sstat->net.udpv4.InDatagrams +
sstat->net.udpv6.Udp6InDatagrams;
udpout = sstat->net.udpv4.OutDatagrams +
sstat->net.udpv6.Udp6OutDatagrams;
if (sstat->net.tcp.InSegs || sstat->net.tcp.OutSegs ||
udpin || udpout || fixedhead )
{
printg("NET | transport | tcpi %s | tcpo %s |"
" udpi %s | udpo %s |\n",
val2valstr(sstat->net.tcp.InSegs, format1, 7,
avgval, nsecs),
val2valstr(sstat->net.tcp.OutSegs, format2, 7,
avgval, nsecs),
val2valstr(udpin, format3, 7, avgval, nsecs),
val2valstr(udpout, format4, 7, avgval, nsecs));
curline++;
}
ipin = sstat->net.ipv4.InReceives +
sstat->net.ipv6.Ip6InReceives;
ipout = sstat->net.ipv4.OutRequests +
sstat->net.ipv6.Ip6OutRequests;
ipindel = sstat->net.ipv4.InDelivers +
sstat->net.ipv6.Ip6InDelivers;
ipfrw = sstat->net.ipv4.ForwDatagrams +
sstat->net.ipv6.Ip6OutForwDatagrams;
if (ipin || ipout || fixedhead )
{
printg("NET | network | ipi %s | ipo %s | ipfrw %s |"
" deliv %s |\n",
val2valstr(ipin, format1, 8, avgval, nsecs),
val2valstr(ipout, format2, 8, avgval, nsecs),
val2valstr(ipfrw, format3, 6, avgval, nsecs),
val2valstr(ipindel, format4, 6, avgval, nsecs));
curline++;
}
for (i=0, lin=0; sstat->intf.intf[i].name[0] && lin < maxintlines; i++)
{
if (sstat->intf.intf[i].rpack ||
sstat->intf.intf[i].spack || fixedhead)
{
char *iform = "Kbps";
char *oform = "Kbps";
count_t ival, ipres, oval, opres;
/*
** convert byte-transfers to bit-transfers (* 8)
** convert bit-transfers to kilobit-transfers (/ 1000)
** per second
*/
ival = sstat->intf.intf[i].rbyte/125/nsecs;
oval = sstat->intf.intf[i].sbyte/125/nsecs;
if (ival >= 10000) /* input value 4 positions */
{
if (ival < 10000000)
{
ipres = ival / 1000;
iform = "Mbps";
}
else
{
ipres = ival / 1000000;
iform = "Gbps";
}
}
else
{
ipres = ival;
}
if (oval >= 10000) /* input value 4 positions */
{
if (oval < 10000000)
{
opres = oval / 1000;
oform = "Mbps";
}
else
{
opres = oval / 1000000;
oform = "Gbps";
}
}
else
{
opres = oval;
}
/*
** calculate busy-percentage for interface
*/
if (sstat->intf.intf[i].speed) /* speed known? */
{
if (sstat->intf.intf[i].duplex)
busy = (ival > oval ? ival : oval) /
(sstat->intf.intf[i].speed *10);
else
busy = (ival + oval) /
(sstat->intf.intf[i].speed *10);
snprintf(busyval, sizeof busyval,
"%3lld%%", busy);
}
else
{
strcpy(busyval, "----"); /* speed unknown */
busy = 0;
}
if (netbadness)
badness = busy * 100 / netbadness;
else
badness = 0;
if (highbadness < badness &&
(supportflags & PATCHSTAT) )
{
highbadness = badness;
*highorderp = MSORTNET;
}
coloron = syscolorlabel("NET", usecolors, badness);
printg(" | %-6.6s %4s | pcki %s | pcko %s |"
" si %4lld %s | so %4lld %s |\n",
sstat->intf.intf[i].name,
busyval,
val2valstr(sstat->intf.intf[i].rpack,
format1, 7, avgval, nsecs),
val2valstr(sstat->intf.intf[i].spack,
format2, 7, avgval, nsecs),
ipres, iform,
opres, oform);
if (coloron)
syscoloroff(coloron);
curline++;
lin++;
}
}
/*
** application statistics
**
** WWW: notice that we cause one access ourselves by fetching
** the statistical counters
*/
#if HTTPSTATS
if (sstat->www.accesses > 1 || fixedhead )
{
printg("WWW | reqs %s | totKB %s | byt/rq %s | iwork %s |"
" bwork %s |\n",
val2valstr(sstat->www.accesses, format1, 6,
avgval, nsecs),
val2valstr(sstat->www.totkbytes, format2, 6,
avgval, nsecs),
val2valstr(sstat->www.accesses ?
sstat->www.totkbytes*1024/sstat->www.accesses : 0,
format3, 5, 0, 0),
val2valstr(sstat->www.iworkers, format4, 6, 0, 0),
val2valstr(sstat->www.bworkers, format5, 6, 0, 0) );
curline++;
}
#endif
/*
** if the system is hardly loaded, still CPU-ordering of
** processes is most interesting (instead of memory)
*/
if (highbadness < 70 && *highorderp == MSORTMEM)
*highorderp = MSORTCPU;
return curline;
}
/*
** sort-functions
*/
int
compcpu(const void *a, const void *b)
{
register count_t acpu = ((struct pstat *)a)->cpu.stime +
((struct pstat *)a)->cpu.utime;
register count_t bcpu = ((struct pstat *)b)->cpu.stime +
((struct pstat *)b)->cpu.utime;
if (acpu < bcpu) return 1;
if (acpu > bcpu) return -1;
return compmem(a, b);
}
int
compdsk(const void *a, const void *b)
{
register count_t adsk = ((struct pstat *)a)->dsk.rio +
((struct pstat *)a)->dsk.wio;
register count_t bdsk = ((struct pstat *)b)->dsk.rio +
((struct pstat *)b)->dsk.wio;
if (adsk < bdsk) return 1;
if (adsk > bdsk) return -1;
return compcpu(a, b);
}
int
compmem(const void *a, const void *b)
{
register count_t amem = ((struct pstat *)a)->mem.rmem;
register count_t bmem = ((struct pstat *)b)->mem.rmem;
if (amem < bmem) return 1;
if (amem > bmem) return -1;
return 0;
}
int
compnet(const void *a, const void *b)
{
register count_t anet = ((struct pstat *)a)->net.tcpsnd +
((struct pstat *)a)->net.tcprcv +
((struct pstat *)a)->net.udpsnd +
((struct pstat *)a)->net.udprcv +
((struct pstat *)a)->net.rawsnd +
((struct pstat *)a)->net.rawrcv ;
register count_t bnet = ((struct pstat *)b)->net.tcpsnd +
((struct pstat *)b)->net.tcprcv +
((struct pstat *)b)->net.udpsnd +
((struct pstat *)b)->net.udprcv +
((struct pstat *)b)->net.rawsnd +
((struct pstat *)b)->net.rawrcv ;
if (anet < bnet) return 1;
if (anet > bnet) return -1;
return compcpu(a, b);
}
int
cpucompar(const void *a, const void *b)
{
register count_t aidle = ((struct percpu *)a)->itime +
((struct percpu *)a)->wtime;
register count_t bidle = ((struct percpu *)b)->itime +
((struct percpu *)b)->wtime;
if (aidle < bidle) return -1;
if (aidle > bidle) return 1;
return 0;
}
int
diskcompar(const void *a, const void *b)
{
register count_t amsio = ((struct perxdsk *)a)->io_ms;
register count_t bmsio = ((struct perxdsk *)b)->io_ms;
if (amsio < bmsio) return 1;
if (amsio > bmsio) return -1;
return 0;
}
int
intfcompar(const void *a, const void *b)
{
register count_t afactor=0, bfactor=0;
count_t aspeed = ((struct perintf *)a)->speed;
count_t bspeed = ((struct perintf *)b)->speed;
char aduplex = ((struct perintf *)a)->duplex;
char bduplex = ((struct perintf *)b)->duplex;
count_t arbyte = ((struct perintf *)a)->rbyte;
count_t brbyte = ((struct perintf *)b)->rbyte;
count_t asbyte = ((struct perintf *)a)->sbyte;
count_t bsbyte = ((struct perintf *)b)->sbyte;
/*
** if speed of first interface known, calculate busy factor
*/
if (aspeed)
{
if (aduplex)
afactor = (arbyte > asbyte ? arbyte : asbyte) /
(aspeed / 10);
else
afactor = (arbyte + asbyte) / (aspeed / 10);
}
/*
** if speed of second interface known, calculate busy factor
*/
if (bspeed)
{
if (bduplex)
bfactor = (brbyte > bsbyte ? brbyte : bsbyte) /
(bspeed / 10);
else
bfactor = (brbyte + bsbyte) / (bspeed / 10);
}
/*
** compare interfaces
*/
if (aspeed && bspeed)
{
if (afactor < bfactor) return 1;
if (afactor > bfactor) return -1;
return 0;
}
if (!aspeed && !bspeed)
{
if ((arbyte + asbyte) < (brbyte + bsbyte)) return 1;
if ((arbyte + asbyte) > (brbyte + bsbyte)) return -1;
return 0;
}
if (aspeed)
return -1;
else
return 1;
}
int
compusr(const void *a, const void *b)
{
register int uida = ((struct pstat *)a)->gen.ruid;
register int uidb = ((struct pstat *)b)->gen.ruid;
if (uida > uidb) return 1;
if (uida < uidb) return -1;
return 0;
}
int
compnam(const void *a, const void *b)
{
register char *nama = ((struct pstat *)a)->gen.name;
register char *namb = ((struct pstat *)b)->gen.name;
return strcmp(nama, namb);
}
/*
** print the label of a system-statistics line and switch on
** colors if needed
*/
static int
syscolorlabel(char *labeltext, int usecolors, unsigned int badness)
{
if (usecolors)
{
if (badness >= 100)
{
attron(A_BOLD);
attron(COLOR_PAIR(COLORHIGH));
attron (A_BLINK);
printg(labeltext);
attroff(A_BLINK);
return COLORHIGH;
}
if (almostcrit && badness >= almostcrit)
{
attron(A_BOLD);
attron(COLOR_PAIR(COLORMED));
printg(labeltext);
return COLORMED;
}
}
/*
** no colors required or no reason to show colors
*/
printg(labeltext);
return 0;
}
static void
syscoloroff(char curcolor)
{
attroff(A_BOLD);
attroff(COLOR_PAIR(curcolor));
}
/*
** handle modifications from the ~/.atoprc file
*/
void
do_cpucritperc(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: cpucritperc value not numeric\n");
exit(1);
}
if (value < 0 || value > 100)
{
fprintf(stderr,
".atoprc: cpucritperc value not in range 0-100\n");
exit(1);
}
cpubadness = value;
}
void
do_memcritperc(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: memcritperc value not numeric\n");
exit(1);
}
if (value < 0 || value > 100)
{
fprintf(stderr,
".atoprc: memcritperc value not in range 0-100\n");
exit(1);
}
membadness = value;
}
void
do_swpcritperc(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: swpcritperc value not numeric\n");
exit(1);
}
if (value < 0 || value > 100)
{
fprintf(stderr,
".atoprc: swpcritperc value not in range 0-100\n");
exit(1);
}
swpbadness = value;
}
void
do_dskcritperc(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: dskcritperc value not numeric\n");
exit(1);
}
if (value < 0 || value > 100)
{
fprintf(stderr,
".atoprc: dskcritperc value not in range 0-100\n");
exit(1);
}
dskbadness = value;
}
void
do_netcritperc(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: netcritperc value not numeric\n");
exit(1);
}
if (value < 0 || value > 100)
{
fprintf(stderr,
".atoprc: netcritperc value not in range 0-100\n");
exit(1);
}
netbadness = value;
}
void
do_swoutcritsec(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: swoutcritsec value not numeric\n");
exit(1);
}
if (value < 0)
{
fprintf(stderr,
".atoprc: swoutcritsec value less then 0\n");
exit(1);
}
pagbadness = value;
}
void
do_almostcrit(char *val)
{
int value = atoi(val);
if ( !numeric(val))
{
fprintf(stderr, ".atoprc: almostcrit value not numeric\n");
exit(1);
}
if (value < 0 || value > 99)
{
fprintf(stderr,
".atoprc: almostcrit value not in range 0-99\n");
exit(1);
}
almostcrit = value;
}
|