Documentation ¶
Index ¶
Constants ¶
const ( Kibibyte int64 = 1024 KiB = Kibibyte Mebibyte = Kibibyte * 1024 MiB = Mebibyte Gibibyte = Mebibyte * 1024 GiB = Gibibyte Tebibyte = Gibibyte * 1024 TiB = Tebibyte Pebibyte = Tebibyte * 1024 PiB = Pebibyte Exbibyte = Pebibyte * 1024 EiB = Exbibyte )
nolint
const ( Kilobyte int64 = 1000 KB = Kilobyte Megabyte = Kilobyte * 1000 MB = Megabyte Gigabyte = Megabyte * 1000 GB = Gigabyte Terabyte = Gigabyte * 1000 TB = Terabyte Petabyte = Terabyte * 1000 PB = Petabyte Exabyte = Petabyte * 1000 EB = Exabyte )
nolint
const ( Kilo int64 = 1000 Mega = Kilo * 1000 Giga = Mega * 1000 Tera = Giga * 1000 Peta = Tera * 1000 Exa = Peta * 1000 Infinity = -1 )
nolint
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
Context defines gotcha context type which is union between `context.Context` and `Tracker` that additionally could be stringified.
func NewContext ¶
func NewContext(parent context.Context, opts ...ContextOpt) Context
NewContext creates new gotcha context instance from provided parent context and list of context limit options. By default next limits are used: - bytes: 64 * MiB - objects: Infinity - calls: Infinity Note that if parent context is gotcha context then Add, Remains and Exceeded will also target parent context as well which is useful if nested tracking is required.
type ContextLimitsExceeded ¶
type ContextLimitsExceeded struct {
Context Context
}
ContextLimitsExceeded defines error type for context limit exceeded.
func (ContextLimitsExceeded) Error ¶
func (err ContextLimitsExceeded) Error() string
type ContextOpt ¶
type ContextOpt func(*gotchactx)
ContextOpt defines gotcha context limit options that could be applied to gotchactx.
func ContextWithLimitBytes ¶
func ContextWithLimitBytes(lbytes int64) ContextOpt
ContextWithLimitBytes defines allocation limit bytes gotcha context option.
func ContextWithLimitCalls ¶
func ContextWithLimitCalls(lcalls int64) ContextOpt
ContextWithLimitCalls defines allocation limit calls gotcha context option.
func ContextWithLimitObjects ¶
func ContextWithLimitObjects(lobjects int64) ContextOpt
ContextWithLimitObjects defines allocation limit objects gotcha context option.
type Tracer ¶
type Tracer func(Context)
Tracer defines function type that will be traced by gotcha it accepts gotcha context that will be seamlessly tracking all allocations inside tracer function.
type Tracker ¶
type Tracker interface { Add(bytes, objects, calls int64) Used() (bytes, objects, calls int64) Limits() (lbytes, lobjects, lcalls int64) Remains() (rbytes, robjects, rcalls int64) Exceeded() bool Reset() }
Tracker defines memory limit tracker type that is capble to track bytes, objects and calls allocations update, reset and compare them against provided limits.