Wire up traced binary

Also simplify a bit the include/ folder. Not sure we'll
ever need more than one header. That the code under
traced contains only leaf executables and not libraries,
one hader for the two Main(s) should be sufficient.
Also fixes static lib generation for Mac.

Change-Id: I3e1fed0f02aef61b1cf797b89855b981e0d73a5e
diff --git a/gn/standalone/toolchain/BUILD.gn b/gn/standalone/toolchain/BUILD.gn
index 5c3389e..d137ad8 100644
--- a/gn/standalone/toolchain/BUILD.gn
+++ b/gn/standalone/toolchain/BUILD.gn
@@ -94,9 +94,13 @@
     }
 
     tool("alink") {
-      rspfile = "{{output}}.rsp"
-      rspfile_content = "{{inputs}}"
-      command = "$ar rcsD {{output}} @$rspfile"
+      if (is_mac && ar != "suppress_unused_ar_variable_warning") {
+        command = "rm -f {{output}} && libtool -static {{arflags}} -o {{output}} {{inputs}}"
+      } else {
+        rspfile = "{{output}}.rsp"
+        rspfile_content = "{{inputs}}"
+        command = "$ar rcsD {{output}} @$rspfile"
+      }
       outputs = [
         "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
       ]
diff --git a/include/perfetto/traced/probes/BUILD.gn b/include/perfetto/traced/BUILD.gn
similarity index 93%
rename from include/perfetto/traced/probes/BUILD.gn
rename to include/perfetto/traced/BUILD.gn
index 4f8af27..4d9fe0c 100644
--- a/include/perfetto/traced/probes/BUILD.gn
+++ b/include/perfetto/traced/BUILD.gn
@@ -12,8 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-source_set("probes") {
+source_set("traced") {
   sources = [
-    "probes.h",
+    "traced.h",
   ]
 }
diff --git a/include/perfetto/traced/probes/probes.h b/include/perfetto/traced/probes/probes.h
deleted file mode 100644
index 55a2ede..0000000
--- a/include/perfetto/traced/probes/probes.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace perfetto {
-
-int ProbesMain(int argc, char** argv);
-
-}  // namespace perfetto
diff --git a/include/perfetto/traced/service/BUILD.gn b/include/perfetto/traced/service/BUILD.gn
deleted file mode 100644
index 601558e..0000000
--- a/include/perfetto/traced/service/BUILD.gn
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2017 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-source_set("service") {
-  sources = [
-    "service.h",
-  ]
-}
diff --git a/include/perfetto/traced/service/service.h b/include/perfetto/traced/service/service.h
deleted file mode 100644
index e4678e0..0000000
--- a/include/perfetto/traced/service/service.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace perfetto {
-
-int ServiceMain(int argc, char** argv);
-
-}  // namespace perfetto
diff --git a/include/perfetto/traced/traced.h b/include/perfetto/traced/traced.h
new file mode 100644
index 0000000..d48d46b
--- /dev/null
+++ b/include/perfetto/traced/traced.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INCLUDE_PERFETTO_TRACED_TRACED_H_
+#define INCLUDE_PERFETTO_TRACED_TRACED_H_
+
+#include "perfetto/base/build_config.h"
+
+namespace perfetto {
+
+// TODO(primiano): The actual paths are TBD after security reviews. For the
+// moment using an abstract socket on Linux/Andriod and a linked socket on /tmp
+// for Mac.
+
+#if BUILDFLAG(OS_ANDROID) || BUILDFLAG(OS_LINUX)
+#define PERFETTO_PRODUCER_SOCK_NAME "@perfetto-producer"
+#define PERFETTO_CONSUMER_SOCK_NAME "@perfetto-consumer"
+#else
+#define PERFETTO_PRODUCER_SOCK_NAME "/tmp/perfetto-producer"
+#define PERFETTO_CONSUMER_SOCK_NAME "/tmp/perfetto-consumer"
+#endif
+
+int ServiceMain(int argc, char** argv);
+int ProbesMain(int argc, char** argv);
+
+}  // namespace perfetto
+
+#endif  // INCLUDE_PERFETTO_TRACED_TRACED_H_
diff --git a/src/base/BUILD.gn b/src/base/BUILD.gn
index 3a8a851..149f856 100644
--- a/src/base/BUILD.gn
+++ b/src/base/BUILD.gn
@@ -44,6 +44,9 @@
       "-Wno-deprecated-dynamic-exception-spec",
       "-Wno-disabled-macro-expansion",
     ]
+    deps = [
+      "../../gn:default_deps",
+    ]
   }
 }
 
