Panda3D

Loading...
Searching...
No Matches
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 public:
47 PStatCollector() = default;
48 INLINE PStatCollector(PStatClient *client, int index);
49
50PUBLISHED:
51 INLINE explicit PStatCollector(const std::string &name,
52 PStatClient *client = nullptr);
53 INLINE explicit PStatCollector(const PStatCollector &parent,
54 const std::string &name);
55
56 INLINE PStatCollector(const PStatCollector &copy);
57 INLINE void operator = (const PStatCollector &copy);
58
59 INLINE bool is_valid() const;
60 INLINE std::string get_name() const;
61 INLINE std::string get_fullname() const;
62 INLINE void output(std::ostream &out) const;
63
64 INLINE bool is_active();
65 INLINE bool is_started();
66 INLINE void start();
67 INLINE void stop();
68
69 INLINE void clear_level();
70 INLINE void set_level(double level);
71 INLINE void add_level(double increment);
72 INLINE void sub_level(double decrement);
73 INLINE void add_level_now(double increment);
74 INLINE void sub_level_now(double decrement);
75 INLINE void flush_level();
76 INLINE double get_level();
77
78 INLINE void clear_thread_level();
79 INLINE void set_thread_level(double level);
80 INLINE void add_thread_level(double increment);
81 INLINE void sub_thread_level(double decrement);
82 INLINE double get_thread_level();
83
84 INLINE bool is_active(const PStatThread &thread);
85 INLINE bool is_started(const PStatThread &thread);
86 INLINE void start(const PStatThread &thread);
87 INLINE void start(const PStatThread &thread, double as_of);
88 INLINE void stop(const PStatThread &thread);
89 INLINE void stop(const PStatThread &thread, double as_of);
90
91 INLINE void clear_level(const PStatThread &thread);
92 INLINE void set_level(const PStatThread &thread, double level);
93 INLINE void add_level(const PStatThread &thread, double increment);
94 INLINE void sub_level(const PStatThread &thread, double decrement);
95 INLINE double get_level(const PStatThread &thread);
96
97 INLINE int get_index() const;
98
99 private:
100 PStatClient *_client = nullptr;
101 int _index = 0;
102 double _level = 0.0;
103
104 friend class PStatClient;
105
106#else // DO_PSTATS
107 public:
108 INLINE PStatCollector();
109
110PUBLISHED:
111 INLINE PStatCollector(const std::string &name,
112 PStatClient *client = nullptr);
113 INLINE PStatCollector(const PStatCollector &parent,
114 const std::string &name);
115
116 INLINE bool is_active() { return false; }
117 INLINE bool is_started() { return false; }
118 INLINE void start() { }
119 INLINE void stop() { }
120
121 INLINE void clear_level() { }
122 INLINE void set_level(double) { }
123 INLINE void add_level(double) { }
124 INLINE void sub_level(double) { }
125 INLINE void add_level_now(double) { }
126 INLINE void sub_level_now(double) { }
127 INLINE void flush_level() { }
128 INLINE double get_level() { return 0.0; }
129
130 INLINE bool is_active(const PStatThread &) { return false; }
131 INLINE void start(const PStatThread &) { }
132 INLINE void start(const PStatThread &, double) { }
133 INLINE void stop(const PStatThread &) { }
134 INLINE void stop(const PStatThread &, double) { }
135
136 INLINE void clear_level(const PStatThread &) { }
137 INLINE void set_level(const PStatThread &, double) { }
138 INLINE void add_level(const PStatThread &, double) { }
139 INLINE void sub_level(const PStatThread &, double) { }
140 INLINE double get_level(const PStatThread &) { return 0.0; }
141
142 INLINE int get_index() const { return 0; }
143
144#endif // DO_PSTATS
145};
146
147#include "pStatCollector.I"
148
149 inline std::ostream &operator << (std::ostream &out, const PStatCollector &pcol) {
150#ifdef DO_PSTATS
151 pcol.output(out);
152#endif // DO_PSTATS
153 return out;
154}
155
156#endif
PStatClient
Manages the communications to report statistics via a network connection to a remote PStatServer.
Definition pStatClient.h:266
PStatCollector
A lightweight class that represents a single element that may be timed and/or counted via stats.
Definition pStatCollector.h:43
PStatCollector::PStatCollector
PStatCollector()
Creates an invalid PStatCollector.
Definition pStatCollector.I:474
PStatThread
A lightweight class that represents a single thread of execution to PStats.
Definition pStatThread.h:28
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
pStatClient.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pStatCollector.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pStatThread.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.