[nemiver/profiler: 45/48] Support system wide profiling



commit 3ea694678a83b1a593ee307006769d8784befc4a
Author: Fabien Parent <parent f gmail com>
Date:   Sun Aug 12 20:53:29 2012 +0200

    Support system wide profiling

 src/confmgr/nmv-conf-keys.h                        |    1 -
 src/confmgr/nmv-gconf-keys-defs.cc                 |    2 -
 src/confmgr/nmv-gsettings-keys-defs.cc             |    1 -
 src/persp/profperspective/menus/menus.xml          |    2 +
 src/persp/profperspective/nmv-prof-perspective.cc  |   41 ++++++++++++++++++++
 .../profperspective/nmv-prof-preferences-dialog.cc |   34 ----------------
 src/persp/profperspective/ui/preferencesdialog.ui  |   17 --------
 src/profengine/nmv-confmgr-record-options.cc       |   12 ------
 src/profengine/nmv-confmgr-record-options.h        |    1 -
 src/profengine/nmv-i-profiler.h                    |    2 +
 src/profengine/nmv-perf-engine.cc                  |   41 +++++++++++++++++--
 src/profengine/nmv-perf-engine.h                   |    1 +
 src/profengine/nmv-perf-server.cc                  |   37 ++++++++++++++++-
 src/profengine/nmv-record-options.h                |    1 -
 .../org.gnome.nemiver.profiler.policy.in           |   29 ++++++++++++++
 15 files changed, 145 insertions(+), 77 deletions(-)
---
diff --git a/src/confmgr/nmv-conf-keys.h b/src/confmgr/nmv-conf-keys.h
index 85beac0..4b07e05 100644
--- a/src/confmgr/nmv-conf-keys.h
+++ b/src/confmgr/nmv-conf-keys.h
@@ -67,7 +67,6 @@ extern const char* CONF_KEY_DBG_PERSPECTIVE_LAYOUT;
 extern const char* CONF_KEY_DO_CALLGRAPH_RECORDING;
 extern const char* CONF_KEY_COLLECT_WITHOUT_BUFFERING;
 extern const char* CONF_KEY_COLLECT_RAW_SAMPLE_RECORDS;
-extern const char* CONF_KEY_SYSTEM_WIDE_COLLECTION;
 extern const char* CONF_KEY_SAMPLE_ADDRESSES;
 extern const char* CONF_KEY_SAMPLE_TIMESTAMPS;
 
diff --git a/src/confmgr/nmv-gconf-keys-defs.cc b/src/confmgr/nmv-gconf-keys-defs.cc
index db65d9d..f8a9c1e 100644
--- a/src/confmgr/nmv-gconf-keys-defs.cc
+++ b/src/confmgr/nmv-gconf-keys-defs.cc
@@ -99,8 +99,6 @@ const char* CONF_KEY_COLLECT_WITHOUT_BUFFERING =
                 "/apps/nemiver/profperspective/collect-without-buffering";
 const char* CONF_KEY_COLLECT_RAW_SAMPLE_RECORDS =
                 "/apps/nemiver/profperspective/collect-raw-sample-records";
-const char* CONF_KEY_SYSTEM_WIDE_COLLECTION =
-                "/apps/nemiver/profperspective/system-wide-collection";
 const char* CONF_KEY_SAMPLE_ADDRESSES =
                 "/apps/nemiver/profperspective/sample-addresses";
 const char* CONF_KEY_SAMPLE_TIMESTAMPS =
diff --git a/src/confmgr/nmv-gsettings-keys-defs.cc b/src/confmgr/nmv-gsettings-keys-defs.cc
index a599b66..6a84b69 100644
--- a/src/confmgr/nmv-gsettings-keys-defs.cc
+++ b/src/confmgr/nmv-gsettings-keys-defs.cc
@@ -74,7 +74,6 @@ const char* CONF_KEY_DBG_PERSPECTIVE_LAYOUT = "dbg-perspective-layout";
 const char* CONF_KEY_DO_CALLGRAPH_RECORDING = "do-callgraph-recording";
 const char* CONF_KEY_COLLECT_WITHOUT_BUFFERING = "collect-without-buffering";
 const char* CONF_KEY_COLLECT_RAW_SAMPLE_RECORDS = "collect-raw-sample-records";
