15 #include "pStatThreadData.h"
17 #include "pStatFrameData.h"
18 #include "pStatCollectorDef.h"
19 #include "config_pstats.h"
31 _client_data(client_data)
33 _first_frame_number = 0;
34 _history = pstats_history;
35 _computed_elapsed_frames =
false;
56 return _frames.empty();
67 nassertr(!_frames.empty(), 0);
68 return _first_frame_number + _frames.size() - 1;
79 nassertr(!_frames.empty(), 0);
80 return _first_frame_number;
92 int rel_frame = frame_number - _first_frame_number;
94 return (rel_frame >= 0 && rel_frame < (
int)_frames.size() &&
108 int rel_frame = frame_number - _first_frame_number;
109 int num_frames = _frames.size();
110 if (rel_frame >= num_frames) {
111 rel_frame = num_frames - 1;
114 while (rel_frame >= 0 && _frames[rel_frame] == (
PStatFrameData *)NULL) {
120 while (rel_frame < num_frames &&
126 if (rel_frame >= 0 && rel_frame < num_frames) {
129 nassertr(frame->
get_start() >= 0.0, _null_frame);
133 nassertr(_null_frame.
get_start() >= 0.0, _null_frame);
145 nassertr(!_frames.empty(), 0.0);
146 return _frames.back()->get_start();
157 nassertr(!_frames.empty(), 0.0);
158 return _frames.front()->get_start();
184 hint -= _first_frame_number;
185 if (hint >= 0 && hint < (
int)_frames.size()) {
187 _frames[hint]->get_start() <= time) {
190 while (i < (
int)_frames.size() &&
192 _frames[i]->get_start() <= time)) {
198 return _first_frame_number + hint;
205 int i = _frames.size() - 1;
214 return _first_frame_number + i;
225 nassertr(!_frames.empty(), _null_frame);
226 return *_frames.back();
240 if (!_computed_elapsed_frames) {
246 return _got_elapsed_frames;
263 int num_frames = now_i - then_i + 1;
264 double now = _frames[now_i - _first_frame_number]->get_end();
265 double elapsed_time = (now - _frames[then_i - _first_frame_number]->get_start());
266 return (
double)num_frames / elapsed_time;
316 double oldest_allowable_time = time - _history;
317 while (!_frames.empty() &&
319 _frames.front()->is_empty() ||
320 _frames.front()->get_start() < oldest_allowable_time)) {
322 delete _frames.front();
325 _first_frame_number++;
331 if (_frames.empty()) {
332 _first_frame_number = frame_number;
333 _frames.push_back(NULL);
336 while (_first_frame_number + (
int)_frames.size() <= frame_number) {
337 _frames.push_back(NULL);
341 int index = frame_number - _first_frame_number;
342 nassertv(index >= 0 && index < (
int)_frames.size());
345 nout <<
"Got repeated frame data for frame " << frame_number <<
"\n";
346 delete _frames[index];
349 _frames[index] = frame_data;
350 _computed_elapsed_frames =
false;
361 void PStatThreadData::
362 compute_elapsed_frames() {
363 if (_frames.empty()) {
365 _got_elapsed_frames =
false;
368 _now_i = _frames.size() - 1;
374 _got_elapsed_frames =
false;
379 double now = _frames[_now_i]->get_end();
380 double then = now - pstats_average_time;
397 nassertv(_then_i >= 0);
399 _got_elapsed_frames =
true;
401 _now_i += _first_frame_number;
402 _then_i += _first_frame_number;
406 _computed_elapsed_frames =
true;
void set_history(double time)
Sets the number of seconds worth of frames that will be retained by the ThreadData structure as each ...
bool is_empty() const
Returns true if the FrameData has no time or level data.
void record_new_frame(int frame_number, PStatFrameData *frame_data)
Makes room for and stores a new frame's worth of data.
bool is_empty() const
Returns true if the structure contains no frames, false otherwise.
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...
The data associated with a particular client, but not with any one particular frame or thread: the li...
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.
const PStatFrameData & get_frame_at_time(double time) const
Returns the FrameData structure associated with the latest frame not later than the indicated time...
double get_oldest_time() const
Returns the timestamp (in seconds elapsed since connection) of the oldest available frame...
double get_start() const
Returns the time of the first data point in the frame data.
Contains the raw timing and level data for a single frame.
const PStatFrameData & get_latest_frame() const
Returns the FrameData associated with the most recent frame.
A collection of FrameData structures for recently-received frames within a particular thread...
double get_history() const
Returns the number of seconds worth of frames that will be retained by the ThreadData structure as ea...
const PStatFrameData & get_frame(int frame_number) const
Returns a FrameData structure associated with the indicated frame number.
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...
double get_latest_time() const
Returns the timestamp (in seconds elapsed since connection) of the latest available frame...
double get_frame_rate() const
Computes the average frame rate over the past pstats_average_time seconds, by counting up the 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.