[nemiver/profiler: 32/48] Add dialog to attach the profiler to a running process
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver/profiler: 32/48] Add dialog to attach the profiler to a running process
- Date: Wed, 15 Aug 2012 10:01:21 +0000 (UTC)
commit 4e2446c61a1c88b76f3d210a3414fe70812438d0
Author: Fabien Parent <parent f gmail com>
Date: Sat Jun 30 19:17:15 2012 +0200
Add dialog to attach the profiler to a running process
src/persp/dbgperspective/Makefile.am | 2 -
src/persp/dbgperspective/nmv-dbg-perspective.cc | 3 +-
src/persp/dbgperspective/ui/Makefile.am | 3 +-
src/persp/profperspective/menus/menus.xml | 2 +
src/persp/profperspective/nmv-prof-perspective.cc | 71 +++++++++++++++++++-
src/profengine/nmv-i-profiler.h | 5 ++
src/profengine/nmv-perf-engine.cc | 9 +--
src/profengine/nmv-perf-engine.h | 3 +-
src/uicommon/Makefile.am | 2 +
.../nmv-proc-list-dialog.cc | 0
.../nmv-proc-list-dialog.h | 0
ui/Makefile.am | 7 ++-
.../dbgperspective/ui => ui}/proclistdialog.ui | 0
13 files changed, 90 insertions(+), 17 deletions(-)
---
diff --git a/src/persp/dbgperspective/Makefile.am b/src/persp/dbgperspective/Makefile.am
index 7ed5a36..b03a325 100644
--- a/src/persp/dbgperspective/Makefile.am
+++ b/src/persp/dbgperspective/Makefile.am
@@ -22,8 +22,6 @@ $(h)/nmv-saved-sessions-dialog.h \
$(h)/nmv-saved-sessions-dialog.cc \
$(h)/nmv-preferences-dialog.h \
$(h)/nmv-preferences-dialog.cc \
-$(h)/nmv-proc-list-dialog.cc \
-$(h)/nmv-proc-list-dialog.h \
$(h)/nmv-expr-inspector-dialog.cc \
$(h)/nmv-expr-inspector-dialog.h \
$(h)/nmv-find-text-dialog.cc \
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 25c993e..716df9b 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -6298,8 +6298,7 @@ DBGPerspective::attach_to_program ()
IProcMgr *process_manager = get_process_manager ();
THROW_IF_FAIL (process_manager);
- ProcListDialog dialog (plugin_path (),
- *process_manager);
+ ProcListDialog dialog ("", *process_manager);
int result = dialog.run ();
if (result != Gtk::RESPONSE_OK) {
return;
diff --git a/src/persp/dbgperspective/ui/Makefile.am b/src/persp/dbgperspective/ui/Makefile.am
index 444449c..ce6a3a6 100644
--- a/src/persp/dbgperspective/ui/Makefile.am
+++ b/src/persp/dbgperspective/ui/Makefile.am
@@ -1,6 +1,5 @@
PLUGIN_NAME=dbgperspective
-uifiles = proclistdialog.ui \
-loadcoredialog.ui \
+uifiles = loadcoredialog.ui \
savedsessionsdialog.ui \
preferencesdialog.ui \
exprinspectordialog.ui \
diff --git a/src/persp/profperspective/menus/menus.xml b/src/persp/profperspective/menus/menus.xml
index 0714b73..a5977fe 100644
--- a/src/persp/profperspective/menus/menus.xml
+++ b/src/persp/profperspective/menus/menus.xml
@@ -7,6 +7,8 @@
name="RunExecutableItem"/>
<menuitem action="LoadReportMenuItemAction"
name="LoadReportMenuItem"/>
+ <menuitem action="AttachToProcessAction"
+ name="AttachToProcessItem"/>
</placeholder>
</menu>
</menubar>
diff --git a/src/persp/profperspective/nmv-prof-perspective.cc b/src/persp/profperspective/nmv-prof-perspective.cc
index efd6a8f..db104f9 100644
--- a/src/persp/profperspective/nmv-prof-perspective.cc
+++ b/src/persp/profperspective/nmv-prof-perspective.cc
@@ -32,7 +32,9 @@
#include "nmv-i-profiler.h"
#include "common/nmv-safe-ptr-utils.h"
#include "common/nmv-str-utils.h"
+#include "common/nmv-proc-mgr.h"
#include "uicommon/nmv-source-editor.h"
+#include "uicommon/nmv-proc-list-dialog.h"
#include <list>
#include <glib/gi18n.h>
@@ -42,6 +44,8 @@ NEMIVER_BEGIN_NAMESPACE (nemiver)
using common::DynamicModuleManager;
using common::GCharSafePtr;
+using nemiver::common::IProcMgrSafePtr;
+using nemiver::common::IProcMgr;
static gchar *gv_report_path = 0;
@@ -74,6 +78,7 @@ class ProfPerspective : public IProfPerspective {
Gtk::Notebook body;
IWorkbench *workbench;
GOptionGroup *opt_group;
+ IProcMgrSafePtr proc_manager;
sigc::signal<void, bool> signal_activated;
sigc::signal<void> signal_layout_changed;
@@ -111,8 +116,12 @@ public:
void annotate_symbol (const UString &a_symbol_name);
void close_symbol_annotation (UString a_symbol_name);
void load_toolbar ();
-
void stop_recording ();
+ void attach_to_process ();
+ void attach_to_process (unsigned a_pid);
+ IProcMgr* process_manager ();
+
+ void on_attach_to_process_action ();
void on_stop_recording_action ();
void on_run_executable_action ();
void on_load_report_file_action ();
@@ -143,6 +152,17 @@ ProfPerspective::option_group () const
return opt_group;
}
+IProcMgr*
+ProfPerspective::process_manager ()
+{
+ if (!proc_manager) {
+ proc_manager = IProcMgr::create ();
+ THROW_IF_FAIL (proc_manager);
+ }
+
+ return proc_manager.get ();
+}
+
bool
ProfPerspective::process_options (GOptionContext *a_context,
int a_argc,
@@ -452,6 +472,17 @@ ProfPerspective::init_actions ()
false
},
{
+ "AttachToProcessAction",
+ Gtk::Stock::CONNECT,
+ _("Attach to Running Program..."),
+ _("Profile a program that's already running"),
+ sigc::mem_fun (*this,
+ &ProfPerspective::on_attach_to_process_action),
+ ui_utils::ActionEntry::DEFAULT,
+ "",
+ false
+ },
+ {
"StopProfilingMenuItemAction",
Gtk::Stock::STOP,
_("_Stop the profiling"),
@@ -548,6 +579,34 @@ ProfPerspective::stop_recording ()
}
void
+ProfPerspective::attach_to_process ()
+{
+ IProcMgr *process_mgr = process_manager ();
+ THROW_IF_FAIL (process_mgr);
+ ProcListDialog dialog ("", *process_mgr);
+ int result = dialog.run ();
+ if (result != Gtk::RESPONSE_OK) {
+ return;
+ }
+
+ if (dialog.has_selected_process ()) {
+ IProcMgr::Process process;
+ THROW_IF_FAIL (dialog.get_selected_process (process));
+ attach_to_process (process.pid ());
+ }
+}
+
+void
+ProfPerspective::attach_to_process (unsigned a_pid)
+{
+ THROW_IF_FAIL (profiler ());
+ profiler ()->attach_to_pid (a_pid, false, true, false);
+
+ THROW_IF_FAIL (throbber);
+ throbber->start ();
+}
+
+void
ProfPerspective::load_report_file ()
{
LoadReportDialog dialog (plugin_path ());
@@ -580,6 +639,16 @@ ProfPerspective::annotate_symbol (const UString &a_symbol_name)
}
void
+ProfPerspective::on_attach_to_process_action ()
+{
+ NEMIVER_TRY;
+
+ attach_to_process ();
+
+ NEMIVER_CATCH;
+}
+
+void
ProfPerspective::on_stop_recording_action ()
{
NEMIVER_TRY
diff --git a/src/profengine/nmv-i-profiler.h b/src/profengine/nmv-i-profiler.h
index eaa9f2c..070bc46 100644
--- a/src/profengine/nmv-i-profiler.h
+++ b/src/profengine/nmv-i-profiler.h
@@ -74,6 +74,11 @@ public:
symbol_annotated_signal () const = 0;
/// @}
+ virtual void attach_to_pid (int a_pid,
+ bool a_scale_counter_values,
+ bool a_do_callgraph,
+ bool a_child_inherit_counters) = 0;
+
virtual void report (const UString &a_data_file) = 0;
virtual void record (const UString &a_program_path,
diff --git a/src/profengine/nmv-perf-engine.cc b/src/profengine/nmv-perf-engine.cc
index 5b1739a..83fe591 100644
--- a/src/profengine/nmv-perf-engine.cc
+++ b/src/profengine/nmv-perf-engine.cc
@@ -328,8 +328,7 @@ void
PerfEngine::record (const std::vector<UString> &a_argv,
bool a_scale_counter_values,
bool a_do_callgraph,
- bool a_child_inherit_counters,
- bool a_run_as_root)
+ bool a_child_inherit_counters)
{
SafePtr<char, DefaultRef, FreeUnref> tmp_filepath (tempnam(0, 0));
THROW_IF_FAIL (tmp_filepath);
@@ -338,10 +337,6 @@ PerfEngine::record (const std::vector<UString> &a_argv,
m_priv->record_filepath = tmp_filepath.get ();
std::vector<UString> argv;
- if (a_run_as_root) {
- argv.push_back ("gksudo");
- }
-
argv.push_back ("perf");
argv.push_back ("record");
@@ -394,7 +389,7 @@ PerfEngine::stop_recording ()
{
THROW_IF_FAIL (m_priv);
THROW_IF_FAIL (m_priv->perf_pid);
- kill(m_priv->perf_pid, SIGQUIT);
+ kill(m_priv->perf_pid, SIGINT);
}
void
diff --git a/src/profengine/nmv-perf-engine.h b/src/profengine/nmv-perf-engine.h
index 19e246a..dba8094 100644
--- a/src/profengine/nmv-perf-engine.h
+++ b/src/profengine/nmv-perf-engine.h
@@ -51,8 +51,7 @@ public:
void record (const std::vector<UString> &a_argv,
bool a_scale_counter_values,
bool a_do_callgraph,
- bool a_child_inherit_counters,
- bool a_run_as_root = false);
+ bool a_child_inherit_counters);
void record (const UString &a_program_path,
const std::vector<UString> &a_argv,
bool a_scale_counter_values,
diff --git a/src/uicommon/Makefile.am b/src/uicommon/Makefile.am
index 45a73ac..e32ab5f 100644
--- a/src/uicommon/Makefile.am
+++ b/src/uicommon/Makefile.am
@@ -6,6 +6,8 @@ sources = \
$(public_headers) \
$(h)/nmv-run-program-dialog.cc \
$(h)/nmv-run-program-dialog.h \
+$(h)/nmv-proc-list-dialog.cc \
+$(h)/nmv-proc-list-dialog.h \
$(h)/nmv-ui-utils.h \
$(h)/nmv-ui-utils.cc \
$(h)/nmv-dialog.cc \
diff --git a/src/persp/dbgperspective/nmv-proc-list-dialog.cc b/src/uicommon/nmv-proc-list-dialog.cc
similarity index 100%
rename from src/persp/dbgperspective/nmv-proc-list-dialog.cc
rename to src/uicommon/nmv-proc-list-dialog.cc
diff --git a/src/persp/dbgperspective/nmv-proc-list-dialog.h b/src/uicommon/nmv-proc-list-dialog.h
similarity index 100%
rename from src/persp/dbgperspective/nmv-proc-list-dialog.h
rename to src/uicommon/nmv-proc-list-dialog.h
diff --git a/ui/Makefile.am b/ui/Makefile.am
index 1dbce14..275a5d8 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -1,4 +1,9 @@
-uifiles = workbench.ui locatefiledialog.ui runprogramdialog.ui
+uifiles = \
+workbench.ui \
+locatefiledialog.ui \
+runprogramdialog.ui \
+proclistdialog.ui
+
uidir = $(datadir)/@PACKAGE@/ui
ui_DATA = $(uifiles)
diff --git a/src/persp/dbgperspective/ui/proclistdialog.ui b/ui/proclistdialog.ui
similarity index 100%
rename from src/persp/dbgperspective/ui/proclistdialog.ui
rename to ui/proclistdialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]