blt::watch(3tcl)
π blt::watch β the manual page, but make it make sense π
okay bestie, gather round, because this is blt::watch(3tcl) from the BLT Built-In Commands set and it's genuinely one of the most underrated little tools in Tcl land. lowkey iconic. let's get into it. π¦
β¨ NAME β¨
watch β call Tcl procedures before and after each command. yes, each command. she's watching everything, she's the main character. π
πΈ SYNOPSIS πΈ
watch create watchName ?options?
watch activate watchName
watch deactivate watchName
watch delete watchName
watch configure watchName ?options
watch info watchName
watch names
look at her. seven whole moods. π
π DESCRIPTION π
so basically, the watch command arranges for Tcl procedures to be invoked before and after the execution of each Tcl command. that's it. that's the whole vibe. she's the girl standing behind you going "okay and now what are you doing" for every single line. π«Ά
π§ INTRODUCTION π§
okay so here's the situation that made this whole thing necessary. when an error happens in Tcl, the global variable errorInfo will contain a stack-trace of the active procedures when the error occured. and like⦠usually that's fine. usually that's enough.
but sometimes it is not enough. π
sometimes you need to know exactly where in the program's execution the error occured, and a stack trace is just giving vague. in cases like this, a more general tracing facility would be useful β and that's her. that's the watch command.
the watch command lets you designate Tcl procedures to be invoked before and after the execution of each Tcl command. so you can display the command line and its results for each command as it executes. another use is to profile your Tcl commands β and ngl this is the part that ate: you can profile any Tcl command (like if and set), not just Tcl procedures. not just the fancy ones. all of them. periodt. π₯
β EXAMPLE β
the following example use watch to trace Tcl commands (printing to standard error) both before and after they are executed.
proc preCmd { level command argv } {
set name [lindex $argv 0]
puts stderr "$level $name => $command"
}
proc postCmd { level command argv retcode results } {
set name [lindex $argv 0]
puts stderr "$level $name => $argv0= ($retcode) $results"
}
watch create trace \
-postcmd postCmd -precmd preCmd
she's printing the tea to stderr before AND after. obsessed. π
π OPERATIONS π
the following operations are available for the watch command:
watch activate watchNameβ activates the watch, causing Tcl commands the be traced to the maximum depth selected. wake her up, she's going in. β¨watch create watchName ?options?...β creates a new watchwatchName. it's an error if another watchwatchNamealready exists and an error message will be returned. (no duplicates bestie, we don't do that here. π) options may have any of the values accepted by thewatch configurecommand. this command returns the empty string.watch configure watchName ?options...?β queries or modifies the configuration options of the watchwatchName.WatchNameis the name of a watch. options may have any of the following values:-active booleanβ specifies if the watch is active. by default, watches are active when created. (yes, she comes out the box ready. eager. π )-postcmd stringβ specifies a Tcl procedure to be called immediately after each Tcl command.Stringis name of a Tcl procedure and any extra arguments to be passed to it. beforestringis invoked, five more arguments are appended: 1) the current level 2) the current command line 3) a list containing the command after substitutions and split into words 4) the return code of the command, and 5) the results of the command. the return status of thepostcmdprocedure is always ignored. π«₯ (she does not care what you return. she's above it.)-precmd stringβ specifies a Tcl procedure to be called immediately before each Tcl command.Stringis name of a Tcl procedure and any extra arguments to be passed to it. beforestringis invoked, three arguments are appended: 1) the current level 2) the current command line, and 3) a list containing the command after substitutions and split into words. the return status of the-precmdprocedure is always ignored. π-maxlevel numberβ specifies the maximum evaluation depth to watch Tcl commands. the default maximum level is10000. that's a lot of levels. she will go that deep. π
watch deactivate watchNameβ deactivates the watch. the-precmdand-postcmdprocedures will no longer be invoked. she's taking a nap. do not disturb. π΄watch info watchNameβ returns the configuration information associated with the watchwatchName.WatchNameis the name of a watch.watch names ?state?β lists the names of the watches for a given state.Statemay be one of the following:active,idle, orignore. if astateargument isn't specified, all watches are listed. π
π KEYWORDS π
debug, profile
okay one tiny thing β the synopsis up top lists watch delete watchName too, so don't come for me, I listed every operation exactly as the page gave them. π
and that's the whole page, bestie!! this was blt::watch from BLT, version 2.5 β a certified classic, a real one, an icon, and honestly? we love her. go trace something. go profile something. go be nosy about your own code. πβ¨π¦
π¦ where this page comes from
- debian bookworm: blt-dev 2.5.3+dfsg-4.1
- debian trixie: blt-dev 2.5.3+dfsg-8
- ubuntu jammy: blt-dev 2.5.3+dfsg-4.1build2
- ubuntu noble: blt-dev 2.5.3+dfsg-7build1
- ubuntu questing: blt-dev 2.5.3+dfsg-8
- ubuntu resolute: blt-dev 2.5.3+dfsg-8build1
- ubuntu stonking: blt-dev 2.5.3+dfsg-9
- Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms