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 std::string
Info::separatorString
= "::";
52 typedef map
<const void *, Info
*> MapType
;
54 // We wrap these in a function to make sure they're built in time.
58 static list
<Info
*> the_list
;
65 static MapType the_map
;
70 InfoAccess::setInfo(Info
*info
)
72 if (statsMap().find(this) != statsMap().end())
73 panic("shouldn't register stat twice!");
75 statsList().push_back(info
);
78 pair
<MapType::iterator
, bool> result
=
80 statsMap().insert(make_pair(this, info
));
81 assert(result
.second
&& "this should never fail");
82 assert(statsMap().find(this) != statsMap().end());
86 InfoAccess::setParams(const StorageParams
*params
)
88 info()->storageParams
= params
;
94 info()->flags
.set(init
);
100 MapType::const_iterator i
= statsMap().find(this);
101 assert(i
!= statsMap().end());
106 InfoAccess::info() const
108 MapType::const_iterator i
= statsMap().find(this);
109 assert(i
!= statsMap().end());
113 StorageParams::~StorageParams()
117 typedef map
<std::string
, Info
*> NameMapType
;
121 static NameMapType the_map
;
125 int Info::id_count
= 0;
127 int debug_break_id
= -1;
130 : flags(none
), precision(-1), prereq(0), storageParams(NULL
)
133 if (debug_break_id
>= 0 and debug_break_id
== id
)
142 Info::setName(const string
&name
)
144 pair
<NameMapType::iterator
, bool> p
=
145 nameMap().insert(make_pair(name
, this));
147 Info
*other
= p
.first
->second
;
148 bool result
= p
.second
;
151 // using other->name instead of just name to avoid a compiler
152 // warning. They should be the same.
153 panic("same statistic name used twice! name=%s\n", other
->name
);
160 Info::less(Info
*stat1
, Info
*stat2
)
162 const string
&name1
= stat1
->name
;
163 const string
&name2
= stat2
->name
;
168 tokenize(v1
, name1
, '.');
169 tokenize(v2
, name2
, '.');
171 size_type last
= min(v1
.size(), v2
.size()) - 1;
172 for (off_type i
= 0; i
< last
; ++i
)
174 return v1
[i
] < v2
[i
];
176 // Special compare for last element.
177 if (v1
[last
] == v2
[last
])
178 return v1
.size() < v2
.size();
180 return v1
[last
] < v2
[last
];
186 Info::baseCheck() const
188 if (!(flags
& Stats::init
)) {
190 cprintf("this is stat number %d\n", id
);
192 panic("Not all stats have been initialized");
196 if ((flags
& display
) && name
.empty()) {
197 panic("all printable stats must be named");
212 size_type s
= size();
213 if (subnames
.size() < s
)
215 if (subdescs
.size() < s
)
220 VectorDistInfo::enable()
222 size_type s
= size();
223 if (subnames
.size() < s
)
225 if (subdescs
.size() < s
)
230 Vector2dInfo::enable()
232 if (subnames
.size() < x
)
234 if (subdescs
.size() < x
)
236 if (y_subnames
.size() < y
)
237 y_subnames
.resize(y
);
243 int size
= cvec
.size();
244 int zero
= size
/ 2; // round down!
245 int top_half
= zero
+ (size
- zero
+ 1) / 2; // round up!
246 int bottom_half
= (size
- zero
) / 2; // round down!
249 int low_pair
= zero
- 1;
250 for (int i
= zero
- 1; i
>= bottom_half
; i
--) {
251 cvec
[i
] = cvec
[low_pair
];
252 if (low_pair
- 1 >= 0)
253 cvec
[i
] += cvec
[low_pair
- 1];
256 assert(low_pair
== 0 || low_pair
== -1 || low_pair
== -2);
258 for (int i
= bottom_half
- 1; i
>= 0; i
--)
262 int high_pair
= zero
;
263 for (int i
= zero
; i
< top_half
; i
++) {
264 cvec
[i
] = cvec
[high_pair
];
265 if (high_pair
+ 1 < size
)
266 cvec
[i
] += cvec
[high_pair
+ 1];
269 assert(high_pair
== size
|| high_pair
== size
+ 1);
271 for (int i
= top_half
; i
< size
; i
++)
280 HistStor::grow_convert()
282 int size
= cvec
.size();
283 int half
= (size
+ 1) / 2; // round up!
284 //bool even = (size & 1) == 0;
287 for (int i
= size
- 1; i
>= half
; --i
) {
288 cvec
[i
] = cvec
[pair
];
290 cvec
[i
] += cvec
[pair
- 1];
294 for (int i
= half
- 1; i
>= 0; i
--)
297 min_bucket
= -max_bucket
;// - (even ? bucket_size : 0);
304 int size
= cvec
.size();
305 int half
= (size
+ 1) / 2; // round up!
308 for (int i
= 0; i
< half
; i
++) {
309 cvec
[i
] = cvec
[pair
];
311 cvec
[i
] += cvec
[pair
+ 1];
314 assert(pair
== size
|| pair
== size
+ 1);
316 for (int i
= half
; i
< size
; i
++)
327 Formula::Formula(Temp r
)
335 Formula::operator=(Temp r
)
337 assert(!root
&& "Can't change formulas");
345 Formula::operator+=(Temp r
)
348 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
359 Formula::result(VResult
&vec
) const
362 vec
= root
->result();
366 Formula::total() const
368 return root
? root
->total() : 0.0;
372 Formula::size() const
386 Formula::zero() const
390 for (VResult::size_type i
= 0; i
< vec
.size(); ++i
)
399 return root
? root
->str() : "";
405 typedef list
<Info
*>::iterator iter_t
;
407 iter_t i
, end
= statsList().end();
408 for (i
= statsList().begin(); i
!= end
; ++i
) {
411 if (!info
->check() || !info
->baseCheck())
412 panic("stat check failed for '%s' %d\n", info
->name
, info
->id
);
416 for (i
= statsList().begin(); i
!= end
; ++i
) {
418 if (!(info
->flags
& display
))
419 info
->name
= "__Stat" + to_string(j
++);
422 statsList().sort(Info::less
);
424 for (i
= statsList().begin(); i
!= end
; ++i
) {
433 list
<Info
*>::iterator i
= statsList().begin();
434 list
<Info
*>::iterator end
= statsList().end();
442 CallbackQueue resetQueue
;
447 list
<Info
*>::iterator i
= statsList().begin();
448 list
<Info
*>::iterator end
= statsList().end();
455 resetQueue
.process();
459 registerResetCallback(Callback
*cb
)