Panda3D
pStatCollector.h
1 // Filename: pStatCollector.h
2 // Created by: drose (10Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PSTATCOLLECTOR_H
16 #define PSTATCOLLECTOR_H
17 
18 #include "pandabase.h"
19 
20 #include "pStatThread.h"
21 #include "pStatClient.h"
22 
23 class Thread;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : PStatCollector
27 // Description : A lightweight class that represents a single element
28 // that may be timed and/or counted via stats.
29 //
30 // Collectors can be used to measure two different kinds
31 // of values: elapsed time, and "other".
32 //
33 // To measure elapsed time, call start() and stop() as
34 // appropriate to bracket the section of code you want
35 // to time (or use a PStatTimer to do this
36 // automatically).
37 //
38 // To measure anything else, call set_level() and/or
39 // add_level() to set the "level" value associated with
40 // this collector. The meaning of the value set for the
41 // "level" is entirely up to the user; it may represent
42 // the number of triangles rendered or the kilobytes of
43 // texture memory consumed, for instance. The level set
44 // will remain fixed across multiple frames until it is
45 // reset via another set_level() or adjusted via a call
46 // to add_level(). It may also be completely removed
47 // via clear_level().
48 ////////////////////////////////////////////////////////////////////
49 class EXPCL_PANDA_PSTATCLIENT PStatCollector {
50 #ifdef DO_PSTATS
51 
52 private:
53  INLINE PStatCollector(PStatClient *client, int index);
54 
55 public:
56  INLINE PStatCollector();
57 
58 PUBLISHED:
59  INLINE PStatCollector(const string &name,
60  PStatClient *client = NULL);
61  INLINE PStatCollector(const PStatCollector &parent,
62  const string &name);
63 
64  INLINE PStatCollector(const PStatCollector &copy);
65  INLINE void operator = (const PStatCollector &copy);
66 
67  INLINE bool is_valid() const;
68  INLINE string get_name() const;
69  INLINE string get_fullname() const;
70  INLINE void output(ostream &out) const;
71 
72  INLINE bool is_active();
73  INLINE bool is_started();
74  INLINE void start();
75  INLINE void stop();
76 
77  INLINE void clear_level();
78  INLINE void set_level(double level);
79  INLINE void add_level(double increment);
80  INLINE void sub_level(double decrement);
81  INLINE void add_level_now(double increment);
82  INLINE void sub_level_now(double decrement);
83  INLINE void flush_level();
84  INLINE double get_level();
85 
86  INLINE void clear_thread_level();
87  INLINE void set_thread_level(double level);
88  INLINE void add_thread_level(double increment);
89  INLINE void sub_thread_level(double decrement);
90  INLINE double get_thread_level();
91 
92  INLINE bool is_active(const PStatThread &thread);
93  INLINE bool is_started(const PStatThread &thread);
94  INLINE void start(const PStatThread &thread);
95  INLINE void start(const PStatThread &thread, double as_of);
96  INLINE void stop(const PStatThread &thread);
97  INLINE void stop(const PStatThread &thread, double as_of);
98 
99  INLINE void clear_level(const PStatThread &thread);
100  INLINE void set_level(const PStatThread &thread, double level);
101  INLINE void add_level(const PStatThread &thread, double increment);
102  INLINE void sub_level(const PStatThread &thread, double decrement);
103  INLINE double get_level(const PStatThread &thread);
104 
105  INLINE int get_index() const;
106 
107 private:
108  PStatClient *_client;
109  int _index;
110  double _level;
111 
112 friend class PStatClient;
113 
114 #else // DO_PSTATS
115 public:
116  INLINE PStatCollector();
117 
118 PUBLISHED:
119  INLINE PStatCollector(const string &name,
120  PStatClient *client = NULL);
121  INLINE PStatCollector(const PStatCollector &parent,
122  const string &name);
123 
124  INLINE bool is_active() { return false; }
125  INLINE bool is_started() { return false; }
126  INLINE void start() { }
127  INLINE void stop() { }
128 
129  INLINE void clear_level() { }
130  INLINE void set_level(double) { }
131  INLINE void add_level(double) { }
132  INLINE void sub_level(double) { }
133  INLINE void add_level_now(double) { }
134  INLINE void sub_level_now(double) { }
135  INLINE void flush_level() { }
136  INLINE double get_level() { return 0.0; }
137 
138  INLINE bool is_active(const PStatThread &) { return false; }
139  INLINE void start(const PStatThread &) { }
140  INLINE void start(const PStatThread &, double) { }
141  INLINE void stop(const PStatThread &) { }
142  INLINE void stop(const PStatThread &, double) { }
143 
144  INLINE void clear_level(const PStatThread &) { }
145  INLINE void set_level(const PStatThread &, double) { }
146  INLINE void add_level(const PStatThread &, double) { }
147  INLINE void sub_level(const PStatThread &, double) { }
148  INLINE double get_level(const PStatThread &) { return 0.0; }
149 
150  INLINE int get_index() const { return 0; }
151 
152 #endif // DO_PSTATS
153 };
154 
155 #include "pStatCollector.I"
156 
157 inline ostream &operator << (ostream &out, const PStatCollector &pcol) {
158 #ifdef DO_PSTATS
159  pcol.output(out);
160 #endif // DO_PSTATS
161  return out;
162 }
163 
164 #endif
165 
A lightweight class that represents a single element that may be timed and/or counted via stats...
A lightweight class that represents a single thread of execution to PStats.
Definition: pStatThread.h:31
A thread; that is, a lightweight process.
Definition: thread.h:51
Manages the communications to report statistics via a network connection to a remote PStatServer...
Definition: pStatClient.h:261