File: alloc_format.dox

package info (click to toggle)
libcwd 1.0.4-1.1
  • links: PTS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 8,136 kB
  • ctags: 10,313
  • sloc: cpp: 23,354; sh: 9,798; ansic: 1,172; makefile: 852; exp: 234; awk: 11
file content (156 lines) | stat: -rw-r--r-- 5,319 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*!
\addtogroup group_alloc_format Format Of The Overview Of Allocated Memory
\ingroup group_overview
*/
/*!
\page page_alloc_format
\ingroup group_alloc_format

<hr><h2>Detailed Description</h2>

The format of the \link group_overview Overview Of Allocated Memory \endlink can be altered
and/or the content can be filtered by passing an object of type libcwd::alloc_filter_ct 
to the function \ref list_allocations_on.  This object is constructed out of
\c alloc_format_t constants which act as bits in a bit-mask.

It is possible to include the time at which each allocation
was made by passing the bit \c show_time.  This
will prepend "hours:minutes:seconds.microseconds" to the output:

\code
04:07:16.712874 malloc    0x8078648          alloctag.cc:65   void*; (sz = 220)
\endcode

It is also possible to show the full path of the location file
by passing the bit \c show_path.  This makes the output
look like:

\code
malloc    0x8078648 /home/carlo/c++/libcwd/testsuite/libcwd.tst/alloctag.cc:65   void*; (sz = 220)
\endcode

It is also possible to show the name of the object file (shared library or
executable name) to which the allocation belongs by using the bit \c show_objectfile.
The name of the corresponding object file is prepended to the location:

\code
malloc    0x8078648 tst_alloctag_shared:         alloctag.cc:65   void*; (sz = 220)
\endcode

Finally, it is possible to show the mangled function name where the allocation
was done by using the bit \c show_function.
The mangled name of the corresponding function is prepended to the location:

\code
new[]     0x8199158 _Z7new1000j           module.cc:47   char[1000]; (sz = 1000)
\endcode

The flags can be combined with the bit-wise OR operator.

<b>Example:</b>

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter(libcwd::show_time | libcwd::show_path);
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

<b>Filtering</b>

There are four criteria on which can be filtered: the time at which an allocation was
made, the shared library that an allocation belongs too, the name of the source file
from which an allocation was made and whether or not an AllocTag was used for the
allocation.

It is possible to give a time interval of the allocations that should be shown.
For each of the limits (start and end) one can use the constant struct timeval libcwd::alloc_filter_ct::no_time_limit
to indicate that there is no limit required.

It is also possible to specify a list of wildcard masks (of the kind where a '*' matches anything) that
will be matched against the names of the shared libraries, hiding the allocations that belong to the
libraries whose name match.

It is also possible to specify a list of wildcard masks (of the kind where a '*' matches anything) that
will be matched against the names of the source file from which the allocation was done, only showing the
allocations that whose name match.

Finally, it is also possible to hide all allocations except when one of the \link group_annotation AllocTag \endlink macros was used.
Please note that using this option makes it hard to see whether or not your application has any
memory leaks in the case the leak has no <CODE>AllocTag</CODE> added.

<b>Examples:</b>

In order to show all allocations that were done one hour or more ago, one could do:

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter(libcwd::show_time);
struct timeval end;
gettimeofday(&end, 0);
end.tv_sec -= 3600;
filter.set_time_interval(libcwd::alloc_filter_ct::no_time_limit, end);
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

In order to hide all allocations that belong to any shared library (only
leaving the allocations that belong to the executable), one could do:

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter(libcwd::show_objectfile);
std::vector<std::string> masks;
masks.push_back("lib*");
filter.hide_objectfiles_matching(masks);
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

In order to hide allocations done from a specific function in a specific
shared library, one could do:

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter(libcwd::show_objectfile|libcwd::show_function);
std::vector<std::pair<std::string, std::string> > hide_list;
hide_list.push_back(std::pair<std::string, std::string>("libdl.so.2", "_dlerror_run"));
hide_list.push_back(std::pair<std::string, std::string>("libstdc++.so.6", "__cxa_get_globals"));
filter.hide_functions_matching(hide_list);
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

Note that also here it is allowed to use masks, for both the object file as well as the mangled function name.

In order to hide all allocations that are done from inside the header files
of installed libraries (like the STL), one could do:

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter(libcwd::show_path);
std::vector<std::string> masks;
masks.push_back("/usr/include/*.h");
filter.hide_sourcefiles_matching(masks);
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

In order to hide everything except those allocations that one explicitely
added an \link group_annotation AllocTag \endlink for, one could do:

\code
#ifdef CWDEBUG
libcwd::alloc_filter_ct filter;
filter.hide_untagged_allocations();
#endif

Debug( list_allocations_on(libcw_do, filter) );
\endcode

*/