mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 08:05:21 +00:00
add isc_mem_setname()
This commit is contained in:
@@ -32,6 +32,12 @@ ISC_LANG_BEGINDECLS
|
|||||||
typedef void * (*isc_memalloc_t)(void *, size_t);
|
typedef void * (*isc_memalloc_t)(void *, size_t);
|
||||||
typedef void (*isc_memfree_t)(void *, void *);
|
typedef void (*isc_memfree_t)(void *, void *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 0 to remove the names from memory pools. This will save
|
||||||
|
* about 16 bytes per pool.
|
||||||
|
*/
|
||||||
|
#define ISC_MEMPOOL_NAMES 1
|
||||||
|
|
||||||
#ifdef ISC_MEM_DEBUG
|
#ifdef ISC_MEM_DEBUG
|
||||||
#define isc_mem_get(c, s) __isc_mem_getdebug(c, s, __FILE__, __LINE__)
|
#define isc_mem_get(c, s) __isc_mem_getdebug(c, s, __FILE__, __LINE__)
|
||||||
#define isc_mem_put(c, p, s) __isc_mem_putdebug(c, p, s, __FILE__, __LINE__)
|
#define isc_mem_put(c, p, s) __isc_mem_putdebug(c, p, s, __FILE__, __LINE__)
|
||||||
@@ -138,10 +144,20 @@ isc_mempool_destroy(isc_mempool_t **mpctxp);
|
|||||||
* Destroy a memory pool.
|
* Destroy a memory pool.
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
* mpctxp is a valid pool.
|
* mpctxp != NULL && *mpctxp is a valid pool.
|
||||||
* The pool has no un"put" allocations outstanding
|
* The pool has no un"put" allocations outstanding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
isc_mempool_setname(isc_mempool_t *mpctx, char *name);
|
||||||
|
/*
|
||||||
|
* Associate a name with a memory pool. At most 15 characters may be used.
|
||||||
|
*
|
||||||
|
* Requires:
|
||||||
|
* mpctx is a valid pool.
|
||||||
|
* name != NULL;
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
|
isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
|
||||||
/*
|
/*
|
||||||
|
@@ -46,6 +46,14 @@
|
|||||||
#define ISC_MEM_FILL 1
|
#define ISC_MEM_FILL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ISC_MEMPOOL_NAMES
|
||||||
|
/*
|
||||||
|
* During development it is nice to be able to see names associated with
|
||||||
|
* memory pools.
|
||||||
|
*/
|
||||||
|
#define ISC_MEMPOOL_NAMES 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Types.
|
* Types.
|
||||||
*/
|
*/
|
||||||
@@ -113,6 +121,10 @@ struct isc_mempool {
|
|||||||
unsigned int fillcount; /* # of items to fetch on each fill */
|
unsigned int fillcount; /* # of items to fetch on each fill */
|
||||||
/* Stats only. */
|
/* Stats only. */
|
||||||
unsigned int gets; /* # of requests to this pool */
|
unsigned int gets; /* # of requests to this pool */
|
||||||
|
/* Debugging only. */
|
||||||
|
#if ISC_MEMPOOL_NAMES
|
||||||
|
char name[16]; /* printed name in stats reports */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Forward. */
|
/* Forward. */
|
||||||
@@ -547,15 +559,15 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out)
|
|||||||
pool = ISC_LIST_HEAD(ctx->pools);
|
pool = ISC_LIST_HEAD(ctx->pools);
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
fprintf(out, "[Pool statistics]\n");
|
fprintf(out, "[Pool statistics]\n");
|
||||||
fprintf(out, "%10s %10s %10s %10s %10s %10s %10s %1s\n",
|
fprintf(out, "%15s %10s %10s %10s %10s %10s %10s %10s %1s\n",
|
||||||
"size", "maxalloc", "allocated", "freecount",
|
"name", "size", "maxalloc", "allocated", "freecount",
|
||||||
"freemax", "fillcount", "gets", "L");
|
"freemax", "fillcount", "gets", "L");
|
||||||
}
|
}
|
||||||
while (pool != NULL) {
|
while (pool != NULL) {
|
||||||
fprintf(out, "%10u %10u %10u %10u %10u %10u %10u %s\n",
|
fprintf(out, "%15s %10u %10u %10u %10u %10u %10u %10u %s\n",
|
||||||
pool->size, pool->maxalloc, pool->allocated,
|
pool->name, pool->size, pool->maxalloc,
|
||||||
pool->freecount, pool->freemax, pool->fillcount,
|
pool->allocated, pool->freecount, pool->freemax,
|
||||||
pool->gets,
|
pool->fillcount, pool->gets,
|
||||||
(pool->lock == NULL ? "N" : "Y"));
|
(pool->lock == NULL ? "N" : "Y"));
|
||||||
pool = ISC_LIST_NEXT(pool, link);
|
pool = ISC_LIST_NEXT(pool, link);
|
||||||
}
|
}
|
||||||
@@ -838,6 +850,9 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
|
|||||||
mpctx->freemax = 1;
|
mpctx->freemax = 1;
|
||||||
mpctx->fillcount = 1;
|
mpctx->fillcount = 1;
|
||||||
mpctx->gets = 0;
|
mpctx->gets = 0;
|
||||||
|
#if ISC_MEMPOOL_NAMES
|
||||||
|
mpctx->name[0] = 0;
|
||||||
|
#endif
|
||||||
mpctx->items = NULL;
|
mpctx->items = NULL;
|
||||||
|
|
||||||
*mpctxp = mpctx;
|
*mpctxp = mpctx;
|
||||||
@@ -849,6 +864,26 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
isc_mempool_setname(isc_mempool_t *mpctx, char *name)
|
||||||
|
{
|
||||||
|
REQUIRE(name != NULL);
|
||||||
|
|
||||||
|
#if ISC_MEMPOOL_NAMES
|
||||||
|
if (mpctx->lock != NULL)
|
||||||
|
LOCK(mpctx->lock);
|
||||||
|
|
||||||
|
memset(mpctx->name, 0, sizeof(mpctx->name));
|
||||||
|
strncpy(mpctx->name, name, sizeof(mpctx->name) - 1);
|
||||||
|
|
||||||
|
if (mpctx->lock != NULL)
|
||||||
|
UNLOCK(mpctx->lock);
|
||||||
|
#else
|
||||||
|
(void)mpctx;
|
||||||
|
(void)name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_mempool_destroy(isc_mempool_t **mpctxp)
|
isc_mempool_destroy(isc_mempool_t **mpctxp)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user