tcl-lib-nstrace - Managing Tcl interpreter initialization
This file implements set of commands and utilities to manage Tcl interpreter initialization for NaviServer. What all this stuff does is simple: synthesize a Tcl script used to initialize new Tcl interpreters.
There are basically two strategies:
A Run an introspective script against an initialized startup interpreter and collect definitions of some "known" things: loaded packages, created Tcl procs, namespaces and namespaced variables. Then stuff all this data in a (potentially large) script and run this script against virgin Tcl interp. This script is obtained by the [nstrace::statescript] command (see below).
B Register traces on selected Tcl commands and get state they create in a set of shared variables (the epoch). Then start bootstrapping the interp. This will trigger trace callbacks and they will start filling the epoch. After the bootstrapping is done, synthesize a script containing minimal fixed state (variables, modules) and a definition of [unknown] command which will on-demand load procedure definitions out of the epoch state. This script is obtained by the [nstrace::tracescript] command (see below).
Which one of the above 2 strategies is currently used by the server, is controlled by the lazyloader parameter of the Tcl library, as defined in the server configuration file. The A Strategy is selected by setting the parameter to false. The B Strategy is selected by setting the parameter to true.
In order to influence script generation, users can add their own tracing implementations. Tracers and other supporting callbacks for the following Tcl commands are provided per default:
load, namespace, variable, proc, rename
For the information of how to add new tracers please look into the source code of already provided callbacks.
[namespace forget] is still not implemented
[namespace origin cmd] breaks if cmd is not already defined
[info procs] does not return list of all cached procedures