-const char* CONF_KEY_SYSTEM_WIDE_COLLECTION = "system-wide-collection";
 const char* CONF_KEY_SAMPLE_ADDRESSES = "sample-addresses";
 const char* CONF_KEY_SAMPLE_TIMESTAMPS = "sample-timestamps";
 
diff --git a/src/persp/profperspective/menus/menus.xml b/src/persp/profperspective/menus/menus.xml
index b6d046b..1bf0058 100644
--- a/src/persp/profperspective/menus/menus.xml
+++ b/src/persp/profperspective/menus/menus.xml
@@ -9,6 +9,8 @@
                       name="LoadReportMenuItem"/>
             <menuitem action="AttachToProcessAction"
                       name="AttachToProcessItem"/>
+            <menuitem action="SystemWideRecordAction"
+                      name="SystemWideRecordItem"/>
         </placeholder>
     </menu>
     <menu action="EditMenuAction" name="EditMenu">
diff --git a/src/persp/profperspective/nmv-prof-perspective.cc b/src/persp/profperspective/nmv-prof-perspective.cc
index 84dd9b8..4cdd7b1 100644
--- a/src/persp/profperspective/nmv-prof-perspective.cc
+++ b/src/persp/profperspective/nmv-prof-perspective.cc
@@ -110,6 +110,7 @@ public:
     void init_body ();
     void load_report_file ();
     void load_report_file (const UString &a_report_file);
+    void system_wide_record ();
     void run_executable ();
     void run_executable (const UString &a_program_name,
                          const UString &a_arguments);
@@ -121,6 +122,7 @@ public:
     void attach_to_process (unsigned a_pid);
     IProcMgr* process_manager ();
 
+    void on_system_wide_record_action ();
     void on_preferences_action ();
     void on_attach_to_process_action ();
     void on_stop_recording_action ();
@@ -488,6 +490,17 @@ ProfPerspective::init_actions ()
             false
         },
         {
+            "SystemWideRecordAction",
+            nil_stock_id,
+            _("Profile system..."),
+            _("Profile the whole system..."),
+            sigc::mem_fun (*this,
+                           &ProfPerspective::on_system_wide_record_action),
+            ui_utils::ActionEntry::DEFAULT,
+            "",
+            false
+        },
+        {
             "ProfilerPreferencesAction",
             Gtk::Stock::PREFERENCES,
             _("Pr_eferences"),
@@ -614,6 +627,24 @@ ProfPerspective::stop_recording ()
 }
 
 void
+ProfPerspective::system_wide_record ()
+{
+    THROW_IF_FAIL (profiler ());
+
+    IConfMgrSafePtr confmgr = get_workbench ().get_configuration_manager ();
+    THROW_IF_FAIL (confmgr);
+
+    ConfMgrRecordOptions options (*confmgr);
+    profiler ()->system_wide_record (options);
+
+    THROW_IF_FAIL (throbber);
+    throbber->start ();
+
+    THROW_IF_FAIL (recording_action_group);
+    recording_action_group->set_sensitive (true);
+}
+
+void
 ProfPerspective::attach_to_process ()
 {
     IProcMgr *process_mgr = process_manager ();
@@ -677,6 +708,16 @@ ProfPerspective::annotate_symbol (const UString &a_symbol_name)
 }
 
 void
