Improve error message if perfetto invocation fails.

Change-Id: Ic6e990ca1b2e1cca988fa5264b36c3b6039b8fca
diff --git a/tools/heap_profile b/tools/heap_profile
index 021fdd0..84a77e9 100755
--- a/tools/heap_profile
+++ b/tools/heap_profile
@@ -186,6 +186,12 @@
 
   perfetto_pid = subprocess.check_output(
       ['adb', 'exec-out', PERFETTO_CMD.format(cfg)]).strip()
+  try:
+    int(perfetto_pid.strip())
+  except ValueError:
+    print("Failed to invoke perfetto: {}".format(perfetto_pid),
+          file=sys.stderr)
+    return 1
 
   old_handler = signal.signal(signal.SIGINT, sigint_handler)
   print("Profiling active. Press Ctrl+C to terminate.")