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_node.h
25 * @brief Data structures to represent a single profiling event.
28 // Written by Lixia Liu and Silvius Rus.
30 #ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H
31 #define _GLIBCXX_PROFILE_PROFILER_NODE_H 1
33 #include <cstdio> // FILE, fprintf
36 #if defined _GLIBCXX_HAVE_EXECINFO_H
40 namespace __gnu_profile
42 typedef void* __instruction_address_t
;
43 typedef std::_GLIBCXX_STD_C::vector
<__instruction_address_t
> __stack_npt
;
44 typedef __stack_npt
* __stack_t
;
46 std::size_t __stack_max_depth();
51 #if defined _GLIBCXX_HAVE_EXECINFO_H
54 std::size_t __max_depth
= __stack_max_depth();
57 __stack_npt
__buffer(__max_depth
);
58 int __depth
= backtrace(&__buffer
[0], __max_depth
);
59 return new(std::nothrow
) __stack_npt(__buffer
.begin(),
60 __buffer
.begin() + __depth
);
72 __size(__stack_t __stack
)
77 return __stack
->size();
82 __write(FILE* __f
, __stack_t __stack
)
87 __stack_npt::const_iterator __it
;
88 for (__it
= __stack
->begin(); __it
!= __stack
->end(); ++__it
)
89 std::fprintf(__f
, "%p ", *__it
);
92 /** @brief Hash function for summary trace using call stack as index. */
97 operator()(__stack_t __s
) const
102 std::size_t __index
= 0;
103 __stack_npt::const_iterator __it
;
104 for (__it
= __s
->begin(); __it
!= __s
->end(); ++__it
)
105 __index
+= reinterpret_cast<std::size_t>(*__it
);
109 bool operator() (__stack_t __stack1
, __stack_t __stack2
) const
111 if (!__stack1
&& !__stack2
)
113 if (!__stack1
|| !__stack2
)
115 if (__stack1
->size() != __stack2
->size())
118 std::size_t __byte_size
119 = __stack1
->size() * sizeof(__stack_npt::value_type
);
120 return __builtin_memcmp(&(*__stack1
)[0], &(*__stack2
)[0],
126 /** @brief Base class for a line in the object table. */
127 class __object_info_base
130 __object_info_base(__stack_t __stack
)
131 : _M_stack(__stack
), _M_valid(true) { }
139 { _M_valid
= false; }
142 __merge(const __object_info_base
& __o
)
143 { _M_valid
&= __o
._M_valid
; }
154 } // namespace __gnu_profile
155 #endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */