Add per thread allocation counters, and enhance heap sampling.

Add the "thread.allocated" and "thread.deallocated" mallctls, which can
be used to query the total number of bytes ever allocated/deallocated by
the calling thread.

Add s2u() and sa2u(), which can be used to compute the usable size that
will result from an allocation request of a particular size/alignment.

Re-factor ipalloc() to use sa2u().

Enhance the heap profiler to trigger samples based on usable size,
rather than request size.  This has a subtle, but important, impact on
the accuracy of heap sampling.  For example, previous to this change,
16- and 17-byte objects were sampled at nearly the same rate, but
17-byte objects actually consume 32 bytes each.  Therefore it was
possible for the sample to be somewhat skewed compared to actual memory
usage of the allocated objects.
This commit is contained in:
Jason Evans
2010-10-20 17:39:18 -07:00
parent 21fb95bba6
commit 93443689a4
10 changed files with 563 additions and 155 deletions

View File

@@ -888,6 +888,21 @@ mallctl), it will be automatically initialized as a side effect of calling this
interface.
.Ed
.\"-----------------------------------------------------------------------------
@roff_stats@.It Sy "thread.allocated (uint64_t) r-"
@roff_stats@.Bd -ragged -offset indent -compact
@roff_stats@Get the total number of bytes ever allocated by the calling thread.
@roff_stats@This counter has the potential to wrap around; it is up to the
@roff_stats@application to appropriately interpret the counter in such cases.
@roff_stats@.Ed
.\"-----------------------------------------------------------------------------
@roff_stats@.It Sy "thread.deallocated (uint64_t) r-"
@roff_stats@.Bd -ragged -offset indent -compact
@roff_stats@Get the total number of bytes ever deallocated by the calling
@roff_stats@thread.
@roff_stats@This counter has the potential to wrap around; it is up to the
@roff_stats@application to appropriately interpret the counter in such cases.
@roff_stats@.Ed
.\"-----------------------------------------------------------------------------
.It Sy "config.debug (bool) r-"
.Bd -ragged -offset indent -compact
--enable-debug was specified during build configuration.