Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/memoryUsagePointerCounts.cxx

Go to the documentation of this file.
00001 // Filename: memoryUsagePointerCounts.cxx
00002 // Created by:  drose (04Jun01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifdef DO_MEMORY_USAGE
00020 
00021 #include "memoryUsagePointerCounts.h"
00022 #include "memoryInfo.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: MemoryUsagePointerCounts::add_info
00026 //       Access: Public
00027 //  Description: Adds a pointer definition to the counter.
00028 ////////////////////////////////////////////////////////////////////
00029 void MemoryUsagePointerCounts::
00030 add_info(MemoryInfo &info) {
00031   _count++;
00032 
00033   if (info.is_size_known()) {
00034     _size += info.get_size();
00035   } else {
00036     _unknown_size_count++;
00037   }
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: MemoryUsagePointerCounts::output
00042 //       Access: Public
00043 //  Description: 
00044 ////////////////////////////////////////////////////////////////////
00045 void MemoryUsagePointerCounts::
00046 output(ostream &out) const {
00047   out << _count << " pointers";
00048   if (_unknown_size_count < _count) {
00049     out << ", ";
00050     output_bytes(out, _size);
00051     out << ", ";
00052     output_bytes(out, _size / (_count - _unknown_size_count));
00053     out << " each";
00054       
00055     if (_unknown_size_count != 0) {
00056       out << " (" << _unknown_size_count << " of unknown size)";
00057     }
00058   }
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: MemoryUsagePointerCounts::output_bytes
00063 //       Access: Private, Static
00064 //  Description: Formats a size in bytes in a meaningful and concise
00065 //               way for output, with units.
00066 ////////////////////////////////////////////////////////////////////
00067 void MemoryUsagePointerCounts::
00068 output_bytes(ostream &out, size_t size) {
00069   if (size < 4 * 1024) {
00070     out << size << " bytes";
00071     
00072   } else if (size < 4 * 1024 * 1024) {
00073     out << size / 1024 << " Kb";
00074     
00075   } else {
00076     out << size / (1024 * 1024) << " Mb";
00077   }
00078 }
00079 
00080 #endif  // DO_MEMORY_USAGE
00081 

Generated on Fri May 2 00:38:25 2003 for Panda by doxygen1.3