changeset 29040:05b8ad7b67e8

gui menu for handling the profile (based on patch #8300 by Hassan Radi) * main-window.cc (main_window): add profiler state to maine window status bar; (profiler_session): slot for starting a new profiler session; (profiler_session_resume): slot for resuming a profiler session; (profiler_stop): slot for stoping a profiler session; (handle_profiler_status_update): slot for updating menus and status, handling the new signal profiler_status_update; (profiler_shoe): slot for showing current profiler data; indicator for the profiler; (construct_menu_bar): add menu for profiler actions; (construct_profile_menu): new method for construction the profiler menu * main-window.h: new signal profiler_status_update, new slots profiler_session, profiler_session_resume, profiler_stop, handle_profiler_status_update, profiler_show, new method construct_profile_menu, new QLabel m_profiler_status_indicator for the profiler status, new actions m_profiler_start, profiler_resume, m_profiler_stop, m_profiler_show
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 08 Nov 2020 21:27:02 +0100
parents 1aa69571a313
children 2190720bca3e
files libgui/src/main-window.cc libgui/src/main-window.h
diffstat 2 files changed, 101 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Mon Sep 07 20:06:35 2020 -0700
+++ b/libgui/src/main-window.cc	Sun Nov 08 21:27:02 2020 +0100
@@ -169,6 +169,9 @@
     construct_central_widget ();
 
     m_status_bar = new QStatusBar ();
+    m_profiler_status_indicator = new QLabel (tr ("Profiler OFF"));
+    m_status_bar->addPermanentWidget (m_profiler_status_indicator);
+
     m_command_window = new terminal_dock_widget (this, m_octave_qobj);
     m_history_window = new history_dock_widget (this, m_octave_qobj);
     m_file_browser_window = new files_dock_widget (this, m_octave_qobj);
@@ -1921,6 +1924,66 @@
        });
   }
 
+  void main_window::profiler_session (void)
+  {
+    emit interpreter_event
+      ([=] (interpreter& interp)
+        {
+          // INTERPRETER THREAD
+
+          Ffeval (interp, ovl ("profile","on"));
+
+          emit profiler_status_update (true);
+        });
+  }
+
+  void main_window::profiler_session_resume (void)
+  {
+    emit interpreter_event
+      ([=] (interpreter& interp)
+        {
+          // INTERPRETER THREAD
+
+          Ffeval (interp, ovl ("profile","resume"));
+
+          emit profiler_status_update (true);
+        });
+  }
+
+  void main_window::profiler_stop (void)
+  {
+    emit interpreter_event
+      ([=] (interpreter& interp)
+        {
+          // INTERPRETER THREAD
+
+          Ffeval (interp, ovl ("profile","resume"));
+
+          emit profiler_status_update (false);
+        });
+  }
+
+  void main_window::handle_profiler_status_update (bool active)
+  {
+    m_profiler_start->setEnabled (! active);
+    m_profiler_resume->setEnabled (! active);
+    m_profiler_stop->setEnabled (active);
+
+    QString status = tr ("Profiler OFF");
+    if (active)
+      status = tr ("Profiler ON");
+    m_profiler_status_indicator->setText (status);
+  }
+
+  void main_window::profiler_show (void)
+  {
+    // Do not use a separate interpreter event as in the other
+    // profiler slots since the output of the command "profshow"
+    // would obscure the prompt and we do not need to emimt a signal
+    // for action that is required in the gui after rhe command
+    execute_command_in_terminal ("profshow");
+  }
+
   void main_window::closeEvent (QCloseEvent *e)
   {
     if (confirm_shutdown ())
@@ -2302,6 +2365,8 @@
 
     construct_debug_menu (menu_bar);
 
+    construct_profile_menu (menu_bar);
+
     construct_window_menu (menu_bar);
 
     construct_help_menu (menu_bar);
@@ -2539,6 +2604,27 @@
                                    SLOT (debug_quit (void)));
   }
 
+  void main_window::construct_profile_menu (QMenuBar *p)
+  {
+    QMenu *profiler_menu = m_add_menu (p, tr ("&Profiler"));
+
+    m_profiler_start = add_action (profiler_menu, QIcon (),
+          tr ("Start &Profiler Session"), SLOT (profiler_session ()));
+
+    m_profiler_resume = add_action (profiler_menu, QIcon (),
+          tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ()));
+
+    m_profiler_stop = add_action (profiler_menu, QIcon (),
+          tr ("&Stop Profiler"), SLOT (profiler_stop ()));
+    m_profiler_stop->setEnabled (false);
+
+    m_profiler_show = add_action (profiler_menu, QIcon (),
+          tr ("&Show Profile Data"), SLOT (profiler_show ()));
+
+    connect (this, SIGNAL (profiler_status_update (bool)),
+             this, SLOT (handle_profiler_status_update (bool)));
+  }
+
   void main_window::editor_tabs_changed (bool have_tabs)
   {
     // Set state of actions which depend on the existence of editor tabs
--- a/libgui/src/main-window.h	Mon Sep 07 20:06:35 2020 -0700
+++ b/libgui/src/main-window.h	Sun Nov 08 21:27:02 2020 +0100
@@ -125,6 +125,8 @@
     void interpreter_event (const fcn_callback& fcn);
     void interpreter_event (const meth_callback& meth);
 
+    void profiler_status_update (bool);
+
   public slots:
 
     void focus_changed (QWidget *w_old, QWidget *w_new);
@@ -211,6 +213,12 @@
     void handle_register_doc (const QString& file);
     void handle_unregister_doc (const QString& file);
 
+    void profiler_session (void);
+    void profiler_session_resume (void);
+    void profiler_stop (void);
+    void handle_profiler_status_update (bool);
+    void profiler_show (void);
+
     void handle_octave_ready ();
 
     void handle_set_path_dialog_request (void);
@@ -283,6 +291,7 @@
     void construct_debug_menu (QMenuBar *p);
     QAction * construct_window_menu_item (QMenu *p, const QString& item,
                                           bool checkable, QWidget*);
+    void construct_profile_menu (QMenuBar *p);
     void construct_window_menu (QMenuBar *p);
     void construct_help_menu (QMenuBar *p);
     void construct_documentation_menu (QMenu *p);
@@ -310,6 +319,7 @@
     //! Toolbar.
 
     QStatusBar *m_status_bar;
+    QLabel *m_profiler_status_indicator;
 
     //! Dock widgets.
     //!@{
@@ -360,6 +370,11 @@
     QAction *m_find_files_action;
     QAction *m_select_all_action;
 
+    QAction *m_profiler_start;
+    QAction *m_profiler_resume;
+    QAction *m_profiler_stop;
+    QAction *m_profiler_show;
+
     QAction *m_show_command_window_action;
     QAction *m_show_history_action;
     QAction *m_show_workspace_action;