RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / include / c++ / 4.5.3 / profile / impl / profiler_node.h
blob77654a8f813e5f998673efc2044b84fb876641be
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009 Free Software Foundation, Inc.
4 //
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
9 // version.
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
29 // Public License.
31 /** @file profile/impl/profiler_node.h
32 * @brief Data structures to represent a single profiling event.
35 // Written by Lixia Liu and Silvius Rus.
37 #ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H
38 #define _GLIBCXX_PROFILE_PROFILER_NODE_H 1
40 #ifdef __GXX_EXPERIMENTAL_CXX0X__
41 #include <cstdio>
42 #include <cstdint>
43 #include <cstring>
44 #else
45 #include <stdio.h>
46 #include <stdint.h>
47 #include <string.h>
48 #endif
49 #include <vector>
50 #if defined _GLIBCXX_HAVE_EXECINFO_H
51 #include <execinfo.h>
52 #endif
54 namespace __gnu_profile
56 typedef const void* __object_t;
57 typedef void* __instruction_address_t;
58 typedef std::_GLIBCXX_STD_PR::vector<__instruction_address_t> __stack_npt;
59 typedef __stack_npt* __stack_t;
61 size_t __stack_max_depth();
63 inline __stack_t __get_stack()
65 #if defined _GLIBCXX_HAVE_EXECINFO_H
66 size_t __max_depth = __stack_max_depth();
67 if (__max_depth == 0)
68 return NULL;
69 __stack_npt __buffer(__max_depth);
70 int __depth = backtrace(&__buffer[0], __max_depth);
71 __stack_t __stack = new __stack_npt(__depth);
72 memcpy(&(*__stack)[0], &__buffer[0], __depth * sizeof(__object_t));
73 return __stack;
74 #else
75 return NULL;
76 #endif
79 inline __size(const __stack_t& __stack)
81 if (!__stack) {
82 return 0;
83 } else {
84 return __stack->size();
88 inline void __write(FILE* __f, const __stack_t __stack)
90 if (!__stack) {
91 return;
94 __stack_npt::const_iterator __it;
95 for (__it = __stack->begin(); __it != __stack->end(); ++__it) {
96 fprintf(__f, "%p ", *__it);
100 /** @brief Hash function for summary trace using call stack as index. */
101 class __stack_hash
103 public:
104 size_t operator()(const __stack_t __s) const
106 if (!__s) {
107 return 0;
110 uintptr_t __index = 0;
111 __stack_npt::const_iterator __it;
112 for (__it = __s->begin(); __it != __s->end(); ++__it) {
113 __index += reinterpret_cast<uintptr_t>(*__it);
115 return __index;
118 bool operator() (const __stack_t __stack1, const __stack_t __stack2) const
120 if (!__stack1 && !__stack2) return true;
121 if (!__stack1 || !__stack2) return false;
122 if (__stack1->size() != __stack2->size()) return false;
124 size_t __byte_size = __stack1->size() * sizeof(__stack_npt::value_type);
125 return memcmp(&(*__stack1)[0], &(*__stack2)[0], __byte_size) == 0;
129 /** @brief Base class for a line in the object table. */
130 class __object_info_base
132 public:
133 __object_info_base() {}
134 __object_info_base(__stack_t __stack);
135 __object_info_base(const __object_info_base& o);
136 virtual ~__object_info_base() {}
137 bool __is_valid() const { return _M_valid; }
138 __stack_t __stack() const { return _M_stack; }
139 virtual void __write(FILE* f) const = 0;
141 protected:
142 __stack_t _M_stack;
143 bool _M_valid;
146 inline __object_info_base::__object_info_base(__stack_t __stack)
148 _M_stack = __stack;
149 _M_valid = true;
152 inline __object_info_base::__object_info_base(const __object_info_base& __o)
154 _M_stack = __o._M_stack;
155 _M_valid = __o._M_valid;
158 /** @brief Base class for a line in the stack table. */
159 template<typename __object_info>
160 class __stack_info_base
162 public:
163 __stack_info_base() {}
164 __stack_info_base(const __object_info& __info) = 0;
165 virtual ~__stack_info_base() {}
166 void __merge(const __object_info& __info) = 0;
167 virtual float __magnitude() const = 0;
168 virtual const char* __get_id() const = 0;
171 } // namespace __gnu_profile
172 #endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */