28 _client_data(client_data)
30 _first_frame_number = 0;
31 _history = pstats_history;
32 _computed_elapsed_frames =
false;
48 return _frames.empty();
56 nassertr(!_frames.empty(), 0);
57 return _first_frame_number + _frames.size() - 1;
65 nassertr(!_frames.empty(), 0);
66 return _first_frame_number;
75 int rel_frame = frame_number - _first_frame_number;
77 return (rel_frame >= 0 && rel_frame < (
int)_frames.size() &&
78 _frames[rel_frame] !=
nullptr);
88 int rel_frame = frame_number - _first_frame_number;
89 int num_frames = _frames.size();
90 if (rel_frame >= num_frames) {
91 rel_frame = num_frames - 1;
94 while (rel_frame >= 0 && _frames[rel_frame] ==
nullptr) {
100 while (rel_frame < num_frames &&
101 _frames[rel_frame] ==
nullptr) {
106 if (rel_frame >= 0 && rel_frame < num_frames) {
108 nassertr(frame !=
nullptr, _null_frame);
109 nassertr(frame->
get_start() >= 0.0, _null_frame);
113 nassertr(_null_frame.
get_start() >= 0.0, _null_frame);
123 nassertr(!_frames.empty(), 0.0);
124 return _frames.back()->get_start();
133 nassertr(!_frames.empty(), 0.0);
134 return _frames.front()->get_start();
155 hint -= _first_frame_number;
156 if (hint >= 0 && hint < (
int)_frames.size()) {
157 if (_frames[hint] !=
nullptr &&
158 _frames[hint]->get_start() <= time) {
161 while (i < (
int)_frames.size() &&
162 (_frames[i] ==
nullptr ||
163 _frames[i]->get_start() <= time)) {
164 if (_frames[i] !=
nullptr) {
169 return _first_frame_number + hint;
175 int i = _frames.size() - 1;
178 if (frame !=
nullptr && frame->
get_start() <= time) {
184 return _first_frame_number + i;
192 nassertr(!_frames.empty(), _null_frame);
193 return *_frames.back();
204 if (!_computed_elapsed_frames) {
210 return _got_elapsed_frames;
224 int num_frames = now_i - then_i + 1;
225 double now = _frames[now_i - _first_frame_number]->get_end();
226 double elapsed_time = (now - _frames[then_i - _first_frame_number]->get_start());
227 return (
double)num_frames / elapsed_time;
262 nassertv(frame_data !=
nullptr);
267 double oldest_allowable_time = time - _history;
268 while (!_frames.empty() &&
269 (_frames.front() ==
nullptr ||
270 _frames.front()->is_empty() ||
271 _frames.front()->get_start() < oldest_allowable_time)) {
272 if (_frames.front() !=
nullptr) {
273 delete _frames.front();
276 _first_frame_number++;
282 if (_frames.empty()) {
283 _first_frame_number = frame_number;
284 _frames.push_back(
nullptr);
287 while (_first_frame_number + (
int)_frames.size() <= frame_number) {
288 _frames.push_back(
nullptr);
292 int index = frame_number - _first_frame_number;
293 nassertv(index >= 0 && index < (
int)_frames.size());
295 if (_frames[index] !=
nullptr) {
296 nout <<
"Got repeated frame data for frame " << frame_number <<
"\n";
297 delete _frames[index];
300 _frames[index] = frame_data;
301 _computed_elapsed_frames =
false;
309void PStatThreadData::
310compute_elapsed_frames() {
311 if (_frames.empty()) {
313 _got_elapsed_frames =
false;
316 _now_i = _frames.size() - 1;
317 while (_now_i > 0 && _frames[_now_i] ==
nullptr) {
322 _got_elapsed_frames =
false;
325 nassertv(_frames[_now_i] !=
nullptr);
327 double now = _frames[_now_i]->get_end();
328 double then = now - pstats_average_time;
335 if (frame !=
nullptr) {
345 nassertv(_then_i >= 0);
346 nassertv(_frames[_then_i] !=
nullptr);
347 _got_elapsed_frames =
true;
349 _now_i += _first_frame_number;
350 _then_i += _first_frame_number;
354 _computed_elapsed_frames =
true;
The data associated with a particular client, but not with any one particular frame or thread: the li...
Contains the raw timing and level data for a single frame.
bool is_empty() const
Returns true if the FrameData has no time or level data.
double get_start() const
Returns the time of the first data point in the frame data.
A collection of FrameData structures for recently-received frames within a particular thread.
void set_history(double time)
Sets the number of seconds worth of frames that will be retained by the ThreadData structure as each ...
bool get_elapsed_frames(int &then_i, int &now_i) const
Computes the oldest frame number not older than pstats_average_time seconds, and the newest frame num...
int get_frame_number_at_time(double time, int hint=-1) const
Returns the frame number of the latest frame not later than the indicated time.
bool is_empty() const
Returns true if the structure contains no frames, false otherwise.
double get_history() const
Returns the number of seconds worth of frames that will be retained by the ThreadData structure as ea...
double get_frame_rate() const
Computes the average frame rate over the past pstats_average_time seconds, by counting up the number ...
const PStatFrameData & get_frame_at_time(double time) const
Returns the FrameData structure associated with the latest frame not later than the indicated time.
const PStatFrameData & get_latest_frame() const
Returns the FrameData associated with the most recent frame.
bool has_frame(int frame_number) const
Returns true if we have received data for the indicated frame number from the client and we still hav...
const PStatFrameData & get_frame(int frame_number) const
Returns a FrameData structure associated with the indicated frame number.
int get_latest_frame_number() const
Returns the frame number of the most recent frame stored in the data.
int get_oldest_frame_number() const
Returns the frame number of the oldest frame still stored in the data.
double get_latest_time() const
Returns the timestamp (in seconds elapsed since connection) of the latest available frame.
void record_new_frame(int frame_number, PStatFrameData *frame_data)
Makes room for and stores a new frame's worth of data.
double get_oldest_time() const
Returns the timestamp (in seconds elapsed since connection) of the oldest available frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.