15 #include "gtkStatsMonitor.h" 17 #include "gtkStatsServer.h" 18 #include "gtkStatsStripChart.h" 19 #include "gtkStatsChartMenu.h" 20 #include "gtkStatsPianoRoll.h" 21 #include "gtkStatsMenuId.h" 22 #include "pStatGraph.h" 23 #include "pStatCollectorDef.h" 28 GtkItemFactoryEntry GtkStatsMonitor::menu_entries[] = {
29 { (gchar *)
"/Options", NULL, NULL, 0, (gchar *)
"<Branch>" },
30 { (gchar *)
"/Options/Units", NULL, NULL, 0, (gchar *)
"<Branch>" },
31 { (gchar *)
"/Options/Units/ms", NULL, (vc *)&handle_menu_command, MI_time_ms, (gchar *)
"<RadioItem>" },
32 { (gchar *)
"/Options/Units/Hz", NULL, (vc *)&handle_menu_command, MI_time_hz, (gchar *)
"/Options/Units/ms" },
33 { (gchar *)
"/Speed", NULL, NULL, 0, (gchar *)
"<Branch>" },
34 { (gchar *)
"/Speed/1", NULL, (vc *)&handle_menu_command, MI_speed_1, (gchar *)
"<RadioItem>" },
35 { (gchar *)
"/Speed/2", NULL, (vc *)&handle_menu_command, MI_speed_2, (gchar *)
"/Speed/1" },
36 { (gchar *)
"/Speed/3", NULL, (vc *)&handle_menu_command, MI_speed_3, (gchar *)
"/Speed/1" },
37 { (gchar *)
"/Speed/6", NULL, (vc *)&handle_menu_command, MI_speed_6, (gchar *)
"/Speed/1" },
38 { (gchar *)
"/Speed/12", NULL, (vc *)&handle_menu_command, MI_speed_12, (gchar *)
"/Speed/1" },
39 { (gchar *)
"/Speed/sep", NULL, NULL, 0, (gchar *)
"<Separator>" },
40 { (gchar *)
"/Speed/pause", NULL, (vc *)&handle_menu_command, MI_pause, (gchar *)
"<CheckItem>" },
43 int GtkStatsMonitor::num_menu_entries =
sizeof(menu_entries) /
sizeof(GtkItemFactoryEntry);
123 int server_major,
int server_minor) {
125 str <<
"Unable to honor connection attempt from " 127 <<
": unsupported PStats version " 128 << client_major <<
"." << client_minor;
130 if (server_minor == 0) {
131 str <<
" (server understands version " << server_major
132 <<
"." << server_minor <<
" only).";
134 str <<
" (server understands versions " << server_major
135 <<
".0 through " << server_major <<
"." << server_minor <<
").";
138 string message = str.str();
140 gtk_message_dialog_new(GTK_WINDOW(main_window),
141 GTK_DIALOG_DESTROY_WITH_PARENT,
144 "%s", message.c_str());
145 gtk_dialog_run(GTK_DIALOG(dialog));
146 gtk_widget_destroy(dialog);
163 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
169 ChartMenus::iterator mi;
170 for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
189 GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory,
"<PStats>");
192 _chart_menus.push_back(chart_menu);
207 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
209 graph->
new_data(thread_index, frame_number);
239 ChartMenus::iterator mi;
240 for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
241 (*mi)->check_update();
247 if (frame_rate != 0.0f) {
249 sprintf(buffer,
"%0.1f ms / %0.1f Hz", 1000.0f / frame_rate, frame_rate);
251 gtk_label_set_text(GTK_LABEL(_frame_rate_label), buffer);
274 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
329 pair<Menus::iterator, bool> result = _menus.insert(menu_def);
330 Menus::iterator mi = result.first;
336 return &new_menu_def;
349 _time_units = unit_mask;
353 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
368 _scroll_speed = scroll_speed;
372 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
390 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
402 void GtkStatsMonitor::
404 _graphs.insert(graph);
412 void GtkStatsMonitor::
414 Graphs::iterator gi = _graphs.find(graph);
415 if (gi != _graphs.end()) {
426 void GtkStatsMonitor::
428 if (_window != NULL) {
432 _window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
434 g_signal_connect(G_OBJECT(_window),
"delete_event",
435 G_CALLBACK(window_delete_event),
this);
436 g_signal_connect(G_OBJECT(_window),
"destroy",
437 G_CALLBACK(window_destroy),
this);
440 gtk_window_set_title(GTK_WINDOW(_window), _window_title.c_str());
442 gtk_window_set_default_size(GTK_WINDOW(_window), 500, 360);
445 GtkAccelGroup *accel_group = gtk_accel_group_new();
447 gtk_item_factory_new(GTK_TYPE_MENU_BAR,
"<PStats>", accel_group);
448 gtk_item_factory_create_items(_item_factory, num_menu_entries, menu_entries,
450 gtk_window_add_accel_group(GTK_WINDOW(_window), accel_group);
451 GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory,
"<PStats>");
452 _next_chart_index = 2;
454 setup_frame_rate_label();
456 ChartMenus::iterator mi;
457 for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
458 (*mi)->add_to_menu_bar(menu_bar, _next_chart_index);
463 GtkWidget *main_vbox = gtk_vbox_new(FALSE, 1);
464 gtk_container_add(GTK_CONTAINER(_window), main_vbox);
465 gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);
467 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(_item_factory,
"/Speed/3")),
471 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(_item_factory,
"/Options/Units/ms")),
475 gtk_widget_show_all(_window);
476 gtk_widget_show(_window);
486 void GtkStatsMonitor::
489 for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
494 ChartMenus::iterator mi;
495 for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
498 _chart_menus.clear();
500 if (_window != NULL) {
501 gtk_widget_destroy(_window);
505 #ifdef DEVELOP_GTKSTATS 516 gboolean GtkStatsMonitor::
517 window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
529 void GtkStatsMonitor::
530 window_destroy(GtkWidget *widget, gpointer data) {
544 void GtkStatsMonitor::
545 setup_frame_rate_label() {
546 GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory,
"<PStats>");
548 _frame_rate_menu_item = gtk_menu_item_new();
549 _frame_rate_label = gtk_label_new(
"");
550 gtk_container_add(GTK_CONTAINER(_frame_rate_menu_item), _frame_rate_label);
552 gtk_widget_show(_frame_rate_menu_item);
553 gtk_widget_show(_frame_rate_label);
554 gtk_menu_item_right_justify(GTK_MENU_ITEM(_frame_rate_menu_item));
556 gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), _frame_rate_menu_item);
564 void GtkStatsMonitor::
565 handle_menu_command(gpointer callback_data, guint menu_id, GtkWidget *widget) {
572 self->set_time_units(PStatGraph::GBU_ms);
576 self->set_time_units(PStatGraph::GBU_hz);
580 self->set_scroll_speed(1);
584 self->set_scroll_speed(2);
588 self->set_scroll_speed(3);
592 self->set_scroll_speed(6);
596 self->set_scroll_speed(12);
600 self->set_pause(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)));
A window that draws a strip chart, given a view.
virtual void new_thread(int thread_index)
Called whenever a new Thread definition is received from the client.
virtual void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void got_hello()
Called when the "hello" message has been received from the client.
void open_piano_roll(int thread_index)
Opens a new piano roll showing the indicated data.
virtual void new_data(int thread_index, int frame_number)
Called whenever new data arrives.
void user_guide_bars_changed()
Called when the user guide bars have been changed.
void set_pause(bool pause)
Changes the pause flag for the graph.
The class that owns the main loop, waiting for client connections.
virtual string get_monitor_name()
Should be redefined to return a descriptive name for the type of PStatsMonitor this is...
void close()
Closes the client connection if it is active.
virtual void got_bad_version(int client_major, int client_minor, int server_major, int server_minor)
Like got_hello(), this is called when the "hello" message has been received from the client...
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
A window that draws a piano-roll style chart, which shows the collectors explicitly stopping and star...
virtual void user_guide_bars_changed()
Called when the user guide bars have been changed.
This is an abstract class that presents the interface to any number of different front-ends for the s...
double get_frame_rate() const
Computes the average frame rate over the past pstats_average_time seconds, by counting up the number ...
virtual void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
A collection of FrameData structures for recently-received frames within a particular thread...
const MenuDef * add_menu(const MenuDef &menu_def)
Adds a new MenuDef to the monitor, or returns an existing one if there is already one just like it...
This class represents a connection to a PStatsClient and manages the data exchange with the client...
void open_strip_chart(int thread_index, int collector_index, bool show_level)
Opens a new strip chart showing the indicated data.
const PStatThreadData * get_thread_data(int index) const
Returns the data associated with the indicated thread.
void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void initialized()
Called after the monitor has been fully set up.
virtual void new_data(int thread_index, int frame_number)
Called as each frame's data is made available.
virtual void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
GtkWidget * get_window() const
Returns the window handle to the monitor's window.
virtual void lost_connection()
Called whenever the connection to the client has been lost.
string get_client_progname() const
Returns the program name of the client we're connected to, if known.
virtual bool has_idle()
Should be redefined to return true if you want to redefine idle() and expect it to be called...
virtual void idle()
If has_idle() returns true, this will be called periodically to allow the monitor to update its displ...
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
void set_pause(bool pause)
Called when the user selects a pause on or pause off option from the menu.
string get_client_hostname() const
Returns the hostname of the client we're connected to, if known.