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