summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2019-04-26 20:25:54 +0300
committerToomas Soome <tsoome@me.com>2019-05-06 19:00:39 +0300
commitd70f65dfb86dedc271c6eacf5767889026db880c (patch)
tree80e417eed65380b4ae0c2f781147c9fa208b3154 /usr
parent916d72b8ac11e271c755a051c19d564f7086892c (diff)
downloadillumos-joyent-d70f65dfb86dedc271c6eacf5767889026db880c.tar.gz
10859 mdb: move mdb_nicenum() to mdb_modapi.c
Reviewed by: Igor Kozhukhov <igor@dilos.org> Reviewed by: John Levon <john.levon@joyent.com> Reviewed by: Cody Mello <cody.mello@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr')
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_modapi.c45
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_modapi.h7
-rw-r--r--usr/src/cmd/mdb/common/modules/conf/mapfile-extern2
-rw-r--r--usr/src/cmd/mdb/common/modules/zfs/zfs.c63
4 files changed, 61 insertions, 56 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_modapi.c b/usr/src/cmd/mdb/common/mdb/mdb_modapi.c
index c944a03729..fd47330ef6 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_modapi.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_modapi.c
@@ -58,6 +58,51 @@ static int
call_idcmd(mdb_idcmd_t *idcp, uintmax_t addr, uintmax_t count,
uint_t flags, mdb_argvec_t *argv);
+int
+mdb_snprintfrac(char *buf, int len,
+ uint64_t numerator, uint64_t denom, int frac_digits)
+{
+ int mul = 1;
+ int whole, frac, i;
+
+ for (i = frac_digits; i; i--)
+ mul *= 10;
+ whole = numerator / denom;
+ frac = mul * numerator / denom - mul * whole;
+ return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
+}
+
+void
+mdb_nicenum(uint64_t num, char *buf)
+{
+ uint64_t n = num;
+ int index = 0;
+ char *u;
+
+ while (n >= 1024) {
+ n = (n + (1024 / 2)) / 1024; /* Round up or down */
+ index++;
+ }
+
+ u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
+
+ if (index == 0) {
+ (void) mdb_snprintf(buf, MDB_NICENUM_BUFLEN, "%llu",
+ (u_longlong_t)n);
+ } else if (n < 10 && (num & (num - 1)) != 0) {
+ (void) mdb_snprintfrac(buf, MDB_NICENUM_BUFLEN,
+ num, 1ULL << 10 * index, 2);
+ strcat(buf, u);
+ } else if (n < 100 && (num & (num - 1)) != 0) {
+ (void) mdb_snprintfrac(buf, MDB_NICENUM_BUFLEN,
+ num, 1ULL << 10 * index, 1);
+ strcat(buf, u);
+ } else {
+ (void) mdb_snprintf(buf, MDB_NICENUM_BUFLEN, "%llu%s",
+ (u_longlong_t)n, u);
+ }
+}
+
ssize_t
mdb_vread(void *buf, size_t nbytes, uintptr_t addr)
{
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_modapi.h b/usr/src/cmd/mdb/common/mdb/mdb_modapi.h
index 4e5d54d7d1..7b4f7ecb2d 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_modapi.h
+++ b/usr/src/cmd/mdb/common/mdb/mdb_modapi.h
@@ -66,7 +66,7 @@ extern "C" {
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
-#define MDB_API_VERSION 4 /* Current API version number */
+#define MDB_API_VERSION 5 /* Current API version number */
/*
* Debugger command function flags:
@@ -257,6 +257,11 @@ extern void *mdb_alloc(size_t, uint_t);
extern void *mdb_zalloc(size_t, uint_t);
extern void mdb_free(void *, size_t);
+#define MDB_NICENUM_BUFLEN 6
+
+extern int mdb_snprintfrac(char *, int, uint64_t, uint64_t, int);
+extern void mdb_nicenum(uint64_t, char *);
+
extern size_t mdb_snprintf(char *, size_t, const char *, ...);
extern void mdb_printf(const char *, ...);
extern void mdb_warn(const char *, ...);
diff --git a/usr/src/cmd/mdb/common/modules/conf/mapfile-extern b/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
index 9371b4834d..0a0b5b77cf 100644
--- a/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
+++ b/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
@@ -124,6 +124,7 @@ SYMBOL_SCOPE {
mdb_memio_create { FLAGS = EXTERN };
mdb_name_to_major { FLAGS = EXTERN };
mdb_nhconvert { FLAGS = EXTERN };
+ mdb_nicenum { FLAGS = EXTERN };
mdb_object_iter { FLAGS = EXTERN };
mdb_one_bit { FLAGS = EXTERN };
mdb_page2pfn { FLAGS = EXTERN };
@@ -132,6 +133,7 @@ SYMBOL_SCOPE {
mdb_pid2proc { FLAGS = EXTERN };
mdb_pread { FLAGS = EXTERN };
mdb_printf { FLAGS = EXTERN };
+ mdb_snprintfrac { FLAGS = EXTERN };
mdb_prop_kernel { FLAGS = EXTERN };
mdb_prop_postmortem { FLAGS = EXTERN };
mdb_pwalk { FLAGS = EXTERN };
diff --git a/usr/src/cmd/mdb/common/modules/zfs/zfs.c b/usr/src/cmd/mdb/common/modules/zfs/zfs.c
index a31665cdf1..6d89e2c797 100644
--- a/usr/src/cmd/mdb/common/modules/zfs/zfs.c
+++ b/usr/src/cmd/mdb/common/modules/zfs/zfs.c
@@ -131,53 +131,6 @@ strisprint(const char *cp)
return (B_TRUE);
}
-#define NICENUM_BUFLEN 6
-
-static int
-snprintfrac(char *buf, int len,
- uint64_t numerator, uint64_t denom, int frac_digits)
-{
- int mul = 1;
- int whole, frac, i;
-
- for (i = frac_digits; i; i--)
- mul *= 10;
- whole = numerator / denom;
- frac = mul * numerator / denom - mul * whole;
- return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
-}
-
-static void
-mdb_nicenum(uint64_t num, char *buf)
-{
- uint64_t n = num;
- int index = 0;
- char *u;
-
- while (n >= 1024) {
- n = (n + (1024 / 2)) / 1024; /* Round up or down */
- index++;
- }
-
- u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
-
- if (index == 0) {
- (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu",
- (u_longlong_t)n);
- } else if (n < 10 && (num & (num - 1)) != 0) {
- (void) snprintfrac(buf, NICENUM_BUFLEN,
- num, 1ULL << 10 * index, 2);
- strcat(buf, u);
- } else if (n < 100 && (num & (num - 1)) != 0) {
- (void) snprintfrac(buf, NICENUM_BUFLEN,
- num, 1ULL << 10 * index, 1);
- strcat(buf, u);
- } else {
- (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu%s",
- (u_longlong_t)n, u);
- }
-}
-
/*
* <addr>::sm_entries <buffer length in bytes>
*
@@ -1552,7 +1505,7 @@ metaslab_stats(uintptr_t addr, int spa_flags)
for (int m = 0; m < vdev.vdev_ms_count; m++) {
mdb_metaslab_t ms;
mdb_space_map_t sm = { 0 };
- char free[NICENUM_BUFLEN];
+ char free[MDB_NICENUM_BUFLEN];
if (mdb_ctf_vread(&ms, "metaslab_t", "mdb_metaslab_t",
(uintptr_t)vdev_ms[m], 0) == -1)
@@ -1861,7 +1814,7 @@ metaslab_print_weight(uint64_t weight)
weight & ~(METASLAB_ACTIVE_MASK | METASLAB_WEIGHT_TYPE),
buf);
} else {
- char size[NICENUM_BUFLEN];
+ char size[MDB_NICENUM_BUFLEN];
mdb_nicenum(1ULL << WEIGHT_GET_INDEX(weight), size);
(void) mdb_snprintf(buf, sizeof (buf), "%llu x %s",
WEIGHT_GET_COUNT(weight), size);
@@ -2930,10 +2883,10 @@ zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
"\t avg\t comp\t%%Total\tType\n");
for (t = 0; t <= DMU_OT_TOTAL; t++) {
- char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
- char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
- char avg[NICENUM_BUFLEN];
- char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
+ char csize[MDB_NICENUM_BUFLEN], lsize[MDB_NICENUM_BUFLEN];
+ char psize[MDB_NICENUM_BUFLEN], asize[MDB_NICENUM_BUFLEN];
+ char avg[MDB_NICENUM_BUFLEN];
+ char comp[MDB_NICENUM_BUFLEN], pct[MDB_NICENUM_BUFLEN];
char typename[64];
int l;
@@ -2979,9 +2932,9 @@ zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
mdb_nicenum(zb->zb_psize, psize);
mdb_nicenum(zb->zb_asize, asize);
mdb_nicenum(zb->zb_asize / zb->zb_count, avg);
- (void) snprintfrac(comp, NICENUM_BUFLEN,
+ (void) mdb_snprintfrac(comp, MDB_NICENUM_BUFLEN,
zb->zb_lsize, zb->zb_psize, 2);
- (void) snprintfrac(pct, NICENUM_BUFLEN,
+ (void) mdb_snprintfrac(pct, MDB_NICENUM_BUFLEN,
100 * zb->zb_asize, tzb->zb_asize, 2);
mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"