s3: smbd: Sanitize any "server" and "share" components of SMB1 DFS paths to remove...
[Samba.git] / lib / util / talloc_report_printf.c
blob3011c62536eb7e4e1a1b3881bd18f672e2134de1
1 /*
2 * talloc_report into a FILE
4 * Copyright Volker Lendecke <vl@samba.org> 2015
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
21 #include "talloc_report_printf.h"
23 static void talloc_report_printf_helper(
24 const void *ptr,
25 int depth,
26 int max_depth,
27 int is_ref,
28 void *private_data)
30 FILE *f = private_data;
31 const char *name = talloc_get_name(ptr);
33 if (is_ref) {
34 fprintf(f,
35 "%*sreference to: %s\n",
36 depth*4,
37 "",
38 name);
39 return;
42 if (depth == 0) {
43 fprintf(f,
44 "%stalloc report on '%s' "
45 "(total %6zu bytes in %3zu blocks)\n",
46 (max_depth < 0 ? "full " :""), name,
47 talloc_total_size(ptr),
48 talloc_total_blocks(ptr));
49 return;
52 if (strcmp(name, "char") == 0) {
54 * Print out the first 50 bytes of the string
56 fprintf(f,
57 "%*s%-30s contains %6zu bytes in %3zu blocks "
58 "(ref %zu): %*s\n", depth*4, "", name,
59 talloc_total_size(ptr),
60 talloc_total_blocks(ptr),
61 talloc_reference_count(ptr),
62 (int)MIN(50, talloc_get_size(ptr)),
63 (const char *)ptr);
64 return;
67 fprintf(f,
68 "%*s%-30s contains %6zu bytes in %3zu blocks (ref %zu) %p\n",
69 depth*4, "", name,
70 talloc_total_size(ptr),
71 talloc_total_blocks(ptr),
72 talloc_reference_count(ptr),
73 ptr);
76 void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
78 talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f);
79 #if defined(HAVE_MALLINFO2)
81 struct mallinfo2 mi2 = mallinfo2();
83 fprintf(f,
84 "mallinfo:\n"
85 " arena: %zu\n"
86 " ordblks: %zu\n"
87 " smblks: %zu\n"
88 " hblks: %zu\n"
89 " hblkhd: %zu\n"
90 " usmblks: %zu\n"
91 " fsmblks: %zu\n"
92 " uordblks: %zu\n"
93 " fordblks: %zu\n"
94 " keepcost: %zu\n",
95 mi2.arena,
96 mi2.ordblks,
97 mi2.smblks,
98 mi2.hblks,
99 mi2.hblkhd,
100 mi2.usmblks,
101 mi2.fsmblks,
102 mi2.uordblks,
103 mi2.fordblks,
104 mi2.keepcost);
106 #elif defined(HAVE_MALLINFO)
108 struct mallinfo mi = mallinfo();
110 fprintf(f,
111 "mallinfo:\n"
112 " arena: %d\n"
113 " ordblks: %d\n"
114 " smblks: %d\n"
115 " hblks: %d\n"
116 " hblkhd: %d\n"
117 " usmblks: %d\n"
118 " fsmblks: %d\n"
119 " uordblks: %d\n"
120 " fordblks: %d\n"
121 " keepcost: %d\n",
122 mi.arena,
123 mi.ordblks,
124 mi.smblks,
125 mi.hblks,
126 mi.hblkhd,
127 mi.usmblks,
128 mi.fsmblks,
129 mi.uordblks,
130 mi.fordblks,
131 mi.keepcost);
133 #endif /* HAVE_MALLINFO2 or HAVE_MALLINFO */