2 * Copyright (c) 2003-2004 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.
36 #include "base/callback.hh"
37 #include "base/cprintf.hh"
38 #include "base/hostinfo.hh"
39 #include "base/misc.hh"
40 #include "base/python.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
177 FormulaBase::binned() const
179 return root
&& root
->binned();
188 FormulaBase::zero() const
192 for (int i
= 0; i
< vec
.size(); ++i
)
199 FormulaBase::update(StatData
*)
204 FormulaBase::str() const
206 return root
? root
->str() : "";
214 Formula::Formula(Temp r
)
221 Formula::operator=(Temp r
)
223 assert(!root
&& "Can't change formulas");
230 Formula::operator+=(Temp r
)
233 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
240 MainBin::MainBin(const string
&name
)
241 : _name(name
), mem(NULL
), memsize(-1)
243 Database::regBin(this, name
);
253 MainBin::memory(off_t off
)
256 memsize
= CeilPow2((size_t) offset());
259 mem
= new char[memsize
];
260 memset(mem
, 0, memsize
);
263 assert(offset() <= size());
270 typedef Database::stat_list_t::iterator iter_t
;
272 iter_t i
, end
= Database::stats().end();
273 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
280 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
282 if (!(data
->flags
& print
))
283 data
->name
= "__Stat" + to_string(j
++);
286 Database::stats().sort(StatData::less
);
294 for (i
= Database::stats().begin(); i
!= end
; ++i
) {
295 if ((*i
)->name
== (*last
)->name
)
296 panic("same name used twice! name=%s\n", (*i
)->name
);
302 CallbackQueue resetQueue
;
307 // reset non-binned stats
308 Database::stat_list_t::iterator i
= Database::stats().begin();
309 Database::stat_list_t::iterator end
= Database::stats().end();
317 // save the bin so we can go back to where we were
318 MainBin
*orig
= MainBin::curBin();
320 // reset binned stats
321 Database::bin_list_t::iterator bi
= Database::bins().begin();
322 Database::bin_list_t::iterator be
= Database::bins().end();
327 i
= Database::stats().begin();
338 MainBin::curBin() = orig
;
340 resetQueue
.process();
344 registerResetCallback(Callback
*cb
)
349 /* namespace Stats */ }