The script I used is below. It's a crappy TCL reader we wrote for a
specific purpose and doesn't work quite right - doesn't handle strings
correctly, probably other stuff.
We don't use nsv_ routines - still on 2.3.3. Personally, I don't like
the nsv_ interface. With ns_share, a variable is a variable except
for its scope; with nsv_ vars, the access semantics are different and
you need to always know if you are dealing with an nsv_ when writing
code. So it's impossible to write generalized routines. Not cool,
IMO. In reading the TCL bible, it seems like linked vars (link TCL
vars to C vars) would have been an interesting avenue to investigate
for implementing ns_share in standard TCL. If we did use nsv_
routines, they would dwarf anything on here by an order of magnitude,
both in static and dynamic references, i.e., we do *a lot* of shared
variable stuff.
I did a quick check of the ns_info references: most are to hostname or
pageroot, pageroot being the more common. When we need to do an
"internal redirect", we source a TCL file and [ns_info pageroot] is
referenced. Lots of our TCL scripts set some variables and then
source another script. Not great, but that's what got established 4
years ago for whatever reason. This is a case where there are lots of
static references, but the frequency of reference at runtime is not
that high.
Jim
Here's the script I used to count references, like:
tcl scantcl.tcl `find modules/tcl pages -name "*.tcl"`>nscounts
sort -n +1 -2<nscounts>nscounts.freq
proc gettclline {fd _tclline _linenr} {
upvar $_tclline tclline
upvar $_linenr linenr
set tclline ""
set tcllinelen 0
while {1} {
incr linenr
if {[gets $fd line] == -1} {
return -1
}
set tclline "[string range $tclline 0 [expr $tcllinelen-2]]$line"
set tcllinelen [string length $tclline]
if {[string index $tclline [expr $tcllinelen-1]] != "\\"} {
return $tclline
}
}
}
foreach f $argv {
set fd [open $f]
set linenr 0
while {[gettclline $fd line linenr] != -1} {
while {[regexp -nocase {(^|[^a-z])(ns_[-a-z0-9_]+)(.*)} $line match dummy command
line]} {
iincr comcount($command)
}
}
close $fd
}
foreach ix [lsort [array names comcount]] {
puts "$ix $comcount($ix)"
}
>
> Jim,
>
> This is absolutely awesome. Yes, static analysis is just fine for
> what I'm trying to answer, and I'm thinking perhaps having some
> profiling in nsd (which can be turned on and off) could be really
> useful for the dynamic analysis.
>
> I'm presuming you didn't count these all by hand, that you did
> it via some script. Would you mind sharing that with the list so
> others can report the same information?
>
> Otherwise, I guess I could write one, but I'd prefer to avoid
> re-inventing the wheel if I know it exists. ;-)
>
> Interestingly, these are your top 10:
>
> ns_set 3550
> ns_share 843
> ns_log 542
> ns_time 519
> ns_dbquotevalue 513
> ns_info 504
> ns_return 450
> ns_urlencode 444
> ns_conn 353
> ns_fmttime 219
> ns_striphtml 115
>
> I'm not surprised to see ns_set be on top, and since you didn't
> include any nsv_* counts, I don't know if ns_share really should
> be #2 or would nsv_set and nsv_get be up there ... I didn't
> expect to see ns_log but now that I do, it makes perfect sense.
>
> I'm really surprised to see ns_info up there, though. What
> are you using it for, if I might ask?
>
>
> - Dossy