statistics.cc (2665:a124942bacb8) statistics.cc (2716:b9114064d77a)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 29 unchanged lines hidden (view full) ---

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"
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 29 unchanged lines hidden (view full) ---

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"
46#include "config/stats_binning.hh"
47
48using namespace std;
49
50namespace Stats {
51
52StatData *
53DataAccess::find() const
54{

--- 114 unchanged lines hidden (view full) ---

169FormulaBase::size() const
170{
171 if (!root)
172 return 0;
173 else
174 return root->size();
175}
176
46
47using namespace std;
48
49namespace Stats {
50
51StatData *
52DataAccess::find() const
53{

--- 114 unchanged lines hidden (view full) ---

168FormulaBase::size() const
169{
170 if (!root)
171 return 0;
172 else
173 return root->size();
174}
175
177bool
178FormulaBase::binned() const
179{
180 return root && root->binned();
181}
182
183void
184FormulaBase::reset()
185{
186}
187
188bool
189FormulaBase::zero() const
190{

--- 42 unchanged lines hidden (view full) ---

233 if (root)
234 root = NodePtr(new BinaryNode<std::plus<Result> >(root, r));
235 else
236 root = r;
237 assert(size());
238 return *this;
239}
240
176void
177FormulaBase::reset()
178{
179}
180
181bool
182FormulaBase::zero() const
183{

--- 42 unchanged lines hidden (view full) ---

226 if (root)
227 root = NodePtr(new BinaryNode<std::plus<Result> >(root, r));
228 else
229 root = r;
230 assert(size());
231 return *this;
232}
233
241MainBin::MainBin(const string &name)
242 : _name(name), mem(NULL), memsize(-1)
243{
244 Database::regBin(this, name);
245}
246
247MainBin::~MainBin()
248{
249 if (mem)
250 delete [] mem;
251}
252
253char *
254MainBin::memory(off_t off)
255{
256 if (memsize == -1)
257 memsize = ceilPow2((size_t) offset());
258
259 if (!mem) {
260 mem = new char[memsize];
261 memset(mem, 0, memsize);
262 }
263
264 assert(offset() <= size());
265 return mem + off;
266}
267
268void
269check()
270{
271 typedef Database::stat_list_t::iterator iter_t;
272
273 iter_t i, end = Database::stats().end();
274 for (i = Database::stats().begin(); i != end; ++i) {
275 StatData *data = *i;

--- 6 unchanged lines hidden (view full) ---

282 for (i = Database::stats().begin(); i != end; ++i) {
283 StatData *data = *i;
284 if (!(data->flags & print))
285 data->name = "__Stat" + to_string(j++);
286 }
287
288 Database::stats().sort(StatData::less);
289
234void
235check()
236{
237 typedef Database::stat_list_t::iterator iter_t;
238
239 iter_t i, end = Database::stats().end();
240 for (i = Database::stats().begin(); i != end; ++i) {
241 StatData *data = *i;

--- 6 unchanged lines hidden (view full) ---

248 for (i = Database::stats().begin(); i != end; ++i) {
249 StatData *data = *i;
250 if (!(data->flags & print))
251 data->name = "__Stat" + to_string(j++);
252 }
253
254 Database::stats().sort(StatData::less);
255
290#if STATS_BINNING
291 if (MainBin::curBin() == NULL) {
292 static MainBin mainBin("main bin");
293 mainBin.activate();
294 }
295#endif
296
297 if (i == end)
298 return;
299
300 iter_t last = i;
301 ++i;
302
303 for (i = Database::stats().begin(); i != end; ++i) {
304 if ((*i)->name == (*last)->name)
305 panic("same name used twice! name=%s\n", (*i)->name);
306
307 last = i;
308 }
309}
310
311CallbackQueue resetQueue;
312
313void
314reset()
315{
256 if (i == end)
257 return;
258
259 iter_t last = i;
260 ++i;
261
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);
265
266 last = i;
267 }
268}
269
270CallbackQueue resetQueue;
271
272void
273reset()
274{
316 // reset non-binned stats
317 Database::stat_list_t::iterator i = Database::stats().begin();
318 Database::stat_list_t::iterator end = Database::stats().end();
319 while (i != end) {
320 StatData *data = *i;
275 Database::stat_list_t::iterator i = Database::stats().begin();
276 Database::stat_list_t::iterator end = Database::stats().end();
277 while (i != end) {
278 StatData *data = *i;
321 if (!data->binned())
322 data->reset();
279 data->reset();
323 ++i;
324 }
325
280 ++i;
281 }
282
326 // save the bin so we can go back to where we were
327 MainBin *orig = MainBin::curBin();
328
329 // reset binned stats
330 Database::bin_list_t::iterator bi = Database::bins().begin();
331 Database::bin_list_t::iterator be = Database::bins().end();
332 while (bi != be) {
333 MainBin *bin = *bi;
334 bin->activate();
335
336 i = Database::stats().begin();
337 while (i != end) {
338 StatData *data = *i;
339 if (data->binned())
340 data->reset();
341 ++i;
342 }
343 ++bi;
344 }
345
346 // restore bin
347 MainBin::curBin() = orig;
348
349 resetQueue.process();
350}
351
352void
353registerResetCallback(Callback *cb)
354{
355 resetQueue.add(cb);
356}
357
358/* namespace Stats */ }
283 resetQueue.process();
284}
285
286void
287registerResetCallback(Callback *cb)
288{
289 resetQueue.add(cb);
290}
291
292/* namespace Stats */ }