TCL interpreter initialization

http://naviserver.sourceforge.net/ns_logobig.gif

MainSource Code Downloads API Documentation Mailing Lists Bugs Developers


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: synthetize a Tcl script used to initialize new Tcl interpreters.

There are basically two strategies:

  1. 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).
  2. Register traces on selected Tcl commands and get state they create in a set of shared variables (the epoch). Then start bootstraping the interp. This will trigger trace callbacks and they will start filling the epoch. After the bootstrapping is done, synthetize 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::tracescriptcommand (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.

Summary of commands:

  nstrace::enabletrace   activates registered Tcl command traces
  nstrace::disabletrace  terminates tracing of Tcl commands
  nstrace::tracescript   returns a script for initializing interps

  nstrace::enablestate   activates generation of the state script
  nstrace::disablestate  terminates generation of the state script
  nstrace::statescript   returns a script for initializing interps

  nstrace::isactive      returns true if tracing Tcl commands is on
  nstrace::config        setup some configuration options

  nstrace::excludensp    skip serializing the given namespace
  nstrace::namespaces    returns list of namespaces for the given parent

  nstrace::addtrace      registers custom tracer callback
  nstrace::addscript     registers custom script generator
  nstrace::addresolver   registers custom command resolver

  nstrace::enablecode    returns signal about start of tracing
  nstrace::disablecode   returns signal about stop of tracing

  nstrace::addentry      adds one entry into the named trace store
  nstrace::getentry      returns the entry value from the named store
  nstrace::delentry      removes the entry from the named store
  nstrace::getentries    returns all entries from the named store

Limitations:

  1. namespace forget is still not implemented
  2. namespace origin cmd breaks if cmd is not already defined
  3. info procs does not return list of all cached procedures