Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

class_alloc_filter.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2002 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_CLASS_ALLOC_FILTER_H
19 #define LIBCWD_CLASS_ALLOC_FILTER_H
20 
21 #ifndef LIBCWD_LIBRARIES_DEBUG_H
22 #error "Don't include <libcwd/class_alloc_filter.h> directly, include the appropriate \"debug.h\" instead."
23 #endif
24 
25 #include <libcwd/config.h>
26 
27 #if CWDEBUG_LOCATION
28 #include <libcwd/class_location.h>
29 #endif
30 
31 #if CWDEBUG_ALLOC
32 
33 #if CWDEBUG_LOCATION
35 #endif
36 #ifndef LIBCW_VECTOR
37 #define LIBCW_VECTOR
38 #include <vector>
39 #endif
40 #include <sys/time.h>
41 
42 #endif // CWDEBUG_ALLOC
43 
44 namespace libcwd {
45 
50 typedef unsigned short int alloc_format_t;
51 
52 #if CWDEBUG_LOCATION
53 alloc_format_t const show_path = 1;
54 alloc_format_t const show_objectfile = 2;
55 alloc_format_t const show_function = 4;
56 #endif
57 #if CWDEBUG_ALLOC
58 alloc_format_t const show_time = 8;
59 alloc_format_t const show_allthreads = 16;
60 #if CWDEBUG_LOCATION
61 alloc_format_t const format_mask = (show_time|show_path|show_objectfile|show_function|show_allthreads);
62 #else
63 alloc_format_t const format_mask = (show_time|show_allthreads);
64 #endif
65 #endif // CWDEBUG_ALLOC
66 
69 #if CWDEBUG_ALLOC
70 
71 unsigned int const hide_untagged = 32; // Call hide_untagged_allocations() to set this flag.
72 unsigned int const hide_unknown_loc = 64; // Call hide_unknown_locations() to set this flag.
73 
74 class dm_alloc_base_ct;
75 class dm_alloc_copy_ct;
76 #if CWDEBUG_MARKER
77 class marker_ct;
78 #endif
79 
90 private:
91 #if CWDEBUG_LOCATION // No synchronization needed when not defined.
92  static int S_next_id; // MT: protected by list_allocations_instance
93  static int S_id; // MT: protected by list_allocations_instance
94  int M_id;
95 #endif
96  friend class ::libcwd::dm_alloc_base_ct;
97  friend class ::libcwd::dm_alloc_copy_ct;
98  alloc_format_t M_flags;
99  struct timeval M_start;
100  struct timeval M_end;
101 #if CWDEBUG_LOCATION
102  typedef std::basic_string<char, std::char_traits<char>, _private_::auto_internal_allocator> string_type;
103  typedef std::vector<string_type, _private_::auto_internal_allocator::rebind<string_type>::other> vector_type;
104  vector_type M_objectfile_masks;
105  vector_type M_sourcefile_masks;
106  typedef std::vector<std::pair<string_type, string_type>,
107  _private_::auto_internal_allocator::rebind<std::pair<string_type, string_type> >::other> vector_pair_type;
108  vector_pair_type M_function_masks;
109 #endif
110 public:
112  static struct timeval const no_time_limit;
114  alloc_filter_ct(alloc_format_t flags = 0);
116  void set_flags(alloc_format_t flags);
118  alloc_format_t get_flags() const;
120  struct timeval get_time_start() const;
122  struct timeval get_time_end() const;
123 #if CWDEBUG_LOCATION
124 
128  std::vector<std::string> get_objectfile_list() const;
129 
134  std::vector<std::string> get_sourcefile_list() const;
135 
140  std::vector<std::pair<std::string, std::string> > get_function_list() const;
141 #endif
142 
151  void set_time_interval(struct timeval const& start, struct timeval const& end);
152 
153 #if CWDEBUG_LOCATION
154 
162  void hide_objectfiles_matching(std::vector<std::string> const& masks);
163 
172  void hide_sourcefiles_matching(std::vector<std::string> const& masks);
173 
191  void hide_functions_matching(std::vector<std::pair<std::string, std::string> > const& masks);
192 #endif
193 
200  void hide_untagged_allocations(bool hide = true) { if (hide) M_flags |= hide_untagged; else M_flags &= ~hide_untagged; }
201 
208  void hide_unknown_locations(bool hide = true) { if (hide) M_flags |= hide_unknown_loc; else M_flags &= ~hide_unknown_loc; }
209 
210 #if CWDEBUG_LOCATION
211  // Return true if filepath matches one of the masks in M_source_masks.
212  _private_::hidden_st check_hide(char const* filepath) const;
213 
214  // Return true if object_file/mangled_function_name matches one of the mask pairs in M_function_masks.
215  _private_::hidden_st check_hide(object_file_ct const* object_file, char const* mangled_function_name) const;
216 #endif
217 
218 private:
219  friend unsigned long list_allocations_on(debug_ct&, alloc_filter_ct const&);
220 #if CWDEBUG_MARKER
221  friend class marker_ct;
222 #endif
223 #if CWDEBUG_LOCATION
224  void M_check_synchronization() const { if (M_id != S_id) M_synchronize(); }
225  void M_synchronize() const;
226  void M_synchronize_locations() const;
227 #endif
228 };
229 
230 #endif // CWDEBUG_ALLOC
231 
232 } // namespace libcwd
233 
234 #endif // LIBCWD_CLASS_ALLOC_FILTER_H
struct timeval get_time_start() const
Returns the start time as passed with set_time_interval.
The Debug Object class, this object represents one output device (ostream).
Definition: class_debug.h:77
void set_time_interval(struct timeval const &start, struct timeval const &end)
Select the time interval that should be shown.
A memory allocation marker.
Definition: class_marker.h:33
void hide_functions_matching(std::vector< std::pair< std::string, std::string > > const &masks)
Select which object-file/function pairs to hide in the Allocator Memory Overview. ...
An allocated-memory filter class.An object of this type can be passed to list_allocations_on containi...
Definition: class_alloc_filter.h:89
friend unsigned long list_allocations_on(debug_ct &, alloc_filter_ct const &)
List all current allocations to a given debug object using a specified format.With CWDEBUG_ALLOC set...
Definition: debugmalloc.cc:3034
An object representing the main executable or a shared library.
Definition: class_object_file.h:52
alloc_format_t get_flags() const
Returns the flags as set with set_flags.
std::vector< std::pair< std::string, std::string > > get_function_list() const
Return a copy of the list of object-file/function pair masks.
alloc_format_t const show_path
Show the full path of the locations where the allocation was made.
Definition: class_alloc_filter.h:53
void hide_untagged_allocations(bool hide=true)
Only show the allocations for which a AllocTag was added in the code.
Definition: class_alloc_filter.h:200
std::vector< std::string > get_sourcefile_list() const
Returns a copy of the list of source file masks.
namespace for libcwd.
Definition: debug.cc:87
alloc_format_t const show_time
Show the time at which the allocation was made.
Definition: class_alloc_filter.h:58
struct timeval get_time_end() const
Returns the end time as passed with set_time_interval.
alloc_format_t const show_allthreads
Show the allocations of all threads, not just the current thread.
Definition: class_alloc_filter.h:59
void hide_sourcefiles_matching(std::vector< std::string > const &masks)
Select which source files to hide in the Allocated Memory Overview.
unsigned short int alloc_format_t
The type used for the formatting flags of an alloc_filter_ct object.
Definition: class_alloc_filter.h:50
alloc_filter_ct(alloc_format_t flags=0)
Construct a formatting object.
void set_flags(alloc_format_t flags)
Set the general formatting flags.
std::vector< std::string > get_objectfile_list() const
Returns a copy of the list of object file masks.
void hide_objectfiles_matching(std::vector< std::string > const &masks)
Select which object files to hide in the Allocated Memory Overview.
void hide_unknown_locations(bool hide=true)
Only show the allocations for which a source file and line number could be found. ...
Definition: class_alloc_filter.h:208
static struct timeval const no_time_limit
Definition: class_alloc_filter.h:112
alloc_format_t const show_objectfile
Show the name of the shared library that is responsible for the allocation.
Definition: class_alloc_filter.h:54
alloc_format_t const show_function
Show the mangled name of the function that allocated the memory.
Definition: class_alloc_filter.h:55
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.