Index: generic/nsf.c =================================================================== diff -u -r9612df653b52256b9e8980af511d6e45ffea5582 -r81788340d06828bb7131be38cc31858cf842612e --- generic/nsf.c (.../nsf.c) (revision 9612df653b52256b9e8980af511d6e45ffea5582) +++ generic/nsf.c (.../nsf.c) (revision 81788340d06828bb7131be38cc31858cf842612e) @@ -6441,7 +6441,7 @@ * sure that a potential parent object has already required a * namespace. If there is no parent namespace yet, try to create a * parent object via __unknown. - + * * If the provided parentNsPtr is not NULL, we know, that (a) the * provided name was relative and simple (contains no ":" * characters) and that (b) this namespace was used to build a fully @@ -25272,6 +25272,65 @@ #endif /* + * Valgrind/callgrind support + */ +#if defined(NSF_VALGRIND) + +#include +/* +cmd __callgrind_dump_stats NsfCallgrindDumpStatsCmd { + {-argName "-name" -required 0 -nrargs 1} +} +cmd __callgrind_start_instrumentation NsfCallgrindStartInstrumentationCmd {} +cmd __callgrind_stop_instrumentation NsfCallgrindStopInstrumentationCmd {} +cmd __callgrind_toggle_collect NsfCallgrindToggleCollectCmd {} +cmd __callgrind_zero_stats NsfCallgrindZeroStatsCmd {} +*/ + +static int +NsfCallgrindDumpStatsCmd(Tcl_Interp *UNUSED(interp), const char *nameString) { + if (nameString == NULL) { + CALLGRIND_DUMP_STATS; + } else { + CALLGRIND_DUMP_STATS_AT(nameString); + } + return TCL_OK; +} + +static int +NsfCallgrindStartInstrumentationCmd(Tcl_Interp *UNUSED(interp)) { + CALLGRIND_START_INSTRUMENTATION; + return TCL_OK; +} + +static int +NsfCallgrindStopInstrumentationCmd(Tcl_Interp *UNUSED(interp)) { + CALLGRIND_STOP_INSTRUMENTATION; + return TCL_OK; +} + +static int +NsfCallgrindToggleCollectCmd(Tcl_Interp *UNUSED(interp)) { + CALLGRIND_TOGGLE_COLLECT; + return TCL_OK; +} + +static int +NsfCallgrindZeroStatsCmd(Tcl_Interp *UNUSED(interp)) { + CALLGRIND_ZERO_STATS; + return TCL_OK; +} +#else + +static int NsfCallgrindDumpStatsCmd(Tcl_Interp *UNUSED(interp), const char *UNUSED(nameString)) { return TCL_OK; } +static int NsfCallgrindStartInstrumentationCmd(Tcl_Interp *UNUSED(interp)) {return TCL_OK;} +static int NsfCallgrindStopInstrumentationCmd(Tcl_Interp *UNUSED(interp)) {return TCL_OK;} +static int NsfCallgrindToggleCollectCmd(Tcl_Interp *UNUSED(interp)) {return TCL_OK;} +static int NsfCallgrindZeroStatsCmd(Tcl_Interp *UNUSED(interp)) {return TCL_OK;} + +#endif + +/* *---------------------------------------------------------------------- * NsfUnsetUnknownArgsCmd -- * Index: generic/nsf.h =================================================================== diff -u -r3f78bdd8db9ec3b80bd2a280a5f148ad81d7c9f5 -r81788340d06828bb7131be38cc31858cf842612e --- generic/nsf.h (.../nsf.h) (revision 3f78bdd8db9ec3b80bd2a280a5f148ad81d7c9f5) +++ generic/nsf.h (.../nsf.h) (revision 81788340d06828bb7131be38cc31858cf842612e) @@ -108,6 +108,10 @@ * #define NSF_MEM_TRACE 1 #define NSF_MEM_COUNT 1 + * + * Activate/deactivate valgrind support + * +#define NSF_VALGRIND 1 */ /* Activate bytecode support Index: generic/nsfAPI.decls =================================================================== diff -u -r4b207001b05300e9c4bbe28da106abadfb7ca1fc -r81788340d06828bb7131be38cc31858cf842612e --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision 4b207001b05300e9c4bbe28da106abadfb7ca1fc) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision 81788340d06828bb7131be38cc31858cf842612e) @@ -6,7 +6,7 @@ # Scripting Framework (NSF) library. This script is sourced by # the C-code generator gentclAPI.tcl in the same directory. # -# Copyright (C) 2009-2016 Gustaf Neumann +# Copyright (C) 2009-2017 Gustaf Neumann # # Vienna University of Economics and Business # Institute of Information Systems and New Media @@ -66,6 +66,18 @@ {-argName "-builtins" -required 0 -nrargs 1 -type tclobj} } +# +# valgrind/callgrind support +# +cmd __callgrind_dump_stats NsfCallgrindDumpStatsCmd { + {-argName "-name" -required 0 -nrargs 1} +} +cmd __callgrind_start_instrumentation NsfCallgrindStartInstrumentationCmd {} +cmd __callgrind_stop_instrumentation NsfCallgrindStopInstrumentationCmd {} +cmd __callgrind_toggle_collect NsfCallgrindToggleCollectCmd {} +cmd __callgrind_zero_stats NsfCallgrindZeroStatsCmd {} + + cmd __unset_unknown_args NsfUnsetUnknownArgsCmd {} cmd "asm::proc" NsfAsmProcCmd { Index: generic/nsfAPI.h =================================================================== diff -u -r96479aa72df034766d8d1866a23bc261b1402a30 -r81788340d06828bb7131be38cc31858cf842612e --- generic/nsfAPI.h (.../nsfAPI.h) (revision 96479aa72df034766d8d1866a23bc261b1402a30) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision 81788340d06828bb7131be38cc31858cf842612e) @@ -281,7 +281,7 @@ /* just to define the symbol */ -static Nsf_methodDefinition method_definitions[114]; +static Nsf_methodDefinition method_definitions[119]; static const char *method_command_namespace_names[] = { "::nsf::methods::object::info", @@ -337,6 +337,16 @@ NSF_nonnull(2) NSF_nonnull(4); static int NsfAsmProcCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) NSF_nonnull(2) NSF_nonnull(4); +static int NsfCallgrindDumpStatsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); +static int NsfCallgrindStartInstrumentationCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); +static int NsfCallgrindStopInstrumentationCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); +static int NsfCallgrindToggleCollectCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); +static int NsfCallgrindZeroStatsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); static int NsfCmdInfoCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) NSF_nonnull(2) NSF_nonnull(4); static int NsfColonCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) @@ -564,6 +574,16 @@ NSF_nonnull(1) NSF_nonnull(2) NSF_nonnull(7) NSF_nonnull(8) NSF_nonnull(9); static int NsfAsmProcCmd(Tcl_Interp *interp, int withAd, int withCheckalways, Tcl_Obj *procName, Tcl_Obj *arguments, Tcl_Obj *body) NSF_nonnull(1) NSF_nonnull(4) NSF_nonnull(5) NSF_nonnull(6); +static int NsfCallgrindDumpStatsCmd(Tcl_Interp *interp, const char *withName) + NSF_nonnull(1); +static int NsfCallgrindStartInstrumentationCmd(Tcl_Interp *interp) + NSF_nonnull(1); +static int NsfCallgrindStopInstrumentationCmd(Tcl_Interp *interp) + NSF_nonnull(1); +static int NsfCallgrindToggleCollectCmd(Tcl_Interp *interp) + NSF_nonnull(1); +static int NsfCallgrindZeroStatsCmd(Tcl_Interp *interp) + NSF_nonnull(1); static int NsfCmdInfoCmd(Tcl_Interp *interp, InfomethodsubcmdIdx_t subcmd, NsfObject *withContext, Tcl_Obj *methodName, const char *pattern) NSF_nonnull(1) NSF_nonnull(4); static int NsfColonCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) @@ -768,6 +788,11 @@ NsfClassInfoSuperclassMethodIdx, NsfAsmMethodCreateCmdIdx, NsfAsmProcCmdIdx, + NsfCallgrindDumpStatsCmdIdx, + NsfCallgrindStartInstrumentationCmdIdx, + NsfCallgrindStopInstrumentationCmdIdx, + NsfCallgrindToggleCollectCmdIdx, + NsfCallgrindZeroStatsCmdIdx, NsfCmdInfoCmdIdx, NsfColonCmdIdx, NsfConfigureCmdIdx, @@ -1544,6 +1569,90 @@ } static int +NsfCallgrindDumpStatsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + ParseContext pc; + (void)clientData; + + if (likely(ArgumentParse(interp, objc, objv, NULL, objv[0], + method_definitions[NsfCallgrindDumpStatsCmdIdx].paramDefs, + method_definitions[NsfCallgrindDumpStatsCmdIdx].nrParameters, 0, NSF_ARGPARSE_BUILTIN, + &pc) == TCL_OK)) { + const char *withName = (const char *)pc.clientData[0]; + + assert(pc.status == 0); + return NsfCallgrindDumpStatsCmd(interp, withName); + + } else { + + return TCL_ERROR; + } +} + +static int +NsfCallgrindStartInstrumentationCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + (void)clientData; + + + + if (unlikely(objc != 1)) { + return NsfArgumentError(interp, "too many arguments:", + method_definitions[NsfCallgrindStartInstrumentationCmdIdx].paramDefs, + NULL, objv[0]); + } + + return NsfCallgrindStartInstrumentationCmd(interp); + +} + +static int +NsfCallgrindStopInstrumentationCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + (void)clientData; + + + + if (unlikely(objc != 1)) { + return NsfArgumentError(interp, "too many arguments:", + method_definitions[NsfCallgrindStopInstrumentationCmdIdx].paramDefs, + NULL, objv[0]); + } + + return NsfCallgrindStopInstrumentationCmd(interp); + +} + +static int +NsfCallgrindToggleCollectCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + (void)clientData; + + + + if (unlikely(objc != 1)) { + return NsfArgumentError(interp, "too many arguments:", + method_definitions[NsfCallgrindToggleCollectCmdIdx].paramDefs, + NULL, objv[0]); + } + + return NsfCallgrindToggleCollectCmd(interp); + +} + +static int +NsfCallgrindZeroStatsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + (void)clientData; + + + + if (unlikely(objc != 1)) { + return NsfArgumentError(interp, "too many arguments:", + method_definitions[NsfCallgrindZeroStatsCmdIdx].paramDefs, + NULL, objv[0]); + } + + return NsfCallgrindZeroStatsCmd(interp); + +} + +static int NsfCmdInfoCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { ParseContext pc; (void)clientData; @@ -3479,7 +3588,7 @@ } } -static Nsf_methodDefinition method_definitions[114] = { +static Nsf_methodDefinition method_definitions[119] = { {"::nsf::methods::class::alloc", NsfCAllocMethodStub, 1, { {"objectName", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, @@ -3588,6 +3697,21 @@ {"arguments", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"body", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, +{"::nsf::__callgrind_dump_stats", NsfCallgrindDumpStatsCmdStub, 1, { + {"-name", 0, 1, Nsf_ConvertTo_String, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, +{"::nsf::__callgrind_start_instrumentation", NsfCallgrindStartInstrumentationCmdStub, 0, { + {NULL, 0, 0, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, +{"::nsf::__callgrind_stop_instrumentation", NsfCallgrindStopInstrumentationCmdStub, 0, { + {NULL, 0, 0, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, +{"::nsf::__callgrind_toggle_collect", NsfCallgrindToggleCollectCmdStub, 0, { + {NULL, 0, 0, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, +{"::nsf::__callgrind_zero_stats", NsfCallgrindZeroStatsCmdStub, 0, { + {NULL, 0, 0, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, {"::nsf::cmd::info", NsfCmdInfoCmdStub, 4, { {"subcmd", NSF_ARG_REQUIRED|NSF_ARG_IS_ENUMERATION, 1, ConvertToInfomethodsubcmd, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"-context", 0, 1, Nsf_ConvertTo_Object, NULL,NULL,"object",NULL,NULL,NULL,NULL,NULL}, Index: generic/nsfInt.h =================================================================== diff -u -r9612df653b52256b9e8980af511d6e45ffea5582 -r81788340d06828bb7131be38cc31858cf842612e --- generic/nsfInt.h (.../nsfInt.h) (revision 9612df653b52256b9e8980af511d6e45ffea5582) +++ generic/nsfInt.h (.../nsfInt.h) (revision 81788340d06828bb7131be38cc31858cf842612e) @@ -1060,7 +1060,6 @@ nonnull(1); #endif - /* * MEM Counting */