2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
37 #include "base/callback.hh"
38 #include "base/cprintf.hh"
39 #include "base/debug.hh"
40 #include "base/hostinfo.hh"
41 #include "base/misc.hh"
42 #include "base/statistics.hh"
43 #include "base/str.hh"
44 #include "base/time.hh"
45 #include "base/trace.hh"
51 typedef map
<const void *, Info
*> MapType
;
53 // We wrap these in a function to make sure they're built in time.
57 static list
<Info
*> the_list
;
64 static MapType the_map
;
69 InfoAccess::setInfo(Info
*info
)
71 if (statsMap().find(this) != statsMap().end())
72 panic("shouldn't register stat twice!");
74 statsList().push_back(info
);
77 pair
<MapType::iterator
, bool> result
=
79 statsMap().insert(make_pair(this, info
));
80 assert(result
.second
&& "this should never fail");
81 assert(statsMap().find(this) != statsMap().end());
85 InfoAccess::setParams(const StorageParams
*params
)
87 info()->storageParams
= params
;
93 info()->flags
.set(init
);
99 MapType::const_iterator i
= statsMap().find(this);
100 assert(i
!= statsMap().end());
105 InfoAccess::info() const
107 MapType::const_iterator i
= statsMap().find(this);
108 assert(i
!= statsMap().end());
112 StorageParams::~StorageParams()
116 typedef map
<std::string
, Info
*> NameMapType
;
120 static NameMapType the_map
;
124 int Info::id_count
= 0;
126 int debug_break_id
= -1;
129 : flags(none
), precision(-1), prereq(0), storageParams(NULL
)
132 if (debug_break_id
>= 0 and debug_break_id
== id
)
141 Info::setName(const string
&name
)
143 pair
<NameMapType::iterator
, bool> p
=
144 nameMap().insert(make_pair(name
, this));
146 Info
*other
= p
.first
->second
;
147 bool result
= p
.second
;
150 // using other->name instead of just name to avoid a compiler
151 // warning. They should be the same.
152 panic("same statistic name used twice! name=%s\n", other
->name
);
159 Info::less(Info
*stat1
, Info
*stat2
)
161 const string
&name1
= stat1
->name
;
162 const string
&name2
= stat2
->name
;
167 tokenize(v1
, name1
, '.');
168 tokenize(v2
, name2
, '.');
170 size_type last
= min(v1
.size(), v2
.size()) - 1;
171 for (off_type i
= 0; i
< last
; ++i
)
173 return v1
[i
] < v2
[i
];
175 // Special compare for last element.
176 if (v1
[last
] == v2
[last
])
177 return v1
.size() < v2
.size();
179 return v1
[last
] < v2
[last
];
185 Info::baseCheck() const
187 if (!(flags
& Stats::init
)) {
189 cprintf("this is stat number %d\n", id
);
191 panic("Not all stats have been initialized");
195 if ((flags
& display
) && name
.empty()) {
196 panic("all printable stats must be named");
211 size_type s
= size();
212 if (subnames
.size() < s
)
214 if (subdescs
.size() < s
)
219 VectorDistInfo::enable()
221 size_type s
= size();
222 if (subnames
.size() < s
)
224 if (subdescs
.size() < s
)
229 Vector2dInfo::enable()
231 if (subnames
.size() < x
)
233 if (subdescs
.size() < x
)
235 if (y_subnames
.size() < y
)
236 y_subnames
.resize(y
);
242 int size
= cvec
.size();
243 int zero
= size
/ 2; // round down!
244 int top_half
= zero
+ (size
- zero
+ 1) / 2; // round up!
245 int bottom_half
= (size
- zero
) / 2; // round down!
248 int low_pair
= zero
- 1;
249 for (int i
= zero
- 1; i
>= bottom_half
; i
--) {
250 cvec
[i
] = cvec
[low_pair
];
251 if (low_pair
- 1 >= 0)
252 cvec
[i
] += cvec
[low_pair
- 1];
255 assert(low_pair
== 0 || low_pair
== -1 || low_pair
== -2);
257 for (int i
= bottom_half
- 1; i
>= 0; i
--)
261 int high_pair
= zero
;
262 for (int i
= zero
; i
< top_half
; i
++) {
263 cvec
[i
] = cvec
[high_pair
];
264 if (high_pair
+ 1 < size
)
265 cvec
[i
] += cvec
[high_pair
+ 1];
268 assert(high_pair
== size
|| high_pair
== size
+ 1);
270 for (int i
= top_half
; i
< size
; i
++)
279 HistStor::grow_convert()
281 int size
= cvec
.size();
282 int half
= (size
+ 1) / 2; // round up!
283 //bool even = (size & 1) == 0;
286 for (int i
= size
- 1; i
>= half
; --i
) {
287 cvec
[i
] = cvec
[pair
];
289 cvec
[i
] += cvec
[pair
- 1];
293 for (int i
= half
- 1; i
>= 0; i
--)
296 min_bucket
= -max_bucket
;// - (even ? bucket_size : 0);
303 int size
= cvec
.size();
304 int half
= (size
+ 1) / 2; // round up!
307 for (int i
= 0; i
< half
; i
++) {
308 cvec
[i
] = cvec
[pair
];
310 cvec
[i
] += cvec
[pair
+ 1];
313 assert(pair
== size
|| pair
== size
+ 1);
315 for (int i
= half
; i
< size
; i
++)
326 Formula::Formula(Temp r
)
334 Formula::operator=(Temp r
)
336 assert(!root
&& "Can't change formulas");
344 Formula::operator+=(Temp r
)
347 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
358 Formula::result(VResult
&vec
) const
361 vec
= root
->result();
365 Formula::total() const
367 return root
? root
->total() : 0.0;
371 Formula::size() const
385 Formula::zero() const
389 for (VResult::size_type i
= 0; i
< vec
.size(); ++i
)
398 return root
? root
->str() : "";
404 typedef list
<Info
*>::iterator iter_t
;
406 iter_t i
, end
= statsList().end();
407 for (i
= statsList().begin(); i
!= end
; ++i
) {
410 if (!info
->check() || !info
->baseCheck())
411 panic("stat check failed for '%s' %d\n", info
->name
, info
->id
);
415 for (i
= statsList().begin(); i
!= end
; ++i
) {
417 if (!(info
->flags
& display
))
418 info
->name
= "__Stat" + to_string(j
++);
421 statsList().sort(Info::less
);
423 for (i
= statsList().begin(); i
!= end
; ++i
) {
432 list
<Info
*>::iterator i
= statsList().begin();
433 list
<Info
*>::iterator end
= statsList().end();
441 CallbackQueue resetQueue
;
446 list
<Info
*>::iterator i
= statsList().begin();
447 list
<Info
*>::iterator end
= statsList().end();
454 resetQueue
.process();
458 registerResetCallback(Callback
*cb
)