3 // Copyright (C) 2009, 2010 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 /** @file profile/impl/profiler_trace.h
32 * @brief Data structures to represent profiling traces.
35 // Written by Lixia Liu and Silvius Rus.
37 #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H
38 #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1
40 #include "profile/impl/profiler.h"
41 #include "profile/impl/profiler_node.h"
42 #include "profile/impl/profiler_trace.h"
44 namespace __gnu_profile
46 /** @brief A hash performance instrumentation line in the object table. */
48 : public __object_info_base
52 : _M_longest_chain(0), _M_accesses(0), _M_hops(0) { }
54 __hashfunc_info(const __hashfunc_info& __o)
55 : __object_info_base(__o), _M_longest_chain(__o._M_longest_chain),
56 _M_accesses(__o._M_accesses), _M_hops(__o._M_hops) { }
58 __hashfunc_info(__stack_t __stack)
59 : __object_info_base(__stack), _M_longest_chain(0),
60 _M_accesses(0), _M_hops(0) { }
62 virtual ~__hashfunc_info() { }
65 __merge(const __hashfunc_info& __o)
67 _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain);
68 _M_accesses += __o._M_accesses;
69 _M_hops += __o._M_hops;
73 __destruct(std::size_t __chain, std::size_t __accesses,
76 _M_longest_chain = std::max(_M_longest_chain, __chain);
77 _M_accesses += __accesses;
82 __write(FILE* __f) const
83 { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
84 _M_accesses, _M_longest_chain); }
88 { return static_cast<float>(_M_hops); }
92 { return "change hash function"; }
95 std::size_t _M_longest_chain;
96 std::size_t _M_accesses;
101 /** @brief A hash performance instrumentation line in the stack table. */
102 class __hashfunc_stack_info
103 : public __hashfunc_info
106 __hashfunc_stack_info(const __hashfunc_info& __o)
107 : __hashfunc_info(__o) { }
111 /** @brief Hash performance instrumentation producer. */
112 class __trace_hash_func
113 : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
117 : __trace_base<__hashfunc_info, __hashfunc_stack_info>()
118 { __id = "hash-distr"; }
120 ~__trace_hash_func() {}
122 // Insert a new node at construct with object, callstack and initial size.
124 __insert(__object_t __obj, __stack_t __stack)
125 { __add_object(__obj, __hashfunc_info(__stack)); }
127 // Call at destruction/clean to set container final size.
129 __destruct(const void* __obj, std::size_t __chain,
130 std::size_t __accesses, std::size_t __hops)
135 // First find the item from the live objects and update the informations.
136 __hashfunc_info* __objs = __get_object_info(__obj);
140 __objs->__destruct(__chain, __accesses, __hops);
141 __retire_object(__obj);
147 __trace_hash_func_init()
148 { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
151 __trace_hash_func_report(FILE* __f, __warning_vector_t& __warnings)
153 if (_GLIBCXX_PROFILE_DATA(_S_hash_func))
155 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__collect_warnings(__warnings);
156 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f);
161 __trace_hash_func_construct(const void* __obj)
163 if (!__profcxx_init())
166 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack());
170 __trace_hash_func_destruct(const void* __obj, std::size_t __chain,
171 std::size_t __accesses, std::size_t __hops)
173 if (!__profcxx_init())
176 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain,
180 } // namespace __gnu_profile
181 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */