perfetto_cmd: print warning when not attached to a TTY

When the user invokes perfetto with 'adb shell perfetto'
print a warning that explains that CTRL-C won't work.
#fixit

Test: manual:
   adb shell perfetto -c :test -o /dev/null  # shows warning
   adb shell -t perfetto -c :test -o /dev/null  # no warning
   adb shell; perfetto -c :test -o /dev/null  # no warning
Bug: 180129616
Bug: 162589153
Change-Id: I15d71db7e66b944a9cd3cd0a48588366d4023712
diff --git a/src/perfetto_cmd/perfetto_cmd.cc b/src/perfetto_cmd/perfetto_cmd.cc
index 526139d..c8f6abc 100644
--- a/src/perfetto_cmd/perfetto_cmd.cc
+++ b/src/perfetto_cmd/perfetto_cmd.cc
@@ -748,6 +748,18 @@
     return 1;
   }
 
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
+  if (!background && !is_detach() && !upload_flag &&
+      triggers_to_activate.empty() && !isatty(STDIN_FILENO) &&
+      !isatty(STDERR_FILENO)) {
+    fprintf(stderr,
+            "Warning: No PTY. CTRL+C won't gracefully stop the trace. If you "
+            "are running perfetto via adb shell, use the -tt arg (adb shell "
+            "-t perfetto ...) or consider using the helper script "
+            "tools/record_android_trace from the Perfetto repository.\n\n");
+  }
+#endif
+
   consumer_endpoint_ =
       ConsumerIPCClient::Connect(GetConsumerSocket(), this, &task_runner_);
   SetupCtrlCSignalHandler();