]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/profile/impl/profiler_node.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / impl / profiler_node.h
CommitLineData
1218d701
SR
1// -*- C++ -*-
2//
cbe34bb5 3// Copyright (C) 2009-2017 Free Software Foundation, Inc.
1218d701
SR
4//
5// This file is part of the GNU ISO C++ Library. This library is free
4bee90f7
PC
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.
1889b253
PC
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
4bee90f7
PC
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/>.
1218d701
SR
23
24/** @file profile/impl/profiler_node.h
25 * @brief Data structures to represent a single profiling event.
26 */
27
28// Written by Lixia Liu and Silvius Rus.
29
6b223191
BK
30#ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H
31#define _GLIBCXX_PROFILE_PROFILER_NODE_H 1
1218d701 32
c7d42abb
PC
33#include <cstdio> // FILE, fprintf
34
1218d701 35#include <vector>
a1360f57 36#if defined _GLIBCXX_HAVE_EXECINFO_H
1218d701
SR
37#include <execinfo.h>
38#endif
39
9ee6a740 40namespace __gnu_profile
1218d701 41{
b0af13ea 42 typedef void* __instruction_address_t;
12ffa228 43 typedef std::_GLIBCXX_STD_C::vector<__instruction_address_t> __stack_npt;
b0af13ea 44 typedef __stack_npt* __stack_t;
1218d701 45
c7d42abb 46 std::size_t __stack_max_depth();
1218d701 47
b0af13ea
PC
48 inline __stack_t
49 __get_stack()
50 {
a1360f57 51#if defined _GLIBCXX_HAVE_EXECINFO_H
b12db708
FD
52 __try
53 {
54 std::size_t __max_depth = __stack_max_depth();
55 if (__max_depth == 0)
56 return 0;
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);
61 }
62 __catch(...)
63 {
64 return 0;
65 }
a1360f57 66#else
a1360f57 67 return 0;
b0af13ea 68#endif
1218d701 69 }
1218d701 70
c7d42abb 71 inline std::size_t
b0af13ea 72 __size(__stack_t __stack)
1218d701 73 {
b0af13ea 74 if (!__stack)
a1360f57 75 return 0;
b0af13ea
PC
76 else
77 return __stack->size();
78 }
1218d701 79
b0af13ea
PC
80 // XXX
81 inline void
82 __write(FILE* __f, __stack_t __stack)
83 {
84 if (!__stack)
85 return;
86
1218d701 87 __stack_npt::const_iterator __it;
b0af13ea 88 for (__it = __stack->begin(); __it != __stack->end(); ++__it)
c7d42abb 89 std::fprintf(__f, "%p ", *__it);
1218d701
SR
90 }
91
b0af13ea
PC
92 /** @brief Hash function for summary trace using call stack as index. */
93 class __stack_hash
1218d701 94 {
b0af13ea 95 public:
c7d42abb 96 std::size_t
b0af13ea
PC
97 operator()(__stack_t __s) const
98 {
99 if (!__s)
100 return 0;
101
e65cf3bc 102 std::size_t __index = 0;
b0af13ea
PC
103 __stack_npt::const_iterator __it;
104 for (__it = __s->begin(); __it != __s->end(); ++__it)
e65cf3bc 105 __index += reinterpret_cast<std::size_t>(*__it);
b0af13ea
PC
106 return __index;
107 }
1218d701 108
b0af13ea
PC
109 bool operator() (__stack_t __stack1, __stack_t __stack2) const
110 {
111 if (!__stack1 && !__stack2)
112 return true;
113 if (!__stack1 || !__stack2)
114 return false;
115 if (__stack1->size() != __stack2->size())
116 return false;
117
c7d42abb
PC
118 std::size_t __byte_size
119 = __stack1->size() * sizeof(__stack_npt::value_type);
120 return __builtin_memcmp(&(*__stack1)[0], &(*__stack2)[0],
121 __byte_size) == 0;
b0af13ea
PC
122 }
123 };
1218d701 124
1218d701 125
b0af13ea
PC
126 /** @brief Base class for a line in the object table. */
127 class __object_info_base
128 {
129 public:
b0af13ea
PC
130 __object_info_base(__stack_t __stack)
131 : _M_stack(__stack), _M_valid(true) { }
132
b0af13ea
PC
133 bool
134 __is_valid() const
135 { return _M_valid; }
136
b12db708
FD
137 void
138 __set_invalid()
139 { _M_valid = false; }
140
141 void
142 __merge(const __object_info_base& __o)
143 { _M_valid &= __o._M_valid; }
144
b0af13ea
PC
145 __stack_t
146 __stack() const
147 { return _M_stack; }
148
b0af13ea
PC
149 protected:
150 __stack_t _M_stack;
151 bool _M_valid;
152 };
153
9ee6a740 154} // namespace __gnu_profile
6b223191 155#endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */