[nemiver/profiler: 46/48] Pass options to server to profile



commit c249996aff6f1aff78689498bbb12e4f3f741bc3
Author: Fabien Parent <parent f gmail com>
Date:   Sun Aug 12 21:36:16 2012 +0200

    Pass options to server to profile

 src/persp/profperspective/nmv-prof-perspective.cc |    7 ++-
 src/profengine/nmv-confmgr-record-options.cc      |   11 ++++
 src/profengine/nmv-i-profiler.h                   |    2 +-
 src/profengine/nmv-perf-engine.cc                 |   35 ++++++++++--
 src/profengine/nmv-perf-engine.h                  |    2 +-
 src/profengine/nmv-perf-server.cc                 |   63 ++++++++++++++------
 6 files changed, 92 insertions(+), 28 deletions(-)
---
diff --git a/src/persp/profperspective/nmv-prof-perspective.cc b/src/persp/profperspective/nmv-prof-perspective.cc
index 4cdd7b1..13b3937 100644
--- a/src/persp/profperspective/nmv-prof-perspective.cc
+++ b/src/persp/profperspective/nmv-prof-perspective.cc
@@ -665,8 +665,13 @@ ProfPerspective::attach_to_process ()
 void
 ProfPerspective::attach_to_process (unsigned a_pid)
 {
+    IConfMgrSafePtr confmgr = get_workbench ().get_configuration_manager ();
+    THROW_IF_FAIL (confmgr);
+
+    ConfMgrRecordOptions options (*confmgr);
+
     THROW_IF_FAIL (profiler ());
-    profiler ()->attach_to_pid (a_pid);
+    profiler ()->attach_to_pid (a_pid, options);
 
     THROW_IF_FAIL (throbber);
     throbber->start ();
diff --git a/src/profengine/nmv-confmgr-record-options.cc b/src/profengine/nmv-confmgr-record-options.cc
index 57a426b..95fb69a 100644
--- a/src/profengine/nmv-confmgr-record-options.cc
+++ b/src/profengine/nmv-confmgr-record-options.cc
@@ -31,6 +31,7 @@ NEMIVER_BEGIN_NAMESPACE (nemiver)
 
 struct ConfMgrRecordOptions::Priv {
     IConfMgr &conf_mgr;
+    std::vector<Glib::VariantBase> parameters;
 
     Priv (IConfMgr &a_confmgr) :
         conf_mgr (a_confmgr)
@@ -50,6 +51,8 @@ ConfMgrRecordOptions::~ConfMgrRecordOptions ()
 bool
 ConfMgrRecordOptions::do_callgraph_recording () const
 {
+    THROW_IF_FAIL (m_priv);
+
     bool callgraph_recording = false;
     if (!m_priv->conf_mgr.get_key_value (CONF_KEY_DO_CALLGRAPH_RECORDING,
                                          callgraph_recording)) {
@@ -62,6 +65,8 @@ ConfMgrRecordOptions::do_callgraph_recording () const
 bool
 ConfMgrRecordOptions::do_collect_without_buffering () const
 {
+    THROW_IF_FAIL (m_priv);
+
     bool collect_without_buffering = false;
     if (!m_priv->conf_mgr.get_key_value (CONF_KEY_COLLECT_WITHOUT_BUFFERING,
                                          collect_without_buffering)) {
@@ -74,6 +79,8 @@ ConfMgrRecordOptions::do_collect_without_buffering () const
 bool
 ConfMgrRecordOptions::do_collect_raw_sample_records () const
 {
+    THROW_IF_FAIL (m_priv);
+
     bool collect_raw_sample_records = false;
     if (!m_priv->conf_mgr.get_key_value (CONF_KEY_COLLECT_RAW_SAMPLE_RECORDS,
                                          collect_raw_sample_records)) {
@@ -86,6 +93,8 @@ ConfMgrRecordOptions::do_collect_raw_sample_records () const
 bool
 ConfMgrRecordOptions::do_sample_addresses () const
 {
+    THROW_IF_FAIL (m_priv);
+
     bool sample_addresses = false;
     if (!m_priv->conf_mgr.get_key_value (CONF_KEY_SAMPLE_ADDRESSES,
                                          sample_addresses)) {
@@ -98,6 +107,8 @@ ConfMgrRecordOptions::do_sample_addresses () const
 bool
 ConfMgrRecordOptions::do_sample_timestamps () const
 {
+    THROW_IF_FAIL (m_priv);
+
     bool sample_timestamps = false;
     if (!m_priv->conf_mgr.get_key_value (CONF_KEY_SAMPLE_TIMESTAMPS,
                                          sample_timestamps)) {
diff --git a/src/profengine/nmv-i-profiler.h b/src/profengine/nmv-i-profiler.h
index ed67fb7..e5e384a 100644
--- a/src/profengine/nmv-i-profiler.h
+++ b/src/profengine/nmv-i-profiler.h
@@ -75,7 +75,7 @@ public:
         symbol_annotated_signal () const = 0;
     /// @}
 
-    virtual void attach_to_pid (int a_pid) = 0;
+    virtual void attach_to_pid (int a_pid, const RecordOptions &a_options) = 0;
 
     virtual void report (const UString &a_data_file) = 0;
 
diff --git a/src/profengine/nmv-perf-engine.cc b/src/profengine/nmv-perf-engine.cc
index 6d86c59..333a821 100644
--- a/src/profengine/nmv-perf-engine.cc
+++ b/src/profengine/nmv-perf-engine.cc
@@ -104,6 +104,31 @@ struct PerfEngine::Priv {
         return *conf_manager;
     }
 
+    void
+    fill_vector_with_dbus_request_options
+        (const RecordOptions &a_options,
+         std::vector<Glib::VariantBase> &a_parameters)
+    {
+        Glib::Variant<bool> callgraph_recording =
+            Glib::Variant<bool>::create (a_options.do_callgraph_recording ());
+        Glib::Variant<bool> collect_without_buffering =
+            Glib::Variant<bool>::create
+                (a_options.do_collect_without_buffering ());
+        Glib::Variant<bool> collect_raw_sample_records =
+            Glib::Variant<bool>::create
+                (a_options.do_collect_raw_sample_records ());
+        Glib::Variant<bool> sample_addresses =
+            Glib::Variant<bool>::create (a_options.do_sample_addresses ());
+        Glib::Variant<bool> sample_timestamps =
+            Glib::Variant<bool>::create (a_options.do_sample_timestamps ());
+
+        a_parameters.push_back (callgraph_recording);
+        a_parameters.push_back (collect_without_buffering);
+        a_parameters.push_back (collect_raw_sample_records);
+        a_parameters.push_back (sample_addresses);
+        a_parameters.push_back (sample_timestamps);
+    }
+
     bool
     on_wait_for_record_to_exit ()
     {
@@ -383,18 +408,17 @@ PerfEngine::do_init (IConfMgrSafePtr a_conf_mgr)
 }
 
 void
-PerfEngine::attach_to_pid (int a_pid)
+PerfEngine::attach_to_pid (int a_pid, const RecordOptions &a_options)
 {
     THROW_IF_FAIL (m_priv);
     THROW_IF_FAIL (m_priv->proxy);
 
-    std::vector<Glib::ustring> options;
-
     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 (getgid ());
 
     std::vector<Glib::VariantBase> parameters;
+    m_priv->fill_vector_with_dbus_request_options (a_options, parameters);
     parameters.push_back (pid_param);
     parameters.push_back (uid_param);
     parameters.push_back (gid_param);
@@ -471,17 +495,16 @@ PerfEngine::record (const std::vector<UString> &a_argv,
 }
 
 void
-PerfEngine::system_wide_record (const RecordOptions &/*a_options*/)
+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;
+    m_priv->fill_vector_with_dbus_request_options (a_options, parameters);
     parameters.push_back (uid_param);
     parameters.push_back (gid_param);
 
diff --git a/src/profengine/nmv-perf-engine.h b/src/profengine/nmv-perf-engine.h
index 8a2b6c7..56eff6f 100644
--- a/src/profengine/nmv-perf-engine.h
+++ b/src/profengine/nmv-perf-engine.h
@@ -43,7 +43,7 @@ public:
     virtual ~PerfEngine ();
 
     void report (const UString &a_data_file);
-    void attach_to_pid (int a_pid);
+    void attach_to_pid (int a_pid, const RecordOptions &a_options);
     void record (const std::vector<UString> &a_argv,
                  const RecordOptions &a_options);
     void record (const UString &a_program_path,
diff --git a/src/profengine/nmv-perf-server.cc b/src/profengine/nmv-perf-server.cc
index a2fbda2..7d62262 100644
--- a/src/profengine/nmv-perf-server.cc
+++ b/src/profengine/nmv-perf-server.cc
@@ -52,11 +52,21 @@ static const char *const NMV_DBUS_PROFILER_SERVER_INTROSPECTION_DATA =
     "<node>"
     "  <interface name='org.gnome.nemiver.profiler'>"
     "    <method name='ProfileSystem'>"
+    "        <arg type='b' name='callgraph_recording' direction='in' />"
+    "        <arg type='b' name='collect_without_buffering' direction='in' />"
+    "        <arg type='b' name='collect_raw_sample_records' direction='in' />"
+    "        <arg type='b' name='sample_addresses' direction='in' />"
+    "        <arg type='b' name='sample_timestamps' direction='in' />"
     "        <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='b' name='callgraph_recording' direction='in' />"
+    "        <arg type='b' name='collect_without_buffering' direction='in' />"
+    "        <arg type='b' name='collect_raw_sample_records' direction='in' />"
+    "        <arg type='b' name='sample_addresses' direction='in' />"
+    "        <arg type='b' name='sample_timestamps' direction='in' />"
     "        <arg type='i' name='pid' direction='in' />"
     "        <arg type='i' name='uid' direction='in' />"
     "        <arg type='i' name='gid' direction='in' />"
@@ -76,47 +86,62 @@ class PerfRecordOptions : public RecordOptions {
     bool callgraph_recording;
     bool collect_without_buffering;
     bool collect_raw_sample_records;
-    bool system_wide_collection;
     bool sample_addresses;
     bool sample_timestamps;
 
 public:
-    PerfRecordOptions () :
+    PerfRecordOptions (const Glib::VariantContainerBase &a_parameters) :
         callgraph_recording (true),
         collect_without_buffering (false),
         collect_raw_sample_records (false),
-        system_wide_collection (false),
         sample_addresses (false),
         sample_timestamps (false)
     {
+        init (a_parameters);
     }
 
-    bool do_callgraph_recording () const
+    void
+    init (const Glib::VariantContainerBase &a_parameters)
     {
-        return callgraph_recording;
+        Glib::Variant<bool> callgraph_recording_param;
+        Glib::Variant<bool> collect_without_buffering_param;
+        Glib::Variant<bool> collect_raw_sample_records_param;
+        Glib::Variant<bool> sample_addresses_param;
+        Glib::Variant<bool> sample_timestamps_param;
+
+        a_parameters.get_child (callgraph_recording_param, 0);
+        a_parameters.get_child (collect_without_buffering_param, 1);
+        a_parameters.get_child (collect_raw_sample_records_param, 2);
+        a_parameters.get_child (sample_addresses_param, 3);
+        a_parameters.get_child (sample_timestamps_param, 4);
     }
 
-    bool do_collect_without_buffering () const
+    bool
+    do_callgraph_recording () const
     {
-        return collect_without_buffering;
+        return callgraph_recording;
     }
 
-    bool do_collect_raw_sample_records () const
+    bool
+    do_collect_without_buffering () const
     {
-        return collect_raw_sample_records;
+        return collect_without_buffering;
     }
 
-    bool do_system_wide_collection () const
+    bool
+    do_collect_raw_sample_records () const
     {
-        return system_wide_collection;
+        return collect_raw_sample_records;
     }
 
-    bool do_sample_addresses () const
+    bool
+    do_sample_addresses () const
     {
         return sample_addresses;
     }
 
-    bool do_sample_timestamps () const
+    bool
+    do_sample_timestamps () const
     {
         return sample_timestamps;
     }
@@ -203,8 +228,8 @@ struct PerfServer::Priv {
         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);
+            a_parameters.get_child (uid_param, 5);
+            a_parameters.get_child (gid_param, 6);
 
             RequestInfo request;
             request.uid = uid_param.get ();
@@ -218,7 +243,7 @@ struct PerfServer::Priv {
             std::vector<UString> argv;
             argv.push_back ("--all-cpus");
 
-            PerfRecordOptions options;
+            PerfRecordOptions options (a_parameters);
             request.profiler->record (argv, options);
 
             Glib::Variant<unsigned> perf_data =
@@ -232,8 +257,8 @@ struct PerfServer::Priv {
             Glib::Variant<int> uid_param;
             Glib::Variant<int> gid_param;
             a_parameters.get_child (pid_param);
-            a_parameters.get_child (uid_param, 1);
-            a_parameters.get_child (gid_param, 2);
+            a_parameters.get_child (uid_param, 5);
+            a_parameters.get_child (gid_param, 6);
 
             RequestInfo request;
 
@@ -248,7 +273,7 @@ struct PerfServer::Priv {
             argv.push_back (UString::compose ("%1", pid));
 
             request_map[next_request_id] = request;
-            PerfRecordOptions options;
+            PerfRecordOptions options (a_parameters);
 
             THROW_IF_FAIL (request.profiler);
             request.profiler->record (argv, options);



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