Add skeleton of traced

Add the build structure for the traced deamon.

Change-Id: I047b6ff62f95e5ea4ef709d57f81eebd0eccf9ae
diff --git a/Android.bp b/Android.bp
index 960e7f9..9b815dd 100644
--- a/Android.bp
+++ b/Android.bp
@@ -559,6 +559,74 @@
   ],
 }
 
+// GN target: //src/traced:traced
+cc_binary {
+  name: "perfetto_src_traced_traced",
+  srcs: [
+    ":perfetto_protos_ftrace_lite_gen",
+    ":perfetto_protos_ftrace_zero_gen",
+    ":perfetto_protos_lite_gen",
+    ":perfetto_protos_tracing_service_lite_gen",
+    ":perfetto_protos_tracing_service_tracing_service_gen",
+    ":perfetto_protos_zero_gen",
+    ":perfetto_src_ipc_wire_protocol_gen",
+    "src/base/android_task_runner.cc",
+    "src/base/thread_checker.cc",
+    "src/base/unix_task_runner.cc",
+    "src/ftrace_reader/cpu_reader.cc",
+    "src/ftrace_reader/event_info.cc",
+    "src/ftrace_reader/format_parser.cc",
+    "src/ftrace_reader/ftrace_controller.cc",
+    "src/ftrace_reader/ftrace_procfs.cc",
+    "src/ftrace_reader/ftrace_to_proto.cc",
+    "src/ftrace_reader/proto_translation_table.cc",
+    "src/ipc/buffered_frame_deserializer.cc",
+    "src/ipc/client_impl.cc",
+    "src/ipc/deferred.cc",
+    "src/ipc/host_impl.cc",
+    "src/ipc/service_proxy.cc",
+    "src/ipc/unix_socket.cc",
+    "src/protozero/proto_utils.cc",
+    "src/protozero/protozero_message.cc",
+    "src/protozero/protozero_message_handle.cc",
+    "src/protozero/scattered_stream_writer.cc",
+    "src/traced/probes/probes.cc",
+    "src/traced/service/service.cc",
+    "src/traced/traced.cc",
+    "src/tracing/core/chunked_protobuf_input_stream.cc",
+    "src/tracing/core/data_source_config.cc",
+    "src/tracing/core/data_source_descriptor.cc",
+    "src/tracing/core/id_allocator.cc",
+    "src/tracing/core/service_impl.cc",
+    "src/tracing/core/shared_memory_abi.cc",
+    "src/tracing/core/shared_memory_arbiter.cc",
+    "src/tracing/core/trace_config.cc",
+    "src/tracing/core/trace_packet.cc",
+    "src/tracing/core/trace_writer_impl.cc",
+  ],
+  shared_libs: [
+    "libandroid",
+    "liblog",
+    "libprotobuf-cpp-lite",
+  ],
+  static_libs: [
+    "libgtest_prod",
+    "perfetto_src_tracing_ipc",
+  ],
+  generated_headers: [
+    "perfetto_protos_ftrace_lite_gen_headers",
+    "perfetto_protos_ftrace_zero_gen_headers",
+    "perfetto_protos_lite_gen_headers",
+    "perfetto_protos_tracing_service_lite_gen_headers",
+    "perfetto_protos_tracing_service_tracing_service_gen_headers",
+    "perfetto_protos_zero_gen_headers",
+    "perfetto_src_ipc_wire_protocol_gen_headers",
+  ],
+  defaults: [
+    "perfetto_defaults",
+  ],
+}
+
 // GN target: //src/tracing:ipc
 cc_library_static {
   name: "perfetto_src_tracing_ipc",
@@ -605,6 +673,9 @@
     "liblog",
     "libprotobuf-cpp-lite",
   ],
+  static_libs: [
+    "libgtest_prod",
+  ],
   generated_headers: [
     "perfetto_protos_ftrace_lite_gen_headers",
     "perfetto_protos_ftrace_zero_gen_headers",
@@ -709,6 +780,7 @@
   ],
   static_libs: [
     "libgmock",
+    "libgtest_prod",
     "perfetto_src_tracing_ipc",
   ],
   generated_headers: [
diff --git a/BUILD.gn b/BUILD.gn
index 0d3c7c2..15ea142 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -20,6 +20,7 @@
     ":perfetto_tests",
     "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
     "src/protozero/protoc_plugin($host_toolchain)",
+    "src/traced",
     "tools/ftrace_proto_gen:ftrace_proto_gen",
     "tools/proto_to_cpp",
   ]
