[Fawkes Git] branch/thofmann/syncpoint: 2 revs updated. (0.5.0-3138-ge4b196a)

Till Hofmann hofmann at kbsg.rwth-aachen.de
Wed Apr 20 16:54:34 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, thofmann/syncpoint has been updated
        to  e4b196a930ae0b711c9b18cc39a7596e0160ca4d (commit)
       via  1b6fcc7dc31ebde2610d719cb53ed5eedc07acb3 (commit)
      from  75ef4c9845fb8c627a68e7c2cc1b08347031d480 (commit)

http://git.fawkesrobotics.org/fawkes.git/thofmann/syncpoint

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 1b6fcc7dc31ebde2610d719cb53ed5eedc07acb3
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Wed Apr 20 15:15:01 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Wed Apr 20 15:15:01 2016 +0200

    aspects: use std::map to translate wakeup hooks into syncpoints
    
    Instead of using a switch() in each method, define a static const map
    that contains the translation from wakeup hooks to syncpoints and use
    that map in each method. This avoids inconsistent naming (e.g. syncpoint
    name is changed in one place and forgotten in the other place) and
    allows us to translate back from syncpoints to hooks.

http://git.fawkesrobotics.org/fawkes.git/commit/1b6fcc7
http://trac.fawkesrobotics.org/changeset/1b6fcc7

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit e4b196a930ae0b711c9b18cc39a7596e0160ca4d
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Wed Apr 20 16:50:50 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Wed Apr 20 16:50:50 2016 +0200

    syncpoint: improve syncpoint visualization for the main loop
    
    Remove the main thread from the graph and add edges between adjacent
    hooks. This improves the readability of the resulting graph while
    retaining the dependencies between hooks.

http://git.fawkesrobotics.org/fawkes.git/commit/e4b196a
http://trac.fawkesrobotics.org/changeset/e4b196a

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/libs/aspect/blocked_timing.cpp       |   48 +++++++++++++----------------
 src/libs/aspect/blocked_timing.h         |    2 +
 src/libs/syncpoint/Makefile              |    2 +-
 src/libs/syncpoint/syncpoint_manager.cpp |   39 +++++++++++++++++++++++-
 4 files changed, 62 insertions(+), 29 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* 1b6fcc7dc31ebde2610d719cb53ed5eedc07acb3 - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Wed Apr 20 15:15:01 2016 +0200
Subject: aspects: use std::map to translate wakeup hooks into syncpoints

 src/libs/aspect/blocked_timing.cpp |   48 ++++++++++++++++-------------------
 src/libs/aspect/blocked_timing.h   |    2 +
 2 files changed, 24 insertions(+), 26 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/aspect/blocked_timing.cpp b/src/libs/aspect/blocked_timing.cpp
index 4a2dd2a..f070fc4 100644
--- a/src/libs/aspect/blocked_timing.cpp
+++ b/src/libs/aspect/blocked_timing.cpp
@@ -103,7 +103,6 @@ BlockedTimingAspect::blockedTimingAspectHook() const
   return __wakeup_hook;
 }
 
