Panda3D
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  // Let's not use the clock at static init time.
28  reset(0.0);
29  //reset(ClockObject::get_global_clock()->get_real_time());
30  _total_cache_size = 0;
31  _num_states = 0;
32 
33  _cache_report = ConfigVariableBool("cache-report", false);
34  _cache_report_interval = ConfigVariableDouble("cache-report-interval", 5.0);
35 #endif // NDEBUG
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: CacheStats::reset
40 // Access: Public
41 // Description: Reinitializes just those parts of the CacheStats that
42 // should be reset between each reporting interval.
43 ////////////////////////////////////////////////////////////////////
44 void CacheStats::
45 reset(double now) {
46 #ifndef NDEBUG
47  _cache_hits = 0;
48  _cache_misses = 0;
49  _cache_adds = 0;
50  _cache_new_adds = 0;
51  _cache_dels = 0;
52  _last_reset = now;
53 #endif // NDEBUG
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: CacheStats::write
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 void CacheStats::
62 write(ostream &out, const char *name) const {
63 #ifndef NDEBUG
64  out << name << " cache: " << _cache_hits << " hits, "
65  << _cache_misses << " misses\n"
66  << _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), "
67  << _cache_dels << " dels, "
68  << _total_cache_size << " / " << _num_states << " = "
69  << (double)_total_cache_size / (double)_num_states
70  << " average cache size\n";
71 #endif // NDEBUG
72 }
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:45
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