diff --git a/src/traced/probes/BUILD.gn b/src/traced/probes/BUILD.gn
index 20f7481..8ebade3 100644
--- a/src/traced/probes/BUILD.gn
+++ b/src/traced/probes/BUILD.gn
@@ -14,7 +14,7 @@
 
 source_set("probes") {
   public_deps = [
-    "../../../include/perfetto/traced/probes",
+    "../../../include/perfetto/traced",
   ]
   deps = [
     "../../../gn:default_deps",
diff --git a/src/traced/probes/probes.cc b/src/traced/probes/probes.cc
index befc2e8..2695eb6 100644
--- a/src/traced/probes/probes.cc
+++ b/src/traced/probes/probes.cc
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#include "perfetto/traced/probes/probes.h"
 #include "perfetto/base/logging.h"
+#include "perfetto/traced/traced.h"
 
 namespace perfetto {
 
diff --git a/src/traced/service/BUILD.gn b/src/traced/service/BUILD.gn
index 48d7dd0..6b027c6 100644
--- a/src/traced/service/BUILD.gn
+++ b/src/traced/service/BUILD.gn
@@ -14,7 +14,7 @@
 
 source_set("service") {
   public_deps = [
-    "../../../include/perfetto/traced/service",
+    "../../../include/perfetto/traced",
   ]
   deps = [
     "../../../gn:default_deps",
diff --git a/src/traced/service/service.cc b/src/traced/service/service.cc
index 41ee1da..8c747a4 100644
--- a/src/traced/service/service.cc
+++ b/src/traced/service/service.cc
@@ -14,13 +14,22 @@
  * limitations under the License.
  */
 
-#include "perfetto/traced/service/service.h"
-#include "perfetto/base/logging.h"
+#include "perfetto/base/unix_task_runner.h"
+#include "perfetto/traced/traced.h"
+#include "perfetto/tracing/ipc/service_ipc_host.h"
 
 namespace perfetto {
 
 int ServiceMain(int argc, char** argv) {
-  PERFETTO_LOG("Service");
+  base::UnixTaskRunner task_runner;
+  std::unique_ptr<ServiceIPCHost> svc;
+  svc = ServiceIPCHost::CreateInstance(&task_runner);
+  unlink(PERFETTO_PRODUCER_SOCK_NAME);
+  unlink(PERFETTO_CONSUMER_SOCK_NAME);
+  svc->Start(PERFETTO_PRODUCER_SOCK_NAME, PERFETTO_CONSUMER_SOCK_NAME);
+  PERFETTO_ILOG("Started traced, listening on %s %s",
+                PERFETTO_PRODUCER_SOCK_NAME, PERFETTO_CONSUMER_SOCK_NAME);
+  task_runner.Run();
   return 0;
 }
 
diff --git a/src/traced/traced.cc b/src/traced/traced.cc
index d946665..468de03 100644
--- a/src/traced/traced.cc
+++ b/src/traced/traced.cc
@@ -14,11 +14,10 @@
  * limitations under the License.
  */
 
+#include <stdio.h>
 #include <string.h>
 
-#include "perfetto/base/logging.h"
-#include "perfetto/traced/probes/probes.h"
-#include "perfetto/traced/service/service.h"
+#include "perfetto/traced/traced.h"
 
 int main(int argc, char** argv) {
   if (argc > 1 && !strcmp(argv[1], "probes"))