# HG changeset patch # User Jacob Dawid # Date 1339264783 -7200 # Node ID 626a8ff2fe8c354fc73650c1888c43774ce5b9bc # Parent c30916f904fb2066c5be988cb86d827f83a7569c The GUI now shows performance information in the status bar of the GUI (ie. how much overhead it causes in the octave thread compares to the terminal version). * main-window: Added update timer. Added slot to update status bar with performance info. * octave-link:: Added performance information struct and timing calls. diff -r c30916f904fb -r 626a8ff2fe8c gui/src/main-window.cc --- a/gui/src/main-window.cc Sat Jun 09 18:51:35 2012 +0200 +++ b/gui/src/main-window.cc Sat Jun 09 19:59:43 2012 +0200 @@ -35,7 +35,6 @@ { // We have to set up all our windows, before we finally launch octave. construct (); - octave_link::instance ()->launch_octave(); } @@ -254,6 +253,25 @@ } void +main_window::update_performance_information () +{ + octave_link::performance_information p + = octave_link::instance ()->get_performance_information (); + + int generate_events_msec + = (p.generate_events_stop - p.generate_events_start) * 1000 / CLOCKS_PER_SEC; + + int process_events_msec + = (p.process_events_stop - p.process_events_start) * 1000 / CLOCKS_PER_SEC; + + _status_bar->showMessage + (QString ("CPU time of the GUI in octave thread - generating rx events: ~%1 ms - processing tx events: ~%2 ms (%3 events)") + .arg (generate_events_msec) + .arg (process_events_msec) + .arg (p.event_queue_size)); +} + +void main_window::show_about_octave () { QString message = @@ -542,5 +560,11 @@ SIGNAL (quit_debug_mode_signal ()), this, SLOT (handle_quit_debug_mode ())); + + _update_performance_information_timer.setInterval (500); + _update_performance_information_timer.setSingleShot (false); + connect (&_update_performance_information_timer, SIGNAL (timeout ()), + this, SLOT (update_performance_information ())); + _update_performance_information_timer.start (); } diff -r c30916f904fb -r 626a8ff2fe8c gui/src/main-window.h --- a/gui/src/main-window.h Sat Jun 09 18:51:35 2012 +0200 +++ b/gui/src/main-window.h Sat Jun 09 19:59:43 2012 +0200 @@ -30,6 +30,7 @@ #include #include #include +#include // Editor includes #include "file-editor-interface.h" @@ -99,6 +100,8 @@ void debug_step_out (); void debug_quit (); + void update_performance_information (); + protected: void closeEvent (QCloseEvent * closeEvent); void read_settings (); @@ -111,6 +114,7 @@ QTerminal * _terminal; file_editor_interface * _file_editor; QMenu * _debug_menu; + QTimer _update_performance_information_timer; // Dock widgets. workspace_view * _workspace_view; diff -r c30916f904fb -r 626a8ff2fe8c gui/src/octave-adapter/octave-link.cc --- a/gui/src/octave-adapter/octave-link.cc Sat Jun 09 18:51:35 2012 +0200 +++ b/gui/src/octave-adapter/octave-link.cc Sat Jun 09 19:59:43 2012 +0200 @@ -20,8 +20,10 @@ int octave_readline_hook () { + octave_link::instance ()->entered_readline_hook (); octave_link::instance ()->generate_events (); octave_link::instance ()->process_events (); + octave_link::instance ()->finished_readline_hook (); return 0; } @@ -36,6 +38,7 @@ octave_link::octave_link () { _event_queue_mutex = new octave_mutex (); + _performance_information_mutex = new octave_mutex (); _last_working_directory = ""; _debugging_mode_active = false; } @@ -63,6 +66,7 @@ void octave_link::generate_events () { + _next_performance_information.generate_events_start = clock (); std::string current_working_directory = octave_env::get_current_directory (); if (current_working_directory != _last_working_directory) { @@ -83,12 +87,15 @@ _octave_event_listener->quit_debug_mode (); } } + _next_performance_information.generate_events_stop = clock (); } void octave_link::process_events () { + _next_performance_information.process_events_start = clock (); _event_queue_mutex->lock (); + _next_performance_information.event_queue_size = _event_queue.size (); while (_event_queue.size () > 0) { octave_event * e = _event_queue.front (); @@ -99,6 +106,7 @@ e->reject (); } _event_queue_mutex->unlock (); + _next_performance_information.process_events_stop = clock (); } void @@ -132,3 +140,25 @@ if (_octave_event_listener) _octave_event_listener->about_to_exit (); } + +void +octave_link::entered_readline_hook () +{ } + +void +octave_link::finished_readline_hook () +{ + _performance_information_mutex->lock (); + _performance_information = _next_performance_information; + _performance_information_mutex->unlock (); +} + +octave_link::performance_information +octave_link::get_performance_information () +{ + performance_information p; + _performance_information_mutex->lock (); + p = _performance_information; + _performance_information_mutex->unlock (); + return p; +} diff -r c30916f904fb -r 626a8ff2fe8c gui/src/octave-adapter/octave-link.h --- a/gui/src/octave-adapter/octave-link.h Sat Jun 09 18:51:35 2012 +0200 +++ b/gui/src/octave-adapter/octave-link.h Sat Jun 09 19:59:43 2012 +0200 @@ -61,6 +61,7 @@ #include #include #include +#include #include "octave-main-thread.h" #include "octave-event.h" @@ -81,6 +82,15 @@ /** Provides a way to access the unique octave_link object. */ static octave_link * instance () { return &_singleton; } + typedef struct + { + clock_t generate_events_start; + clock_t generate_events_stop; + clock_t process_events_start; + clock_t process_events_stop; + int event_queue_size; + } performance_information; + /** Starts octave. */ void launch_octave (); void register_event_listener (octave_event_listener *oel); @@ -92,6 +102,11 @@ void event_reject (octave_event *e); void about_to_exit (); + + void entered_readline_hook (); + void finished_readline_hook (); + performance_information get_performance_information (); + private: /** Singleton. */ octave_link (); @@ -112,6 +127,13 @@ std::string _last_working_directory; bool _debugging_mode_active; + /** Semaphore to lock access to the performance information. */ + octave_mutex *_performance_information_mutex; + + /** Stores performance data. */ + performance_information _next_performance_information; + performance_information _performance_information; + /** Unique instance. Singelton! */ static octave_link _singleton; }; diff -r c30916f904fb -r 626a8ff2fe8c gui/src/octave-qt-event-listener.cc --- a/gui/src/octave-qt-event-listener.cc Sat Jun 09 18:51:35 2012 +0200 +++ b/gui/src/octave-qt-event-listener.cc Sat Jun 09 19:59:43 2012 +0200 @@ -43,3 +43,4 @@ void octave_qt_event_listener::quit_debug_mode () { emit quit_debug_mode_signal (); } +