summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2003-12-29 08:25:32 +0000
committerbde <bde@FreeBSD.org>2003-12-29 08:25:32 +0000
commit3b08616924a192a0293d4098ce94e7ae42b98fc4 (patch)
tree20b19ac8b4d76c3235b809f747bc26bec0d1570f /usr.bin
parentb7c552b38a3df97d3e5bd0c5410c1dc6609a529d (diff)
downloadFreeBSD-src-3b08616924a192a0293d4098ce94e7ae42b98fc4.zip
FreeBSD-src-3b08616924a192a0293d4098ce94e7ae42b98fc4.tar.gz
Use floating point instead of unsigned long longs in percentage
calculations. Long longs should never be used, since they break compiling with C90 compilers and don't necessarily work any better than longs for avoiding overflow. Print percentages with another digit of precision since they can be small and this is easy to do now that the format is floating point. Restored some more of the old -m output: Print the percentage of allocated memory that is in use. This is the amount of memory in active mbufs and mbuf clusters relative to the total amount of memory soft-allocated for mbufs and mbuf clusters. Print the percentage of allocated memory that is wired (cached). The old mbuf allocator never freed memory so printing this value wasn't useful. A previous version of netstat for the new allocator printed the in-use amount as a percentage of the wired amount. Fixed some nearby style bugs (excessive parenthesization and a redundant return). Reviewed by: alfred
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/mbuf.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index 8fb657c..c50fe9d 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -102,9 +102,9 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
int i, j, nmbufs, nmbclusters, page_size, num_objs;
int nsfbufs, nsfbufspeak, nsfbufsused;
u_int mbuf_hiwm, clust_hiwm, mbuf_lowm, clust_lowm;
- unsigned long long totspace[2];
- u_long totused[2];
+ u_long totspace[2], totused[2];
u_long gentotnum, gentotfree, totnum, totfree;
+ u_long totmem, totmemalloced, totmemused;
short nmbtypes;
size_t mlen;
long *mbtypes = NULL;
@@ -289,8 +289,8 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
mbtypes[i], i);
}
if (cflag)
- printf("\t%llu%% of mbuf map consumed\n",
- ((totspace[0] * 100) / (nmbufs * MSIZE)));
+ printf("\t%.1f%% of mbuf map consumed\n",
+ totspace[0] * 100.0 / (nmbufs * MSIZE));
totnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
totfree = mbpstat[GENLST]->mb_clfree;
@@ -333,8 +333,8 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
#endif
}
if (cflag)
- printf("\t%llu%% of cluster map consumed\n",
- ((totspace[1] * 100) / (nmbclusters * MCLBYTES)));
+ printf("\t%.1f%% of cluster map consumed\n",
+ totspace[1] * 100.0 / (nmbclusters * MCLBYTES));
mlen = sizeof(nsfbufs);
if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, NULL) &&
!sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen, NULL,
@@ -344,11 +344,13 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
nsfbufsused, nsfbufspeak, nsfbufs);
}
- printf("%llu KBytes allocated to network "
- "(%lluK mbuf, %lluK mbuf cluster)\n",
- (totspace[0] + totspace[1]) / 1024,
- totspace[0] / 1024,
- totspace[1] / 1024);
+ totmem = nmbufs * MSIZE + nmbclusters * MCLBYTES;
+ totmemalloced = totspace[0] + totspace[1];
+ totmemused = totused[0] * MSIZE + totused[1] * MCLBYTES;
+ printf(
+ "%lu KBytes allocated to network (%.1f%% in use, %.1f%% wired)\n",
+ totmem / 1024, totmemused * 100.0 / totmem,
+ totmemalloced * 100.0 / totmem);
printf("%lu requests for memory denied\n", mbstat->m_drops);
printf("%lu requests for memory delayed\n", mbstat->m_wait);
printf("%lu requests for sfbufs denied\n", mbstat->sf_allocfail);
@@ -369,6 +371,4 @@ err:
free(mbpstat[0]);
free(mbpstat);
}
-
- return;
}
OpenPOWER on IntegriCloud