VarTra (from Variable Tracking) is a low-performance-impact mechanism to synchronousuly react to variable assignments in Squeak/Smalltalk. It uses an altered compilation process to inline notification code around all variable assignments. To ensure that the transformed code is minimally expensive, VarTra emits optimized bytecode for its instrumented assignments.
Supported variable types:
- Instance variables
- Temporary variables
- Literal variables (class, global, shared pools).
WARNING! This project overrides system methods to change the default compilation process.
A successful installation involves recompilation of all methods within your image.
Check Travis to see whether your version of Squeak is supported.
- Make sure to have Metacello installed.
- Then you can use the following code to load VarTra and all its prerequisites:
Metacello new baseline: 'VarTra'; repository: 'github://stlutz/VarTra/src'; load.
Only for Squeak 5.2 and newer
- Make sure to have Squot installed
Installer installGitInfrastructure.
- Clone this repository
- Make sure to have FileTree installed
- Clone this repository somewhere on your file system
- Add the
src/
folder of this repository as afiletree://
repository - Load the individual packages via Monticello in the following order:
- (If you use a Squeak older than 5.2:)
VarTra-Compat51-Compiling
VarTra-Compiling
VarTra-Core
VarTra-Tests
- (If you use a Squeak older than 5.2:)
"Activate variable tracking and recompile all methods with it."
VarTra install.
"Deactivate variable tracking and recompile all methods to remove it."
VarTra uninstall.
"Subscribe to changes of a variable"
VarTra subscribe: self toInstVarNamed: 'instVar' ofObject: VtMockInstVarPublisher new.
VarTra subscribe: self toLitVar: (self environment bindingOf: #VtMockGlobal).
VarTra subscribe: self toTempVarNamed: 'tempVar' ofContext: thisContext.
"Unsubscribe from variable changes"
VarTra unsubscribe: self fromInstVarNamed: 'instVar' ofObject: anObject.
VarTra unsubscribe: self fromLitVar: (self environment bindingOf: #VtMockGlobal).
VarTra unsubscribe: self fromTempVarNamed: 'tempVar' ofContext: thisContext.
"When a variable changes, its subscribers are notified via a message send.
To react, subclasses of Object need to override the respective methods."
Object >> #'instVarNamed:ofObject:changedFrom:to:inContext:'.
Object >> #'litVar:changedFrom:to:inContext:'.
Object >> #'tempVarNamed:changedFrom:to:inContext:'.
To be notified of variable assignments, VarTra emits modified bytecodes for variable assignments. It does so by parsing assignments as VtTrackedAssignmentNodes, a subclass of the normal AssignmentNode. The actual injection of instrumentation code then happens during bytecode generation.
More details can be found here.