counter(3tcl)
π counter β bestie's guide to counting things π
okay so you want to count stuff and make little bar charts about it?? say less. this is counter, a package from tcllib, and honestly it's giving statistics girlboss and i'm obsessed. β¨
πΈ NAME πΈ
counter β procedures for counters and histograms. that's it. that's the vibe. π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require counter ?2.0.6?
::counter::init tag args
::counter::count tag ?delta? ?instance?
::counter::start tag instance
::counter::stop tag instance
::counter::get tag args
::counter::exists tag
::counter::names
::counter::histHtmlDisplay tag args
::counter::reset tag args
π¦ DESCRIPTION π¦
okay so the counter package literally hands you a whole counter facility, and it can compute statistics and histograms over all the data you collected. it's the main character of data tallying fr fr. π
π ::counter::init tag args
this defines a counter with the name tag. the args decides what kind of counter this is gonna be, and here are all your options bestie:
-group nameβ keeps a grouped counter, where the name of the histogram bucket gets passed into::counter::count.-hist bucketsizeβ accumulates the counter into histogram buckets of size bucketsize. for example, if your samples are millisecond time values and bucketsize is10, then each histogram bucket represents time values of0to10msec,10to20msec,20to30msec, and so on. slay.-hist2x bucketsizeβ accumulates the statistic into histogram buckets. the size of the first bucket is bucketsize, and every other bucket holds values2times the size of the previous bucket. so if bucketsize is10, each histogram bucket represents time values of0to10msec,10to20msec,20to40msec,40to80msec, and so on. exponential era. π-hist10x bucketsizeβ same energy but bigger. the size of the first bucket is bucketsize, and each other bucket holds values10times the size of the previous bucket. so with bucketsize of10, each bucket represents time values of0to10msec,10to100msec,100to1000msec, and so on.-lastn Nβ saves the last N values of the counter so you can maintain a "running average" over the last N values. lowkey so useful. π«Ά-timehist secsPerMinuteβ keeps a time-based histogram. the counter gets summed into a histogram bucket based on the current time. there are60per-minute buckets with a size determined by secsPerMinute, which is normally60, but for testing purposes can be less. every "hour" (i.e.,60"minutes") the contents of the per-minute buckets are summed into the next hourly bucket. every24"hours" the contents of the per-hour buckets are summed into the next daily bucket. and here's the tea β: the counter package keeps all time-based histograms in sync, so the first secsPerMinute value seen by the package is used for all subsequent time-based histograms. no cap.
π§ ::counter::count tag ?delta? ?instance?
increments the counter identified by tag. the default increment is 1, but you can increment by any value β integer or real β by specifying delta. β¨
β οΈ bestie you must declare each counter with ::counter::init to define its characteristics before you start using it. no skipping steps.
if the counter type is -group, then the counter identified by instance is the one that gets incremented.
π ::counter::start tag instance
records the starting time of an interval. tag is the name of the counter defined as a -hist value-based histogram. instance distinguishes this interval from any other intervals that might be overlapping this one. so you can have multiple timers running and not get them confused, iconic.
π ::counter::stop tag instance
records the ending time of an interval. the delta time since the corresponding ::counter::start call for instance gets recorded in the histogram identified by tag. boom, timed. β±οΈ
π ::counter::get tag args
returns statistics about a counter identified by tag. the args decides which value you get back:
-totalβ returns the total value of the counter. this is the default if args isn't specified.-totalVarβ returns the name of the total variable. super handy for specifying with-textvariablein a Tk widget.-Nβ returns the number of samples accumulated into the counter.-avgβ returns the average of samples accumulated into the counter.-avgnβ returns the average over the last N samples taken. that N value is set in the::counter::initcall.-hist bucketβ if bucket is specified, returns the value in that bucket of the histogram. otherwise returns the complete histogram inarray getformat, sorted by bucket.-histVarβ returns the name of the histogram array variable.-histHourβ returns the complete hourly histogram inarray getformat, sorted by bucket.-histHourVarβ returns the name of the hourly histogram array variable.-histDayβ returns the complete daily histogram inarray getformat, sorted by bucket.-histDayVarβ returns the name of the daily histogram array variable.-resetDateβ returns the clock seconds value recorded when the counter was last reset.-allβ returns anarray getof the array used to store the counter. this includes the total, the number of samples (N), and any type-specific information. this does not include the histogram array. note it. π
π ::counter::exists tag
returns 1 if the counter is defined. yes/no, that's the whole thing. πββοΈ
π ::counter::names
returns a list of all counters defined. the full roster, the whole friend group.
π¦ ::counter::histHtmlDisplay tag args
generates HTML to display a histogram for a counter. the args controls the format of the display:
-title stringβ label to display above the bar chart.-unit unitβ specifyminutes,hours, ordaysfor the time-base histograms. for value-based histograms, the unit is used in the title.-images urlβ URL of/imagesdirectory.-gif filenameβ image for normal histogram bars. the filename is relative to the-imagesdirectory.-ongif filenameβ image for the active histogram bar. the filename is relative to the-imagesdirectory.-max Nβ maximum number of value-based buckets to display.-height Nβ pixel height of the highest bar.-width Nβ pixel width of each bar.-skip Nβ buckets to skip when labeling value-based histograms.-format stringβ format used to display labels of buckets.-text booleanβ if1, a text version of the histogram is dumped; otherwise a graphical one is generated.
π
::counter::reset tag args
resets the counter with the name tag to an initial state. the args determine the new characteristics of the counter, and they have the exact same meaning as described for ::counter::init. fresh start energy. π±
π BUGS, IDEAS, FEEDBACK π
okay real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. π not me being honest about it but that's what it says. please report such in the category counter of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either the package and/or the documentation. we love feedback bestie. π«Ά
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
β οΈ note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. got it? good. π
πΈ KEYWORDS πΈ
counting, histogram, statistics, tallying
π CATEGORY π
Data structures
and that's the whole page bestie!! this was written for tcllib, version 2.0.6, and the page is dated with that same 2.0.6 (yes it's the same number twice, it's giving matching outfits π ). the manual name is counter(3tcl) in case you forgot. now go count something and slay. πβ¨π¦
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms