00001 // Filename: pStatClient.I 00002 // Created by: drose (16Jul00) 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: PStatClient::set_client_name 00018 // Access: Published 00019 // Description: Sets the name of the client. This is reported to the 00020 // PStatsServer, and will presumably be written in the 00021 // title bar or something. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE void PStatClient:: 00024 set_client_name(const string &name) { 00025 get_impl()->set_client_name(name); 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: PStatClient::get_client_name 00030 // Access: Published 00031 // Description: Retrieves the name of the client as set. 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE string PStatClient:: 00034 get_client_name() const { 00035 return get_impl()->get_client_name(); 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: PStatClient::set_max_rate 00040 // Access: Published 00041 // Description: Controls the number of packets that will be sent to 00042 // the server. Normally, one packet is sent per frame, 00043 // but this can flood the server with more packets than 00044 // it can handle if the frame rate is especially good 00045 // (e.g. if nothing is onscreen at the moment). Set 00046 // this parameter to a reasonable number to prevent this 00047 // from happening. 00048 // 00049 // This number specifies the maximum number of packets 00050 // that will be sent to the server per second, per 00051 // thread. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE void PStatClient:: 00054 set_max_rate(double rate) { 00055 get_impl()->set_max_rate(rate); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: PStatClient::get_max_rate 00060 // Access: Published 00061 // Description: Returns the maximum number of packets that will be 00062 // sent to the server per second, per thread. See 00063 // set_max_rate(). 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE double PStatClient:: 00066 get_max_rate() const { 00067 return get_impl()->get_max_rate(); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: PStatClient::get_num_collectors 00072 // Access: Published 00073 // Description: Returns the total number of collectors the Client 00074 // knows about. 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE int PStatClient:: 00077 get_num_collectors() const { 00078 ReMutexHolder holder(_lock); 00079 return _num_collectors; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: PStatClient::get_collector_def 00084 // Access: Published 00085 // Description: Returns the definition body of the nth collector. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE PStatCollectorDef *PStatClient:: 00088 get_collector_def(int index) const { 00089 nassertr(index >= 0 && index < _num_collectors, NULL); 00090 00091 return get_collector_ptr(index)->get_def(this, index); 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: PStatClient::get_num_threads 00096 // Access: Published 00097 // Description: Returns the total number of threads the Client 00098 // knows about. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE int PStatClient:: 00101 get_num_threads() const { 00102 ReMutexHolder holder(_lock); 00103 return _num_threads; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: PStatClient::get_thread_name 00108 // Access: Published 00109 // Description: Returns the name of the indicated thread. 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE string PStatClient:: 00112 get_thread_name(int index) const { 00113 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), string()); 00114 return get_thread_ptr(index)->_name; 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: PStatClient::get_thread_sync_name 00119 // Access: Published 00120 // Description: Returns the sync_name of the indicated thread. 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE string PStatClient:: 00123 get_thread_sync_name(int index) const { 00124 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), string()); 00125 return get_thread_ptr(index)->_sync_name; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: PStatClient::get_thread_object 00130 // Access: Published 00131 // Description: Returns the Panda Thread object associated with the 00132 // indicated PStatThread. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE Thread *PStatClient:: 00135 get_thread_object(int index) const { 00136 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), NULL); 00137 InternalThread *thread = get_thread_ptr(index); 00138 if (thread->_thread.was_deleted()) { 00139 return NULL; 00140 } 00141 return thread->_thread; 00142 } 00143 00144 //////////////////////////////////////////////////////////////////// 00145 // Function: PStatClient::get_real_time 00146 // Access: Published 00147 // Description: Returns the time according to to the PStatClient's 00148 // clock object. It keeps its own clock, instead of 00149 // using the global clock object, so the stats won't get 00150 // mucked up if you put the global clock in 00151 // non-real-time mode or something. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE double PStatClient:: 00154 get_real_time() const { 00155 if (has_impl()) { 00156 return _impl->get_real_time(); 00157 } 00158 return 0.0f; 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: PStatClient::connect 00163 // Access: Published, Static 00164 // Description: Attempts to establish a connection to the indicated 00165 // PStatServer. Returns true if successful, false on 00166 // failure. 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE bool PStatClient:: 00169 connect(const string &hostname, int port) { 00170 return get_global_pstats()->client_connect(hostname, port); 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: PStatClient::disconnect 00175 // Access: Published, Static 00176 // Description: Closes the connection previously established. 00177 //////////////////////////////////////////////////////////////////// 00178 INLINE void PStatClient:: 00179 disconnect() { 00180 get_global_pstats()->client_disconnect(); 00181 } 00182 00183 //////////////////////////////////////////////////////////////////// 00184 // Function: PStatClient::is_connected 00185 // Access: Published, Static 00186 // Description: Returns true if the client believes it is connected 00187 // to a working PStatServer, false otherwise. 00188 //////////////////////////////////////////////////////////////////// 00189 INLINE bool PStatClient:: 00190 is_connected() { 00191 return get_global_pstats()->client_is_connected(); 00192 } 00193 00194 //////////////////////////////////////////////////////////////////// 00195 // Function: PStatClient::resume_after_pause 00196 // Access: Published, Static 00197 // Description: Resumes the PStatClient after the simulation has been 00198 // paused for a while. This allows the stats to 00199 // continue exactly where it left off, instead of 00200 // leaving a big gap that would represent a chug. 00201 //////////////////////////////////////////////////////////////////// 00202 INLINE void PStatClient:: 00203 resume_after_pause() { 00204 get_global_pstats()->client_resume_after_pause(); 00205 } 00206 00207 //////////////////////////////////////////////////////////////////// 00208 // Function: PStatClient::client_connect 00209 // Access: Published 00210 // Description: The nonstatic implementation of connect(). 00211 //////////////////////////////////////////////////////////////////// 00212 INLINE bool PStatClient:: 00213 client_connect(string hostname, int port) { 00214 ReMutexHolder holder(_lock); 00215 client_disconnect(); 00216 return get_impl()->client_connect(hostname, port); 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: PStatClient::client_is_connected 00221 // Access: Published 00222 // Description: The nonstatic implementation of is_connected(). 00223 //////////////////////////////////////////////////////////////////// 00224 INLINE bool PStatClient:: 00225 client_is_connected() const { 00226 return has_impl() && _impl->client_is_connected(); 00227 } 00228 00229 //////////////////////////////////////////////////////////////////// 00230 // Function: PStatClient::client_resume_after_pause 00231 // Access: Published 00232 // Description: Resumes the PStatClient after the simulation has been 00233 // paused for a while. This allows the stats to 00234 // continue exactly where it left off, instead of 00235 // leaving a big gap that would represent a chug. 00236 //////////////////////////////////////////////////////////////////// 00237 INLINE void PStatClient:: 00238 client_resume_after_pause() { 00239 if (has_impl()) { 00240 _impl->client_resume_after_pause(); 00241 } 00242 } 00243 00244 //////////////////////////////////////////////////////////////////// 00245 // Function: PStatClient::has_impl 00246 // Access: Private 00247 // Description: Returns true if the PStatClientImpl object has been 00248 // created for this object yet, false otherwise. 00249 //////////////////////////////////////////////////////////////////// 00250 INLINE bool PStatClient:: 00251 has_impl() const { 00252 return (_impl != (PStatClientImpl *)NULL); 00253 } 00254 00255 //////////////////////////////////////////////////////////////////// 00256 // Function: PStatClient::get_impl 00257 // Access: Private 00258 // Description: Returns the PStatClientImpl object for this object. 00259 // If the PStatClientImpl object has not yet been 00260 // created, implicitly creates it. 00261 //////////////////////////////////////////////////////////////////// 00262 INLINE PStatClientImpl *PStatClient:: 00263 get_impl() { 00264 ReMutexHolder holder(_lock); 00265 if (_impl == (PStatClientImpl *)NULL) { 00266 _impl = new PStatClientImpl(this); 00267 } 00268 00269 return _impl; 00270 } 00271 00272 //////////////////////////////////////////////////////////////////// 00273 // Function: PStatClient::get_impl 00274 // Access: Private 00275 // Description: Returns the PStatClientImpl object for this object. 00276 // If the PStatClientImpl object has not yet been 00277 // created, implicitly creates it. 00278 //////////////////////////////////////////////////////////////////// 00279 INLINE const PStatClientImpl *PStatClient:: 00280 get_impl() const { 00281 return ((PStatClient *)this)->get_impl(); 00282 } 00283 00284 //////////////////////////////////////////////////////////////////// 00285 // Function: PStatClient::get_collector_ptr 00286 // Access: Private 00287 // Description: Returns the nth collector in a thread-safe manner, 00288 // even if _lock is not held. 00289 //////////////////////////////////////////////////////////////////// 00290 INLINE PStatClient::Collector *PStatClient:: 00291 get_collector_ptr(int collector_index) const { 00292 CollectorPointer *collectors = (CollectorPointer *)AtomicAdjust::get_ptr(_collectors); 00293 return collectors[collector_index]; 00294 } 00295 00296 //////////////////////////////////////////////////////////////////// 00297 // Function: PStatClient::get_thread_ptr 00298 // Access: Private 00299 // Description: Returns the nth thread in a thread-safe manner, 00300 // even if _lock is not held. 00301 //////////////////////////////////////////////////////////////////// 00302 INLINE PStatClient::InternalThread *PStatClient:: 00303 get_thread_ptr(int thread_index) const { 00304 ThreadPointer *threads = (ThreadPointer *)AtomicAdjust::get_ptr(_threads); 00305 return threads[thread_index]; 00306 } 00307 00308 //////////////////////////////////////////////////////////////////// 00309 // Function: PStatClient::Collector::Constructor 00310 // Access: Public 00311 // Description: 00312 //////////////////////////////////////////////////////////////////// 00313 INLINE PStatClient::Collector:: 00314 Collector(int parent_index, const string &name) : 00315 _def(NULL), 00316 _parent_index(parent_index), 00317 _name(name) 00318 { 00319 } 00320 00321 //////////////////////////////////////////////////////////////////// 00322 // Function: PStatClient::Collector::get_parent_index 00323 // Access: Public 00324 // Description: 00325 //////////////////////////////////////////////////////////////////// 00326 INLINE int PStatClient::Collector:: 00327 get_parent_index() const { 00328 return _parent_index; 00329 } 00330 00331 //////////////////////////////////////////////////////////////////// 00332 // Function: PStatClient::Collector::get_name 00333 // Access: Public 00334 // Description: 00335 //////////////////////////////////////////////////////////////////// 00336 INLINE const string &PStatClient::Collector:: 00337 get_name() const { 00338 return _name; 00339 } 00340 00341 //////////////////////////////////////////////////////////////////// 00342 // Function: PStatClient::Collector::is_active 00343 // Access: Public 00344 // Description: Returns true if the indicated collector has been 00345 // designated as active, false otherwise. This might 00346 // return initially false until the collector def has 00347 // actually been created. 00348 //////////////////////////////////////////////////////////////////// 00349 INLINE bool PStatClient::Collector:: 00350 is_active() const { 00351 return _def != (PStatCollectorDef *)NULL && _def->_is_active; 00352 } 00353 00354 //////////////////////////////////////////////////////////////////// 00355 // Function: PStatClient::Collector::get_def 00356 // Access: Public 00357 // Description: Returns the PStatCollectorDef that contains all of 00358 // the information about the collector. If this object 00359 // has not yet been created, creates it. 00360 //////////////////////////////////////////////////////////////////// 00361 INLINE PStatCollectorDef *PStatClient::Collector:: 00362 get_def(const PStatClient *client, int this_index) const { 00363 if (_def == (PStatCollectorDef *)NULL) { 00364 ((Collector *)this)->make_def(client, this_index); 00365 } 00366 00367 return _def; 00368 }