Index: dtrace/README =================================================================== diff -u -rc4f449cb353be812ba6502ef8e9587e87881f59b -ree6699cdfbf3ad89cccfa9d52dd23767d13f9d73 --- dtrace/README (.../README) (revision c4f449cb353be812ba6502ef8e9587e87881f59b) +++ dtrace/README (.../README) (revision ee6699cdfbf3ad89cccfa9d52dd23767d13f9d73) @@ -1,24 +1,37 @@ DTrace provider for the Next Scripting Language This is an implementation of a DTrace provider for the Next Scripting -Language (nsf). The nsf provider is designed to be used with and -without the DTrace support for Tcl. Therefore, nsf can be configured +Language (NSF). The NSF provider is designed to be used with and +without the DTrace support for Tcl. Therefore, NSF can be configured with --with-dtrace also in cases where Tcl was compiled without it. -To enable DTrace, run configure with the flag --enable-dtrace. The -DTrace support for nsf was developed under Mac OS X, other platforms -might require some fine tuning to get it running. Please report -improvements back to the nsf developers. +To enable DTrace, run configure with the flag --with-dtrace configure +flag. The DTrace support for NSF was developed under Mac OS X, other +platforms might require some fine tuning to get it running. Please +report improvements back to the NSF developers. -Once DTrace support is compiled into nsf, one can run D scripts like -in the following example: +In Mac OS X version including System Integrity Protection (SIP), one +must deactivate SIP for DTrace, first: - sudo dtrace -q -F -s dtrace/timestamps.d -c "./nxsh tests/object-system.test" +1) Boot into Recovery OS +2) Open Terminal +3) Run: "csrutil disable" +4) Run: "csrutil enable --without dtrace" -DTrace requires normally that dtrace is run with root permissions. In -case the provided sample scrips in the dtrace directory don't work the -following hints might help: +Once SIP has been disarmed, and once DTrace support is compiled into +NSF, one can run D scripts like so: +1) (Terminal window 1): sudo dtrace -q -F -s dtrace/timestamps.d -W tclsh +2) (Terminal window 2): tclsh dtrace/sample.tcl + +(Note: The "dtrace -c" option, as shown below, is not operative unless +SIP is fully disabled: Run "csrutil disable" only, omit the fourth +step.) + +DTrace requires normally that the dtrace command is run with root +permissions. In case the provided sample scrips in the dtrace +directory don't work out of the box, the following hints might help: + * Make sure that a "package require nx" works for root as well (install nx, or provide a TCLLIBPATH, etc.). You might want to add e.g. the following line Index: dtrace/nsf_calltime.d =================================================================== diff -u --- dtrace/nsf_calltime.d (revision 0) +++ dtrace/nsf_calltime.d (revision ee6699cdfbf3ad89cccfa9d52dd23767d13f9d73) @@ -0,0 +1,130 @@ +/* -*- D -*- + * + * nsf_calltime.d -- + * + * Measure time between method-entry and method-returns + * + * Activate tracing between + * ::nsf::configure dtrace on + * and + * ::nsf::configure dtrace off + * + * FIELDS: + * PROVIDER Object/class providing the method called. + * SCOPE Scope for which the method called is provided (per-class, per-object, direct) + * NAME Name of called method + * TOTAL Total count of calls or elapsed time for calls (us) + * + * Copyright (c) 2018 Stefan Sobernig + * + * Vienna University of Economics and Business + * Institute of Information Systems and New Media + * A-1020, Welthandelsplatz 1 + * Vienna, Austria + * + * This work is licensed under the MIT License http://www.opensource.org/licenses/MIT + * + * Copyright: + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Based on https://github.com/opendtrace/toolkit/blob/master/Tcl/tcl_calltime.d + * + * 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 + * + * 09-Sep-2007 Brendan Gregg Created this. + */ + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); + top = 20; +} + +nsf*:::configure-probe /!self->tracing && copyinstr(arg0) == "dtrace" / { + self->tracing = (arg1 && copyinstr(arg1) == "on") ? 1 : 0; +} + +nsf*:::configure-probe /self->tracing && copyinstr(arg0) == "dtrace" / { + self->tracing = (arg1 && copyinstr(arg1) == "off") ? 0 : 1; +} + +/* + * Measure time differences + */ +nsf*:::method-entry /self->tracing/ { + self->depth++; + self->exclude[self->depth] = 0; + self->proc[self->depth] = timestamp; +} + +nsf*:::method-return /self->tracing && self->proc[self->depth] / { + + this->elapsed_incl = timestamp - self->proc[self->depth]; + this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth]; + self->proc[self->depth] = 0; + self->exclude[self->depth] = 0; + this->name = copyinstr(arg2); + this->scope = (copyinstr(arg1) != "") ? ((copyinstr(arg0) == copyinstr(arg1)) ? "object" : "class") : "direct"; + + @num[copyinstr(arg1), this->scope, this->name] = count(); + @num["", "total", "-"] = count(); + @types_incl[copyinstr(arg0), this->scope, this->name] = sum(this->elapsed_incl); + @types_excl[copyinstr(arg0), this->scope, this->name] = sum(this->elapsed_excl); + @types_excl["", "total", "-"] = sum(this->elapsed_excl); + + self->depth--; + self->exclude[self->depth] += this->elapsed_incl; +} + +/* + * Print aggregate with own format (less wide than the default) + */ +END { + trunc(@num, top); + printf("\nTop %d counts,\n", top); + printf(" %48s %-10s %-48s %8s\n", "PROVIDER", "SCOPE", "NAME", "COUNT"); + printa(" %48s %-10s %-48s %@8d\n", @num); + + trunc(@types_excl, top); + normalize(@types_excl, 1000); + printf("\nTop %d exclusive elapsed times (us),\n", top); + printf(" %48s %-10s %-48s %8s\n", "PROVIDER", "SCOPE", "NAME", "TOTAL"); + printa(" %48s %-10s %-48s %@8d\n", @types_excl); + + trunc(@types_incl, top); + normalize(@types_incl, 1000); + printf("\nTop %d inclusive elapsed times (us),\n", top); + printf(" %48s %-10s %-48s %8s\n", "PROVIDER", "SCOPE", "NAME", "TOTAL"); + printa(" %48s %-10s %-48s %@8d\n", @types_incl); +} Index: generic/nsfDTrace.d =================================================================== diff -u -rcbcfec72376d549a806859c873195cc0ebc9c9ea -ree6699cdfbf3ad89cccfa9d52dd23767d13f9d73 --- generic/nsfDTrace.d (.../nsfDTrace.d) (revision cbcfec72376d549a806859c873195cc0ebc9c9ea) +++ generic/nsfDTrace.d (.../nsfDTrace.d) (revision ee6699cdfbf3ad89cccfa9d52dd23767d13f9d73) @@ -4,6 +4,7 @@ * Next Scripting Framework DTrace provider. * * Copyright (c) 2011-2014 Gustaf Neumann + * Copyright (c) 2018 Stefan Sobernig * * Vienna University of Economics and Business * Institute of Information Systems and New Media @@ -37,7 +38,7 @@ typedef struct Tcl_Obj Tcl_Obj; /* - * Next Scripting DTrace probes + * Next Scripting Framework (NSF) DTrace probes * * Modeled in alignment with the Tcl DTrace probes */ @@ -55,22 +56,14 @@ */ probe method__entry(char* object, char *class, char* method, int objc, Tcl_Obj **objv); /* - * nsf*:::proc-return probe + * nsf*:::method-return probe * triggered immediately after proc bytecode execution * arg0: object name (string) * arg1: class/object name (string) * arg2: method name (string) * arg3: return code (int) */ probe method__return(char *object, char *class, char* name, int code); - /* - * tcl*:::proc-result probe - * triggered after proc-return probe and result processing - * arg0: proc name (string) - * arg1: return code (int) - * arg2: proc result (string) - * arg3: proc result object (Tcl_Obj*) - */ /***************************** Object probes ******************************/ /* @@ -82,13 +75,13 @@ probe object__alloc(char *object, char *class); /* * nsf*:::object-free probe - * triggered whean an NSF object is freeed + * triggered whean an NSF object is freed * arg0: object (string) * arg1: class (string) */ probe object__free(char *object, char *class); - /***************************** nsf configure probe ******************************/ + /***************************** NSF configure probe ******************************/ /* * nsf*:::configure-probe probe * triggered when the ::nsf::configure is called Index: generic/nsfDTrace.h =================================================================== diff -u -rcbcfec72376d549a806859c873195cc0ebc9c9ea -ree6699cdfbf3ad89cccfa9d52dd23767d13f9d73 --- generic/nsfDTrace.h (.../nsfDTrace.h) (revision cbcfec72376d549a806859c873195cc0ebc9c9ea) +++ generic/nsfDTrace.h (.../nsfDTrace.h) (revision ee6699cdfbf3ad89cccfa9d52dd23767d13f9d73) @@ -1,37 +1,5 @@ /* - * nsfDTrace.h -- - * * Generated by dtrace(1M). - * - * Copyright (c) 2011-2014 Gustaf Neumann - * - * Vienna University of Economics and Business - * Institute of Information Systems and New Media - * A-1020, Welthandelsplatz 1 - * Vienna, Austria - * - * This work is licensed under the MIT License http://www.opensource.org/licenses/MIT - * - * Copyright: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * */ #ifndef _NSFDTRACE_H @@ -47,59 +15,97 @@ #define NSF_TYPEDEFS "___dtrace_typedefs$nsf$v2$54636c5f4f626a" +#if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED + #define NSF_CONFIGURE_PROBE(arg0, arg1) \ do { \ __asm__ volatile(".reference " NSF_TYPEDEFS); \ __dtrace_probe$nsf$configure__probe$v1$63686172202a$63686172202a(arg0, arg1); \ __asm__ volatile(".reference " NSF_STABILITY); \ } while (0) #define NSF_CONFIGURE_PROBE_ENABLED() \ - __dtrace_isenabled$nsf$configure__probe$v1() + ({ int _r = __dtrace_isenabled$nsf$configure__probe$v1(); \ + __asm__ volatile(""); \ + _r; }) #define NSF_METHOD_ENTRY(arg0, arg1, arg2, arg3, arg4) \ do { \ __asm__ volatile(".reference " NSF_TYPEDEFS); \ __dtrace_probe$nsf$method__entry$v1$63686172202a$63686172202a$63686172202a$696e74$54636c5f4f626a202a2a(arg0, arg1, arg2, arg3, arg4); \ __asm__ volatile(".reference " NSF_STABILITY); \ } while (0) #define NSF_METHOD_ENTRY_ENABLED() \ - __dtrace_isenabled$nsf$method__entry$v1() + ({ int _r = __dtrace_isenabled$nsf$method__entry$v1(); \ + __asm__ volatile(""); \ + _r; }) #define NSF_METHOD_RETURN(arg0, arg1, arg2, arg3) \ do { \ __asm__ volatile(".reference " NSF_TYPEDEFS); \ __dtrace_probe$nsf$method__return$v1$63686172202a$63686172202a$63686172202a$696e74(arg0, arg1, arg2, arg3); \ __asm__ volatile(".reference " NSF_STABILITY); \ } while (0) #define NSF_METHOD_RETURN_ENABLED() \ - __dtrace_isenabled$nsf$method__return$v1() + ({ int _r = __dtrace_isenabled$nsf$method__return$v1(); \ + __asm__ volatile(""); \ + _r; }) #define NSF_OBJECT_ALLOC(arg0, arg1) \ do { \ __asm__ volatile(".reference " NSF_TYPEDEFS); \ __dtrace_probe$nsf$object__alloc$v1$63686172202a$63686172202a(arg0, arg1); \ __asm__ volatile(".reference " NSF_STABILITY); \ } while (0) #define NSF_OBJECT_ALLOC_ENABLED() \ - __dtrace_isenabled$nsf$object__alloc$v1() + ({ int _r = __dtrace_isenabled$nsf$object__alloc$v1(); \ + __asm__ volatile(""); \ + _r; }) #define NSF_OBJECT_FREE(arg0, arg1) \ do { \ __asm__ volatile(".reference " NSF_TYPEDEFS); \ __dtrace_probe$nsf$object__free$v1$63686172202a$63686172202a(arg0, arg1); \ __asm__ volatile(".reference " NSF_STABILITY); \ } while (0) #define NSF_OBJECT_FREE_ENABLED() \ - __dtrace_isenabled$nsf$object__free$v1() + ({ int _r = __dtrace_isenabled$nsf$object__free$v1(); \ + __asm__ volatile(""); \ + _r; }) -extern void __dtrace_probe$nsf$configure__probe$v1$63686172202a$63686172202a(char *, char *); +extern void __dtrace_probe$nsf$configure__probe$v1$63686172202a$63686172202a(const char *, const char *); extern int __dtrace_isenabled$nsf$configure__probe$v1(void); -extern void __dtrace_probe$nsf$method__entry$v1$63686172202a$63686172202a$63686172202a$696e74$54636c5f4f626a202a2a(char *, char *, char *, int, Tcl_Obj **); +extern void __dtrace_probe$nsf$method__entry$v1$63686172202a$63686172202a$63686172202a$696e74$54636c5f4f626a202a2a(const char *, const char *, const char *, int, Tcl_Obj **); extern int __dtrace_isenabled$nsf$method__entry$v1(void); -extern void __dtrace_probe$nsf$method__return$v1$63686172202a$63686172202a$63686172202a$696e74(char *, char *, char *, int); +extern void __dtrace_probe$nsf$method__return$v1$63686172202a$63686172202a$63686172202a$696e74(const char *, const char *, const char *, int); extern int __dtrace_isenabled$nsf$method__return$v1(void); -extern void __dtrace_probe$nsf$object__alloc$v1$63686172202a$63686172202a(char *, char *); +extern void __dtrace_probe$nsf$object__alloc$v1$63686172202a$63686172202a(const char *, const char *); extern int __dtrace_isenabled$nsf$object__alloc$v1(void); -extern void __dtrace_probe$nsf$object__free$v1$63686172202a$63686172202a(char *, char *); +extern void __dtrace_probe$nsf$object__free$v1$63686172202a$63686172202a(const char *, const char *); extern int __dtrace_isenabled$nsf$object__free$v1(void); +#else + +#define NSF_CONFIGURE_PROBE(arg0, arg1) \ +do { \ + } while (0) +#define NSF_CONFIGURE_PROBE_ENABLED() (0) +#define NSF_METHOD_ENTRY(arg0, arg1, arg2, arg3, arg4) \ +do { \ + } while (0) +#define NSF_METHOD_ENTRY_ENABLED() (0) +#define NSF_METHOD_RETURN(arg0, arg1, arg2, arg3) \ +do { \ + } while (0) +#define NSF_METHOD_RETURN_ENABLED() (0) +#define NSF_OBJECT_ALLOC(arg0, arg1) \ +do { \ + } while (0) +#define NSF_OBJECT_ALLOC_ENABLED() (0) +#define NSF_OBJECT_FREE(arg0, arg1) \ +do { \ + } while (0) +#define NSF_OBJECT_FREE_ENABLED() (0) + +#endif /* !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED */ + + #ifdef __cplusplus } #endif