Reland "tp: Reduce memory usage related to TimestampedTracePiece"

This reverts commit f106ab5f09325d74b7c17866f957595d6dfa6c96.

Reason for revert: not the cause of problems

Change-Id: I93d872df7102d72ce2ab90cedb14882f615f90fb
diff --git a/tools/measure_tp_performance.py b/tools/measure_tp_performance.py
index e5e09ce..88a372e 100755
--- a/tools/measure_tp_performance.py
+++ b/tools/measure_tp_performance.py
@@ -146,9 +146,25 @@
       action='store_true',
       help='Whether to ingest ftrace into raw table',
       default=False)
+  parser.add_argument(
+      '--kill-existing',
+      action='store_true',
+      help='Kill traced, perfetto_cmd '
+      'and trace processor shell if running')
   parser.add_argument('trace_file', type=str, help='Path to trace')
   args = parser.parse_args()
 
+  if args.kill_existing:
+    subprocess.run(['killall', 'traced'],
+                   stdout=subprocess.DEVNULL,
+                   stderr=subprocess.DEVNULL)
+    subprocess.run(['killall', 'perfetto'],
+                   stdout=subprocess.DEVNULL,
+                   stderr=subprocess.DEVNULL)
+    subprocess.run(['killall', 'trace_processor_shell'],
+                   stdout=subprocess.DEVNULL,
+                   stderr=subprocess.DEVNULL)
+
   traced = subprocess.Popen([os.path.join(args.out, 'traced')],
                             stdout=subprocess.DEVNULL,
                             stderr=subprocess.DEVNULL)