-
 /** Get string for wakeup hook.
  * @param hook wakeup hook to get string for
  * @return string representation of hook
@@ -126,6 +125,20 @@ BlockedTimingAspect::blocked_timing_hook_to_string(WakeupHook hook)
   }
 }
 
+const std::map<const BlockedTimingAspect::WakeupHook, const std::string>
+BlockedTimingAspect::hook_to_syncpoint = {
+  { WAKEUP_HOOK_PRE_LOOP,       "/preloop" },
+  { WAKEUP_HOOK_SENSOR_ACQUIRE, "/sensors/acquire" },
+  { WAKEUP_HOOK_SENSOR_PREPARE, "/sensors/prepare" },
+  { WAKEUP_HOOK_SENSOR_PROCESS, "/sensors/process" },
+  { WAKEUP_HOOK_WORLDSTATE,     "/worldstate" },
+  { WAKEUP_HOOK_THINK,          "/agent" },
+  { WAKEUP_HOOK_SKILL,          "/skill" },
+  { WAKEUP_HOOK_ACT,            "/act/main" },
+  { WAKEUP_HOOK_ACT_EXEC,       "/act/exec" },
+  { WAKEUP_HOOK_POST_LOOP,      "/postloop" }
+};
+
 /** Get the syncpoint identifier corresponding to the end of a wakeup hook.
  * This is the syncpoint emitted at the end of a hook.
  * @param hook wakeup hook to get the syncpoint identifier for
@@ -134,18 +147,10 @@ BlockedTimingAspect::blocked_timing_hook_to_string(WakeupHook hook)
 std::string
 BlockedTimingAspect::blocked_timing_hook_to_end_syncpoint(WakeupHook hook)
 {
-  switch (hook) {
-    case WAKEUP_HOOK_PRE_LOOP:       return "/preloop/end";
-    case WAKEUP_HOOK_SENSOR_ACQUIRE: return "/sensors/acquire/end";
-    case WAKEUP_HOOK_SENSOR_PREPARE: return "/sensors/prepare/end";
-    case WAKEUP_HOOK_SENSOR_PROCESS: return "/sensors/process/end";
-    case WAKEUP_HOOK_WORLDSTATE:     return "/worldstate/end";
-    case WAKEUP_HOOK_THINK:          return "/agent/end";
-    case WAKEUP_HOOK_SKILL:          return "/skill/end";
-    case WAKEUP_HOOK_ACT:            return "/act/main/end";
-    case WAKEUP_HOOK_ACT_EXEC:       return "/act/exec/end";
-    case WAKEUP_HOOK_POST_LOOP:      return "/postloop/end";
-    default: throw Exception("Unknown blocked timing wakeup hook");
+  try {
+    return std::string(hook_to_syncpoint.at(hook)) + "/end";
+  } catch (const std::out_of_range &e) {
+    throw Exception("Unknown blocked timing wakeup hook. Error: %s", e.what());
   }
 }
 
@@ -157,22 +162,13 @@ BlockedTimingAspect::blocked_timing_hook_to_end_syncpoint(WakeupHook hook)
 std::string
 BlockedTimingAspect::blocked_timing_hook_to_start_syncpoint(WakeupHook hook)
 {
-  switch (hook) {
-    case WAKEUP_HOOK_PRE_LOOP:       return "/preloop/start";
-    case WAKEUP_HOOK_SENSOR_ACQUIRE: return "/sensors/acquire/start";
-    case WAKEUP_HOOK_SENSOR_PREPARE: return "/sensors/prepare/start";
-    case WAKEUP_HOOK_SENSOR_PROCESS: return "/sensors/process/start";
-    case WAKEUP_HOOK_WORLDSTATE:     return "/worldstate/start";
-    case WAKEUP_HOOK_THINK:          return "/agent/start";
-    case WAKEUP_HOOK_SKILL:          return "/skill/start";
-    case WAKEUP_HOOK_ACT:            return "/act/main/start";
-    case WAKEUP_HOOK_ACT_EXEC:       return "/act/exec/start";
-    case WAKEUP_HOOK_POST_LOOP:      return "/postloop/start";
-    default: throw Exception("Unknown blocked timing wakeup hook");
+  try {
+    return std::string(hook_to_syncpoint.at(hook)) + "/start";
+  } catch (const std::out_of_range &e) {
+    throw Exception("Unknown blocked timing wakeup hook. Error: %s", e.what());
   }
 }
 
-
 /** The post loop function of the BlockedTimingAspect
  * This function is called right after the loop of the thread with the aspect.
  * @param thread thread this loop listener belongs to
diff --git a/src/libs/aspect/blocked_timing.h b/src/libs/aspect/blocked_timing.h
index 5a11f81..a781abb 100644
--- a/src/libs/aspect/blocked_timing.h
+++ b/src/libs/aspect/blocked_timing.h
@@ -87,6 +87,8 @@ class BlockedTimingAspect : public SyncPointAspect
 
   WakeupHook blockedTimingAspectHook() const;
 
+  static const std::map<const WakeupHook, const std::string> hook_to_syncpoint;
+
  private:
   WakeupHook __wakeup_hook;
   BlockedTimingLoopListener *__loop_listener;

- *commit* e4b196a930ae0b711c9b18cc39a7596e0160ca4d - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Wed Apr 20 16:50:50 2016 +0200
Subject: syncpoint: improve syncpoint visualization for the main loop

 src/libs/syncpoint/Makefile              |    2 +-
 src/libs/syncpoint/syncpoint_manager.cpp |   39 ++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 3 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/syncpoint/Makefile b/src/libs/syncpoint/Makefile
index 154a448..0a3e911 100644
--- a/src/libs/syncpoint/Makefile
+++ b/src/libs/syncpoint/Makefile
@@ -17,7 +17,7 @@ BASEDIR = ../../..
 include $(BASEDIR)/etc/buildsys/config.mk
 
 
-LIBS_libfawkessyncpoint = fawkescore fawkesutils
+LIBS_libfawkessyncpoint = fawkescore fawkesutils fawkesaspects
 OBJS_libfawkessyncpoint = $(patsubst %.cpp,%.o,$(patsubst qa/%,,$(subst $(SRCDIR)/,,$(realpath $(wildcard $(SRCDIR)/*.cpp)))))
 HDRS_libfawkessyncpoint = $(subst $(SRCDIR)/,,$(wildcard $(SRCDIR)/*.h))
 
diff --git a/src/libs/syncpoint/syncpoint_manager.cpp b/src/libs/syncpoint/syncpoint_manager.cpp
index 4b5e93c..faa6d61 100644
--- a/src/libs/syncpoint/syncpoint_manager.cpp
+++ b/src/libs/syncpoint/syncpoint_manager.cpp
@@ -21,6 +21,8 @@
 
 #include <core/threading/mutex_locker.h>
 
+#include <aspect/blocked_timing.h>
+
 #include <syncpoint/syncpoint_manager.h>
 #include <syncpoint/exceptions.h>
 
@@ -144,7 +146,6 @@ SyncPointManager::all_syncpoints_as_dot(float max_age)
 
   for (std::set<RefPtr<SyncPoint>, SyncPointSetLessThan>::const_iterator sp_it = syncpoints_.begin();
       sp_it != syncpoints_.end(); sp_it++) {
-    Time lifetime = Time() - (*sp_it)->creation_time_;
     graph << "\"" << (*sp_it)->get_identifier() << "\";";
 
     // EMIT CALLS
@@ -153,6 +154,15 @@ SyncPointManager::all_syncpoints_as_dot(float max_age)
     std::map<std::string, SyncPointCallStats> emit_call_stats;
     for (CircularBuffer<SyncPointCall>::iterator emitcalls_it = emit_calls.begin();
         emitcalls_it != emit_calls.end(); emitcalls_it++) {
+      // Remove the main thread from the graph, and also remove any emit calls
+      // to the SyncPoint "/" to improve the resulting graph.
+      // The main thread emits and waits for every hook, which adds a lot of
+      // uninteresting edges to the graph.
+      // Similarly, all emitters also emit "/", which is not interesting to see.
+      if (emitcalls_it->get_caller() == "FawkesMainThread" ||
+          (*sp_it)->get_identifier() == "/") {
+        continue;
+      }
       emit_call_stats[emitcalls_it->get_caller()].update_calls(emitcalls_it->get_call_time());
     }
 
@@ -181,6 +191,9 @@ SyncPointManager::all_syncpoints_as_dot(float max_age)
 
     for (std::map<std::string, SyncPointCallStats>::iterator wait_call_stats_it = wait_one_call_stats.begin();
         wait_call_stats_it != wait_one_call_stats.end(); wait_call_stats_it++) {
+      if (wait_call_stats_it->first == "FawkesMainThread") {
+        continue;
+      }
       float age = (Time() - wait_call_stats_it->second.get_last_call()).in_sec();
       if (age < max_age) {
         graph << "\"" << (*sp_it)->get_identifier() << "\"" << " -> "
@@ -209,6 +222,9 @@ SyncPointManager::all_syncpoints_as_dot(float max_age)
 
     for (std::map<std::string, SyncPointCallStats>::iterator wait_call_stats_it = wait_all_call_stats.begin();
         wait_call_stats_it != wait_all_call_stats.end(); wait_call_stats_it++) {
+      if (wait_call_stats_it->first == "FawkesMainThread") {
+        continue;
+      }
       float age = (Time() - wait_call_stats_it->second.get_last_call()).in_sec();
       if (age < max_age) {
         graph << "\"" << (*sp_it)->get_identifier() << "\"" << " -> "
@@ -225,7 +241,26 @@ SyncPointManager::all_syncpoints_as_dot(float max_age)
         graph << "];";
       }
     }
-
+  }
+  // Visualize hook dependencies by directly adding edges from one hook to the
+  // next. This is necessary because we removed the main thread from the
+  // visualization, which makes sure that the hooks are started in the right
+  // order. To retain the dependencies between the hooks, add edges manually.
+  // Essentially, these edges represent the order that is guaranteed by the
+  // main thread.
+  // Note: this expects that
+  //   (1) pre loop is the first, post loop th last hook,
+  //   (2) no custom enum values (e.g. WAKEUP_HOOK_ACT = 5) are specified.
+  for (uint i = BlockedTimingAspect::WAKEUP_HOOK_PRE_LOOP;
+       i != BlockedTimingAspect::WAKEUP_HOOK_POST_LOOP;
+       i++) {
+    graph << "\""
+      << BlockedTimingAspect::blocked_timing_hook_to_end_syncpoint(
+        static_cast<BlockedTimingAspect::WakeupHook>(i)) << "\""
+      << " -> " << "\""
+      << BlockedTimingAspect::blocked_timing_hook_to_start_syncpoint(
+        static_cast<BlockedTimingAspect::WakeupHook>(i+1))
+      << "\";";
   }
   graph << "}";
   return graph.str();




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list