beetlebug▾
/

ztcl::meter create

Makes a meter, or sets the options of a meter, and gives its name.

ztcl::meter create NAME ?-budget UNITS? ?-tenant TEXT?

Description

Makes the meter NAME with each count at zero, or sets the options of the meter NAME when it exists. It gives NAME.

Arguments

ArgumentTypeDefaultDescription
NAMEstringrequiredThe name of the meter.

Options

OptionTypeDefaultDescription
-budgetinteger or emptyan empty string, no capCaps the compute units of all the work of the meter.
-tenantstringan empty stringGives the tenant of the records of the meter.

-budget UNITS

Caps the compute units of all the work of the meter.

The most compute units of the scripts, threads, and children of the meter, 0 or more. An empty UNITS removes the cap.

A thread that starts with a meter that has a budget gets at most the units that are left, and the meter holds them until the thread ends, so two threads that run at the same time cannot spend more than the budget. At the end of its units a thread gets the compute-limit error, which no script can catch, and ends. A script of run gets the error compute limit reached, and the caller of run can catch it.

% ztcl::meter create b -budget 1000
> ztcl::meter run b {set x 1}
> set m [ztcl::meter get b]
> list [dict get $m budget] [dict get $m left]
1000 999

% ztcl::meter create a -budget 50
> ztcl::meter create a -budget {}
> dict get [ztcl::meter get a] budget
% ztcl::meter create d -budget x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

% ztcl::meter create d -budget -5
bad budget "-5": must be 0 or more
-errorcode NONE

% ztcl::meter create d -budget
wrong # args: should be "ztcl::meter create name ?-budget units? ?-tenant text?"
-errorcode TCL WRONGARGS

-tenant TEXT

Gives the tenant of the records of the meter.

The text of the field tenant of each record of the meter.

% ztcl::meter create c -tenant t1
> ztcl::json get [ztcl::meter record c] tenant
t1

Each text is a valid tenant.

Returns

NAME.

Examples

Each example of this page runs after package require ztcl::json.

% ztcl::meter create demo
demo

% interp create c -meter m9
> lsearch -inline [ztcl::meter list] m9
m9

Errors

% ztcl::meter create
wrong # args: should be "ztcl::meter create name ?-budget units? ?-tenant text?"
-errorcode TCL WRONGARGS

% ztcl::meter create d -bogus 1
bad option "-bogus": must be -budget or -tenant
-errorcode TCL LOOKUP INDEX option

% ztcl::meter create d -t x
bad option "-t": must be -budget or -tenant
-errorcode TCL LOOKUP INDEX option

Facts

Capability
meter. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also