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 validateStatName(const string
&name
)
148 tokenize(vec
, name
, '.');
149 vector
<string
>::const_iterator item
= vec
.begin();
150 while (item
!= vec
.end()) {
154 string::const_iterator c
= item
->begin();
156 // The first character is different
157 if (!isalpha(*c
) && *c
!= '_')
160 // The rest of the characters have different rules.
161 while (++c
!= item
->end()) {
162 if (!isalnum(*c
) && *c
!= '_')
173 Info::setName(const string
&name
)
175 if (!validateStatName(name
))
176 panic("invalid stat name '%s'", name
);
178 pair
<NameMapType::iterator
, bool> p
=
179 nameMap().insert(make_pair(name
, this));
181 Info
*other
= p
.first
->second
;
182 bool result
= p
.second
;
185 // using other->name instead of just name to avoid a compiler
186 // warning. They should be the same.
187 panic("same statistic name used twice! name=%s\n", other
->name
);
194 Info::less(Info
*stat1
, Info
*stat2
)
196 const string
&name1
= stat1
->name
;
197 const string
&name2
= stat2
->name
;
202 tokenize(v1
, name1
, '.');
203 tokenize(v2
, name2
, '.');
205 size_type last
= min(v1
.size(), v2
.size()) - 1;
206 for (off_type i
= 0; i
< last
; ++i
)
208 return v1
[i
] < v2
[i
];
210 // Special compare for last element.
211 if (v1
[last
] == v2
[last
])
212 return v1
.size() < v2
.size();
214 return v1
[last
] < v2
[last
];
220 Info::baseCheck() const
222 if (!(flags
& Stats::init
)) {
224 cprintf("this is stat number %d\n", id
);
226 panic("Not all stats have been initialized");
230 if ((flags
& display
) && name
.empty()) {
231 panic("all printable stats must be named");
246 size_type s
= size();
247 if (subnames
.size() < s
)
249 if (subdescs
.size() < s
)
254 VectorDistInfo::enable()
256 size_type s
= size();
257 if (subnames
.size() < s
)
259 if (subdescs
.size() < s
)
264 Vector2dInfo::enable()
266 if (subnames
.size() < x
)
268 if (subdescs
.size() < x
)
270 if (y_subnames
.size() < y
)
271 y_subnames
.resize(y
);
277 int size
= cvec
.size();
278 int zero
= size
/ 2; // round down!
279 int top_half
= zero
+ (size
- zero
+ 1) / 2; // round up!
280 int bottom_half
= (size
- zero
) / 2; // round down!
283 int low_pair
= zero
- 1;
284 for (int i
= zero
- 1; i
>= bottom_half
; i
--) {
285 cvec
[i
] = cvec
[low_pair
];
286 if (low_pair
- 1 >= 0)
287 cvec
[i
] += cvec
[low_pair
- 1];
290 assert(low_pair
== 0 || low_pair
== -1 || low_pair
== -2);
292 for (int i
= bottom_half
- 1; i
>= 0; i
--)
296 int high_pair
= zero
;
297 for (int i
= zero
; i
< top_half
; i
++) {
298 cvec
[i
] = cvec
[high_pair
];
299 if (high_pair
+ 1 < size
)
300 cvec
[i
] += cvec
[high_pair
+ 1];
303 assert(high_pair
== size
|| high_pair
== size
+ 1);
305 for (int i
= top_half
; i
< size
; i
++)
314 HistStor::grow_convert()
316 int size
= cvec
.size();
317 int half
= (size
+ 1) / 2; // round up!
318 //bool even = (size & 1) == 0;
321 for (int i
= size
- 1; i
>= half
; --i
) {
322 cvec
[i
] = cvec
[pair
];
324 cvec
[i
] += cvec
[pair
- 1];
328 for (int i
= half
- 1; i
>= 0; i
--)
331 min_bucket
= -max_bucket
;// - (even ? bucket_size : 0);
338 int size
= cvec
.size();
339 int half
= (size
+ 1) / 2; // round up!
342 for (int i
= 0; i
< half
; i
++) {
343 cvec
[i
] = cvec
[pair
];
345 cvec
[i
] += cvec
[pair
+ 1];
348 assert(pair
== size
|| pair
== size
+ 1);
350 for (int i
= half
; i
< size
; i
++)
361 Formula::Formula(Temp r
)
369 Formula::operator=(Temp r
)
371 assert(!root
&& "Can't change formulas");
379 Formula::operator+=(Temp r
)
382 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
393 Formula::result(VResult
&vec
) const
396 vec
= root
->result();
400 Formula::total() const
402 return root
? root
->total() : 0.0;
406 Formula::size() const
420 Formula::zero() const
424 for (VResult::size_type i
= 0; i
< vec
.size(); ++i
)
433 return root
? root
->str() : "";
436 CallbackQueue resetQueue
;
439 registerResetCallback(Callback
*cb
)