00001 // Filename: pStatCollector.I 00002 // Created by: drose (10Jul00) 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 00020 #ifdef DO_PSTATS 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: PStatCollector::Default Constructor 00024 // Access: Private 00025 // Description: Normally, this constructor is called only from 00026 // PStatClient. Use one of the constructors below to 00027 // create your own Collector. 00028 //////////////////////////////////////////////////////////////////// 00029 INLINE PStatCollector:: 00030 PStatCollector() { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: PStatCollector::Constructor 00035 // Access: Private 00036 // Description: Normally, this constructor is called only from 00037 // PStatClient. Use one of the constructors below to 00038 // create your own Collector. 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE PStatCollector:: 00041 PStatCollector(PStatClient *client, int index) : 00042 _client(client), 00043 _index(index) 00044 { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: PStatCollector::Constructor 00049 // Access: Published 00050 // Description: Creates a new PStatCollector, ready to start 00051 // accumulating data. The name of the collector 00052 // uniquely identifies it among the other collectors; if 00053 // two collectors share the same name then they are 00054 // really the same collector. 00055 // 00056 // The name may also be a compound name, something like 00057 // "Cull:Sort", which indicates that this is a collector 00058 // named "Sort", a child of the collector named "Cull". 00059 // The parent may also be named explicitly by reference 00060 // in the other flavor of the constructor; see further 00061 // comments on this for that constructor. 00062 // 00063 // If the client pointer is non-null, it specifies a 00064 // particular client to register the collector with; 00065 // otherwise, the global client is used. 00066 //////////////////////////////////////////////////////////////////// 00067 INLINE PStatCollector:: 00068 PStatCollector(const string &name, PStatClient *client) { 00069 if (client == (PStatClient *)NULL) { 00070 client = PStatClient::get_global_pstats(); 00071 } 00072 (*this) = client->make_collector_with_relname(0, name); 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: PStatCollector::Constructor 00077 // Access: Published 00078 // Description: Creates a new PStatCollector, ready to start 00079 // accumulating data. The name of the collector 00080 // uniquely identifies it among the other collectors; if 00081 // two collectors share the same name then they are 00082 // really the same collector. 00083 // 00084 // The parent is the collector that conceptually 00085 // includes all of the time measured for this collector. 00086 // For instance, a particular character's animation time 00087 // is owned by the "Animation" collector, which is in 00088 // turn owned by the "Frame" collector. It is not 00089 // strictly necessary that all of the time spent in a 00090 // particular collector is completely nested within time 00091 // spent in its parent's collector. If parent is the 00092 // empty string, the collector is owned by "Frame". 00093 // 00094 // This constructor does not take a client pointer; it 00095 // always creates the new collector on the same client 00096 // as its parent. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE PStatCollector:: 00099 PStatCollector(const PStatCollector &parent, const string &name) { 00100 nassertv(parent._client != (PStatClient *)NULL); 00101 (*this) = 00102 parent._client->make_collector_with_relname(parent._index, name); 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: PStatCollector::Copy Constructor 00107 // Access: Published 00108 // Description: 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE PStatCollector:: 00111 PStatCollector(const PStatCollector ©) : 00112 _client(copy._client), 00113 _index(copy._index) 00114 { 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: PStatCollector::Copy Assignment Operator 00119 // Access: Published 00120 // Description: 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE void PStatCollector:: 00123 operator = (const PStatCollector ©) { 00124 _client = copy._client; 00125 _index = copy._index; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: PStatCollector::is_active 00130 // Access: Published 00131 // Description: Returns true if this particular collector is active 00132 // on the default thread, and we are currently 00133 // transmitting PStats data. 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE bool PStatCollector:: 00136 is_active() { 00137 return _client->is_active(_index, 0); 00138 } 00139 00140 //////////////////////////////////////////////////////////////////// 00141 // Function: PStatCollector::start 00142 // Access: Published 00143 // Description: Starts this particular timer ticking. This should be 00144 // called before the code you want to measure. 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE void PStatCollector:: 00147 start() { 00148 _client->start(_index, 0); 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: PStatCollector::stop 00153 // Access: Published 00154 // Description: Stops this timer. This should be called after the 00155 // code you want to measure. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE void PStatCollector:: 00158 stop() { 00159 _client->stop(_index, 0); 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: PStatCollector::clear_level 00164 // Access: Published 00165 // Description: Removes the level setting associated with this 00166 // collector for the main thread. The collector 00167 // will no longer show up on any level graphs in the 00168 // main thread. 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE void PStatCollector:: 00171 clear_level() { 00172 _client->clear_level(_index, 0); 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function: PStatCollector::set_level 00177 // Access: Published 00178 // Description: Sets the level setting associated with this 00179 // collector for the main thread to the indicated 00180 // value. 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE void PStatCollector:: 00183 set_level(float level) { 00184 _client->set_level(_index, 0, level); 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: PStatCollector::add_level 00189 // Access: Published 00190 // Description: Adds the indicated increment (which may be negative) 00191 // to the level setting associated with this collector 00192 // for the main thread. If the collector did not 00193 // already have a level setting for the main thread, it 00194 // is initialized to 0. 00195 //////////////////////////////////////////////////////////////////// 00196 INLINE void PStatCollector:: 00197 add_level(float increment) { 00198 _client->add_level(_index, 0, increment); 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function: PStatCollector::sub_level 00203 // Access: Published 00204 // Description: Subtracts the indicated decrement (which may be 00205 // negative) to the level setting associated with this 00206 // collector for the main thread. If the collector did 00207 // not already have a level setting for the main thread, 00208 // it is initialized to 0. 00209 //////////////////////////////////////////////////////////////////// 00210 INLINE void PStatCollector:: 00211 sub_level(float decrement) { 00212 _client->add_level(_index, 0, -decrement); 00213 } 00214 00215 //////////////////////////////////////////////////////////////////// 00216 // Function: PStatCollector::get_level 00217 // Access: Published 00218 // Description: Returns the current level value of the given collector. 00219 //////////////////////////////////////////////////////////////////// 00220 INLINE float PStatCollector:: 00221 get_level() { 00222 return _client->get_level(_index, 0); 00223 } 00224 00225 //////////////////////////////////////////////////////////////////// 00226 // Function: PStatCollector::is_active 00227 // Access: Public 00228 // Description: Returns true if this particular collector is active 00229 // on the indicated thread, and we are currently 00230 // transmitting PStats data. 00231 //////////////////////////////////////////////////////////////////// 00232 INLINE bool PStatCollector:: 00233 is_active(const PStatThread &thread) { 00234 return _client->is_active(_index, thread._index); 00235 } 00236 00237 //////////////////////////////////////////////////////////////////// 00238 // Function: PStatCollector::start 00239 // Access: Public 00240 // Description: Starts this timer ticking within a particular thread. 00241 //////////////////////////////////////////////////////////////////// 00242 INLINE void PStatCollector:: 00243 start(const PStatThread &thread) { 00244 _client->start(_index, thread._index); 00245 } 00246 00247 //////////////////////////////////////////////////////////////////// 00248 // Function: PStatCollector::start 00249 // Access: Public 00250 // Description: Marks that the timer should have been started as of 00251 // the indicated time. This must be a time based on the 00252 // PStatClient's clock (see PStatClient::get_clock()), 00253 // and care should be taken that all such calls exhibit 00254 // a monotonically increasing series of time values. 00255 //////////////////////////////////////////////////////////////////// 00256 INLINE void PStatCollector:: 00257 start(const PStatThread &thread, float as_of) { 00258 _client->start(_index, thread._index, as_of); 00259 } 00260 00261 //////////////////////////////////////////////////////////////////// 00262 // Function: PStatCollector::stop 00263 // Access: Public 00264 // Description: Stops this timer within a particular thread. 00265 //////////////////////////////////////////////////////////////////// 00266 INLINE void PStatCollector:: 00267 stop(const PStatThread &thread) { 00268 _client->stop(_index, thread._index); 00269 } 00270 00271 //////////////////////////////////////////////////////////////////// 00272 // Function: PStatCollector::stop 00273 // Access: Public 00274 // Description: Marks that the timer should have been stopped as of 00275 // the indicated time. This must be a time based on the 00276 // PStatClient's clock (see PStatClient::get_clock()), 00277 // and care should be taken that all such calls exhibit 00278 // a monotonically increasing series of time values. 00279 //////////////////////////////////////////////////////////////////// 00280 INLINE void PStatCollector:: 00281 stop(const PStatThread &thread, float as_of) { 00282 _client->stop(_index, thread._index, as_of); 00283 } 00284 00285 //////////////////////////////////////////////////////////////////// 00286 // Function: PStatCollector::clear_level 00287 // Access: Public 00288 // Description: Removes the level setting associated with this 00289 // collector for the indicated thread. The collector 00290 // will no longer show up on any level graphs in this 00291 // thread. 00292 //////////////////////////////////////////////////////////////////// 00293 INLINE void PStatCollector:: 00294 clear_level(const PStatThread &thread) { 00295 _client->clear_level(_index, thread._index); 00296 } 00297 00298 //////////////////////////////////////////////////////////////////// 00299 // Function: PStatCollector::set_level 00300 // Access: Public 00301 // Description: Sets the level setting associated with this 00302 // collector for the indicated thread to the indicated 00303 // value. 00304 //////////////////////////////////////////////////////////////////// 00305 INLINE void PStatCollector:: 00306 set_level(const PStatThread &thread, float level) { 00307 _client->set_level(_index, thread._index, level); 00308 } 00309 00310 //////////////////////////////////////////////////////////////////// 00311 // Function: PStatCollector::add_level 00312 // Access: Public 00313 // Description: Adds the indicated increment (which may be negative) 00314 // to the level setting associated with this collector 00315 // for the indicated thread. If the collector did not 00316 // already have a level setting for this thread, it is 00317 // initialized to 0. 00318 //////////////////////////////////////////////////////////////////// 00319 INLINE void PStatCollector:: 00320 add_level(const PStatThread &thread, float increment) { 00321 _client->add_level(_index, thread._index, increment); 00322 } 00323 00324 //////////////////////////////////////////////////////////////////// 00325 // Function: PStatCollector::sub_level 00326 // Access: Public 00327 // Description: Subtracts the indicated decrement (which may be 00328 // negative) to the level setting associated with this 00329 // collector for the indicated thread. If the collector 00330 // did not already have a level setting for this thread, 00331 // it is initialized to 0. 00332 //////////////////////////////////////////////////////////////////// 00333 INLINE void PStatCollector:: 00334 sub_level(const PStatThread &thread, float decrement) { 00335 _client->add_level(_index, thread._index, -decrement); 00336 } 00337 00338 //////////////////////////////////////////////////////////////////// 00339 // Function: PStatCollector::get_level 00340 // Access: Public 00341 // Description: Returns the current level value of the given collector. 00342 //////////////////////////////////////////////////////////////////// 00343 INLINE float PStatCollector:: 00344 get_level(const PStatThread &thread) { 00345 return _client->get_level(_index, thread._index); 00346 } 00347 00348 #else // DO_PSTATS 00349 00350 //////////////////////////////////////////////////////////////////// 00351 // Function: PStatCollector::Constructor 00352 // Access: Published 00353 // Description: This bogus version of the function is only defined if 00354 // DO_PSTATS is not defined, meaning all these functions 00355 // should compile to nothing. 00356 //////////////////////////////////////////////////////////////////// 00357 INLINE PStatCollector:: 00358 PStatCollector(const string &, PStatClient *client) { 00359 // We need this bogus comparison just to prevent the SGI compiler 00360 // from dumping core. It's perfectly meaningless. 00361 #ifdef mips 00362 if (client == (PStatClient *)NULL) { 00363 return; 00364 } 00365 #endif 00366 } 00367 00368 //////////////////////////////////////////////////////////////////// 00369 // Function: PStatCollector::Constructor 00370 // Access: Published 00371 // Description: This bogus version of the function is only defined if 00372 // DO_PSTATS is not defined, meaning all these functions 00373 // should compile to nothing. 00374 //////////////////////////////////////////////////////////////////// 00375 INLINE PStatCollector:: 00376 PStatCollector(const PStatCollector &parent, const string &) { 00377 // We need this bogus comparison just to prevent the SGI compiler 00378 // from dumping core. It's perfectly meaningless. 00379 #ifdef mips 00380 if (&parent == (const PStatCollector *)NULL) { 00381 return; 00382 } 00383 #endif 00384 } 00385 00386 00387 #endif // DO_PSTATS