+ProfPerspective::on_system_wide_record_action ()
+{
+    NEMIVER_TRY;
+
+    system_wide_record ();
+
+    NEMIVER_CATCH;
+}
+
+void
 ProfPerspective::on_attach_to_process_action ()
 {
     NEMIVER_TRY;
diff --git a/src/persp/profperspective/nmv-prof-preferences-dialog.cc b/src/persp/profperspective/nmv-prof-preferences-dialog.cc
index cad9201..021bb7d 100644
--- a/src/persp/profperspective/nmv-prof-preferences-dialog.cc
+++ b/src/persp/profperspective/nmv-prof-preferences-dialog.cc
@@ -40,7 +40,6 @@ class ProfPreferencesDialog::Priv {
     Gtk::CheckButton *callgraph_checkbutton;
     Gtk::CheckButton *no_buffering_checkbutton;
     Gtk::CheckButton *raw_sample_checkbutton;
-    Gtk::CheckButton *system_wide_collection_checkbutton;
     Gtk::CheckButton *sample_addresses_checkbutton;
     Gtk::CheckButton *sample_timestamps_checkbutton;
 
@@ -53,7 +52,6 @@ public:
         callgraph_checkbutton (0),
         no_buffering_checkbutton (0),
         raw_sample_checkbutton (0),
-        system_wide_collection_checkbutton (0),
         sample_addresses_checkbutton (0),
         sample_timestamps_checkbutton (0)
     {
@@ -79,12 +77,6 @@ public:
     }
 
     void
-    on_system_wide_collection_toggled_signal ()
-    {
-        update_system_wide_collection_key ();
-    }
-
-    void
     on_sample_addresses_toggled_signal ()
     {
         update_sample_addresses_key ();
@@ -128,14 +120,6 @@ public:
             (*this,
              &ProfPreferencesDialog::Priv::on_raw_sample_toggled_signal));
 
-        system_wide_collection_checkbutton =
-            ui_utils::get_widget_from_gtkbuilder<Gtk::CheckButton>
-                (gtkbuilder, "systemcollctioncheckbutton");
-        THROW_IF_FAIL (system_wide_collection_checkbutton);
-        system_wide_collection_checkbutton->signal_toggled ().connect
-            (sigc::mem_fun (*this, &ProfPreferencesDialog::Priv
-                                ::on_system_wide_collection_toggled_signal));
-
         sample_timestamps_checkbutton =
             ui_utils::get_widget_from_gtkbuilder<Gtk::CheckButton>
                 (gtkbuilder, "timestampsamplecheckbutton");
@@ -189,14 +173,6 @@ public:
     }
 
     void
-    update_system_wide_collection_key ()
-    {
-        THROW_IF_FAIL (system_wide_collection_checkbutton);
-        bool is_on = system_wide_collection_checkbutton->get_active ();
-        conf_manager ().set_key_value (CONF_KEY_SYSTEM_WIDE_COLLECTION, is_on);
-    }
-
-    void
     update_sample_addresses_key ()
     {
         THROW_IF_FAIL (sample_addresses_checkbutton);
@@ -218,7 +194,6 @@ public:
         THROW_IF_FAIL (callgraph_checkbutton);
         THROW_IF_FAIL (no_buffering_checkbutton);
         THROW_IF_FAIL (raw_sample_checkbutton);
-        THROW_IF_FAIL (system_wide_collection_checkbutton);
         THROW_IF_FAIL (sample_addresses_checkbutton);
         THROW_IF_FAIL (sample_timestamps_checkbutton);
 
@@ -246,15 +221,6 @@ public:
         }
         raw_sample_checkbutton->set_active (do_collect_raw_sample_records);
 
-        bool do_system_wide_collection = false;
-        if (!conf_manager ().get_key_value (CONF_KEY_SYSTEM_WIDE_COLLECTION,
-                                            do_system_wide_collection)) {
-            LOG_ERROR ("failed to get gconf key "
-                       << CONF_KEY_SYSTEM_WIDE_COLLECTION);
-        }
-        system_wide_collection_checkbutton->set_active
-            (do_system_wide_collection);
-
         bool do_sample_addresses = false;
         if (!conf_manager ().get_key_value (CONF_KEY_SAMPLE_ADDRESSES,
                                             do_sample_addresses)) {
diff --git a/src/persp/profperspective/ui/preferencesdialog.ui b/src/persp/profperspective/ui/preferencesdialog.ui
index 0bae537..b1e062f 100644
--- a/src/persp/profperspective/ui/preferencesdialog.ui
+++ b/src/persp/profperspective/ui/preferencesdialog.ui
@@ -106,23 +106,6 @@
                                 <property name="position">1</property>
                               </packing>
                             </child>
-                            <child>
-                              <object class="GtkCheckButton" id="systemcollctioncheckbutton">
-                                <property name="label" translatable="yes">System-wide collection from all CPUs</property>
-                                <property name="use_action_appearance">False</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">False</property>
-                                <property name="use_action_appearance">False</property>
-                                <property name="xalign">0</property>
-                                <property name="draw_indicator">True</property>
-                              </object>
-                              <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">2</property>
-                              </packing>
-                            </child>
                           </object>
                         </child>
                       </object>
diff --git a/src/profengine/nmv-confmgr-record-options.cc b/src/profengine/nmv-confmgr-record-options.cc
index 72a8daf..57a426b 100644
--- a/src/profengine/nmv-confmgr-record-options.cc
+++ b/src/profengine/nmv-confmgr-record-options.cc
@@ -84,18 +84,6 @@ ConfMgrRecordOptions::do_collect_raw_sample_records () const
 }
 
 bool
-ConfMgrRecordOptions::do_system_wide_collection () const
-{
-    bool system_wide_collection = false;
-    if (!m_priv->conf_mgr.get_key_value (CONF_KEY_SYSTEM_WIDE_COLLECTION,
-                                         system_wide_collection)) {
-        LOG_ERROR ("failed to get gconf key "
-                   << CONF_KEY_SYSTEM_WIDE_COLLECTION);
-    }
-    return system_wide_collection;
-}
-
-bool
 ConfMgrRecordOptions::do_sample_addresses () const
 {
     bool sample_addresses = false;
diff --git a/src/profengine/nmv-confmgr-record-options.h b/src/profengine/nmv-confmgr-record-options.h
index ea44d1e..3d12f25 100644
--- a/src/profengine/nmv-confmgr-record-options.h
+++ b/src/profengine/nmv-confmgr-record-options.h
@@ -48,7 +48,6 @@ public:
     bool do_callgraph_recording () const;
     bool do_collect_without_buffering () const;
     bool do_collect_raw_sample_records () const;
-    bool do_system_wide_collection () const;
     bool do_sample_addresses () const;
     bool do_sample_timestamps () const;
 }; // end namespace ConfMgrRecordOptions
diff --git a/src/profengine/nmv-i-profiler.h b/src/profengine/nmv-i-profiler.h
index f728cab..ed67fb7 100644
--- a/src/profengine/nmv-i-profiler.h
+++ b/src/profengine/nmv-i-profiler.h
@@ -79,6 +79,8 @@ public:
 
     virtual void report (const UString &a_data_file) = 0;
 
+    virtual void system_wide_record (const RecordOptions &a_options) = 0;
+
     virtual void record (const UString &a_program_path,
                          const std::vector<UString> &a_argv,
                          const RecordOptions &a_options) = 0;
diff --git a/src/profengine/nmv-perf-engine.cc b/src/profengine/nmv-perf-engine.cc
index a4095e5..6d86c59 100644
--- a/src/profengine/nmv-perf-engine.cc
+++ b/src/profengine/nmv-perf-engine.cc
@@ -392,7 +392,7 @@ PerfEngine::attach_to_pid (int a_pid)
 
     Glib::Variant<int> pid_param = Glib::Variant<int>::create (a_pid);
     Glib::Variant<int> uid_param = Glib::Variant<int>::create (getuid ());
-    Glib::Variant<int> gid_param = Glib::Variant<int>::create (a_pid);
+    Glib::Variant<int> gid_param = Glib::Variant<int>::create (getgid ());
 
     std::vector<Glib::VariantBase> parameters;
     parameters.push_back (pid_param);
@@ -445,10 +445,6 @@ PerfEngine::record (const std::vector<UString> &a_argv,
         argv.push_back ("--raw-samples");
     }
 
-    if (a_options.do_system_wide_collection ()) {
-        argv.push_back ("--all-cpus");
-    }
-
     if (a_options.do_sample_addresses ()) {
         argv.push_back ("--data");
     }
@@ -475,6 +471,41 @@ PerfEngine::record (const std::vector<UString> &a_argv,
 }
 
 void
+PerfEngine::system_wide_record (const RecordOptions &/*a_options*/)
+{
+    THROW_IF_FAIL (m_priv);
+    THROW_IF_FAIL (m_priv->proxy);
+
+    std::vector<Glib::ustring> options;
+
+    Glib::Variant<int> uid_param = Glib::Variant<int>::create (getuid ());
+    Glib::Variant<int> gid_param = Glib::Variant<int>::create (getgid ());
+
+    std::vector<Glib::VariantBase> parameters;
+    parameters.push_back (uid_param);
+    parameters.push_back (gid_param);
+
+    Glib::VariantContainerBase parameters_variant =
+        Glib::VariantContainerBase::create_tuple (parameters);
+    Glib::VariantContainerBase response;
+
+    m_priv->is_using_prof_server = true;
+    response = m_priv->proxy->call_sync ("ProfileSystem", parameters_variant);
+
+    Glib::Variant<unsigned> request_id_param;
+    response.get_child (request_id_param);
+    m_priv->request_id = request_id_param.get ();
+
+    parameters.clear ();
+    parameters.push_back (request_id_param);
+    parameters_variant = Glib::VariantContainerBase::create_tuple (parameters);
+    m_priv->proxy->call
+        ("RecordDoneSignal",
+         sigc::mem_fun (*m_priv, &PerfEngine::Priv::on_detached_from_process),
+         parameters_variant);
+}
+
+void
 PerfEngine::record (const UString &a_program_path,
                     const std::vector<UString> &a_argv,
                     const RecordOptions &a_options)
diff --git a/src/profengine/nmv-perf-engine.h b/src/profengine/nmv-perf-engine.h
index 25bfd15..8a2b6c7 100644
--- a/src/profengine/nmv-perf-engine.h
+++ b/src/profengine/nmv-perf-engine.h
@@ -49,6 +49,7 @@ public:
     void record (const UString &a_program_path,
                  const std::vector<UString> &a_argv,
                  const RecordOptions &a_options);
+    void system_wide_record (const RecordOptions &a_options);
     void stop_recording ();
     void annotate_symbol (const UString &a_symbol_name);
 
diff --git a/src/profengine/nmv-perf-server.cc b/src/profengine/nmv-perf-server.cc
index b40b5ba..a2fbda2 100644
--- a/src/profengine/nmv-perf-server.cc
+++ b/src/profengine/nmv-perf-server.cc
@@ -51,11 +51,15 @@ static const char *const NMV_BUS_NAME = "org.gnome.nemiver.profiler";
 static const char *const NMV_DBUS_PROFILER_SERVER_INTROSPECTION_DATA =
     "<node>"
     "  <interface name='org.gnome.nemiver.profiler'>"
+    "    <method name='ProfileSystem'>"
+    "        <arg type='i' name='uid' direction='in' />"
+    "        <arg type='i' name='gid' direction='in' />"
+    "        <arg type='u' name='request_id' direction='out' />"
+    "    </method>"
     "    <method name='AttachToPID'>"
     "        <arg type='i' name='pid' direction='in' />"
     "        <arg type='i' name='uid' direction='in' />"
     "        <arg type='i' name='gid' direction='in' />"
-//    "        <arg type='u' name='cookie' direction='in' />"
     "        <arg type='u' name='request_id' direction='out' />"
     "    </method>"
     "    <method name='DetachFromProcess'>"
@@ -196,7 +200,34 @@ struct PerfServer::Priv {
         THROW_IF_FAIL (result);
         THROW_IF_FAIL (polkit_authorization_result_get_is_authorized(result));
 
-        if(a_request_name == "AttachToPID") {
+        if(a_request_name == "ProfileSystem") {
+            Glib::Variant<int> uid_param;
+            Glib::Variant<int> gid_param;
+            a_parameters.get_child (uid_param, 0);
+            a_parameters.get_child (gid_param, 1);
+
+            RequestInfo request;
+            request.uid = uid_param.get ();
+            request.gid = gid_param.get ();
+
+            THROW_IF_FAIL (!request_map.count (next_request_id));
+            request_map[next_request_id] = request;
+
+            THROW_IF_FAIL (request.profiler);
+
+            std::vector<UString> argv;
+            argv.push_back ("--all-cpus");
+
+            PerfRecordOptions options;
+            request.profiler->record (argv, options);
+
+            Glib::Variant<unsigned> perf_data =
+                Glib::Variant<unsigned>::create (next_request_id++);
+
+            Glib::VariantContainerBase response;
+            response = Glib::VariantContainerBase::create_tuple (perf_data);
+            a_invocation->return_value (response);
+        } else if(a_request_name == "AttachToPID") {
             Glib::Variant<int> pid_param;
             Glib::Variant<int> uid_param;
             Glib::Variant<int> gid_param;
@@ -210,7 +241,7 @@ struct PerfServer::Priv {
             request.uid = uid_param.get ();
             request.gid = gid_param.get ();
 
-            THROW_IF_FAIL (!request_map.count (pid));
+            THROW_IF_FAIL (!request_map.count (next_request_id));
 
             std::vector<UString> argv;
             argv.push_back ("--pid");
diff --git a/src/profengine/nmv-record-options.h b/src/profengine/nmv-record-options.h
index d089ad8..bc07c2a 100644
--- a/src/profengine/nmv-record-options.h
+++ b/src/profengine/nmv-record-options.h
@@ -46,7 +46,6 @@ public:
     virtual bool do_callgraph_recording () const = 0;
     virtual bool do_collect_without_buffering () const = 0;
     virtual bool do_collect_raw_sample_records () const = 0;
-    virtual bool do_system_wide_collection () const = 0;
     virtual bool do_sample_addresses () const = 0;
     virtual bool do_sample_timestamps () const = 0;
 }; // end namespace RecordOptions
diff --git a/src/profengine/org.gnome.nemiver.profiler.policy.in b/src/profengine/org.gnome.nemiver.profiler.policy.in
new file mode 100644
index 0000000..00caea4
--- /dev/null
+++ b/src/profengine/org.gnome.nemiver.profiler.policy.in
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD polkit Policy Configuration 1.0//EN"
+"http://www.freedesktop.org/software/polkit/policyconfig-1.dtd";>
+<policyconfig>
+
+  <vendor>The GNOME Project</vendor>
+  <vendor_url>http://www.gnome.org/</vendor_url>
+
+  <action id="org.gnome.nemiver.profiler.profile-system">
+    <description>Profile the whole system</description>
+    <defaults>
+      <allow_any>auth_admin</allow_any>
+      <allow_inactive>auth_admin</allow_inactive>
+      <allow_active>auth_admin</allow_active>
+    </defaults>
+    <annotate key="org.freedesktop.policykit.exec.path">@NEMIVER_BINDIR@/nmvperfserver</annotate>
+  </action>
+
+  <action id="org.gnome.nemiver.profiler.profile-running-process">
+    <description>Profile an running process</description>
+    <defaults>
+      <allow_any>auth_admin</allow_any>
+      <allow_inactive>auth_admin</allow_inactive>
+      <allow_active>auth_admin</allow_active>
+    </defaults>
+    <annotate key="org.freedesktop.policykit.exec.path">@NEMIVER_BINDIR@/nmvperfserver</annotate>
+  </action>
+
+</policyconfig>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]