counter(n)
β¨ NAME β¨
counter β Procedures for counters and histograms. Also known as counter(n), the Counters and Histograms page. No cap, this is the whole 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 π
The counter package provides a counter facility and can compute statistics and histograms over the collected data. Periodt. β¨
::counter::init tag args
This defines a counter with the name tag. The args determines the characteristics of the counter. The args are:
-group nameβ Keep a grouped counter where the name of the histogram bucket is passed into::counter::count. It's giving group chat energy. π«Ά-hist bucketsizeβ Accumulate the counter into histogram buckets of sizebucketsize. For example, if the samples are millisecond time values andbucketsizeis10, then each histogram bucket represents time values of0to10msec,10to20msec,20to30msec, and so on. Lowkey obsessed with this bucketing. π-hist2x bucketsizeβ Accumulate the statistic into histogram buckets. The size of the first bucket isbucketsize, each other bucket holds values2times the size of the previous bucket. For example, ifbucketsizeis10, then each histogram bucket represents time values of0to10msec,10to20msec,20to40msec,40to80msec, and so on. The way it doubles? Iconic. π₯-hist10x bucketsizeβ Accumulate the statistic into histogram buckets. The size of the first bucket isbucketsize, each other bucket holds values10times the size of the previous bucket. For example, ifbucketsizeis10, then each histogram bucket represents time values of0to10msec,10to100msec,100to1000msec, and so on. Ten times? Slay. π-lastn Nβ Save the lastNvalues of the counter to maintain a "running average" over the lastNvalues. Bestie, this is your running average era. π-timehist secsPerMinuteβ Keep a time-based histogram. The counter is summed into a histogram bucket based on the current time. There are60per-minute buckets that have a size determined bysecsPerMinute, 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. Thecounterpackage keeps all time-based histograms in sync, so the firstsecsPerMinutevalue seen by the package is used for all subsequent time-based histograms. The way it syncs? Main character energy. β°
::counter::count tag ?delta? ?instance?
Increment the counter identified by tag. The default increment is 1, although you can increment by any value, integer or real, by specifying delta. You must declare each counter with ::counter::init to define the characteristics of counter before you start to use it. If the counter type is -group, then the counter identified by instance is incremented. Not me forgetting to ::counter::init first, couldn't be me. π
::counter::start tag instance
Record the starting time of an interval. The tag is the name of the counter defined as a -hist value-based histogram. The instance is used to distinguish this interval from any other intervals that might be overlapping this one. It's giving overlapping intervals? We love a distinguished instance. π¦
::counter::stop tag instance
Record the ending time of an interval. The delta time since the corresponding ::counter::start call for instance is recorded in the histogram identified by tag. And that's on periodt. β±οΈ
::counter::get tag args
Return statistics about a counter identified by tag. The args determine what value to return:
-totalβ Return the total value of the counter. This is the default ifargsis not specified. The default? We love a default. π-totalVarβ Return the name of the total variable. Useful for specifying with-textvariablein a Tk widget. Tk widget besties, this one's for you. π-Nβ Return the number of samples accumulated into the counter. CapitalNenergy. π’-avgβ Return the average of samples accumulated into the counter. The average? Mid? No, average is valid. π-avgnβ Return the average over the lastNsamples taken. TheNvalue is set in the::counter::initcall. LastN? Lowkey specific. π-hist bucketβ Ifbucketis specified, then the value in that bucket of the histogram is returned. Otherwise the complete histogram is returned inarray getformat sorted by bucket. Array get format? Iykyk. π§-histVarβ Return the name of the histogram array variable. Var? We stan a variable name. π-histHourβ Return the complete hourly histogram inarray getformat sorted by bucket. Hourly? The tea is piping hot. β-histHourVarβ Return the name of the hourly histogram array variable. Hourly var? Okay. π-histDayβ Return the complete daily histogram inarray getformat sorted by bucket. Daily? The drama continues. π-histDayVarβ Return the name of the daily histogram array variable. Daily var? Slay. β-resetDateβ Return the clock seconds value recorded when the counter was last reset. Clock seconds? Time is a construct. β³-allβ Return 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. All but not the histogram? Noted. π
::counter::exists tag
Returns 1 if the counter is defined. Existence is a vibe. β¨
::counter::names
Returns a list of all counters defined. A whole list? We love a list. π
::counter::histHtmlDisplay tag args
Generate HTML to display a histogram for a counter. The args control the format of the display. They are:
-title stringβ Label to display above bar chart. Title? Main character energy. π-unit unitβ Specifyminutes,hours, ordaysfor the time-base histograms. For value-based histograms, theunitis used in the title. Unit? We love a unit. π-images urlβ URL of/imagesdirectory. URL? Bestie, link it. π-gif filenameβ Image for normal histogram bars. Thefilenameis relative to the-imagesdirectory. GIF? We love a GIF. ποΈ-ongif filenameβ Image for the active histogram bar. Thefilenameis relative to the-imagesdirectory. Ongif? Active bar? Hot. π₯-max Nβ Maximum number of value-based buckets to display. Max? Cap it. π§’-height Nβ Pixel height of the highest bar. Height? Pixels? Okay. π-width Nβ Pixel width of each bar. Width? Also pixels. π-skip Nβ Buckets to skip when labeling value-based histograms. Skip? We love a skip. βοΈ-format stringβ Format used to display labels of buckets. Format? String? Iconic. π-text booleanβ If1, a text version of the histogram is dumped, otherwise a graphical one is generated. Boolean?1? Say less. 1οΈβ£
::counter::reset tag args
Resets the counter with the name tag to an initial state. The args determine the new characteristics of the counter. They have the same meaning as described for ::counter::init. Reset? We love a fresh start. π
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category counter of the Tcllib Trackers (http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation.
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.
bestie, don't be shy, report those bugs. The Tcllib Trackers are waiting. π
π KEYWORDS π
counting, histogram, statistics, tallying
ποΈ CATEGORY ποΈ
Data structures
this page is from tcllib, version 2.0.6, and it's the counter(n) manual. bye bestie πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms