/src/samba/lib/util/talloc_report_printf.c
Line | Count | Source (jump to first uncovered line) |
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 | | 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 | 0 | { |
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 | 0 | "%*sreference to: %s\n", |
36 | 0 | depth*4, |
37 | 0 | "", |
38 | 0 | name); |
39 | 0 | return; |
40 | 0 | } |
41 | | |
42 | 0 | if (depth == 0) { |
43 | 0 | fprintf(f, |
44 | 0 | "%stalloc report on '%s' " |
45 | 0 | "(total %6zu bytes in %3zu blocks)\n", |
46 | 0 | (max_depth < 0 ? "full " :""), name, |
47 | 0 | talloc_total_size(ptr), |
48 | 0 | talloc_total_blocks(ptr)); |
49 | 0 | return; |
50 | 0 | } |
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 | 0 | "%*s%-30s contains %6zu bytes in %3zu blocks " |
58 | 0 | "(ref %zu): %*s\n", depth*4, "", name, |
59 | 0 | talloc_total_size(ptr), |
60 | 0 | talloc_total_blocks(ptr), |
61 | 0 | talloc_reference_count(ptr), |
62 | 0 | (int)MIN(50, talloc_get_size(ptr)), |
63 | 0 | (const char *)ptr); |
64 | 0 | return; |
65 | 0 | } |
66 | | |
67 | 0 | fprintf(f, |
68 | 0 | "%*s%-30s contains %6zu bytes in %3zu blocks (ref %zu) %p\n", |
69 | 0 | depth*4, "", name, |
70 | 0 | talloc_total_size(ptr), |
71 | 0 | talloc_total_blocks(ptr), |
72 | 0 | talloc_reference_count(ptr), |
73 | 0 | ptr); |
74 | 0 | } |
75 | | |
76 | | void talloc_full_report_printf(TALLOC_CTX *root, FILE *f) |
77 | 0 | { |
78 | 0 | talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f); |
79 | | #if defined(HAVE_MALLINFO2) |
80 | | { |
81 | | struct mallinfo2 mi2 = mallinfo2(); |
82 | | |
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); |
105 | | } |
106 | | #elif defined(HAVE_MALLINFO) |
107 | | { |
108 | 0 | struct mallinfo mi = mallinfo(); |
109 | |
|
110 | 0 | fprintf(f, |
111 | 0 | "mallinfo:\n" |
112 | 0 | " arena: %d\n" |
113 | 0 | " ordblks: %d\n" |
114 | 0 | " smblks: %d\n" |
115 | 0 | " hblks: %d\n" |
116 | 0 | " hblkhd: %d\n" |
117 | 0 | " usmblks: %d\n" |
118 | 0 | " fsmblks: %d\n" |
119 | 0 | " uordblks: %d\n" |
120 | 0 | " fordblks: %d\n" |
121 | 0 | " keepcost: %d\n", |
122 | 0 | mi.arena, |
123 | 0 | mi.ordblks, |
124 | 0 | mi.smblks, |
125 | 0 | mi.hblks, |
126 | 0 | mi.hblkhd, |
127 | 0 | mi.usmblks, |
128 | 0 | mi.fsmblks, |
129 | 0 | mi.uordblks, |
130 | 0 | mi.fordblks, |
131 | 0 | mi.keepcost); |
132 | 0 | } |
133 | 0 | #endif /* HAVE_MALLINFO2 or HAVE_MALLINFO */ |
134 | 0 | } |