libstdc++
profiler_hash_func.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009-2017 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 
24 /** @file profile/impl/profiler_hash_func.h
25  * @brief Data structures to represent profiling traces.
26  */
27 
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 {
39  /** @brief A hash performance instrumentation line in the object table. */
41  : public __object_info_base
42  {
43  public:
44  __hashfunc_info(__stack_t __stack)
45  : __object_info_base(__stack), _M_longest_chain(0),
46  _M_accesses(0), _M_hops(0) { }
47 
48  void
49  __merge(const __hashfunc_info& __o)
50  {
51  __object_info_base::__merge(__o);
52  _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain);
53  _M_accesses += __o._M_accesses;
54  _M_hops += __o._M_hops;
55  }
56 
57  void
58  __destruct(std::size_t __chain, std::size_t __accesses,
59  std::size_t __hops)
60  {
61  _M_longest_chain = std::max(_M_longest_chain, __chain);
62  _M_accesses += __accesses;
63  _M_hops += __hops;
64  }
65 
66  void
67  __write(FILE* __f) const
68  { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
69  _M_accesses, _M_longest_chain); }
70 
71  float
72  __magnitude() const
73  { return static_cast<float>(_M_hops); }
74 
76  __advice() const
77  { return "change hash function"; }
78 
79  private:
80  std::size_t _M_longest_chain;
81  std::size_t _M_accesses;
82  std::size_t _M_hops;
83  };
84 
85  /** @brief A hash performance instrumentation line in the stack table. */
87  : public __hashfunc_info
88  {
89  public:
91  : __hashfunc_info(__o) { }
92  };
93 
94  /** @brief Hash performance instrumentation producer. */
96  : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
97  {
98  public:
101  { __id = "hash-distr"; }
102 
103  ~__trace_hash_func() {}
104 
105  // Call at destruction/clean to set container final size.
106  void
107  __destruct(__hashfunc_info* __obj_info,
108  std::size_t __chain, std::size_t __accesses, std::size_t __hops)
109  {
110  if (!__obj_info)
111  return;
112 
113  __obj_info->__destruct(__chain, __accesses, __hops);
114  __retire_object(__obj_info);
115  }
116  };
117 
118  inline void
119  __trace_hash_func_init()
120  { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
121 
122  inline void
123  __trace_hash_func_free()
124  { delete _GLIBCXX_PROFILE_DATA(_S_hash_func); }
125 
126  inline void
127  __trace_hash_func_report(FILE* __f, __warning_vector_t& __warnings)
128  { __trace_report(_GLIBCXX_PROFILE_DATA(_S_hash_func), __f, __warnings); }
129 
130  inline __hashfunc_info*
131  __trace_hash_func_construct()
132  {
133  if (!__profcxx_init())
134  return 0;
135 
136  if (!__reentrance_guard::__get_in())
137  return 0;
138 
139  __reentrance_guard __get_out;
140  return _GLIBCXX_PROFILE_DATA(_S_hash_func)->__add_object(__get_stack());
141  }
142 
143  inline void
144  __trace_hash_func_destruct(__hashfunc_info* __obj_info,
145  std::size_t __chain, std::size_t __accesses,
146  std::size_t __hops)
147  {
148  _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj_info, __chain,
149  __accesses, __hops);
150  }
151 
152 } // namespace __gnu_profile
153 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */
GNU profile code for public use.
Hash performance instrumentation producer.
Interface of the profiling runtime library.
bool __profcxx_init()
This function must be called by each instrumentation point.
Data structures to represent profiling traces.
A hash performance instrumentation line in the object table.
Data structures to represent a single profiling event.
Base class for a line in the object table.
Base class for all trace producers.
A hash performance instrumentation line in the stack table.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:219