changeset 14802:626a8ff2fe8c gui

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.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sat, 09 Jun 2012 19:59:43 +0200
parents c30916f904fb
children 50bf75766ac0
files gui/src/main-window.cc gui/src/main-window.h gui/src/octave-adapter/octave-link.cc gui/src/octave-adapter/octave-link.h gui/src/octave-qt-event-listener.cc
diffstat 5 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/main-window.cc
+++ b/gui/src/main-window.cc
@@ -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 ();
 }
 
--- a/gui/src/main-window.h
+++ b/gui/src/main-window.h
@@ -30,6 +30,7 @@
 #include <QCloseEvent>
 #include <QToolButton>
 #include <QComboBox>
+#include <QTimer>
 
 // 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;
--- a/gui/src/octave-adapter/octave-link.cc
+++ b/gui/src/octave-adapter/octave-link.cc
@@ -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;
+}
--- a/gui/src/octave-adapter/octave-link.h
+++ b/gui/src/octave-adapter/octave-link.h
@@ -61,6 +61,7 @@
 #include <vector>
 #include <readline/readline.h>
 #include <queue>
+#include <time.h>
 
 #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;
 };
--- a/gui/src/octave-qt-event-listener.cc
+++ b/gui/src/octave-qt-event-listener.cc
@@ -43,3 +43,4 @@
 void
 octave_qt_event_listener::quit_debug_mode ()
 { emit quit_debug_mode_signal (); }
+