3 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
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)
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. */
41 : public __object_info_base
44 __hashfunc_info(__stack_t __stack
)
45 : __object_info_base(__stack
), _M_longest_chain(0),
46 _M_accesses(0), _M_hops(0) { }
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
;
58 __destruct(std::size_t __chain
, std::size_t __accesses
,
61 _M_longest_chain
= std::max(_M_longest_chain
, __chain
);
62 _M_accesses
+= __accesses
;
67 __write(FILE* __f
) const
68 { std::fprintf(__f
, "%Zu %Zu %Zu\n", _M_hops
,
69 _M_accesses
, _M_longest_chain
); }
73 { return static_cast<float>(_M_hops
); }
77 { return "change hash function"; }
80 std::size_t _M_longest_chain
;
81 std::size_t _M_accesses
;
85 /** @brief A hash performance instrumentation line in the stack table. */
86 class __hashfunc_stack_info
87 : public __hashfunc_info
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
>
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.
107 __destruct(__hashfunc_info
* __obj_info
,
108 std::size_t __chain
, std::size_t __accesses
, std::size_t __hops
)
113 __obj_info
->__destruct(__chain
, __accesses
, __hops
);
114 __retire_object(__obj_info
);
119 __trace_hash_func_init()
120 { _GLIBCXX_PROFILE_DATA(_S_hash_func
) = new __trace_hash_func(); }
123 __trace_hash_func_free()
124 { delete _GLIBCXX_PROFILE_DATA(_S_hash_func
); }
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())
136 if (!__reentrance_guard::__get_in())
139 __reentrance_guard __get_out
;
140 return _GLIBCXX_PROFILE_DATA(_S_hash_func
)->__add_object(__get_stack());
144 __trace_hash_func_destruct(__hashfunc_info
* __obj_info
,
145 std::size_t __chain
, std::size_t __accesses
,
148 _GLIBCXX_PROFILE_DATA(_S_hash_func
)->__destruct(__obj_info
, __chain
,
152 } // namespace __gnu_profile
153 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */