[dtrace-discuss] Some of my nanoseconds are missing...
Michael Shapiro
mws at zion.eng.sun.com
Tue Aug 8 11:12:11 PDT 2006
> I'm instrumenting Sendmail (as some of you are probably bored of hearing).
> ...
>
> PS: Any chance D could grow a pragma to automatically insert commas in
> large numbers? It would make comparing results much easier.
There is actually already a way to do this, but unfortunately it's a bit
blocked behind a stupid bug/oversight. printf(3S) uses the quote (')
character as a format flag that tells it to insert the locale's thousands
grouping character for %i, %d, %u, %f, %F, %g, or %G. And this is actually
implemented by DTrace printf() as well. That is, this is legal D:
printf("%'d\n", 123000);
However, in order for the underlying printf to do anything with %', the
locale subsystem has to be initialized by a call to setlocale(). And I
lazily forgot to put this into dtrace(1M), in part because my locale of
choice, POSIX C, maddeningly doesn't implement the thousands separator,
and thus until that issue is fixed or worked-around, I can't use it (!)
So, if you want to fix this yourself temporarily, put this into
usr/src/cmd/dtrace/dtrace.c:
#include <locale.h>
setlocale(LC_NUMERIC, "");
and then do something like this:
LC_NUMERIC=en_US dtrace <args ...>
(or just have your default locale be a non-C locale, or set LC_ALL) and it
should work. We'll get this fixed, although with the POSIX locale issue
still to be resolved. If you want to see if your locale supports a grouping
character you can do this:
$ LC_NUMERIC=en_US locale -k thousands_sep
thousands_sep=","
$ LC_NUMERIC=C locale -k thousands_sep
thousands_sep=""
Since you're in the UK, I'm sure you've got the appropriate character
set as Her Majesty intended it to be :)
-Mike
--
Mike Shapiro, Solaris Kernel Development. blogs.sun.com/mws/
More information about the dtrace-discuss
mailing list