33 int thread_index,
int collector_index,
int xsize,
int ysize) :
35 _thread_index(thread_index),
37 _collector_index(collector_index)
39 _scroll_mode = pstats_scroll_mode;
40 _average_mode =
false;
47 _value_height = 1.0/10.0;
51 _title_unknown =
true;
56 _unit_name = def._level_units;
59 set_default_vertical_scale();
77 _next_frame = min(frame_number, _next_frame);
95 if (latest > _next_frame) {
96 draw_frames(_next_frame, latest);
106 while (di != _data.end() &&
108 dec_label_usage((*di).second);
137 if (_collector_index != collector_index) {
138 _collector_index = collector_index;
139 _title_unknown =
true;
157 if (def._suggested_scale != 0.0) {
173 double max_value = 0.0;
175 int frame_number = -1;
176 for (
int x = 0; x <= _xsize; x++) {
181 if (thread_data->
has_frame(frame_number)) {
182 double net_value = get_net_value(frame_number);
183 max_value = max(max_value, net_value);
189 if (max_value == 0.0) {
217 compute_average_pixel_data(fdata, then_i, now_i, start_time);
218 double overall_value = 0.0;
221 FrameData::const_iterator fi;
222 for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
223 const ColorData &cd = (*fi);
224 overall_value += cd._net_value;
227 return cd._collector_index;
233 const FrameData &fdata = get_frame_data(frame_number);
234 double overall_value = 0.0;
237 FrameData::const_iterator fi;
238 for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
239 const ColorData &cd = (*fi);
240 overall_value += cd._net_value;
243 return cd._collector_index;
258 _title_unknown =
false;
265 if (!def._level_units.empty()) {
266 text +=
" (" + def._level_units +
")";
272 _title_unknown =
true;
275 if (_thread_index != 0) {
277 text +=
" (" + client_data->
get_thread_name(_thread_index) +
" thread)";
279 _title_unknown =
true;
294 if (level !=
nullptr && level->
get_count() > 0) {
295 text +=
" / " + format_string(level->
get_count()) +
"x";
305void PStatStripChart::
306accumulate_frame_data(FrameData &fdata,
const FrameData &additional,
308 FrameData::iterator ai;
309 FrameData::const_iterator bi;
312 bi = additional.begin();
316 if (fdata.size() == additional.size()) {
320 while (ai != fdata.end() &&
321 (*ai)._collector_index == (*bi)._collector_index) {
322 (*ai)._net_value += ((*bi)._net_value * weight);
327 if (ai == fdata.end()) {
336 result.reserve(max(fdata.size(), additional.size()));
337 FrameData::const_iterator ci;
338 for (ci = fdata.begin(); ci != ai; ++ci) {
339 result.push_back(*ci);
344 result.reserve(max(fdata.size(), additional.size()));
347 while (ai != fdata.end() && bi != additional.end()) {
348 if ((*ai)._i < (*bi)._i) {
350 result.push_back(*ai);
353 }
else if ((*bi)._i < (*ai)._i) {
356 scaled._collector_index = (*bi)._collector_index;
357 scaled._i = (*bi)._i;
358 scaled._net_value = (*bi)._net_value * weight;
359 result.push_back(scaled);
365 combined._collector_index = (*ai)._collector_index;
366 combined._i = (*bi)._i;
367 combined._net_value = (*ai)._net_value + (*bi)._net_value * weight;
368 result.push_back(combined);
374 while (ai != fdata.end()) {
376 result.push_back(*ai);
380 while (bi != additional.end()) {
383 scaled._collector_index = (*bi)._collector_index;
384 scaled._i = (*bi)._i;
385 scaled._net_value = (*bi)._net_value * weight;
386 result.push_back(scaled);
396void PStatStripChart::
397scale_frame_data(FrameData &fdata,
double factor) {
398 FrameData::iterator fi;
399 for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
400 (*fi)._net_value *= factor;
411get_frame_data(
int frame_number) {
412 Data::const_iterator di;
413 di = _data.find(frame_number);
414 if (di != _data.end()) {
421 FrameData &fdata = _data[frame_number];
425 for (
int i = 0; i < num_children; i++) {
428 cd._collector_index = (
unsigned short)child->
get_collector();
429 cd._i = (
unsigned short)i;
431 if (cd._net_value != 0.0) {
439 cd._collector_index = (
unsigned short)level->
get_collector();
440 cd._i = (
unsigned short)num_children;
442 if (cd._net_value > 0.0) {
446 inc_label_usage(fdata);
461void PStatStripChart::
463 int &then_i,
int &now_i,
double now) {
472 double then = now - pstats_average_time;
475 while (then_i <= latest_frame &&
479 while (now_i <= latest_frame &&
490 accumulate_frame_data(result, get_frame_data(then_i),
495 for (
int frame_number = then_i + 1;
496 frame_number < now_i;
498 accumulate_frame_data(result, get_frame_data(frame_number),
505 accumulate_frame_data(result, get_frame_data(now_i), now - last);
508 scale_frame_data(result, 1.0f / (now - then));
515double PStatStripChart::
516get_net_value(
int frame_number)
const {
517 const FrameData &frame =
520 double net_value = 0.0;
521 FrameData::const_iterator fi;
522 for (fi = frame.begin(); fi != frame.end(); ++fi) {
523 const ColorData &cd = (*fi);
524 net_value += cd._net_value;
534double PStatStripChart::
535get_average_net_value()
const {
541 double now = _time_width + _start_time;
542 double then = now - pstats_average_time;
544 int num_frames = now_i - then_i + 1;
554 double now = now_frame_data.
get_end();
555 double elapsed_time = (now - then_frame_data.
get_start());
556 return elapsed_time / (double)num_frames;
566 double net_value = 0.0f;
567 double net_time = 0.0f;
573 net_value += get_net_value(then_i) * this_time;
574 net_time += this_time;
577 for (
int frame_number = then_i + 1;
578 frame_number <= now_i;
581 net_value += get_net_value(frame_number) * this_time;
582 net_time += this_time;
585 return net_value / net_time;
594void PStatStripChart::
595changed_size(
int xsize,
int ysize) {
596 if (xsize != _xsize || ysize != _ysize) {
599 if (_xsize > 0 && _ysize > 0) {
600 _cursor_pixel = xsize * _cursor_pixel / _xsize;
604 draw_pixels(0, _xsize);
608 double old_start_time = _start_time;
611 _start_time -= _time_width;
612 draw_pixels(_cursor_pixel, _xsize);
615 _start_time = old_start_time;
616 draw_pixels(0, _cursor_pixel);
627void PStatStripChart::
630 draw_pixels(0, _xsize);
638void PStatStripChart::
649void PStatStripChart::
657void PStatStripChart::
658copy_region(
int,
int,
int) {
666void PStatStripChart::
667begin_draw(
int,
int) {
675void PStatStripChart::
683void PStatStripChart::
684draw_empty(
int,
int) {
692void PStatStripChart::
701void PStatStripChart::
711void PStatStripChart::
718class SortCollectorLabels2 {
721 _client_data(client_data) {
723 bool operator () (
int a,
int b)
const {
734void PStatStripChart::
740 for (
int i = 0; i < num_children; i++) {
743 if (is_label_used(collector_index)) {
744 _labels.push_back(collector_index);
748 SortCollectorLabels2 sort_labels(
get_monitor()->get_client_data());
749 sort(_labels.begin(), _labels.end(), sort_labels);
752 _labels.push_back(collector_index);
754 _labels_changed =
true;
761void PStatStripChart::
763 update_guide_bars(4, _value_height);
770void PStatStripChart::
771draw_frames(
int first_frame,
int last_frame) {
787 if (thread_data->
has_frame(first_frame)) {
797 if (_first_data && !_scroll_mode) {
798 first_pixel = min(_cursor_pixel, first_pixel);
802 if (last_pixel - first_pixel >= _xsize) {
810 if (last_pixel <= _xsize) {
812 _cursor_pixel = last_pixel;
813 draw_pixels(first_pixel, last_pixel);
818 int slide_pixels = last_pixel - _xsize;
819 copy_region(slide_pixels, first_pixel, 0);
820 first_pixel -= slide_pixels;
821 last_pixel -= slide_pixels;
822 _start_time += (double)slide_pixels / (
double)_xsize * _time_width;
823 draw_pixels(first_pixel, last_pixel);
828 draw_pixels(first_pixel, _xsize);
830 last_pixel -= _xsize;
831 _cursor_pixel = last_pixel;
832 draw_pixels(0, last_pixel);
840void PStatStripChart::
841draw_pixels(
int first_pixel,
int last_pixel) {
842 begin_draw(first_pixel, last_pixel);
845 if (_average_mode && !thread_data->
is_empty()) {
850 for (
int x = first_pixel; x <= last_pixel; x++) {
851 if (x == _cursor_pixel && !_scroll_mode) {
856 draw_slice(x, 1, fdata);
863 int frame_number = -1;
865 while (x <= last_pixel) {
866 if (x == _cursor_pixel && !_scroll_mode) {
874 int stop_pixel = last_pixel;
876 stop_pixel = min(stop_pixel, _cursor_pixel);
878 while (x + w < stop_pixel &&
882 if (thread_data->
has_frame(frame_number)) {
883 draw_slice(x, w, get_frame_data(frame_number));
892 end_draw(first_pixel, last_pixel);
898void PStatStripChart::
900 _label_usage.clear();
909void PStatStripChart::
910dec_label_usage(
const FrameData &fdata) {
911 FrameData::const_iterator fi;
912 for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
913 const ColorData &cd = (*fi);
914 nassertv(cd._collector_index < (
int)_label_usage.size());
915 nassertv(_label_usage[cd._collector_index] > 0);
916 _label_usage[cd._collector_index]--;
917 if (_label_usage[cd._collector_index] == 0) {
931void PStatStripChart::
932inc_label_usage(
const FrameData &fdata) {
933 FrameData::const_iterator fi;
934 for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
935 const ColorData &cd = (*fi);
936 while (cd._collector_index >= (
int)_label_usage.size()) {
937 _label_usage.push_back(0);
939 nassertv(_label_usage[cd._collector_index] >= 0);
940 _label_usage[cd._collector_index]++;
941 if (_label_usage[cd._collector_index] == 1) {
The data associated with a particular client, but not with any one particular frame or thread: the li...
std::string get_collector_fullname(int index) const
Returns the "full name" of the indicated collector.
bool has_thread(int index) const
Returns true if the indicated thread has been defined by the client already, false otherwise.
const PStatCollectorDef & get_collector_def(int index) const
Returns the nth collector definition.
int get_num_threads() const
Returns the total number of threads the Data knows about.
std::string get_thread_name(int index) const
Returns the name of the indicated thread.
int get_num_collectors() const
Returns the total number of collectors the Data knows about.
bool has_collector(int index) const
Returns true if the indicated collector has been defined by the client already, false otherwise.
Defines the details about the Collectors: the name, the suggested color, etc.
Contains the raw timing and level data for a single frame.
double get_end() const
Returns the time of the last data point in the frame data.
double get_net_time() const
Returns the total time elapsed for the frame.
double get_start() const
Returns the time of the first data point in the frame data.
This is an abstract base class for several different kinds of graphs that have a few things in common...
const std::string & get_guide_bar_unit_name() const
Returns the name of the units to be used for the guide bars if the units type is set to GBU_named | G...
int get_guide_bar_units() const
Returns the units that are displayed for the guide bar labels.
double get_target_frame_rate() const
Returns the indicated target frame rate in Hz.
PStatMonitor * get_monitor() const
Returns the monitor associated with this chart.
static std::string format_number(double value)
Returns a string representing the value nicely formatted for its range.
int get_ysize() const
Returns the height of the chart in pixels.
This is an abstract class that presents the interface to any number of different front-ends for the s...
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
This is an abstract class that presents the interface for drawing a basic strip-chart,...
std::string get_title_text()
Returns the text suitable for the title label on the top line.
int height_to_pixel(double value) const
Converts a value (i.e.
void set_auto_vertical_scale()
Sets the vertical scale to make all the data visible.
void update()
Updates the chart with the latest data.
int get_collector_under_pixel(int xpoint, int ypoint)
Return the collector index associated with the particular band of color at the indicated pixel locati...
std::string get_total_text()
Returns the text suitable for the total label above the graph.
void set_collector_index(int collector_index)
Changes the collector represented by this strip chart.
double pixel_to_timestamp(int x) const
Converts a horizontal pixel offset to a timestamp.
void set_default_vertical_scale()
Sets the vertical scale according to the suggested scale of the base collector, if any,...
void new_data(int frame_number)
Indicates that new data has become available.
int timestamp_to_pixel(double time) const
Converts a timestamp to a horizontal pixel offset.
bool first_data() const
Returns true if the chart has seen its first data appear on it, false if it is still a virgin chart.
int get_collector_index() const
Returns the particular collector whose data this strip chart reflects.
void set_vertical_scale(double value_height)
Changes the value the height of the vertical axis represents.
A collection of FrameData structures for recently-received frames within a particular thread.
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.
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.
double get_oldest_time() const
Returns the timestamp (in seconds elapsed since connection) of the oldest available frame.
This is a single level value, or band of color, within a View.
const PStatViewLevel * get_child(int n) const
Returns the nth child of this Level/Collector.
double get_net_value() const
Returns the total level value (or elapsed time) represented by this Collector, including all values i...
int get_num_children() const
Returns the number of children of this Level/Collector.
int get_collector() const
Returns the Collector index associated with this level.
int get_count() const
Returns the number of start/stop pairs for this collector.
double get_value_alone() const
Returns the total level value (or elapsed time value) for this Collector, not including any values ac...
A View boils down the frame data to a linear list of times spent in a number of different Collectors,...
int get_level_index() const
Returns an index number that can be used to determine when the set of known levels has changed.
void set_to_frame(const PStatFrameData &frame_data)
Supplies the View with the data for the current frame.
bool get_show_level() const
Returns true if we are showing level data, false if time data.
const PStatThreadData * get_thread_data()
Returns the current PStatThreadData associated with the view.
PStatViewLevel * get_level(int collector)
Returns a pointer to the level that corresponds to the indicated Collector.
This is our own Panda specialization on the default STL vector.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.