Panda3D
 All Classes Functions Variables Enumerations
cacheStats.cxx
1 // Filename: cacheStats.cxx
2 // Created by: drose (24Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "cacheStats.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: CacheStats::init
19 // Access: Public
20 // Description: Initializes the CacheStats for the first time. We
21 // don't use the constructor for this, since we can't
22 // guarantee ordering of static constructors.
23 ////////////////////////////////////////////////////////////////////
24 void CacheStats::
25 init() {
26 #ifndef NDEBUG
27  reset(ClockObject::get_global_clock()->get_real_time());
28  _total_cache_size = 0;
29  _num_states = 0;
30 
31  _cache_report = ConfigVariableBool("cache-report", false);
32  _cache_report_interval = ConfigVariableDouble("cache-report-interval", 5.0);
33 #endif // NDEBUG
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: CacheStats::reset
38 // Access: Public
39 // Description: Reinitializes just those parts of the CacheStats that
40 // should be reset between each reporting interval.
41 ////////////////////////////////////////////////////////////////////
42 void CacheStats::
43 reset(double now) {
44 #ifndef NDEBUG
45  _cache_hits = 0;
46  _cache_misses = 0;
47  _cache_adds = 0;
48  _cache_new_adds = 0;
49  _cache_dels = 0;
50  _last_reset = now;
51 #endif // NDEBUG
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: CacheStats::write
56 // Access: Public
57 // Description:
58 ////////////////////////////////////////////////////////////////////
59 void CacheStats::
60 write(ostream &out, const char *name) const {
61 #ifndef NDEBUG
62  out << name << " cache: " << _cache_hits << " hits, "
63  << _cache_misses << " misses\n"
64  << _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), "
65  << _cache_dels << " dels, "
66  << _total_cache_size << " / " << _num_states << " = "
67  << (double)_total_cache_size / (double)_num_states
68  << " average cache size\n";
69 #endif // NDEBUG
70 }
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Definition: clockObject.I:271
This is a convenience class to specialize ConfigVariable as a boolean type.
void reset(double now)
Reinitializes just those parts of the CacheStats that should be reset between each reporting interval...
Definition: cacheStats.cxx:43
This is a convenience class to specialize ConfigVariable as a floating-point type.
void init()
Initializes the CacheStats for the first time.
Definition: cacheStats.cxx:25