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/hostinfo.hh"
40 #include "base/misc.hh"
41 #include "base/statistics.hh"
42 #include "base/str.hh"
43 #include "base/time.hh"
44 #include "base/trace.hh"
45 #include "base/stats/statdb.hh"
52 DataAccess::find() const
54 return Database::find(const_cast<void *>((const void *)this));
58 getStatData(const void *stat
)
60 return Database::find(const_cast<void *>(stat
));
64 DataAccess::map(StatData
*data
)
66 Database::regStat(this, data
);
70 DataAccess::statData()
72 StatData
*ptr
= find();
78 DataAccess::statData() const
80 const StatData
*ptr
= find();
88 statData()->flags
|= init
;
92 DataAccess::setPrint()
94 Database::regPrint(this);
98 : flags(none
), precision(-1), prereq(0)
100 static int count
= 0;
104 StatData::~StatData()
109 StatData::less(StatData
*stat1
, StatData
*stat2
)
111 const string
&name1
= stat1
->name
;
112 const string
&name2
= stat2
->name
;
117 tokenize(v1
, name1
, '.');
118 tokenize(v2
, name2
, '.');
120 int last
= min(v1
.size(), v2
.size()) - 1;
121 for (int i
= 0; i
< last
; ++i
)
123 return v1
[i
] < v2
[i
];
125 // Special compare for last element.
126 if (v1
[last
] == v2
[last
])
127 return v1
.size() < v2
.size();
129 return v1
[last
] < v2
[last
];
135 StatData::baseCheck() const
137 if (!(flags
& init
)) {
139 cprintf("this is stat number %d\n", id
);
141 panic("Not all stats have been initialized");
145 if ((flags
& print
) && name
.empty()) {
146 panic("all printable stats must be named");
155 FormulaBase::result(VResult
&vec
) const
158 vec
= root
->result();
162 FormulaBase::total() const
164 return root
? root
->total() : 0.0;
168 FormulaBase::size() const
182 FormulaBase::zero() const
186 for (int i
= 0; i
< vec
.size(); ++i
)
193 FormulaBase::update(StatData
*)
198 FormulaBase::str() const
200 return root
? root
->str() : "";
208 Formula::Formula(Temp r
)
215 Formula::operator=(Temp r
)
217 assert(!root
&& "Can't change formulas");
224 Formula::operator+=(Temp r
)
227 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
237 typedef Database::stat_list_t::iterator iter_t
;
239 iter_t i
, end
= Database::stats().end();
240 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
243 if (!data
->check() || !data
->baseCheck())
244 panic("stat check failed for %s\n", data
->name
);
248 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
250 if (!(data
->flags
& print
))
251 data
->name
= "__Stat" + to_string(j
++);
254 Database::stats().sort(StatData::less
);
262 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
263 if ((*i
)->name
== (*last
)->name
)
264 panic("same name used twice! name=%s\n", (*i
)->name
);
270 CallbackQueue resetQueue
;
275 Database::stat_list_t::iterator i
= Database::stats().begin();
276 Database::stat_list_t::iterator end
= Database::stats().end();
283 resetQueue
.process();
287 registerResetCallback(Callback
*cb
)
292 /* namespace Stats */ }