diff options
author | gnn <gnn@FreeBSD.org> | 2012-05-12 21:25:48 +0000 |
---|---|---|
committer | gnn <gnn@FreeBSD.org> | 2012-05-12 21:25:48 +0000 |
commit | 2325662608ef525d2b16f218c7f92205ae571d5c (patch) | |
tree | 349c87edcb2d1f2a1040b9630b1fddf85a3484a0 /cddl/contrib/dtracetoolkit/Include | |
parent | 0778d9c814eb131045e6c28e219184601f3c9e19 (diff) | |
parent | 4297c1b2d07fec7f50b70e26e3adb4d062b19e15 (diff) | |
download | FreeBSD-src-2325662608ef525d2b16f218c7f92205ae571d5c.zip FreeBSD-src-2325662608ef525d2b16f218c7f92205ae571d5c.tar.gz |
Import dtracetoolkit into cddl/contrib
Diffstat (limited to 'cddl/contrib/dtracetoolkit/Include')
-rw-r--r-- | cddl/contrib/dtracetoolkit/Include/Readme | 18 | ||||
-rwxr-xr-x | cddl/contrib/dtracetoolkit/Include/test.ksh | 68 | ||||
-rw-r--r-- | cddl/contrib/dtracetoolkit/Include/time.h | 38 | ||||
-rw-r--r-- | cddl/contrib/dtracetoolkit/Include/tostr.h | 89 |
4 files changed, 213 insertions, 0 deletions
diff --git a/cddl/contrib/dtracetoolkit/Include/Readme b/cddl/contrib/dtracetoolkit/Include/Readme new file mode 100644 index 0000000..4aa4688 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Include/Readme @@ -0,0 +1,18 @@ +Include - include scripts for D scripting + + This directory contains files that can be included for use with D scripts. + + There are two types of include files, + + *.h + These can be included using, + + #!/usr/sbin/dtrace -Cs + #include <filename.h> + + *.d + These must be copyied to a translator directory (/usr/lib/dtrace), + and should be automatically pulled in. + + This directory does not contain runnable DTrace scripts. + diff --git a/cddl/contrib/dtracetoolkit/Include/test.ksh b/cddl/contrib/dtracetoolkit/Include/test.ksh new file mode 100755 index 0000000..a3e1036 --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Include/test.ksh @@ -0,0 +1,68 @@ +#!/usr/bin/ksh +/* + * test.ksh - DTrace include file test script. + * + * $Id: test.ksh 36 2007-09-15 06:51:18Z brendan $ + * + * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. + * + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at Docs/cddl1.txt + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * CDDL HEADER END + * + * 16-Sep-2007 Brendan Gregg Created this. + */ + +dtrace -CI . -s /dev/stdin << END + +#include "tostr.h" +#include "time.h" + +#pragma D option quiet +#pragma D option destructive + +dtrace:::BEGIN +{ + i = 1; + printf("\nNUM_TO_STR %12d = %s\n", i, NUM_TO_STR(i)); + i = 1100; + printf("NUM_TO_STR %12d = %s\n", i, NUM_TO_STR(i)); + i = 1100000; + printf("NUM_TO_STR %12d = %s\n", i, NUM_TO_STR(i)); + i = 999999999; + printf("NUM_TO_STR %12d = %s\n", i, NUM_TO_STR(i)); + + i = 1; + printf("\nBYTES_TO_STR %12d = %s\n", i, BYTES_TO_STR(i)); + i = 1024; + printf("BYTES_TO_STR %12d = %s\n", i, BYTES_TO_STR(i)); + i = 1000000; + printf("BYTES_TO_STR %12d = %s\n", i, BYTES_TO_STR(i)); + i = 999999999; + printf("BYTES_TO_STR %12d = %s\n", i, BYTES_TO_STR(i)); + + i = 1; + printf("\nUS_TO_STR %12d = %s\n", i, US_TO_STR(i)); + i = 1100; + printf("US_TO_STR %12d = %s\n", i, US_TO_STR(i)); + i = 999999; + printf("US_TO_STR %12d = %s\n", i, US_TO_STR(i)); + + printf("\nwalltimestamp : %Y\n", walltimestamp); + printf("TZ=GMT date : "); + system("TZ=GMT date '+%%H:%%M:%%S'"); + printf("TIME_HHMMSS : %s\n", TIME_HHMMSS); + + exit(0); +} +END diff --git a/cddl/contrib/dtracetoolkit/Include/time.h b/cddl/contrib/dtracetoolkit/Include/time.h new file mode 100644 index 0000000..76caa2e --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Include/time.h @@ -0,0 +1,38 @@ +/* + * time.h - DTrace Time include file. + * + * $Id: time.h 36 2007-09-15 06:51:18Z brendan $ + * + * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. + * + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at Docs/cddl1.txt + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * CDDL HEADER END + * + * 16-Sep-2007 Brendan Gregg Created this. + */ + +/* + * TIME_HHMMSS - Returns GMT time as a "HH:MM:SS" string. + * + * eg, "21:53:07" + */ +#define TIME_HHMMSS \ + strjoin(strjoin(strjoin(strjoin(strjoin( \ + (((walltimestamp / 1000000000) % 86400) / 3600) < 10 ? "0" : "",\ + lltostr(((walltimestamp / 1000000000) % 86400) / 3600)), ":"), \ + strjoin((((walltimestamp / 1000000000) % 3600) / 60) < 10 ? \ + "0" : "", lltostr(((walltimestamp / 1000000000) % 3600) / 60))),\ + ":"), strjoin(((walltimestamp / 1000000000) % 60) < 10 ? \ + "0" : "", lltostr((walltimestamp / 1000000000) % 60))) + diff --git a/cddl/contrib/dtracetoolkit/Include/tostr.h b/cddl/contrib/dtracetoolkit/Include/tostr.h new file mode 100644 index 0000000..6032f6a --- /dev/null +++ b/cddl/contrib/dtracetoolkit/Include/tostr.h @@ -0,0 +1,89 @@ +/* + * tostr.h - DTrace To-String include file. + * + * $Id: tostr.h 36 2007-09-15 06:51:18Z brendan $ + * + * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. + * + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at Docs/cddl1.txt + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * CDDL HEADER END + * + * 16-Sep-2007 Brendan Gregg Created this. + */ + +/* + * NUM_TO_STR(n) - takes a number and returns a string with a prefix, + * intended to fit withen 6 chars. + * + * Input Output + * 0 0 + * 1 1 + * 10 10 + * 999 999 + * 1000 1.0K + * 1100 1.1K + * 10000 10.0K + * 999999 999.0K + * 1000000 1.0M + * 10000000 10.0M + * 999999999 999.9M + */ +#define NUM_TO_STR(n) \ + n >= 1000000 ? \ + strjoin(strjoin(strjoin(lltostr(n / 1000000), "."), \ + lltostr((n % 1000000) / 100000)), "M") : n >= 1000 ? \ + strjoin(strjoin(strjoin(lltostr(n / 1000), "."), \ + lltostr((n % 1000) / 100)), "K") : lltostr(n) + +/* + * BYTES_TO_STR(n) - takes a byte count and returns a string with a prefix, + * intended to fit withen 6 chars. + * + * Input Output + * 0 0 + * 1 1 + * 10 10 + * 999 0.9K + * 1000 0.9K + * 1024 1.0K + * 10240 10.0K + * 1000000 976.5K + * 1048576 1.0M + * 1000000000 953.6M + */ +#define BYTES_TO_STR(n) \ + n >= 1024000 ? \ + strjoin(strjoin(strjoin(lltostr(n / 1048576), "."), \ + lltostr((n % 1048576) / 104858)), "M") : n >= 1000 ? \ + strjoin(strjoin(strjoin(lltostr(n / 1024), "."), \ + lltostr((n % 1024) / 103)), "K") : lltostr(n) + +/* + * US_TO_STR(n) - takes microseconds and returns a string with a prefix, + * intended to fit withen 6 chars. + * + * Input Output + * 0 0 + * 1 1u + * 10 10u + * 999 999u + * 1000 1.0m + * 1100 1.1m + * 10000 10.0m + * 999999 999.0m + */ +#define US_TO_STR(n) \ + n == 0 ? "0" : n >= 1000 ? \ + strjoin(lltostr(n / 1000), "m") : strjoin(lltostr(n), "u") + |