Changeset 988 for vendor/current/source3/lib/tallocmsg.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/tallocmsg.c
r740 r988 19 19 #include "includes.h" 20 20 #include "messages.h" 21 22 /** 23 * @file tallocmsg.c 24 * 25 * Glue code between talloc profiling and the Samba messaging system. 26 **/ 27 28 struct msg_pool_usage_state { 29 TALLOC_CTX *mem_ctx; 30 ssize_t len; 31 size_t buflen; 32 char *s; 33 }; 34 35 static void msg_pool_usage_helper(const void *ptr, int depth, int max_depth, int is_ref, void *_s) 36 { 37 const char *name = talloc_get_name(ptr); 38 struct msg_pool_usage_state *state = (struct msg_pool_usage_state *)_s; 39 40 if (is_ref) { 41 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen, 42 "%*sreference to: %s\n", depth*4, "", name); 43 return; 44 } 45 46 if (depth == 0) { 47 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen, 48 "%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n", 49 (max_depth < 0 ? "full " :""), name, 50 (unsigned long)talloc_total_size(ptr), 51 (unsigned long)talloc_total_blocks(ptr)); 52 return; 53 } 54 55 if (strcmp(name, "char") == 0) { 56 /* 57 * Print out the first 50 bytes of the string 58 */ 59 sprintf_append(state->mem_ctx, &state->s, &state->len, 60 &state->buflen, 61 "%*s%-30s contains %6lu bytes in %3lu blocks " 62 "(ref %d): %*s\n", depth*4, "", 63 name, 64 (unsigned long)talloc_total_size(ptr), 65 (unsigned long)talloc_total_blocks(ptr), 66 talloc_reference_count(ptr), 67 MIN(50, talloc_get_size(ptr)), 68 (char *)ptr); 69 return; 70 } 71 72 sprintf_append(state->mem_ctx, &state->s, &state->len, &state->buflen, 73 "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n", 74 depth*4, "", 75 name, 76 (unsigned long)talloc_total_size(ptr), 77 (unsigned long)talloc_total_blocks(ptr), 78 talloc_reference_count(ptr)); 79 } 21 #include "lib/util/talloc_report.h" 80 22 81 23 /** … … 89 31 DATA_BLOB *data) 90 32 { 91 struct msg_pool_usage_state state;33 char *report; 92 34 93 35 SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE); … … 95 37 DEBUG(2,("Got POOL_USAGE\n")); 96 38 97 state.mem_ctx = talloc_init("msg_pool_usage"); 98 if (!state.mem_ctx) { 99 return; 100 } 101 state.len = 0; 102 state.buflen = 512; 103 state.s = NULL; 39 report = talloc_report_str(msg_ctx, NULL); 104 40 105 talloc_report_depth_cb(NULL, 0, -1, msg_pool_usage_helper, &state); 106 107 if (!state.s) { 108 talloc_destroy(state.mem_ctx); 109 return; 41 if (report != NULL) { 42 messaging_send_buf(msg_ctx, src, MSG_POOL_USAGE, 43 (uint8_t *)report, 44 talloc_get_size(report)-1); 110 45 } 111 46 112 messaging_send_buf(msg_ctx, src, MSG_POOL_USAGE, 113 (uint8 *)state.s, strlen(state.s)+1); 114 115 talloc_destroy(state.mem_ctx); 47 talloc_free(report); 116 48 } 117 49
Note:
See TracChangeset
for help on using the changeset viewer.