15 #include "pStatView.h" 17 #include "pStatFrameData.h" 18 #include "pStatCollectorDef.h" 19 #include "vector_int.h" 44 void data_point(
double time,
bool is_start, Started &started) {
59 nassertv(is_start != _is_started);
61 _is_started = is_start;
64 nassertv(!_is_started);
65 Started::iterator si = find(started.begin(), started.end(),
this);
66 nassertv(si != started.end());
72 push_all(time, started);
73 started.push_back(
this);
76 Started::iterator si = find(started.begin(), started.end(),
this);
77 nassertv(si != started.end());
79 pop_one(time, started);
83 void push(
double time) {
91 void pop(
double time) {
100 void push_all(
double time, Started &started) {
101 Started::iterator si;
102 for (si = started.begin(); si != started.end(); ++si) {
107 void pop_one(
double time, Started &started) {
108 Started::reverse_iterator si;
109 for (si = started.rbegin(); si != started.rend(); ++si) {
110 if ((*si)->_pushed) {
134 _all_collectors_known =
false;
171 _constraint = collector;
172 _show_level = show_level;
194 _thread_data = thread_data;
197 _all_collectors_known =
false;
217 nassertv(!_thread_data.is_null());
218 nassertv(!_client_data.is_null());
221 update_level_data(frame_data);
223 update_time_data(frame_data);
238 return _all_collectors_known;
252 Levels::const_iterator li;
253 for (li = _levels.begin(); li != _levels.end(); ++li) {
254 net += (*li).second->_value_alone;
271 return get_level(_constraint);
282 Levels::const_iterator li;
283 li = _levels.find(collector);
284 return (li != _levels.end());
298 Levels::const_iterator li;
299 li = _levels.find(collector);
300 if (li != _levels.end()) {
305 level->_collector = collector;
306 level->_parent = NULL;
307 _levels[collector] = level;
324 Samples samples(_client_data->get_num_collectors());
328 _all_collectors_known =
true;
333 GotSamples got_samples;
336 for (i = 0; i < num_events; i++) {
338 bool is_start = frame_data.
is_start(i);
340 if (!_client_data->has_collector(collector_index)) {
341 _all_collectors_known =
false;
344 nassertv(collector_index >= 0 && collector_index < (
int)samples.size());
346 if (_client_data->get_child_distance(_constraint, collector_index) >= 0) {
349 if (is_start == samples[collector_index]._is_started) {
354 samples[collector_index].data_point(frame_data.
get_time(0),
true, started);
355 samples[collector_index].data_point(frame_data.
get_time(i), is_start, started);
359 nout <<
"Unexpected data point for " 360 << _client_data->get_collector_fullname(collector_index)
364 samples[collector_index].data_point(frame_data.
get_time(i), is_start, started);
365 got_samples.insert(collector_index);
373 Samples::iterator si;
374 for (i = 0, si = samples.begin(); si != samples.end(); ++i, ++si) {
375 if ((*si)._is_started) {
376 (*si).data_point(frame_data.
get_end(),
false, started);
380 nassertv(started.empty());
382 bool any_new_levels =
false;
386 Levels::iterator li, lnext;
387 li = _levels.begin();
388 while (li != _levels.end()) {
395 if (reset_level(level)) {
396 any_new_levels =
true;
399 int collector_index = level->_collector;
400 GotSamples::iterator gi;
401 gi = got_samples.find(collector_index);
402 if (gi != got_samples.end()) {
403 level->_value_alone = samples[collector_index]._net_time;
404 got_samples.erase(gi);
412 if (!got_samples.empty()) {
413 any_new_levels =
true;
415 GotSamples::const_iterator gi;
416 for (gi = got_samples.begin(); gi != got_samples.end(); ++gi) {
417 int collector_index = (*gi);
419 level->_value_alone = samples[*gi]._net_time;
423 if (any_new_levels) {
436 _all_collectors_known =
true;
441 GotValues net_values;
445 for (i = 0; i < num_levels; i++) {
449 if (!_client_data->has_collector(collector_index)) {
450 _all_collectors_known =
false;
453 if (_client_data->get_child_distance(_constraint, collector_index) >= 0) {
454 net_values[collector_index] = value;
463 GotValues alone_values = net_values;
465 GotValues::iterator gi;
466 for (gi = net_values.begin(); gi != net_values.end(); ++gi) {
467 int collector_index = (*gi).first;
468 double value = (*gi).second;
472 while (collector_index != 0 && collector_index != _constraint) {
474 _client_data->get_collector_def(collector_index);
475 int parent_index = def._parent_index;
476 GotValues::iterator pi = alone_values.find(parent_index);
477 if (pi != alone_values.end()) {
479 (*pi).second -= value;
482 collector_index = parent_index;
487 bool any_new_levels =
false;
491 Levels::iterator li, lnext;
492 li = _levels.begin();
493 while (li != _levels.end()) {
500 if (reset_level(level)) {
501 any_new_levels =
true;
504 int collector_index = level->_collector;
505 GotValues::iterator gi;
506 gi = alone_values.find(collector_index);
507 if (gi != alone_values.end()) {
508 level->_value_alone = (*gi).second;
509 alone_values.erase(gi);
517 if (!alone_values.empty()) {
518 any_new_levels =
true;
520 GotValues::const_iterator gi;
521 for (gi = alone_values.begin(); gi != alone_values.end(); ++gi) {
522 int collector_index = (*gi).first;
524 level->_value_alone = (*gi).second;
528 if (any_new_levels) {
541 for (li = _levels.begin(); li != _levels.end(); ++li) {
562 bool any_changed =
false;
563 level->_value_alone = 0.0;
565 if (level->_collector == _constraint) {
569 if (_client_data->has_collector(level->_collector)) {
571 _client_data->get_collector_def(level->_collector)._parent_index;
576 nassertr(parent_level != level,
true);
578 level->_parent = parent_level;
579 parent_level->_children.push_back(level);
583 }
else if (level->_parent->_collector != parent_index) {
587 nassertr(old_parent_level != level,
true);
589 if (parent_index != 0) {
591 nassertr(new_parent_level != level,
true);
592 level->_parent = new_parent_level;
593 new_parent_level->_children.push_back(level);
596 level->_parent = NULL;
599 PStatViewLevel::Children::iterator ci =
600 find(old_parent_level->_children.begin(),
601 old_parent_level->_children.end(),
604 nassertr(ci != old_parent_level->_children.end(),
true);
605 old_parent_level->_children.erase(ci);
const PStatViewLevel * get_top_level()
Returns a pointer to the level that corresponds to the Collector we've constrained to...
int get_num_events() const
Returns the number of individual events stored in the FrameData.
void sort_children(const PStatClientData *client_data)
Sorts the children of this view level into order as specified by the client's sort index...
This is our own Panda specialization on the default STL map.
void set_to_frame(const PStatFrameData &frame_data)
Supplies the View with the data for the current frame.
int get_level_collector(int n) const
Returns the index of the collector associated with the nth level value.
bool is_start(int n) const
Returns true if the nth event represents a start event, or false if it represents a stop event...
void unconstrain()
Restores the view to the full frame.
This is our own Panda specialization on the default STL list.
double get_net_value() const
Returns the total value accounted for by the frame (or by whatever Collector we are constrained to)...
int get_num_levels() const
Returns the number of individual level values stored in the FrameData.
This is our own Panda specialization on the default STL vector.
This is a single level value, or band of color, within a View.
int get_time_collector(int n) const
Returns the index of the collector associated with the nth event.
Contains the raw timing and level data for a single frame.
bool all_collectors_known() const
After a call to set_to_frame(), this returns true if all collectors in the FrameData are known by the...
A collection of FrameData structures for recently-received frames within a particular thread...
This class is used within this module only–in fact, within PStatView::set_to_frame() only–to help c...
void constrain(int collector, bool show_level)
Changes the focus of the View.
double get_end() const
Returns the time of the last data point in the frame data.
double get_time(int n) const
Returns the timestamp of the nth event, in seconds elapsed since some undefined epoch (which is guara...
double get_level(int n) const
Returns the height of the nth level value.
Defines the details about the Collectors: the name, the suggested color, etc.
bool has_level(int collector) const
Returns true if there is a level defined for the particular collector, false otherwise.
PStatViewLevel * get_level(int collector)
Returns a pointer to the level that corresponds to the indicated Collector.
const PStatClientData * get_client_data() const
Returns a pointer to the ClientData structure associated with this data.