]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/profile/impl/profiler_node.h
avr.md (neghi2): Remove "!d,0" alternative.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / impl / profiler_node.h
CommitLineData
1218d701
SR
1// -*- C++ -*-
2//
e65cf3bc 3// Copyright (C) 2009, 2010, 2011 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.
15//
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
1218d701
SR
19
20/** @file profile/impl/profiler_node.h
21 * @brief Data structures to represent a single profiling event.
22 */
23
24// Written by Lixia Liu and Silvius Rus.
25
6b223191
BK
26#ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H
27#define _GLIBCXX_PROFILE_PROFILER_NODE_H 1
1218d701 28
c7d42abb
PC
29#include <cstdio> // FILE, fprintf
30
1218d701 31#include <vector>
a1360f57 32#if defined _GLIBCXX_HAVE_EXECINFO_H
1218d701
SR
33#include <execinfo.h>
34#endif
35
9ee6a740 36namespace __gnu_profile
1218d701 37{
b0af13ea
PC
38 typedef const void* __object_t;
39 typedef void* __instruction_address_t;
12ffa228 40 typedef std::_GLIBCXX_STD_C::vector<__instruction_address_t> __stack_npt;
b0af13ea 41 typedef __stack_npt* __stack_t;
1218d701 42
c7d42abb 43 std::size_t __stack_max_depth();
1218d701 44
b0af13ea
PC
45 inline __stack_t
46 __get_stack()
47 {
a1360f57 48#if defined _GLIBCXX_HAVE_EXECINFO_H
c7d42abb 49 std::size_t __max_depth = __stack_max_depth();
b0af13ea
PC
50 if (__max_depth == 0)
51 return 0;
52 __stack_npt __buffer(__max_depth);
53 int __depth = backtrace(&__buffer[0], __max_depth);
54 __stack_t __stack = new __stack_npt(__depth);
c7d42abb
PC
55 __builtin_memcpy(&(*__stack)[0], &__buffer[0],
56 __depth * sizeof(__object_t));
b0af13ea 57 return __stack;
a1360f57 58#else
a1360f57 59 return 0;
b0af13ea 60#endif
1218d701 61 }
1218d701 62
c7d42abb 63 inline std::size_t
b0af13ea 64 __size(__stack_t __stack)
1218d701 65 {
b0af13ea 66 if (!__stack)
a1360f57 67 return 0;
b0af13ea
PC
68 else
69 return __stack->size();
70 }
1218d701 71
b0af13ea
PC
72 // XXX
73 inline void
74 __write(FILE* __f, __stack_t __stack)
75 {
76 if (!__stack)
77 return;
78
1218d701 79 __stack_npt::const_iterator __it;
b0af13ea 80 for (__it = __stack->begin(); __it != __stack->end(); ++__it)
c7d42abb 81 std::fprintf(__f, "%p ", *__it);
1218d701
SR
82 }
83
b0af13ea
PC
84 /** @brief Hash function for summary trace using call stack as index. */
85 class __stack_hash
1218d701 86 {
b0af13ea 87 public:
c7d42abb 88 std::size_t
b0af13ea
PC
89 operator()(__stack_t __s) const
90 {
91 if (!__s)
92 return 0;
93
e65cf3bc 94 std::size_t __index = 0;
b0af13ea
PC
95 __stack_npt::const_iterator __it;
96 for (__it = __s->begin(); __it != __s->end(); ++__it)
e65cf3bc 97 __index += reinterpret_cast<std::size_t>(*__it);
b0af13ea
PC
98 return __index;
99 }
1218d701 100
b0af13ea
PC
101 bool operator() (__stack_t __stack1, __stack_t __stack2) const
102 {
103 if (!__stack1 && !__stack2)
104 return true;
105 if (!__stack1 || !__stack2)
106 return false;
107 if (__stack1->size() != __stack2->size())
108 return false;
109
c7d42abb
PC
110 std::size_t __byte_size
111 = __stack1->size() * sizeof(__stack_npt::value_type);
112 return __builtin_memcmp(&(*__stack1)[0], &(*__stack2)[0],
113 __byte_size) == 0;
b0af13ea
PC
114 }
115 };
1218d701 116
1218d701 117
b0af13ea
PC
118 /** @brief Base class for a line in the object table. */
119 class __object_info_base
120 {
121 public:
122 __object_info_base() { }
123
124 __object_info_base(__stack_t __stack)
125 : _M_stack(__stack), _M_valid(true) { }
126
127 __object_info_base(const __object_info_base& __o)
128 : _M_stack(__o._M_stack), _M_valid(__o._M_valid) { }
129
130 virtual ~__object_info_base() { }
131
132 bool
133 __is_valid() const
134 { return _M_valid; }
135
136 __stack_t
137 __stack() const
138 { return _M_stack; }
139
6e687a9a 140 virtual void __write(FILE* __f) const = 0;
b0af13ea
PC
141
142 protected:
143 __stack_t _M_stack;
144 bool _M_valid;
145 };
146
147
148 /** @brief Base class for a line in the stack table. */
149 template<typename __object_info>
150 class __stack_info_base
151 {
152 public:
153 __stack_info_base() { }
154 __stack_info_base(const __object_info& __info) = 0;
155 virtual ~__stack_info_base() {}
156 void __merge(const __object_info& __info) = 0;
157 virtual float __magnitude() const = 0;
158 virtual const char* __get_id() const = 0;
159 };
1218d701 160
9ee6a740 161} // namespace __gnu_profile
6b223191 162#endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */