Panda3D

cacheStats.cxx

00001 // Filename: cacheStats.cxx
00002 // Created by:  drose (24Jul07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "cacheStats.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: CacheStats::init
00019 //       Access: Public
00020 //  Description: Initializes the CacheStats for the first time.  We
00021 //               don't use the constructor for this, since we can't
00022 //               guarantee ordering of static constructors.
00023 ////////////////////////////////////////////////////////////////////
00024 void CacheStats::
00025 init() {
00026 #ifndef NDEBUG
00027   reset(ClockObject::get_global_clock()->get_real_time());
00028   _total_cache_size = 0;
00029   _num_states = 0;
00030 
00031   _cache_report = ConfigVariableBool("cache-report", false);
00032   _cache_report_interval = ConfigVariableDouble("cache-report-interval", 5.0);
00033 #endif  // NDEBUG
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: CacheStats::reset
00038 //       Access: Public
00039 //  Description: Reinitializes just those parts of the CacheStats that
00040 //               should be reset between each reporting interval.
00041 ////////////////////////////////////////////////////////////////////
00042 void CacheStats::
00043 reset(double now) {
00044 #ifndef NDEBUG
00045   _cache_hits = 0;
00046   _cache_misses = 0;
00047   _cache_adds = 0;
00048   _cache_new_adds = 0;
00049   _cache_dels = 0;
00050   _last_reset = now;
00051 #endif  // NDEBUG
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: CacheStats::write
00056 //       Access: Public
00057 //  Description: 
00058 ////////////////////////////////////////////////////////////////////
00059 void CacheStats::
00060 write(ostream &out, const char *name) const {
00061 #ifndef NDEBUG
00062   out << name << " cache: " << _cache_hits << " hits, " 
00063       << _cache_misses << " misses\n"
00064       << _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), "
00065       << _cache_dels << " dels, "
00066       << _total_cache_size << " / " << _num_states << " = "
00067       << (double)_total_cache_size / (double)_num_states 
00068       << " average cache size\n";
00069 #endif  // NDEBUG
00070 }
 All Classes Functions Variables Enumerations