Add ftrace to detect and end on SIGCHLD

Call ftrace and have it end upon getting a SIGCHLD so we can see what
went on leading up to that time.

Change-Id: I84edb1b470dbadf231ba87e3a5d083fd7088cfa9
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/starter/starterd_lib.cc b/aos/starter/starterd_lib.cc
index 95210c0..38d519d 100644
--- a/aos/starter/starterd_lib.cc
+++ b/aos/starter/starterd_lib.cc
@@ -19,6 +19,7 @@
 DEFINE_uint32(queue_initialization_threads, 0,
               "Number of threads to spin up to initialize the queue.  0 means "
               "use the main thread.");
+DECLARE_bool(enable_ftrace);
 
 namespace aos::starter {
 
@@ -214,6 +215,11 @@
   if (info.ssi_signo == SIGCHLD) {
     // SIGCHLD messages can be collapsed if multiple are received, so all
     // applications must check their status.
+    if (FLAGS_enable_ftrace) {
+      ftrace_.FormatMessage("SIGCHLD");
+      ftrace_.TurnOffOrDie();
+    }
+
     for (auto iter = applications_.begin(); iter != applications_.end();) {
       if (iter->second.MaybeHandleSignal()) {
         iter = applications_.erase(iter);