2 * tostr.h - DTrace To-String include file.
4 * $Id: tostr.h 36 2007-09-15 06:51:18Z brendan $
6 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
10 * The contents of this file are subject to the terms of the
11 * Common Development and Distribution License, Version 1.0 only
12 * (the "License"). You may not use this file except in compliance
15 * You can obtain a copy of the license at Docs/cddl1.txt
16 * or http://www.opensolaris.org/os/licensing.
17 * See the License for the specific language governing permissions
18 * and limitations under the License.
22 * 16-Sep-2007 Brendan Gregg Created this.
26 * NUM_TO_STR(n) - takes a number and returns a string with a prefix,
27 * intended to fit withen 6 chars.
42 #define NUM_TO_STR(n) \
44 strjoin(strjoin(strjoin(lltostr(n / 1000000), "."), \
45 lltostr((n % 1000000) / 100000)), "M") : n >= 1000 ? \
46 strjoin(strjoin(strjoin(lltostr(n / 1000), "."), \
47 lltostr((n % 1000) / 100)), "K") : lltostr(n)
50 * BYTES_TO_STR(n) - takes a byte count and returns a string with a prefix,
51 * intended to fit withen 6 chars.
65 #define BYTES_TO_STR(n) \
67 strjoin(strjoin(strjoin(lltostr(n / 1048576), "."), \
68 lltostr((n % 1048576) / 104858)), "M") : n >= 1000 ? \
69 strjoin(strjoin(strjoin(lltostr(n / 1024), "."), \
70 lltostr((n % 1024) / 103)), "K") : lltostr(n)
73 * US_TO_STR(n) - takes microseconds and returns a string with a prefix,
74 * intended to fit withen 6 chars.
86 #define US_TO_STR(n) \
87 n == 0 ? "0" : n >= 1000 ? \
88 strjoin(lltostr(n / 1000), "m") : strjoin(lltostr(n), "u")