00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "includes.h"
00021
00022
00023
00024
00025
00026
00027
00028 struct msg_pool_usage_state {
00029 TALLOC_CTX *mem_ctx;
00030 ssize_t len;
00031 size_t buflen;
00032 char *s;
00033 };
00034
00035 static void msg_pool_usage_helper(const void *ptr, int depth, int max_depth, int is_ref, void *_s)
00036 {
00037 const char *name = talloc_get_name(ptr);
00038 struct msg_pool_usage_state *state = (struct msg_pool_usage_state *)_s;
00039
00040 if (is_ref) {
00041 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
00042 "%*sreference to: %s\n", depth*4, "", name);
00043 return;
00044 }
00045
00046 if (depth == 0) {
00047 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
00048 "%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
00049 (max_depth < 0 ? "full " :""), name,
00050 (unsigned long)talloc_total_size(ptr),
00051 (unsigned long)talloc_total_blocks(ptr));
00052 return;
00053 }
00054
00055 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen,
00056 "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n",
00057 depth*4, "",
00058 name,
00059 (unsigned long)talloc_total_size(ptr),
00060 (unsigned long)talloc_total_blocks(ptr),
00061 talloc_reference_count(ptr));
00062 }
00063
00064
00065
00066
00067
00068 void msg_pool_usage(int msg_type, struct process_id src_pid,
00069 void *UNUSED(buf), size_t UNUSED(len),
00070 void *private_data)
00071 {
00072 struct msg_pool_usage_state state;
00073
00074 SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
00075
00076 DEBUG(2,("Got POOL_USAGE\n"));
00077
00078 state.mem_ctx = talloc_init("msg_pool_usage");
00079 if (!state.mem_ctx) {
00080 return;
00081 }
00082 state.len = 0;
00083 state.buflen = 512;
00084 state.s = NULL;
00085
00086 talloc_report_depth_cb(NULL, 0, -1, msg_pool_usage_helper, &state);
00087
00088 if (!state.s) {
00089 talloc_destroy(state.mem_ctx);
00090 return;
00091 }
00092
00093 message_send_pid(src_pid, MSG_POOL_USAGE,
00094 state.s, strlen(state.s)+1, True);
00095
00096 talloc_destroy(state.mem_ctx);
00097 }
00098
00099
00100
00101
00102 void register_msg_pool_usage(void)
00103 {
00104 message_register(MSG_REQ_POOL_USAGE, msg_pool_usage, NULL);
00105 DEBUG(2, ("Registered MSG_REQ_POOL_USAGE\n"));
00106 }