2014-11-10 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / profile / impl / profiler_hash_func.h
blob9e915bb9e5f63edbbcb838d02750994745773e57
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009-2014 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.
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.
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.
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/>.
24 /** @file profile/impl/profiler_hash_func.h
25 * @brief Data structures to represent profiling traces.
28 // Written by Lixia Liu and Silvius Rus.
30 #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H
31 #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1
33 #include "profile/impl/profiler.h"
34 #include "profile/impl/profiler_node.h"
35 #include "profile/impl/profiler_trace.h"
37 namespace __gnu_profile
39 /** @brief A hash performance instrumentation line in the object table. */
40 class __hashfunc_info
41 : public __object_info_base
43 public:
44 __hashfunc_info(__stack_t __stack)
45 : __object_info_base(__stack), _M_longest_chain(0),
46 _M_accesses(0), _M_hops(0) { }
48 void
49 __merge(const __hashfunc_info& __o)
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;
57 void
58 __destruct(std::size_t __chain, std::size_t __accesses,
59 std::size_t __hops)
61 _M_longest_chain = std::max(_M_longest_chain, __chain);
62 _M_accesses += __accesses;
63 _M_hops += __hops;
66 void
67 __write(FILE* __f) const
68 { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
69 _M_accesses, _M_longest_chain); }
71 float
72 __magnitude() const
73 { return static_cast<float>(_M_hops); }
75 std::string
76 __advice() const
77 { return "change hash function"; }
79 private:
80 std::size_t _M_longest_chain;
81 std::size_t _M_accesses;
82 std::size_t _M_hops;
85 /** @brief A hash performance instrumentation line in the stack table. */
86 class __hashfunc_stack_info
87 : public __hashfunc_info
89 public:
90 __hashfunc_stack_info(const __hashfunc_info& __o)
91 : __hashfunc_info(__o) { }
94 /** @brief Hash performance instrumentation producer. */
95 class __trace_hash_func
96 : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
98 public:
99 __trace_hash_func()
100 : __trace_base<__hashfunc_info, __hashfunc_stack_info>()
101 { __id = "hash-distr"; }
103 ~__trace_hash_func() {}
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)
110 if (!__obj_info)
111 return;
113 __obj_info->__destruct(__chain, __accesses, __hops);
114 __retire_object(__obj_info);
118 inline void
119 __trace_hash_func_init()
120 { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
122 inline void
123 __trace_hash_func_free()
124 { delete _GLIBCXX_PROFILE_DATA(_S_hash_func); }
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); }
130 inline __hashfunc_info*
131 __trace_hash_func_construct()
133 if (!__profcxx_init())
134 return 0;
136 if (!__reentrance_guard::__get_in())
137 return 0;
139 __reentrance_guard __get_out;
140 return _GLIBCXX_PROFILE_DATA(_S_hash_func)->__add_object(__get_stack());
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)
148 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj_info, __chain,
149 __accesses, __hops);
152 } // namespace __gnu_profile
153 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */