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 a local clone.
Allocator that collects useful statistics about allocations, both global and per calling point. The statistics collected can be configured statically by choosing combinations of Options appropriately.
import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.building_blocks.free_list : FreeList; alias Allocator = StatsCollector!(GCAllocator, Options.bytesUsed);
- Options for StatsCollector defined below. Each enables during compilation one specific counter, statistic, or other piece of information.
- Counts the number of calls to owns.
- Counts the number of calls to allocate. All calls are counted, including requests for zero bytes or failed requests.
- Counts the number of calls to allocate that succeeded, i.e. they returned a block as large as requested. (N.B. requests for zero bytes count as successful.)
- Counts the number of calls to expand, regardless of arguments or result.
- Counts the number of calls to expand that resulted in a successful expansion.
- Counts the number of calls to reallocate, regardless of arguments or result.
- Counts the number of calls to reallocate that succeeded. (Reallocations to zero bytes count as successful.)
- Counts the number of calls to reallocate that resulted in an in-place reallocation (no memory moved). If this number is close to the total number of reallocations, that indicates the allocator finds room at the current block's end in a large fraction of the cases, but also that internal fragmentation may be high (the size of the unit of allocation is large compared to the typical allocation size of the application).
- Counts the number of calls to deallocate.
- Counts the number of calls to deallocateAll.
- Chooses all numXxx flags.
- Tracks bytes currently allocated by this allocator. This number goes up and down as memory is allocated and deallocated, and is zero if the allocator currently has no active allocation.
- Tracks the sum of all delta values in calls of the form expand(b, delta) that succeed (return true).
- Tracks the sum of all b.length - s with b.length > s in calls of the form realloc(b, s) that succeed (return true). In per-call statistics, also unambiguously counts the bytes deallocated with deallocate.
- Tracks the sum of all bytes moved as a result of calls to realloc that were unable to reallocate in place. A large number (relative to bytesAllocated) indicates that the application should use larger preallocations.
- Tracks the sum of all bytes NOT moved as result of calls to realloc that managed to reallocate in place. A large number (relative to bytesAllocated) indicates that the application is expansion-intensive and is saving a good amount of moves. However, if this number is relatively small and bytesSlack is high, it means the application is overallocating for little benefit.
- Measures the sum of extra bytes allocated beyond the bytes requested, i.e. the internal fragmentation. This is the current effective number of slack bytes, and it goes up and down with time.
- Measures the maximum bytes allocated over the time. This is useful for dimensioning allocators.
- Chooses all byteXxx flags.
- 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.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.Examples:
import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.building_blocks.free_list : FreeList; 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.stdio : File; import std.range : walkLength; auto f = deleteme ~ "-dlang.std.experimental.allocator.stats_collector.txt"; scope(exit) remove(f); Allocator.reportPerCallStatistics(File(f, "w")); alloc.reportStatistics(File(f, "a")); assert(File(f).byLine.walkLength == 22);
- 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.
- Defined only if Options.bytesUsed is defined. Returns bytesUsed == 0.
- 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
- Defined if perCallFlags is nonzero.
- The options corresponding to the statistics collected.
- Format to a string such as: mymodule.d(655): [numAllocate:21, numAllocateOK:21, bytesAllocated:324202].
- 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.
- Defined if perCallFlags is nonzero. Outputs (e.g. to a File) a simple report of the collected per-call statistics.
Copyright © 1999-2017 by Digital Mars ®, All Rights Reserved | Page generated by Ddoc on (no date time)