00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef LIBCWD_CLASS_ALLOC_FILTER_H
00019 #define LIBCWD_CLASS_ALLOC_FILTER_H
00020
00021 #ifndef LIBCWD_LIBRARIES_DEBUG_H
00022 #error "Don't include <libcwd/class_alloc_filter.h> directly, include the appropriate \"debug.h\" instead."
00023 #endif
00024
00025 #include <libcwd/config.h>
00026
00027 #if CWDEBUG_LOCATION
00028 #include <libcwd/class_location.h>
00029 #endif
00030
00031 #if CWDEBUG_ALLOC
00032
00033 #if CWDEBUG_LOCATION
00034 #include <libcwd/private_allocator.h>
00035 #endif
00036 #ifndef LIBCW_VECTOR
00037 #define LIBCW_VECTOR
00038 #include <vector>
00039 #endif
00040 #include <sys/time.h>
00041
00042 #endif // CWDEBUG_ALLOC
00043
00044 namespace libcwd {
00045
00050 typedef unsigned short int alloc_format_t;
00051
00052 #if CWDEBUG_LOCATION
00053 alloc_format_t const show_path = 1;
00054 alloc_format_t const show_objectfile = 2;
00055 alloc_format_t const show_function = 4;
00056 #endif
00057 #if CWDEBUG_ALLOC
00058 alloc_format_t const show_time = 8;
00059 alloc_format_t const show_allthreads = 16;
00060 #if CWDEBUG_LOCATION
00061 alloc_format_t const format_mask = (show_time|show_path|show_objectfile|show_function|show_allthreads);
00062 #else
00063 alloc_format_t const format_mask = (show_time|show_allthreads);
00064 #endif
00065 #endif // CWDEBUG_ALLOC
00066
00069 #if CWDEBUG_ALLOC
00070
00071 unsigned int const hide_untagged = 32;
00072 unsigned int const hide_unknown_loc = 64;
00073
00074 class dm_alloc_base_ct;
00075 class dm_alloc_copy_ct;
00076 #if CWDEBUG_MARKER
00077 class marker_ct;
00078 #endif
00079
00089 class alloc_filter_ct {
00090 private:
00091 #if CWDEBUG_LOCATION // No synchronization needed when not defined.
00092 static int S_next_id;
00093 static int S_id;
00094 int M_id;
00095 #endif
00096 friend class ::libcwd::dm_alloc_base_ct;
00097 friend class ::libcwd::dm_alloc_copy_ct;
00098 alloc_format_t M_flags;
00099 struct timeval M_start;
00100 struct timeval M_end;
00101 #if CWDEBUG_LOCATION
00102 typedef std::basic_string<char, std::char_traits<char>, _private_::auto_internal_allocator> string_type;
00103 typedef std::vector<string_type, _private_::auto_internal_allocator::rebind<string_type>::other> vector_type;
00104 vector_type M_objectfile_masks;
00105 vector_type M_sourcefile_masks;
00106 typedef std::vector<std::pair<string_type, string_type>,
00107 _private_::auto_internal_allocator::rebind<std::pair<string_type, string_type> >::other> vector_pair_type;
00108 vector_pair_type M_function_masks;
00109 #endif
00110 public:
00112 static struct timeval const no_time_limit;
00114 alloc_filter_ct(alloc_format_t flags = 0);
00116 void set_flags(alloc_format_t flags);
00118 alloc_format_t get_flags(void) const;
00120 struct timeval get_time_start(void) const;
00122 struct timeval get_time_end(void) const;
00123 #if CWDEBUG_LOCATION
00124
00128 std::vector<std::string> get_objectfile_list(void) const;
00129
00134 std::vector<std::string> get_sourcefile_list(void) const;
00135
00140 std::vector<std::pair<std::string, std::string> > get_function_list(void) const;
00141 #endif
00142
00151 void set_time_interval(struct timeval const& start, struct timeval const& end);
00152
00153 #if CWDEBUG_LOCATION
00154
00162 void hide_objectfiles_matching(std::vector<std::string> const& masks);
00163
00172 void hide_sourcefiles_matching(std::vector<std::string> const& masks);
00173
00191 void hide_functions_matching(std::vector<std::pair<std::string, std::string> > const& masks);
00192 #endif
00193
00200 void hide_untagged_allocations(bool hide = true) { if (hide) M_flags |= hide_untagged; else M_flags &= ~hide_untagged; }
00201
00208 void hide_unknown_locations(bool hide = true) { if (hide) M_flags |= hide_unknown_loc; else M_flags &= ~hide_unknown_loc; }
00209
00210 #if CWDEBUG_LOCATION
00211
00212 _private_::hidden_st check_hide(char const* filepath) const;
00213
00214
00215 _private_::hidden_st check_hide(object_file_ct const* object_file, char const* mangled_function_name) const;
00216 #endif
00217
00218 private:
00219 friend unsigned long list_allocations_on(debug_ct&, alloc_filter_ct const&);
00220 #if CWDEBUG_MARKER
00221 friend class marker_ct;
00222 #endif
00223 #if CWDEBUG_LOCATION
00224 void M_check_synchronization(void) const { if (M_id != S_id) M_synchronize(); }
00225 void M_synchronize(void) const;
00226 void M_synchronize_locations(void) const;
00227 #endif
00228 };
00229
00230 #endif // CWDEBUG_ALLOC
00231
00232 }
00233
00234 #endif // LIBCWD_CLASS_ALLOC_FILTER_H