OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [include/] [profile/] [impl/] [profiler_container_size.h] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// -*- C++ -*-
2
//
3
// Copyright (C) 2009, 2010 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_trace.h
32
 *  @brief Diagnostics for container sizes.
33
 */
34
 
35
// Written by Lixia Liu and Silvius Rus.
36
 
37
#ifndef _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H
38
#define _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_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
 
50
#include <sstream>
51
 
52
#include "profile/impl/profiler.h"
53
#include "profile/impl/profiler_node.h"
54
#include "profile/impl/profiler_trace.h"
55
 
56
namespace __gnu_profile
57
{
58
 
59
/** @brief A container size instrumentation line in the object table.  */
60
class __container_size_info: public __object_info_base
61
{
62
 public:
63
  __container_size_info();
64
  __container_size_info(const __container_size_info& __o);
65
  __container_size_info(__stack_t __stack, size_t __num);
66
  virtual ~__container_size_info() {}
67
 
68
  void __write(FILE* f) const;
69
  float __magnitude() const { return static_cast<float>(_M_cost); }
70
  const char* __advice() const;
71
 
72
  void __merge(const __container_size_info& __o);
73
  // Call if a container is destructed or cleaned.
74
  void __destruct(size_t __num, size_t __inum);
75
  // Estimate the cost of resize/rehash. 
76
  float __resize_cost(size_t __from, size_t __to) { return __from; }
77
  // Call if container is resized.
78
  void __resize(size_t __from, size_t __to);
79
 
80
 private:
81
  size_t _M_init;
82
  size_t _M_max;  // range of # buckets
83
  size_t _M_min;
84
  size_t _M_total;
85
  size_t _M_item_min;  // range of # items
86
  size_t _M_item_max;
87
  size_t _M_item_total;
88
  size_t _M_count;
89
  size_t _M_resize;
90
  size_t _M_cost;
91
};
92
 
93
inline const char* __container_size_info::__advice() const
94
{
95
  std::stringstream __message;
96
  if (_M_init < _M_item_max)
97
    __message << "change initial container size from " << _M_init
98
              << " to " << _M_item_max;
99
 
100
  return strdup(__message.str().c_str());
101
}
102
 
103
inline void __container_size_info::__destruct(size_t __num, size_t __inum)
104
{
105
  _M_max = std::max(_M_max, __num);
106
  _M_item_max = std::max(_M_item_max, __inum);
107
  if (_M_min == 0) {
108
    _M_min = __num;
109
    _M_item_min = __inum;
110
  } else {
111
    _M_min = std::min(_M_min, __num);
112
    _M_item_min = std::min(_M_item_min, __inum);
113
  }
114
  _M_total += __num;
115
  _M_item_total += __inum;
116
  _M_count += 1;
117
}
118
 
119
inline void __container_size_info::__resize(size_t __from, size_t __to)
120
{
121
  _M_cost += this->__resize_cost(__from, __to);
122
  _M_resize += 1;
123
  _M_max = std::max(_M_max, __to);
124
}
125
 
126
inline __container_size_info::__container_size_info(__stack_t __stack,
127
                                                    size_t __num)
128
    : __object_info_base(__stack), _M_init(0), _M_max(0), _M_item_max(0),
129
      _M_min(0), _M_item_min(0), _M_total(0), _M_item_total(0), _M_cost(0),
130
      _M_count(0), _M_resize(0)
131
{
132
  _M_init = _M_max = __num;
133
  _M_item_min = _M_item_max = _M_item_total = _M_total = 0;
134
  _M_min = 0;
135
  _M_count = 0;
136
  _M_resize = 0;
137
}
138
 
139
inline void __container_size_info::__merge(const __container_size_info& __o)
140
{
141
  _M_init        = std::max(_M_init, __o._M_init);
142
  _M_max         = std::max(_M_max, __o._M_max);
143
  _M_item_max    = std::max(_M_item_max, __o._M_item_max);
144
  _M_min         = std::min(_M_min, __o._M_min);
145
  _M_item_min    = std::min(_M_item_min, __o._M_item_min);
146
  _M_total      += __o._M_total;
147
  _M_item_total += __o._M_item_total;
148
  _M_count      += __o._M_count;
149
  _M_cost       += __o._M_cost;
150
  _M_resize     += __o._M_resize;
151
}
152
 
153
inline __container_size_info::__container_size_info()
154
    : _M_init(0), _M_max(0), _M_item_max(0), _M_min(0), _M_item_min(0),
155
      _M_total(0), _M_item_total(0), _M_cost(0), _M_count(0), _M_resize(0)
156
{
157
}
158
 
159
inline __container_size_info::__container_size_info(
160
    const __container_size_info& __o)
161
    : __object_info_base(__o)
162
{
163
  _M_init        = __o._M_init;
164
  _M_max         = __o._M_max;
165
  _M_item_max    = __o._M_item_max;
166
  _M_min         = __o._M_min;
167
  _M_item_min    = __o._M_item_min;
168
  _M_total       = __o._M_total;
169
  _M_item_total  = __o._M_item_total;
170
  _M_cost        = __o._M_cost;
171
  _M_count       = __o._M_count;
172
  _M_resize      = __o._M_resize;
173
}
174
 
175
/** @brief A container size instrumentation line in the stack table.  */
176
class __container_size_stack_info: public __container_size_info
177
{
178
 public:
179
  __container_size_stack_info(const __container_size_info& __o)
180
      : __container_size_info(__o) {}
181
};
182
 
183
/** @brief Container size instrumentation trace producer.  */
184
class __trace_container_size
185
    : public __trace_base<__container_size_info, __container_size_stack_info>
186
{
187
 public:
188
  ~__trace_container_size() {}
189
  __trace_container_size()
190
      : __trace_base<__container_size_info, __container_size_stack_info>() {};
191
 
192
  // Insert a new node at construct with object, callstack and initial size. 
193
  void __insert(const __object_t __obj, __stack_t __stack, size_t __num);
194
  // Call at destruction/clean to set container final size.
195
  void __destruct(const void* __obj, size_t __num, size_t __inum);
196
  void __construct(const void* __obj, size_t __inum);
197
  // Call at resize to set resize/cost information.
198
  void __resize(const void* __obj, int __from, int __to);
199
};
200
 
201
inline void __trace_container_size::__insert(const __object_t __obj,
202
                                             __stack_t __stack, size_t __num)
203
{
204
  __add_object(__obj, __container_size_info(__stack, __num));
205
}
206
 
207
inline void __container_size_info::__write(FILE* __f) const
208
{
209
  fprintf(__f, "%Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu\n",
210
          _M_init, _M_count, _M_cost, _M_resize, _M_min, _M_max, _M_total,
211
          _M_item_min, _M_item_max, _M_item_total);
212
}
213
 
214
inline void __trace_container_size::__destruct(const void* __obj,
215
                                               size_t __num, size_t __inum)
216
{
217
  if (!__is_on()) return;
218
 
219
  __object_t __obj_handle = static_cast<__object_t>(__obj);
220
 
221
  __container_size_info* __object_info = __get_object_info(__obj_handle);
222
  if (!__object_info)
223
    return;
224
 
225
  __object_info->__destruct(__num, __inum);
226
  __retire_object(__obj_handle);
227
}
228
 
229
inline void __trace_container_size::__resize(const void* __obj, int __from,
230
                                             int __to)
231
{
232
  if (!__is_on()) return;
233
 
234
  __container_size_info* __object_info = __get_object_info(__obj);
235
  if (!__object_info)
236
    return;
237
 
238
  __object_info->__resize(__from, __to);
239
}
240
 
241
} // namespace __gnu_profile
242
#endif /* _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.