+struct msg_pool_usage_state {
+ TALLOC_CTX *mem_ctx;
+ ssize_t len;
+ size_t buflen;
+ char *s;
+};
+
+static void msg_pool_usage_helper(const void *ptr, int depth, int max_depth, int is_ref, void *_s)
+{
+ const char *name = talloc_get_name(ptr);
+ struct msg_pool_usage_state *state = (struct msg_pool_usage_state *)_s;
+
+ if (is_ref) {
+ sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
+ "%*sreference to: %s\n", depth*4, "", name);
+ return;
+ }
+
+ if (depth == 0) {
+ sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
+ "%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
+ (max_depth < 0 ? "full " :""), name,
+ (unsigned long)talloc_total_size(ptr),
+ (unsigned long)talloc_total_blocks(ptr));
+ return;
+ }
+
+ if (strcmp(name, "char") == 0) {
+ /*
+ * Print out the first 50 bytes of the string
+ */
+ sprintf_append(state->mem_ctx, &state->s, &state->len,
+ &state->buflen,
+ "%*s%-30s contains %6lu bytes in %3lu blocks "
+ "(ref %d): %*s\n", depth*4, "",
+ name,
+ (unsigned long)talloc_total_size(ptr),
+ (unsigned long)talloc_total_blocks(ptr),
+ talloc_reference_count(ptr),
+ MIN(50, talloc_get_size(ptr)),
+ (const char *)ptr);
+ return;
+ }
+
+ sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
+ "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n",
+ depth*4, "",
+ name,
+ (unsigned long)talloc_total_size(ptr),
+ (unsigned long)talloc_total_blocks(ptr),
+ talloc_reference_count(ptr));
+}