Panda3D
|
00001 // Filename: bufferResidencyTracker.cxx 00002 // Created by: drose (16Mar06) 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 "bufferResidencyTracker.h" 00016 #include "bufferContext.h" 00017 #include "clockObject.h" 00018 #include "indent.h" 00019 00020 PStatCollector BufferResidencyTracker::_gmem_collector("Graphics memory"); 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: BufferResidencyTracker::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 BufferResidencyTracker:: 00028 BufferResidencyTracker(const string &pgo_name, const string &type_name) : 00029 _pgo_collector(_gmem_collector, pgo_name), 00030 _active_resident_collector(PStatCollector(_pgo_collector, "Active"), type_name), 00031 _active_nonresident_collector(PStatCollector(_pgo_collector, "Thrashing"), type_name), 00032 _inactive_resident_collector(PStatCollector(_pgo_collector, "Inactive"), type_name), 00033 _inactive_nonresident_collector(PStatCollector(_pgo_collector, "Nonresident"), type_name), 00034 _active_frame(0) 00035 { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: BufferResidencyTracker::Destructor 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 BufferResidencyTracker:: 00044 ~BufferResidencyTracker() { 00045 _inactive_nonresident_collector.set_level(0); 00046 _active_nonresident_collector.set_level(0); 00047 _inactive_resident_collector.set_level(0); 00048 _active_resident_collector.set_level(0); 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: BufferResidencyTracker::begin_frame 00053 // Access: Public 00054 // Description: To be called at the beginning of a frame, this 00055 // initializes the active/inactive status. 00056 //////////////////////////////////////////////////////////////////// 00057 void BufferResidencyTracker:: 00058 begin_frame(Thread *current_thread) { 00059 int this_frame = ClockObject::get_global_clock()->get_frame_count(current_thread); 00060 if (_active_frame != this_frame) { 00061 _active_frame = this_frame; 00062 00063 // Move all of the previously "active" objects into "inactive". 00064 // They'll get re-added to "active" as they get rendered. 00065 move_inactive(_chains[S_inactive_nonresident], 00066 _chains[S_active_nonresident]); 00067 move_inactive(_chains[S_inactive_resident], 00068 _chains[S_active_resident]); 00069 } 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: BufferResidencyTracker::end_frame 00074 // Access: Public 00075 // Description: To be called at the end of a frame, this 00076 // updates the PStatCollectors appropriately. 00077 //////////////////////////////////////////////////////////////////// 00078 void BufferResidencyTracker:: 00079 end_frame(Thread *current_thread) { 00080 _inactive_nonresident_collector.set_level(_chains[S_inactive_nonresident].get_total_size()); 00081 _active_nonresident_collector.set_level(_chains[S_active_nonresident].get_total_size()); 00082 _inactive_resident_collector.set_level(_chains[S_inactive_resident].get_total_size()); 00083 _active_resident_collector.set_level(_chains[S_active_resident].get_total_size()); 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: BufferResidencyTracker::set_levels 00088 // Access: Public 00089 // Description: Resets the pstats levels to their appropriate values, 00090 // possibly in the middle of a frame. 00091 //////////////////////////////////////////////////////////////////// 00092 void BufferResidencyTracker:: 00093 set_levels() { 00094 _inactive_nonresident_collector.set_level(_chains[S_inactive_nonresident].get_total_size()); 00095 _active_nonresident_collector.set_level(_chains[S_active_nonresident].get_total_size()); 00096 _inactive_resident_collector.set_level(_chains[S_inactive_resident].get_total_size()); 00097 _active_resident_collector.set_level(_chains[S_active_resident].get_total_size()); 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: BufferResidencyTracker::write 00102 // Access: Public 00103 // Description: 00104 //////////////////////////////////////////////////////////////////// 00105 void BufferResidencyTracker:: 00106 write(ostream &out, int indent_level) const { 00107 if (_chains[S_inactive_nonresident].get_count() != 0) { 00108 indent(out, indent_level) << "Inactive nonresident:\n"; 00109 _chains[S_inactive_nonresident].write(out, indent_level + 2); 00110 } 00111 00112 if (_chains[S_active_nonresident].get_count() != 0) { 00113 indent(out, indent_level) << "Active nonresident:\n"; 00114 _chains[S_active_nonresident].write(out, indent_level + 2); 00115 } 00116 00117 if (_chains[S_inactive_resident].get_count() != 0) { 00118 indent(out, indent_level) << "Inactive resident:\n"; 00119 _chains[S_inactive_resident].write(out, indent_level + 2); 00120 } 00121 00122 if (_chains[S_active_resident].get_count() != 0) { 00123 indent(out, indent_level) << "Active resident:\n"; 00124 _chains[S_active_resident].write(out, indent_level + 2); 00125 } 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: BufferResidencyTracker::move_inactive 00130 // Access: Private 00131 // Description: Moves all of the "active" objects into "inactive". 00132 //////////////////////////////////////////////////////////////////// 00133 void BufferResidencyTracker:: 00134 move_inactive(BufferContextChain &inactive, BufferContextChain &active) { 00135 BufferContext *node = active.get_first(); 00136 while (node != (BufferContext *)NULL) { 00137 nassertv((node->_residency_state & S_active) != 0); 00138 node->_residency_state &= ~S_active; 00139 node = node->get_next(); 00140 } 00141 00142 inactive.take_from(active); 00143 }