[nemiver/profiler: 13/16] Add basic stuff to stop a profiling session
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver/profiler: 13/16] Add basic stuff to stop a profiling session
- Date: Sun, 8 Jul 2012 14:29:17 +0000 (UTC)
commit 55495a34c8bf9f67b4edafa2c3b7cb2e2f623930
Author: Fabien Parent <parent f gmail com>
Date: Sat Jun 30 16:30:08 2012 +0200
Add basic stuff to stop a profiling session
src/persp/profperspective/menus/Makefile.am | 3 +-
src/persp/profperspective/menus/toolbar.xml | 8 +++
src/persp/profperspective/nmv-prof-perspective.cc | 64 +++++++++++++++++++--
src/profengine/nmv-i-profiler.h | 2 +
src/profengine/nmv-perf-engine.cc | 52 +++++++++++++++--
src/profengine/nmv-perf-engine.h | 11 ++++
6 files changed, 128 insertions(+), 12 deletions(-)
---
diff --git a/src/persp/profperspective/menus/Makefile.am b/src/persp/profperspective/menus/Makefile.am
index 2563be1..e7a0afa 100644
--- a/src/persp/profperspective/menus/Makefile.am
+++ b/src/persp/profperspective/menus/Makefile.am
@@ -1,7 +1,8 @@
PLUGIN_NAME=profperspective
menusfiles = \
-menus.xml
+menus.xml \
+toolbar.xml
menusdir = @NEMIVER_PLUGINS_DIR@/$(PLUGIN_NAME)/menus
menus_DATA = $(menusfiles)
diff --git a/src/persp/profperspective/menus/toolbar.xml b/src/persp/profperspective/menus/toolbar.xml
new file mode 100644
index 0000000..f2af9df
--- /dev/null
+++ b/src/persp/profperspective/menus/toolbar.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+ <ui>
+ <toolbar name="ProfToolBar">
+ <toolitem action="StopProfilingMenuItemAction"
+ name="StopProfilingToolItem"/>
+ </toolbar>
+ </ui>
+
diff --git a/src/persp/profperspective/nmv-prof-perspective.cc b/src/persp/profperspective/nmv-prof-perspective.cc
index 1f5d434..2a61725 100644
--- a/src/persp/profperspective/nmv-prof-perspective.cc
+++ b/src/persp/profperspective/nmv-prof-perspective.cc
@@ -67,7 +67,7 @@ class ProfPerspective : public IProfPerspective {
IProfilerSafePtr prof;
SafePtr<CallList> call_list;
SafePtr<SpinnerToolItem> throbber;
- SafePtr<Gtk::Toolbar> toolbar;
+ SafePtr<Gtk::HBox> toolbar;
std::map<UString, int> symbol_to_pagenum_map;
Glib::RefPtr<Gtk::ActionGroup> default_action_group;
@@ -110,7 +110,10 @@ public:
bool a_child_inherit_counters);
void annotate_symbol (const UString &a_symbol_name);
void close_symbol_annotation (UString a_symbol_name);
+ void load_toolbar ();
+ void stop_recording ();
+ void on_stop_recording_action ();
void on_run_executable_action ();
void on_load_report_file_action ();
void on_report_done_signal (CallGraphSafePtr a_call_graph);
@@ -210,9 +213,10 @@ void
ProfPerspective::do_init (IWorkbench *a_workbench)
{
workbench = a_workbench;
+ init_actions ();
+ load_toolbar ();
init_signals ();
init_toolbar ();
- init_actions ();
init_body ();
}
@@ -243,14 +247,34 @@ ProfPerspective::get_workbench ()
}
void
+ProfPerspective::load_toolbar ()
+{
+ THROW_IF_FAIL (workbench);
+
+ std::string relative_path = Glib::build_filename ("menus",
+ "toolbar.xml");
+ string absolute_path;
+ THROW_IF_FAIL (build_absolute_resource_path
+ (Glib::filename_to_utf8 (relative_path), absolute_path));
+
+ workbench->get_ui_manager ()->add_ui_from_file
+ (Glib::filename_to_utf8 (absolute_path));
+}
+
+
+void
ProfPerspective::init_toolbar ()
{
throbber.reset (new SpinnerToolItem);
- toolbar.reset ((new Gtk::Toolbar));
+ toolbar.reset ((new Gtk::HBox));
THROW_IF_FAIL (toolbar);
+ Gtk::Toolbar *glade_toolbar = dynamic_cast<Gtk::Toolbar*>
+ (workbench->get_ui_manager ()->get_widget ("/ProfToolBar"));
+ THROW_IF_FAIL (glade_toolbar);
+
Glib::RefPtr<Gtk::StyleContext> style_context =
- toolbar->get_style_context ();
+ glade_toolbar->get_style_context ();
if (style_context) {
style_context->add_class (GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
}
@@ -258,8 +282,9 @@ ProfPerspective::init_toolbar ()
Gtk::SeparatorToolItem *sep = Gtk::manage (new Gtk::SeparatorToolItem);
sep->set_draw (false);
sep->set_expand (true);
- toolbar->insert (*sep, -1);
- toolbar->insert (*throbber, -1);
+ glade_toolbar->insert (*sep, -1);
+ glade_toolbar->insert (*throbber, -1);
+ toolbar->pack_start (*glade_toolbar);
toolbar->show ();
}
@@ -425,6 +450,16 @@ ProfPerspective::init_actions ()
ui_utils::ActionEntry::DEFAULT,
"",
false
+ },
+ {
+ "StopProfilingMenuItemAction",
+ Gtk::Stock::STOP,
+ _("_Stop the profiling"),
+ _("Stop the profiling"),
+ sigc::mem_fun (*this, &ProfPerspective::on_stop_recording_action),
+ ui_utils::ActionEntry::DEFAULT,
+ "",
+ false
}
};
@@ -507,6 +542,13 @@ ProfPerspective::load_report_file (const UString &a_report_file)
}
void
+ProfPerspective::stop_recording ()
+{
+ THROW_IF_FAIL (profiler ());
+ profiler ()->stop_recording ();
+}
+
+void
ProfPerspective::load_report_file ()
{
LoadReportDialog dialog (plugin_path ());
@@ -539,6 +581,16 @@ ProfPerspective::annotate_symbol (const UString &a_symbol_name)
}
void
+ProfPerspective::on_stop_recording_action ()
+{
+ NEMIVER_TRY
+
+ stop_recording ();
+
+ NEMIVER_CATCH
+}
+
+void
ProfPerspective::on_load_report_file_action ()
{
NEMIVER_TRY
diff --git a/src/profengine/nmv-i-profiler.h b/src/profengine/nmv-i-profiler.h
index d8277ed..eaa9f2c 100644
--- a/src/profengine/nmv-i-profiler.h
+++ b/src/profengine/nmv-i-profiler.h
@@ -82,6 +82,8 @@ public:
bool a_do_callgraph,
bool a_child_inherit_counters) = 0;
+ virtual void stop_recording () = 0;
+
virtual void annotate_symbol (const UString &a_symbol_name) = 0;
// virtual void attach_to_pid () = 0;
diff --git a/src/profengine/nmv-perf-engine.cc b/src/profengine/nmv-perf-engine.cc
index 8a5e961..5b1739a 100644
--- a/src/profengine/nmv-perf-engine.cc
+++ b/src/profengine/nmv-perf-engine.cc
@@ -30,6 +30,8 @@
#include <istream>
#include <stack>
#include <sys/wait.h>
+#include <sys/types.h>
+#include <signal.h>
#include <cstdio>
NEMIVER_BEGIN_NAMESPACE (nemiver)
@@ -309,11 +311,25 @@ PerfEngine::~PerfEngine ()
}
void
-PerfEngine::record (const UString &a_program_path,
- const std::vector<UString> &a_argv,
+PerfEngine::attach_to_pid (int a_pid,
+ bool a_scale_counter_values,
+ bool a_do_callgraph,
+ bool a_child_inherit_counters)
+{
+ std::vector<UString> argv;
+ argv.push_back ("--pid");
+ argv.push_back (UString::compose ("%1", a_pid));
+
+ record (argv, a_scale_counter_values, a_do_callgraph,
+ a_child_inherit_counters);
+}
+
+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_child_inherit_counters,
+ bool a_run_as_root)
{
SafePtr<char, DefaultRef, FreeUnref> tmp_filepath (tempnam(0, 0));
THROW_IF_FAIL (tmp_filepath);
@@ -322,6 +338,10 @@ PerfEngine::record (const UString &a_program_path,
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");
@@ -339,8 +359,6 @@ PerfEngine::record (const UString &a_program_path,
argv.push_back ("--output");
argv.push_back (m_priv->record_filepath);
- argv.push_back ("--");
- argv.push_back (a_program_path);
argv.insert (argv.end (), a_argv.begin (), a_argv.end ());
bool is_launched = common::launch_program (argv,
@@ -356,6 +374,30 @@ PerfEngine::record (const UString &a_program_path,
}
void
+PerfEngine::record (const UString &a_program_path,
+ const std::vector<UString> &a_argv,
+ bool a_scale_counter_values,
+ bool a_do_callgraph,
+ bool a_child_inherit_counters)
+{
+ std::vector<UString> argv;
+ argv.push_back ("--");
+ argv.push_back (a_program_path);
+ argv.insert (argv.end (), a_argv.begin (), a_argv.end ());
+
+ record (argv, a_scale_counter_values, a_do_callgraph,
+ a_child_inherit_counters);
+}
+
+void
+PerfEngine::stop_recording ()
+{
+ THROW_IF_FAIL (m_priv);
+ THROW_IF_FAIL (m_priv->perf_pid);
+ kill(m_priv->perf_pid, SIGQUIT);
+}
+
+void
PerfEngine::report (const UString &a_data_file)
{
std::vector<UString> argv;
diff --git a/src/profengine/nmv-perf-engine.h b/src/profengine/nmv-perf-engine.h
index dfdd966..19e246a 100644
--- a/src/profengine/nmv-perf-engine.h
+++ b/src/profengine/nmv-perf-engine.h
@@ -44,12 +44,23 @@ public:
void report (const UString &a_data_file);
+ void attach_to_pid (int a_pid,
+ bool a_scale_counter_values,
+ bool a_do_callgraph,
+ bool a_child_inherit_counters);
+ 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);
void record (const UString &a_program_path,
const std::vector<UString> &a_argv,
bool a_scale_counter_values,
bool a_do_callgraph,
bool a_child_inherit_counters);
+ void stop_recording ();
+
void annotate_symbol (const UString &a_symbol_name);
sigc::signal<void, CallGraphSafePtr> report_done_signal () const;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]