STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
profiler_hash_func.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library 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 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
23 
28 // Written by Lixia Liu and Silvius Rus.
29 
30 #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H
31 #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1
32 
33 #include "profile/impl/profiler.h"
36 
37 namespace __gnu_profile
38 {
41  : public __object_info_base
42  {
43  public:
45  : _M_longest_chain(0), _M_accesses(0), _M_hops(0) { }
46 
49  _M_accesses(__o._M_accesses), _M_hops(__o._M_hops) { }
50 
52  : __object_info_base(__stack), _M_longest_chain(0),
53  _M_accesses(0), _M_hops(0) { }
54 
55  virtual ~__hashfunc_info() { }
56 
57  void
59  {
61  _M_accesses += __o._M_accesses;
62  _M_hops += __o._M_hops;
63  }
64 
65  void
66  __destruct(std::size_t __chain, std::size_t __accesses,
67  std::size_t __hops)
68  {
70  _M_accesses += __accesses;
71  _M_hops += __hops;
72  }
73 
74  void
75  __write(FILE* __f) const
76  { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
78 
79  float
80  __magnitude() const
81  { return static_cast<float>(_M_hops); }
82 
84  __advice() const
85  { return "change hash function"; }
86 
87  private:
91  };
92 
93 
96  : public __hashfunc_info
97  {
98  public:
100  : __hashfunc_info(__o) { }
101  };
102 
103 
106  : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
107  {
108  public:
111  { __id = "hash-distr"; }
112 
114 
115  // Insert a new node at construct with object, callstack and initial size.
116  void
117  __insert(__object_t __obj, __stack_t __stack)
118  { __add_object(__obj, __hashfunc_info(__stack)); }
119 
120  // Call at destruction/clean to set container final size.
121  void
122  __destruct(const void* __obj, std::size_t __chain,
123  std::size_t __accesses, std::size_t __hops)
124  {
125  if (!__is_on())
126  return;
127 
128  // First find the item from the live objects and update the informations.
129  __hashfunc_info* __objs = __get_object_info(__obj);
130  if (!__objs)
131  return;
132 
133  __objs->__destruct(__chain, __accesses, __hops);
134  __retire_object(__obj);
135  }
136  };
137 
138 
139  inline void
141  { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
142 
143  inline void
145  {
146  if (_GLIBCXX_PROFILE_DATA(_S_hash_func))
147  {
148  _GLIBCXX_PROFILE_DATA(_S_hash_func)->__collect_warnings(__warnings);
149  _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f);
150  }
151  }
152 
153  inline void
154  __trace_hash_func_construct(const void* __obj)
155  {
156  if (!__profcxx_init())
157  return;
158 
159  _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack());
160  }
161 
162  inline void
163  __trace_hash_func_destruct(const void* __obj, std::size_t __chain,
164  std::size_t __accesses, std::size_t __hops)
165  {
166  if (!__profcxx_init())
167  return;
168 
169  _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain,
170  __accesses, __hops);
171  }
172 
173 } // namespace __gnu_profile
174 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */
__stack_t __get_stack()
Definition: profiler_node.h:50
bool __is_on()
Definition: profiler_state.h:57
void __trace_hash_func_init()
Definition: profiler_hash_func.h:140
float __magnitude() const
Definition: profiler_hash_func.h:80
void __trace_hash_func_construct(const void *)
Definition: profiler_hash_func.h:154
void __destruct(const void *__obj, std::size_t __chain, std::size_t __accesses, std::size_t __hops)
Definition: profiler_hash_func.h:122
~__trace_hash_func()
Definition: profiler_hash_func.h:113
std::size_t _M_longest_chain
Definition: profiler_hash_func.h:88
Data structures to represent profiling traces.
void __write(FILE *__f) const
Definition: profiler_hash_func.h:75
A hash performance instrumentation line in the object table.
Definition: profiler_hash_func.h:40
std::size_t _M_hops
Definition: profiler_hash_func.h:90
basic_string< char > string
Definition: string:1153
__stack_t __stack() const
Definition: profiler_node.h:141
std::_GLIBCXX_STD_C::vector< __warning_data > __warning_vector_t
Definition: profiler_trace.h:93
void __destruct(std::size_t __chain, std::size_t __accesses, std::size_t __hops)
Definition: profiler_hash_func.h:66
__trace_hash_func()
Definition: profiler_hash_func.h:109
Base class for all trace producers.
Definition: profiler_trace.h:183
void __trace_hash_func_destruct(const void *, std::size_t, std::size_t, std::size_t)
Definition: profiler_hash_func.h:163
void __merge(const __hashfunc_info &__o)
Definition: profiler_hash_func.h:58
__hashfunc_info()
Definition: profiler_hash_func.h:44
Interface of the profiling runtime library.
std::string __advice() const
Definition: profiler_hash_func.h:84
__hashfunc_stack_info(const __hashfunc_info &__o)
Definition: profiler_hash_func.h:99
A hash performance instrumentation line in the stack table.
Definition: profiler_hash_func.h:95
bool __profcxx_init()
This function must be called by each instrumentation point.
Definition: profiler_trace.h:649
__hashfunc_info(__stack_t __stack)
Definition: profiler_hash_func.h:51
std::size_t _M_accesses
Definition: profiler_hash_func.h:89
#define _GLIBCXX_PROFILE_DATA(__name)
Definition: profiler.h:48
virtual ~__hashfunc_info()
Definition: profiler_hash_func.h:55
__stack_npt * __stack_t
Definition: profiler_node.h:45
const _Tp & max(const _Tp &__a, const _Tp &__b)
Equivalent to std::max.
Definition: base.h:150
void __add_object(__object_t object, __hashfunc_info__info)
__hashfunc_info(const __hashfunc_info &__o)
Definition: profiler_hash_func.h:47
__SIZE_TYPE__ size_t
Definition: stddef.h:212
Data structures to represent a single profiling event.
Base class for a line in the object table.
Definition: profiler_node.h:123
void __insert(__object_t __obj, __stack_t __stack)
Definition: profiler_hash_func.h:117
void __trace_hash_func_report(FILE *__f, __warning_vector_t &__warnings)
Definition: profiler_hash_func.h:144
Hash performance instrumentation producer.
Definition: profiler_hash_func.h:105
const void * __object_t
Definition: profiler_node.h:42