View source code
Display the source code in std/experimental/allocator/building_blocks/stats_collector.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Struct std.experimental.allocator.building_blocks.stats_collector.StatsCollector

Allocator that collects extra data about allocations. Since each piece of information adds size and time overhead, statistics can be individually enabled or disabled through compile-time flags.

struct StatsCollector(Allocator, ulong flags = Options.all, ulong perCallFlags = 0) ;

All stats of the form numXxx record counts of events occurring, such as calls to functions and specific results. The stats of the form bytesXxx collect cumulative sizes.

In addition, the data callerSize, callerModule, callerFile, callerLine, and callerTime is associated with each specific allocation. This data prefixes each allocation.

Fields

NameTypeDescription
parent AllocatorThe parent allocator is publicly accessible either as a direct member if it holds state, or as an alias to Allocator.instance otherwise. One may use it for making calls that won't count toward statistics collection.

Properties

NameTypeDescription
bytesAllocated[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesContracted[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesExpanded[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesHighTide[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesMoved[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesNotMoved[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesSlack[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
bytesUsed[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numAlignedAllocate[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numAlignedAllocateOk[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numAllocate[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numAllocateOK[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numDeallocate[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numDeallocateAll[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numExpand[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numExpandOK[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numOwns[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numReallocate[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numReallocateInPlace[get] ulongRead-only properties enabled by the homonym flags chosen by the user.
numReallocateOK[get] ulongRead-only properties enabled by the homonym flags chosen by the user.

Methods

NameDescription
alignedAllocate (n, a) Forwards to parent.alignedAllocate. Affects per instance: numAlignedAllocate, bytesUsed, bytesAllocated, bytesSlack, numAlignedAllocateOk, and bytesHighTide. Affects per call: numAlignedAllocate, numAlignedAllocateOk, and bytesAllocated.
allocate (n) Forwards to parent.allocate. Affects per instance: numAllocate, bytesUsed, bytesAllocated, bytesSlack, numAllocateOK, and bytesHighTide. Affects per call: numAllocate, numAllocateOK, and bytesAllocated.
byFileLine () Defined if perCallFlags is nonzero. Iterates all monitored file/line instances. The order of iteration is not meaningful (items are inserted at the front of a list upon the first call), so preprocessing the statistics after collection might be appropriate.
deallocate (b) Defined whether or not Allocator.deallocate is defined. Affects per instance: numDeallocate, bytesUsed, and bytesSlack. Affects per call: numDeallocate and bytesContracted.
deallocateAll () Defined only if Allocator.deallocateAll is defined. Affects per instance and per call numDeallocateAll.
empty () Defined only if Options.bytesUsed is defined. Returns bytesUsed == 0.
expand (b, delta) Defined whether or not Allocator.expand is defined. Affects per instance: numExpand, numExpandOK, bytesExpanded, bytesSlack, bytesAllocated, and bytesUsed. Affects per call: numExpand, numExpandOK, bytesExpanded, and bytesAllocated.
owns (b) Increments numOwns (per instance and and per call) and forwards to parent.owns(b).
reallocate (b, s) Defined whether or not Allocator.reallocate is defined. Affects per instance: numReallocate, numReallocateOK, numReallocateInPlace, bytesNotMoved, bytesAllocated, bytesSlack, bytesExpanded, and bytesContracted. Affects per call: numReallocate, numReallocateOK, numReallocateInPlace, bytesNotMoved, bytesExpanded, bytesContracted, and bytesMoved.
reportPerCallStatistics (output) Defined if perCallFlags is nonzero. Outputs (e.g. to a File) a simple report of the collected per-call statistics.
reportStatistics (output) Reports per instance statistics to output (e.g. stdout). The format is simple: one kind and value per line, separated by a colon, e.g. bytesAllocated:7395404

Inner structs

NameDescription
PerCallStatistics Defined if perCallFlags is nonzero.

Aliases

NameDescription
alignment Alignment offered is equal to Allocator.alignment.

Example

import std.experimental.allocator.building_blocks.free_list : FreeList;
import std.experimental.allocator.gc_allocator : GCAllocator;
alias Allocator = StatsCollector!(GCAllocator, Options.all, Options.all);

Allocator alloc;
auto b = alloc.allocate(10);
alloc.reallocate(b, 20);
alloc.deallocate(b);

import std.file : deleteme, remove;
import std.range : walkLength;
import std.stdio : File;

auto f = deleteme ~ "-dlang.std.experimental.allocator.stats_collector.txt";
scope(exit) remove(f);
Allocator.reportPerCallStatistics(File(f, "w"));
alloc.reportStatistics(File(f, "a"));
writeln(File(f).byLine.walkLength); // 24

Authors

License