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 "config.h"
26 
27 #if CWDEBUG_LOCATION
28 #include "class_location.h"
29 #endif
30 
31 #if CWDEBUG_ALLOC
32 
33 #if CWDEBUG_LOCATION
34 #include "private_allocator.h"
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 
89 class alloc_filter_ct {
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
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
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
A memory allocation marker.
Definition: class_marker.h:33
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
unsigned long list_allocations_on(debug_ct &debug_object)
List all current allocations to a given debug object.
Definition: debugmalloc.cc:3020
namespace for libcwd.
Definition: debug.cc:87
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.