Panda3D
|
00001 // Filename: pStatCollector.h 00002 // Created by: drose (10Jul00) 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 #ifndef PSTATCOLLECTOR_H 00016 #define PSTATCOLLECTOR_H 00017 00018 #include "pandabase.h" 00019 00020 #include "pStatThread.h" 00021 #include "pStatClient.h" 00022 00023 class Thread; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : PStatCollector 00027 // Description : A lightweight class that represents a single element 00028 // that may be timed and/or counted via stats. 00029 // 00030 // Collectors can be used to measure two different kinds 00031 // of values: elapsed time, and "other". 00032 // 00033 // To measure elapsed time, call start() and stop() as 00034 // appropriate to bracket the section of code you want 00035 // to time (or use a PStatTimer to do this 00036 // automatically). 00037 // 00038 // To measure anything else, call set_level() and/or 00039 // add_level() to set the "level" value associated with 00040 // this collector. The meaning of the value set for the 00041 // "level" is entirely up to the user; it may represent 00042 // the number of triangles rendered or the kilobytes of 00043 // texture memory consumed, for instance. The level set 00044 // will remain fixed across multiple frames until it is 00045 // reset via another set_level() or adjusted via a call 00046 // to add_level(). It may also be completely removed 00047 // via clear_level(). 00048 //////////////////////////////////////////////////////////////////// 00049 class EXPCL_PANDA_PSTATCLIENT PStatCollector { 00050 #ifdef DO_PSTATS 00051 00052 private: 00053 INLINE PStatCollector(PStatClient *client, int index); 00054 00055 public: 00056 INLINE PStatCollector(); 00057 00058 PUBLISHED: 00059 INLINE PStatCollector(const string &name, 00060 PStatClient *client = NULL); 00061 INLINE PStatCollector(const PStatCollector &parent, 00062 const string &name); 00063 00064 INLINE PStatCollector(const PStatCollector ©); 00065 INLINE void operator = (const PStatCollector ©); 00066 00067 INLINE bool is_valid() const; 00068 INLINE string get_name() const; 00069 INLINE string get_fullname() const; 00070 INLINE void output(ostream &out) const; 00071 00072 INLINE bool is_active(); 00073 INLINE bool is_started(); 00074 INLINE void start(); 00075 INLINE void stop(); 00076 00077 INLINE void clear_level(); 00078 INLINE void set_level(double level); 00079 INLINE void add_level(double increment); 00080 INLINE void sub_level(double decrement); 00081 INLINE void add_level_now(double increment); 00082 INLINE void sub_level_now(double decrement); 00083 INLINE void flush_level(); 00084 INLINE double get_level(); 00085 00086 INLINE void clear_thread_level(); 00087 INLINE void set_thread_level(double level); 00088 INLINE void add_thread_level(double increment); 00089 INLINE void sub_thread_level(double decrement); 00090 INLINE double get_thread_level(); 00091 00092 INLINE bool is_active(const PStatThread &thread); 00093 INLINE bool is_started(const PStatThread &thread); 00094 INLINE void start(const PStatThread &thread); 00095 INLINE void start(const PStatThread &thread, double as_of); 00096 INLINE void stop(const PStatThread &thread); 00097 INLINE void stop(const PStatThread &thread, double as_of); 00098 00099 INLINE void clear_level(const PStatThread &thread); 00100 INLINE void set_level(const PStatThread &thread, double level); 00101 INLINE void add_level(const PStatThread &thread, double increment); 00102 INLINE void sub_level(const PStatThread &thread, double decrement); 00103 INLINE double get_level(const PStatThread &thread); 00104 00105 INLINE int get_index() const; 00106 00107 private: 00108 PStatClient *_client; 00109 int _index; 00110 double _level; 00111 00112 friend class PStatClient; 00113 00114 #else // DO_PSTATS 00115 public: 00116 INLINE PStatCollector(); 00117 00118 PUBLISHED: 00119 INLINE PStatCollector(const string &name, 00120 PStatClient *client = NULL); 00121 INLINE PStatCollector(const PStatCollector &parent, 00122 const string &name); 00123 00124 INLINE bool is_active() { return false; } 00125 INLINE bool is_started() { return false; } 00126 INLINE void start() { } 00127 INLINE void stop() { } 00128 00129 INLINE void clear_level() { } 00130 INLINE void set_level(double) { } 00131 INLINE void add_level(double) { } 00132 INLINE void sub_level(double) { } 00133 INLINE void add_level_now(double) { } 00134 INLINE void sub_level_now(double) { } 00135 INLINE void flush_level() { } 00136 INLINE double get_level() { return 0.0; } 00137 00138 INLINE bool is_active(const PStatThread &) { return false; } 00139 INLINE void start(const PStatThread &) { } 00140 INLINE void start(const PStatThread &, double) { } 00141 INLINE void stop(const PStatThread &) { } 00142 INLINE void stop(const PStatThread &, double) { } 00143 00144 INLINE void clear_level(const PStatThread &) { } 00145 INLINE void set_level(const PStatThread &, double) { } 00146 INLINE void add_level(const PStatThread &, double) { } 00147 INLINE void sub_level(const PStatThread &, double) { } 00148 INLINE double get_level(const PStatThread &) { return 0.0; } 00149 00150 INLINE int get_index() const { return 0; } 00151 00152 #endif // DO_PSTATS 00153 }; 00154 00155 #include "pStatCollector.I" 00156 00157 inline ostream &operator << (ostream &out, const PStatCollector &pcol) { 00158 #ifdef DO_PSTATS 00159 pcol.output(out); 00160 #endif // DO_PSTATS 00161 return out; 00162 } 00163 00164 #endif 00165