Line data Source code
1 : /*
2 : * talloc_report into a FILE
3 : *
4 : * Copyright Volker Lendecke <vl@samba.org> 2015
5 : *
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.
10 : *
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.
15 : *
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/>.
18 : */
19 :
20 : #include "replace.h"
21 : #include "talloc_report_printf.h"
22 :
23 0 : 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)
29 : {
30 0 : FILE *f = private_data;
31 0 : const char *name = talloc_get_name(ptr);
32 :
33 0 : if (is_ref) {
34 0 : fprintf(f,
35 : "%*sreference to: %s\n",
36 : depth*4,
37 : "",
38 : name);
39 0 : return;
40 : }
41 :
42 0 : if (depth == 0) {
43 0 : 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 0 : return;
50 : }
51 :
52 0 : if (strcmp(name, "char") == 0) {
53 : /*
54 : * Print out the first 50 bytes of the string
55 : */
56 0 : 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 0 : (int)MIN(50, talloc_get_size(ptr)),
63 : (const char *)ptr);
64 0 : return;
65 : }
66 :
67 0 : 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);
74 : }
75 :
76 0 : void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
77 : {
78 0 : talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f);
79 :
80 : #ifdef HAVE_MALLINFO
81 : {
82 : struct mallinfo mi;
83 :
84 0 : mi = mallinfo();
85 0 : fprintf(f,
86 : "mallinfo:\n"
87 : " arena: %d\n"
88 : " ordblks: %d\n"
89 : " smblks: %d\n"
90 : " hblks: %d\n"
91 : " hblkhd: %d\n"
92 : " usmblks: %d\n"
93 : " fsmblks: %d\n"
94 : " uordblks: %d\n"
95 : " fordblks: %d\n"
96 : " keepcost: %d\n",
97 : mi.arena,
98 : mi.ordblks,
99 : mi.smblks,
100 : mi.hblks,
101 : mi.hblkhd,
102 : mi.usmblks,
103 : mi.fsmblks,
104 : mi.uordblks,
105 : mi.fordblks,
106 : mi.keepcost);
107 : }
108 : #endif /* HAVE_MALLINFO */
109 0 : }
|