Panda3D
Loading...
Searching...
No Matches
pStatClient.I
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 pStatClient.I
10 * @author drose
11 * @date 2000-07-16
12 */
13
14/**
15 * Returns the total number of collectors the Client knows about.
16 */
17INLINE int PStatClient::
18get_num_collectors() const {
19 ReMutexHolder holder(_lock);
20 return (int)_num_collectors;
21}
22
23/**
24 * Returns the definition body of the nth collector.
25 */
26INLINE PStatCollectorDef *PStatClient::
27get_collector_def(int index) const {
28 nassertr(index >= 0 && index < _num_collectors, nullptr);
29
30 return get_collector_ptr(index)->get_def(this, index);
31}
32
33/**
34 * Returns the total number of threads the Client knows about.
35 */
36INLINE int PStatClient::
37get_num_threads() const {
38 ReMutexHolder holder(_lock);
39 return (int)_num_threads;
40}
41
42/**
43 * Returns the name of the indicated thread.
44 */
45INLINE std::string PStatClient::
46get_thread_name(int index) const {
47 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), std::string());
48 return get_thread_ptr(index)->_name;
49}
50
51/**
52 * Returns the sync_name of the indicated thread.
53 */
54INLINE std::string PStatClient::
55get_thread_sync_name(int index) const {
56 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), std::string());
57 return get_thread_ptr(index)->_sync_name;
58}
59
60/**
61 * Returns the Panda Thread object associated with the indicated PStatThread.
62 */
63INLINE PT(Thread) PStatClient::
64get_thread_object(int index) const {
65 nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), nullptr);
66 InternalThread *thread = get_thread_ptr(index);
67 return thread->_thread.lock();
68}
69
70/**
71 * Attempts to establish a connection to the indicated PStatServer. Returns
72 * true if successful, false on failure.
73 */
74INLINE bool PStatClient::
75connect(const std::string &hostname, int port) {
76 return get_global_pstats()->client_connect(hostname, port);
77}
78
79/**
80 * Closes the connection previously established.
81 */
82INLINE void PStatClient::
83disconnect() {
84 get_global_pstats()->client_disconnect();
85}
86
87/**
88 * Returns true if the client believes it is connected to a working
89 * PStatServer, false otherwise.
90 */
91INLINE bool PStatClient::
93 return get_global_pstats()->client_is_connected();
94}
95
96/**
97 * Resumes the PStatClient after the simulation has been paused for a while.
98 * This allows the stats to continue exactly where it left off, instead of
99 * leaving a big gap that would represent a chug.
100 */
101INLINE void PStatClient::
103 get_global_pstats()->client_resume_after_pause();
104}
105
106/**
107 * Returns true if the PStatClientImpl object has been created for this object
108 * yet, false otherwise.
109 */
110INLINE bool PStatClient::
111has_impl() const {
112 return (_impl != nullptr);
113}
114
115/**
116 * Returns the PStatClientImpl object for this object. If the PStatClientImpl
117 * object has not yet been created, implicitly creates it.
118 */
119INLINE PStatClientImpl *PStatClient::
120get_impl() {
121 ReMutexHolder holder(_lock);
122 if (_impl == nullptr) {
123 make_impl();
124 }
125 return _impl;
126}
127
128/**
129 * Returns the PStatClientImpl object for this object. If the PStatClientImpl
130 * object has not yet been created, implicitly creates it.
131 */
132INLINE const PStatClientImpl *PStatClient::
133get_impl() const {
134 ReMutexHolder holder(_lock);
135 if (_impl == nullptr) {
136 make_impl();
137 }
138 return _impl;
139}
140
141/**
142 * Returns the nth collector in a thread-safe manner, even if _lock is not
143 * held.
144 */
145INLINE PStatClient::Collector *PStatClient::
146get_collector_ptr(int collector_index) const {
147 CollectorPointer *collectors = (CollectorPointer *)AtomicAdjust::get_ptr(_collectors);
148 return collectors[collector_index];
149}
150
151/**
152 * Returns the nth thread in a thread-safe manner, even if _lock is not held.
153 */
154INLINE PStatClient::InternalThread *PStatClient::
155get_thread_ptr(int thread_index) const {
156 ThreadPointer *threads = (ThreadPointer *)AtomicAdjust::get_ptr(_threads);
157 return threads[thread_index];
158}
159
160/**
161 *
162 */
163INLINE PStatClient::Collector::
164Collector(int parent_index, const std::string &name) :
165 _def(nullptr),
166 _parent_index(parent_index),
167 _name(name)
168{
169}
170
171/**
172 *
173 */
174INLINE int PStatClient::Collector::
175get_parent_index() const {
176 return _parent_index;
177}
178
179/**
180 *
181 */
182INLINE const std::string &PStatClient::Collector::
183get_name() const {
184 return _name;
185}
186
187/**
188 * Returns true if the indicated collector has been designated as active,
189 * false otherwise. This might return initially false until the collector def
190 * has actually been created.
191 */
192INLINE bool PStatClient::Collector::
193is_active() const {
194 return _def != nullptr && _def->_is_active;
195}
196
197/**
198 * Returns the PStatCollectorDef that contains all of the information about
199 * the collector. If this object has not yet been created, creates it.
200 */
201INLINE PStatCollectorDef *PStatClient::Collector::
202get_def(const PStatClient *client, int this_index) const {
203 if (_def == nullptr) {
204 ((Collector *)this)->make_def(client, this_index);
205 }
206
207 return _def;
208}
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
Manages the communications to report statistics via a network connection to a remote PStatServer.
std::string get_thread_sync_name(int index) const
Returns the sync_name of the indicated thread.
static void resume_after_pause()
Resumes the PStatClient after the simulation has been paused for a while.
static void disconnect()
Closes the connection previously established.
int get_num_threads() const
Returns the total number of threads the Client knows about.
static bool is_connected()
Returns true if the client believes it is connected to a working PStatServer, false otherwise.
std::string get_thread_name(int index) const
Returns the name of the indicated thread.
Defines the details about the Collectors: the name, the suggested color, etc.
Similar to MutexHolder, but for a reentrant mutex.
A thread; that is, a lightweight process.
Definition thread.h:46