forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpStatClient.I
More file actions
208 lines (186 loc) · 5.05 KB
/
pStatClient.I
File metadata and controls
208 lines (186 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file pStatClient.I
* @author drose
* @date 2000-07-16
*/
/**
* Returns the total number of collectors the Client knows about.
*/
INLINE int PStatClient::
get_num_collectors() const {
ReMutexHolder holder(_lock);
return (int)_num_collectors;
}
/**
* Returns the definition body of the nth collector.
*/
INLINE PStatCollectorDef *PStatClient::
get_collector_def(int index) const {
nassertr(index >= 0 && index < _num_collectors, nullptr);
return get_collector_ptr(index)->get_def(this, index);
}
/**
* Returns the total number of threads the Client knows about.
*/
INLINE int PStatClient::
get_num_threads() const {
ReMutexHolder holder(_lock);
return (int)_num_threads;
}
/**
* Returns the name of the indicated thread.
*/
INLINE std::string PStatClient::
get_thread_name(int index) const {
nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), std::string());
return get_thread_ptr(index)->_name;
}
/**
* Returns the sync_name of the indicated thread.
*/
INLINE std::string PStatClient::
get_thread_sync_name(int index) const {
nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), std::string());
return get_thread_ptr(index)->_sync_name;
}
/**
* Returns the Panda Thread object associated with the indicated PStatThread.
*/
INLINE PT(Thread) PStatClient::
get_thread_object(int index) const {
nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), nullptr);
InternalThread *thread = get_thread_ptr(index);
return thread->_thread.lock();
}
/**
* Attempts to establish a connection to the indicated PStatServer. Returns
* true if successful, false on failure.
*/
INLINE bool PStatClient::
connect(const std::string &hostname, int port) {
return get_global_pstats()->client_connect(hostname, port);
}
/**
* Closes the connection previously established.
*/
INLINE void PStatClient::
disconnect() {
get_global_pstats()->client_disconnect();
}
/**
* Returns true if the client believes it is connected to a working
* PStatServer, false otherwise.
*/
INLINE bool PStatClient::
is_connected() {
return get_global_pstats()->client_is_connected();
}
/**
* Resumes the PStatClient after the simulation has been paused for a while.
* This allows the stats to continue exactly where it left off, instead of
* leaving a big gap that would represent a chug.
*/
INLINE void PStatClient::
resume_after_pause() {
get_global_pstats()->client_resume_after_pause();
}
/**
* Returns true if the PStatClientImpl object has been created for this object
* yet, false otherwise.
*/
INLINE bool PStatClient::
has_impl() const {
return (_impl != nullptr);
}
/**
* Returns the PStatClientImpl object for this object. If the PStatClientImpl
* object has not yet been created, implicitly creates it.
*/
INLINE PStatClientImpl *PStatClient::
get_impl() {
ReMutexHolder holder(_lock);
if (_impl == nullptr) {
make_impl();
}
return _impl;
}
/**
* Returns the PStatClientImpl object for this object. If the PStatClientImpl
* object has not yet been created, implicitly creates it.
*/
INLINE const PStatClientImpl *PStatClient::
get_impl() const {
ReMutexHolder holder(_lock);
if (_impl == nullptr) {
make_impl();
}
return _impl;
}
/**
* Returns the nth collector in a thread-safe manner, even if _lock is not
* held.
*/
INLINE PStatClient::Collector *PStatClient::
get_collector_ptr(int collector_index) const {
CollectorPointer *collectors = (CollectorPointer *)AtomicAdjust::get_ptr(_collectors);
return collectors[collector_index];
}
/**
* Returns the nth thread in a thread-safe manner, even if _lock is not held.
*/
INLINE PStatClient::InternalThread *PStatClient::
get_thread_ptr(int thread_index) const {
ThreadPointer *threads = (ThreadPointer *)AtomicAdjust::get_ptr(_threads);
return threads[thread_index];
}
/**
*
*/
INLINE PStatClient::Collector::
Collector(int parent_index, const std::string &name) :
_def(nullptr),
_parent_index(parent_index),
_name(name)
{
}
/**
*
*/
INLINE int PStatClient::Collector::
get_parent_index() const {
return _parent_index;
}
/**
*
*/
INLINE const std::string &PStatClient::Collector::
get_name() const {
return _name;
}
/**
* Returns true if the indicated collector has been designated as active,
* false otherwise. This might return initially false until the collector def
* has actually been created.
*/
INLINE bool PStatClient::Collector::
is_active() const {
return _def != nullptr && _def->_is_active;
}
/**
* Returns the PStatCollectorDef that contains all of the information about
* the collector. If this object has not yet been created, creates it.
*/
INLINE PStatCollectorDef *PStatClient::Collector::
get_def(const PStatClient *client, int this_index) const {
if (_def == nullptr) {
((Collector *)this)->make_def(client, this_index);
}
return _def;
}