diff --git a/include/perfetto/traced/probes/BUILD.gn b/include/perfetto/traced/probes/BUILD.gn
new file mode 100644
index 0000000..4f8af27
--- /dev/null
+++ b/include/perfetto/traced/probes/BUILD.gn
@@ -0,0 +1,19 @@
+# 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("probes") {
+  sources = [
+    "probes.h",
+  ]
+}
diff --git a/include/perfetto/traced/probes/probes.h b/include/perfetto/traced/probes/probes.h
new file mode 100644
index 0000000..55a2ede
--- /dev/null
+++ b/include/perfetto/traced/probes/probes.h
@@ -0,0 +1,21 @@
+/*
+ * 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
new file mode 100644
index 0000000..601558e
--- /dev/null
+++ b/include/perfetto/traced/service/BUILD.gn
@@ -0,0 +1,19 @@
+# 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
new file mode 100644
index 0000000..e4678e0
--- /dev/null
+++ b/include/perfetto/traced/service/service.h
@@ -0,0 +1,21 @@
+/*
+ * 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/src/ftrace_reader/BUILD.gn b/src/ftrace_reader/BUILD.gn
index 419ec6c..8534419 100644
--- a/src/ftrace_reader/BUILD.gn
+++ b/src/ftrace_reader/BUILD.gn
@@ -84,12 +84,12 @@
 
 source_set("ftrace_reader") {
   public_deps = [
+    "../../gn:gtest_prod_config",
     "../../include/perfetto/ftrace_reader",
     "../../protos/ftrace:zero",
   ]
   deps = [
     "../../gn:default_deps",
-    "../../gn:gtest_prod_config",
     "../base",
     "../protozero",
   ]
diff --git a/src/traced/BUILD.gn b/src/traced/BUILD.gn
new file mode 100644
index 0000000..7d96116
--- /dev/null
+++ b/src/traced/BUILD.gn
@@ -0,0 +1,25 @@
+# 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.
+
+executable("traced") {
+  sources = [
+    "traced.cc",
+  ]
+  deps = [
+    "../../gn:default_deps",
+    "../base",
+    "probes",
+    "service",
+  ]
+}
diff --git a/src/traced/probes/BUILD.gn b/src/traced/probes/BUILD.gn
new file mode 100644
index 0000000..20f7481
--- /dev/null
+++ b/src/traced/probes/BUILD.gn
@@ -0,0 +1,27 @@
+# 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("probes") {
+  public_deps = [
+    "../../../include/perfetto/traced/probes",
+  ]
+  deps = [
+    "../../../gn:default_deps",
+    "../../base",
+    "../../ftrace_reader",
+  ]
+  sources = [
+    "probes.cc",
+  ]
+}
diff --git a/src/traced/probes/probes.cc b/src/traced/probes/probes.cc
new file mode 100644
index 0000000..befc2e8
--- /dev/null
+++ b/src/traced/probes/probes.cc
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#include "perfetto/traced/probes/probes.h"
+#include "perfetto/base/logging.h"
+
+namespace perfetto {
+
+int ProbesMain(int argc, char** argv) {
+  PERFETTO_LOG("Probes");
+  return 0;
+}
+
+}  // namespace perfetto
diff --git a/src/traced/service/BUILD.gn b/src/traced/service/BUILD.gn
new file mode 100644
index 0000000..48d7dd0
--- /dev/null
+++ b/src/traced/service/BUILD.gn
@@ -0,0 +1,28 @@
+# 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") {
+  public_deps = [
+    "../../../include/perfetto/traced/service",
+  ]
+  deps = [
+    "../../../gn:default_deps",
+    "../../base",
+    "../../tracing",
+    "../../tracing:ipc",
+  ]
+  sources = [
+    "service.cc",
+  ]
+}
diff --git a/src/traced/service/service.cc b/src/traced/service/service.cc
new file mode 100644
index 0000000..41ee1da
--- /dev/null
+++ b/src/traced/service/service.cc
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#include "perfetto/traced/service/service.h"
+#include "perfetto/base/logging.h"
+
+namespace perfetto {
+
+int ServiceMain(int argc, char** argv) {
+  PERFETTO_LOG("Service");
+  return 0;
+}
+
+}  // namespace perfetto
diff --git a/src/traced/traced.cc b/src/traced/traced.cc
new file mode 100644
index 0000000..d946665
--- /dev/null
+++ b/src/traced/traced.cc
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+#include <string.h>
+
+#include "perfetto/base/logging.h"
+#include "perfetto/traced/probes/probes.h"
+#include "perfetto/traced/service/service.h"
+
+int main(int argc, char** argv) {
+  if (argc > 1 && !strcmp(argv[1], "probes"))
+    return perfetto::ProbesMain(argc, argv);
+
+  if (argc > 1 && !strcmp(argv[1], "service"))
+    return perfetto::ServiceMain(argc, argv);
+
+  printf("Usage: %s probes | service\n", argv[0]);
+  return 1;
+}
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index 3b4be0c..eb5e051 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -34,7 +34,7 @@
 import sys
 
 # Default targets to translate to the blueprint file.
-default_targets = ['//:perfetto_tests']
+default_targets = ['//:perfetto_tests', '//src/traced:traced']
 
 # Arguments for the GN output directory.
 gn_args = 'target_os="android" target_cpu="arm" is_debug=false'
@@ -60,6 +60,10 @@
     module.static_libs.append('libgmock')
 
 
+def enable_gtest_prod(module):
+    module.static_libs.append('libgtest_prod')
+
+
 def enable_gtest(module):
     assert module.type == 'cc_test'
 
@@ -86,6 +90,7 @@
 builtin_deps = {
     '//buildtools:gmock': enable_gmock,
     '//buildtools:gtest': enable_gtest,
+    '//gn:gtest_prod_config': enable_gtest_prod,
     '//buildtools:gtest_main': enable_gtest,
     '//buildtools:libunwind': enable_libunwind,
     '//buildtools:protobuf_full': enable_protobuf_full,