lib/tallocmsg.c

説明を見る。
00001 /* 
00002    samba -- Unix SMB/CIFS implementation.
00003    Copyright (C) 2001, 2002 by Martin Pool
00004    
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #include "includes.h"
00021 
00022 /**
00023  * @file tallocmsg.c
00024  *
00025  * Glue code between talloc profiling and the Samba messaging system.
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  * Respond to a POOL_USAGE message by sending back string form of memory
00066  * usage stats.
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  * Register handler for MSG_REQ_POOL_USAGE
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 }       

Sambaに対してSat Aug 29 21:22:59 2009に生成されました。  doxygen 1.4.7