Hide ftrace behind a flag so it is disabled by default

We were spending like 10% CPU formatting all the Fetch and Watch
and Send messages for the kernel.  Hide those behind a flag so the
default configuration is a lot quieter.

Change-Id: I58a313e27b8ebe41775af76b1529be8d1f258e5c
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/ftrace.cc b/aos/ftrace.cc
index f159a76..0afbcf5 100644
--- a/aos/ftrace.cc
+++ b/aos/ftrace.cc
@@ -3,8 +3,20 @@
 #include <cstdarg>
 #include <cstdio>
 
+DEFINE_bool(
+    enable_ftrace, false,
+    "If false, disable logging to /sys/kernel/debug/tracing/trace_marker");
+
 namespace aos {
 
+Ftrace::Ftrace()
+    : message_fd_(FLAGS_enable_ftrace
+                      ? open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY)
+                      : -1),
+      on_fd_(FLAGS_enable_ftrace
+                 ? open("/sys/kernel/debug/tracing/tracing_on", O_WRONLY)
+                 : -1) {}
+
 Ftrace::~Ftrace() {
   if (message_fd_ != -1) {
     PCHECK(close(message_fd_) == 0);
diff --git a/aos/ftrace.h b/aos/ftrace.h
index 42147ad..3b5326f 100644
--- a/aos/ftrace.h
+++ b/aos/ftrace.h
@@ -17,9 +17,7 @@
 // continue working in that case.
 class Ftrace {
  public:
-  Ftrace()
-      : message_fd_(open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY)),
-        on_fd_(open("/sys/kernel/debug/tracing/tracing_on", O_WRONLY)) {}
+  Ftrace();
   ~Ftrace();
 
   // Writes a message with a printf-style format.