• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/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/
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.
10
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.
15
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.
20
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.
30
31/** @file profile/impl/profiler_list_to_slist.h
32 *  @brief Diagnostics for list to slist.
33 */
34
35// Written by Changhee Jung.
36
37#ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H
38#define _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H 1
39
40#ifdef __GXX_EXPERIMENTAL_CXX0X__
41#include <cstdlib>
42#include <cstdio>
43#include <cstring>
44#else
45#include <stdlib.h>
46#include <stdio.h>
47#include <string.h>
48#endif
49#include "profile/impl/profiler.h"
50#include "profile/impl/profiler_node.h"
51#include "profile/impl/profiler_trace.h"
52
53namespace __gnu_profile
54{
55
56class __list2slist_info: public __object_info_base
57{
58 public:
59  __list2slist_info() : _M_rewind(false), _M_operations(0) {}
60  __list2slist_info(__stack_t __stack)
61      : _M_rewind(false), _M_operations(0),__object_info_base(__stack) {}
62  virtual ~__list2slist_info() {}
63  __list2slist_info(const __list2slist_info& __o) : __object_info_base(__o)
64  { _M_rewind = __o._M_rewind; _M_operations = __o._M_operations; }
65  // XXX: the magnitude should be multiplied with a constant factor F,
66  // where F is 1 when the malloc size class of list nodes is different
67  // from the malloc size class of slist nodes.  When they fall into the same
68  // class, the only slist benefit is from having to set fewer links, so
69  // the factor F should be much smaller, closer to 0 than to 1.
70  // This could be implemented by passing the size classes in the config file.
71  // For now, we always assume F to be 1.
72  float __magnitude() const
73  { if (!_M_rewind) return _M_operations; else return 0; }
74  void __merge(const __list2slist_info& __o) {};
75  void __write(FILE* __f) const;
76  const char* __advice() const
77  { return strdup("change std::list to std::forward_list"); }
78  void __opr_rewind() { _M_rewind = true; _M_valid = false;}
79  void __record_operation() { _M_operations++; }
80  bool __has_rewind() { return _M_rewind; }
81
82private:
83  bool _M_rewind;
84  size_t _M_operations;
85};
86
87class __list2slist_stack_info: public __list2slist_info {
88 public:
89  __list2slist_stack_info(const __list2slist_info& __o)
90      : __list2slist_info(__o) {}
91};
92
93class __trace_list_to_slist
94    : public __trace_base<__list2slist_info, __list2slist_stack_info>
95{
96 public:
97  ~__trace_list_to_slist() {}
98  __trace_list_to_slist()
99      : __trace_base<__list2slist_info, __list2slist_stack_info>()
100  { __id = "list-to-slist"; }
101  void __opr_rewind(const void* __obj);
102  void __record_operation(const void* __obj);
103  void __insert(const __object_t __obj, __stack_t __stack)
104  { __add_object(__obj, __list2slist_info(__stack)); }
105  void __destruct(const void* __obj);
106};
107
108inline void __list2slist_info::__write(FILE* __f) const
109{
110  fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid");
111}
112
113inline void __trace_list_to_slist::__destruct(const void* __obj)
114{
115  if (!__is_on())
116    return;
117
118  __list2slist_info* __res = __get_object_info(__obj);
119  if (!__res)
120    return;
121
122  __retire_object(__obj);
123}
124
125inline void __trace_list_to_slist_init()
126{
127  _GLIBCXX_PROFILE_DATA(_S_list_to_slist) = new __trace_list_to_slist();
128}
129
130inline void __trace_list_to_slist_report(FILE* __f,
131                                       __warning_vector_t& __warnings)
132{
133  if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist)) {
134    _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__collect_warnings(__warnings);
135    _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__write(__f);
136  }
137}
138
139inline void __trace_list_to_slist::__opr_rewind(const void* __obj)
140{
141  __list2slist_info* __res = __get_object_info(__obj);
142  if (__res)
143    __res->__opr_rewind();
144}
145
146inline void __trace_list_to_slist::__record_operation(const void* __obj)
147{
148  __list2slist_info* __res = __get_object_info(__obj);
149  if (__res)
150    __res->__record_operation();
151}
152
153inline void __trace_list_to_slist_rewind(const void* __obj)
154{
155  if (!__profcxx_init()) return;
156
157  _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj);
158}
159
160inline void __trace_list_to_slist_operation(const void* __obj)
161{
162  if (!__profcxx_init()) return;
163
164  _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj);
165}
166
167inline void __trace_list_to_slist_construct(const void* __obj)
168{
169  if (!__profcxx_init()) return;
170
171  _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack());
172}
173
174inline void __trace_list_to_slist_destruct(const void* __obj)
175{
176  if (!__profcxx_init()) return;
177
178  _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj);
179}
180
181} // namespace __gnu_profile
182#endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */
183