Fix merged perfetto trace

The change to group the ftrace protos broke the merged proto because
I had accidentally duplicated some entries in gen_merged_protos. This
fixes the issue and adds a build target so this can't happen in future.

Change-Id: Iba2a3dfa1836f2c36bdd65fea67b2518f1b03eeb
diff --git a/BUILD.gn b/BUILD.gn
index ca8a9c3..307f3aa 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -54,6 +54,7 @@
       ":traced",
       ":traced_probes",
       "protos/perfetto/config:merged_config",  # For syntax-checking the proto.
+      "protos/perfetto/trace:merged_trace",  # For syntax-checking the proto.
       "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
       "tools:protoc_helper",
     ]
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index 517d281..a3d7940 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -152,435 +152,29 @@
 }
 // End of protos/perfetto/common/sys_stats_counters.proto
 
-// Begin of protos/perfetto/trace/trace.proto
+// Begin of protos/perfetto/trace/clock_snapshot.proto
 
-message Trace {
-  repeated TracePacket packet = 1;
-
-  // Do NOT add any other field here. This is just a convenience wrapper for
-  // the use case of a trace being saved to a file. There are other cases
-  // (streaming) where TracePacket are directly streamed without being wrapped
-  // in a Trace proto. Nothing should ever rely on the full trace, all the
-  // logic should be based on TracePacket(s).
-}
-
-// End of protos/perfetto/trace/trace.proto
-
-// Begin of protos/perfetto/trace/trace_packet.proto
-
-// The root object emitted by Perfetto. A perfetto trace is just a stream of
-// TracePacket(s).
-//
-// Next id: 10.
-message TracePacket {
-  // TODO: in future we should add a timestamp_clock_domain field to
-  // allow mixing timestamps from different clock domains.
-  optional uint64 timestamp = 8;  // Timestamp [ns].
-
-  oneof data {
-    FtraceEventBundle ftrace_events = 1;
-    ProcessTree process_tree = 2;
-    ProcessStats process_stats = 9;
-    InodeFileMap inode_file_map = 4;
-    // removed field with id 5
-    ClockSnapshot clock_snapshot = 6;
-    SysStats sys_stats = 7;
-
-    // IDs up to 32 are reserved for events that are quite frequent because they
-    // take only one byte to encode their preamble.
-
-    // removed field with id 33
-    FtraceStats ftrace_stats = 34;
-    // removed field with id 35
-    // removed field with id 37
-
-    // This field is emitted at periodic intervals (~10s) and
-    // contains always the binary representation of the UUID
-    // {82477a76-b28d-42ba-81dc-33326d57a079}. This is used to be able to
-    // efficiently partition long traces without having to fully parse them.
-    bytes synchronization_marker = 36;
-
-    // This field is only used for testing.
-    // removed field with id 268435455  // 2^28 - 1, max field id for protos.
+// A snapshot of clock readings to allow for trace alignment.
+message ClockSnapshot {
+  message Clock {
+    enum Type {
+      UNKNOWN = 0;
+      REALTIME = 1;
+      REALTIME_COARSE = 2;
+      MONOTONIC = 3;
+      MONOTONIC_COARSE = 4;
+      MONOTONIC_RAW = 5;
+      BOOTTIME = 6;
+      PROCESS_CPUTIME = 7;
+      THREAD_CPUTIME = 8;
+    }
+    optional Type type = 1;
+    optional uint64 timestamp = 2;
   }
-
-  // Trusted user id of the producer which generated this packet. Keep in sync
-  // with TrustedPacket.trusted_uid.
-  oneof optional_trusted_uid { int32 trusted_uid = 3; };
+  repeated Clock clocks = 1;
 }
 
-// End of protos/perfetto/trace/trace_packet.proto
-
-// Begin of protos/perfetto/trace/ftrace/ftrace_event_bundle.proto
-
-message FtraceEventBundle {
-  optional uint32 cpu = 1;
-  repeated FtraceEvent event = 2;
-  // Total of all overwrite fields from the headers of all kernel
-  // ftrace pages we parsed into this FtraceEventBundle. Zero if
-  // no overwriting occurred, a number larger than zero if some overwriting
-  // occurred.
-  optional uint32 overwrite_count = 3;
-}
-
-// End of protos/perfetto/trace/ftrace/ftrace_event_bundle.proto
-
-// Begin of protos/perfetto/trace/ftrace/ftrace_event.proto
-
-message FtraceEvent {
-  // Nanoseconds since an epoch.
-  // Epoch is configurable by writing into trace_clock.
-  // By default this timestamp is CPU local.
-  // TODO: Figure out a story for reconciling the various clocks.
-  optional uint64 timestamp = 1;
-
-  // Kernel pid (do not confuse with userspace pid aka tgid)
-  optional uint32 pid = 2;
-
-  oneof event {
-    PrintFtraceEvent print = 3;
-    SchedSwitchFtraceEvent sched_switch = 4;
-    // removed field with id 5;
-    // removed field with id 6;
-    // removed field with id 7;
-    // removed field with id 8;
-    // removed field with id 9;
-    // removed field with id 10;
-    CpuFrequencyFtraceEvent cpu_frequency = 11;
-    CpuFrequencyLimitsFtraceEvent cpu_frequency_limits = 12;
-    CpuIdleFtraceEvent cpu_idle = 13;
-    ClockEnableFtraceEvent clock_enable = 14;
-    ClockDisableFtraceEvent clock_disable = 15;
-    ClockSetRateFtraceEvent clock_set_rate = 16;
-    SchedWakeupFtraceEvent sched_wakeup = 17;
-    SchedBlockedReasonFtraceEvent sched_blocked_reason = 18;
-    SchedCpuHotplugFtraceEvent sched_cpu_hotplug = 19;
-    SchedWakingFtraceEvent sched_waking = 20;
-    // removed field with id 21
-    // removed field with id 22
-    // removed field with id 23
-    // removed field with id 24
-    // removed field with id 25
-    // removed field with id 26
-    // removed field with id 27
-    // removed field with id 28
-    // removed field with id 29
-    // removed field with id 30
-    // removed field with id 31
-    // removed field with id 32
-    // removed field with id 33
-    // removed field with id 34
-    LowmemoryKillFtraceEvent lowmemory_kill = 35;
-    // removed field with id 36
-    // removed field with id 37
-    // removed field with id 38
-    // removed field with id 39
-    // removed field with id 40
-    Ext4DaWriteBeginFtraceEvent ext4_da_write_begin = 41;
-    Ext4DaWriteEndFtraceEvent ext4_da_write_end = 42;
-    Ext4SyncFileEnterFtraceEvent ext4_sync_file_enter = 43;
-    Ext4SyncFileExitFtraceEvent ext4_sync_file_exit = 44;
-    BlockRqIssueFtraceEvent block_rq_issue = 45;
-    MmVmscanDirectReclaimBeginFtraceEvent mm_vmscan_direct_reclaim_begin = 46;
-    MmVmscanDirectReclaimEndFtraceEvent mm_vmscan_direct_reclaim_end = 47;
-    MmVmscanKswapdWakeFtraceEvent mm_vmscan_kswapd_wake = 48;
-    MmVmscanKswapdSleepFtraceEvent mm_vmscan_kswapd_sleep = 49;
-    BinderTransactionFtraceEvent binder_transaction = 50;
-    BinderTransactionReceivedFtraceEvent binder_transaction_received = 51;
-    BinderSetPriorityFtraceEvent binder_set_priority = 52;
-    BinderLockFtraceEvent binder_lock = 53;
-    BinderLockedFtraceEvent binder_locked = 54;
-    BinderUnlockFtraceEvent binder_unlock = 55;
-    // removed field with id 56
-    // removed field with id 57
-    // removed field with id 58
-    // removed field with id 59
-    // removed field with id 60
-    // removed field with id 61
-    // removed field with id 62
-    // removed field with id 63
-    // removed field with id 64
-    // removed field with id 65
-    // removed field with id 66
-    // removed field with id 67
-    // removed field with id 68
-    // removed field with id 69
-    // removed field with id 70
-    // removed field with id 71
-    // removed field with id 72
-    // removed field with id 73
-    // removed field with id 74
-    // removed field with id 75
-    // removed field with id 76
-    // removed field with id 77
-    // removed field with id 78
-    // removed field with id 79
-    // removed field with id 80
-    // removed field with id 81
-    // removed field with id 82
-    // removed field with id 83
-    // removed field with id 84
-    // removed field with id 85
-    // removed field with id 86
-    // removed field with id 87
-    // removed field with id 88
-    // removed field with id 89
-    // removed field with id 90
-    // removed field with id 91
-    // removed field with id 92
-    // removed field with id 93
-    // removed field with id 94
-    // removed field with id 95
-    // removed field with id 96
-    MmFilemapAddToPageCacheFtraceEvent mm_filemap_add_to_page_cache = 97;
-    MmFilemapDeleteFromPageCacheFtraceEvent mm_filemap_delete_from_page_cache =
-        98;
-    // removed field with id 99
-    // removed field with id 100
-    // removed field with id 101
-    // removed field with id 102
-    // removed field with id 103
-    // removed field with id 104
-    // removed field with id 105
-    // removed field with id 106
-    // removed field with id 107
-    // removed field with id 108
-    // removed field with id 109
-    // removed field with id 110
-    // removed field with id 111
-    // removed field with id 112
-    SuspendResumeFtraceEvent suspend_resume = 113;
-    SchedWakeupNewFtraceEvent sched_wakeup_new = 114;
-    BlockBioBackmergeFtraceEvent block_bio_backmerge = 115;
-    BlockBioBounceFtraceEvent block_bio_bounce = 116;
-    BlockBioCompleteFtraceEvent block_bio_complete = 117;
-    BlockBioFrontmergeFtraceEvent block_bio_frontmerge = 118;
-    BlockBioQueueFtraceEvent block_bio_queue = 119;
-    BlockBioRemapFtraceEvent block_bio_remap = 120;
-    BlockDirtyBufferFtraceEvent block_dirty_buffer = 121;
-    BlockGetrqFtraceEvent block_getrq = 122;
-    BlockPlugFtraceEvent block_plug = 123;
-    BlockRqAbortFtraceEvent block_rq_abort = 124;
-    BlockRqCompleteFtraceEvent block_rq_complete = 125;
-    BlockRqInsertFtraceEvent block_rq_insert = 126;
-    // removed field with id 127;
-    BlockRqRemapFtraceEvent block_rq_remap = 128;
-    BlockRqRequeueFtraceEvent block_rq_requeue = 129;
-    BlockSleeprqFtraceEvent block_sleeprq = 130;
-    BlockSplitFtraceEvent block_split = 131;
-    BlockTouchBufferFtraceEvent block_touch_buffer = 132;
-    BlockUnplugFtraceEvent block_unplug = 133;
-    Ext4AllocDaBlocksFtraceEvent ext4_alloc_da_blocks = 134;
-    Ext4AllocateBlocksFtraceEvent ext4_allocate_blocks = 135;
-    Ext4AllocateInodeFtraceEvent ext4_allocate_inode = 136;
-    Ext4BeginOrderedTruncateFtraceEvent ext4_begin_ordered_truncate = 137;
-    Ext4CollapseRangeFtraceEvent ext4_collapse_range = 138;
-    Ext4DaReleaseSpaceFtraceEvent ext4_da_release_space = 139;
-    Ext4DaReserveSpaceFtraceEvent ext4_da_reserve_space = 140;
-    Ext4DaUpdateReserveSpaceFtraceEvent ext4_da_update_reserve_space = 141;
-    Ext4DaWritePagesFtraceEvent ext4_da_write_pages = 142;
-    Ext4DaWritePagesExtentFtraceEvent ext4_da_write_pages_extent = 143;
-    Ext4DirectIOEnterFtraceEvent ext4_direct_IO_enter = 144;
-    Ext4DirectIOExitFtraceEvent ext4_direct_IO_exit = 145;
-    Ext4DiscardBlocksFtraceEvent ext4_discard_blocks = 146;
-    Ext4DiscardPreallocationsFtraceEvent ext4_discard_preallocations = 147;
-    Ext4DropInodeFtraceEvent ext4_drop_inode = 148;
-    Ext4EsCacheExtentFtraceEvent ext4_es_cache_extent = 149;
-    Ext4EsFindDelayedExtentRangeEnterFtraceEvent
-        ext4_es_find_delayed_extent_range_enter = 150;
-    Ext4EsFindDelayedExtentRangeExitFtraceEvent
-        ext4_es_find_delayed_extent_range_exit = 151;
-    Ext4EsInsertExtentFtraceEvent ext4_es_insert_extent = 152;
-    Ext4EsLookupExtentEnterFtraceEvent ext4_es_lookup_extent_enter = 153;
-    Ext4EsLookupExtentExitFtraceEvent ext4_es_lookup_extent_exit = 154;
-    Ext4EsRemoveExtentFtraceEvent ext4_es_remove_extent = 155;
-    Ext4EsShrinkFtraceEvent ext4_es_shrink = 156;
-    Ext4EsShrinkCountFtraceEvent ext4_es_shrink_count = 157;
-    Ext4EsShrinkScanEnterFtraceEvent ext4_es_shrink_scan_enter = 158;
-    Ext4EsShrinkScanExitFtraceEvent ext4_es_shrink_scan_exit = 159;
-    Ext4EvictInodeFtraceEvent ext4_evict_inode = 160;
-    Ext4ExtConvertToInitializedEnterFtraceEvent
-        ext4_ext_convert_to_initialized_enter = 161;
-    Ext4ExtConvertToInitializedFastpathFtraceEvent
-        ext4_ext_convert_to_initialized_fastpath = 162;
-    Ext4ExtHandleUnwrittenExtentsFtraceEvent ext4_ext_handle_unwritten_extents =
-        163;
-    Ext4ExtInCacheFtraceEvent ext4_ext_in_cache = 164;
-    Ext4ExtLoadExtentFtraceEvent ext4_ext_load_extent = 165;
-    Ext4ExtMapBlocksEnterFtraceEvent ext4_ext_map_blocks_enter = 166;
-    Ext4ExtMapBlocksExitFtraceEvent ext4_ext_map_blocks_exit = 167;
-    Ext4ExtPutInCacheFtraceEvent ext4_ext_put_in_cache = 168;
-    Ext4ExtRemoveSpaceFtraceEvent ext4_ext_remove_space = 169;
-    Ext4ExtRemoveSpaceDoneFtraceEvent ext4_ext_remove_space_done = 170;
-    Ext4ExtRmIdxFtraceEvent ext4_ext_rm_idx = 171;
-    Ext4ExtRmLeafFtraceEvent ext4_ext_rm_leaf = 172;
-    Ext4ExtShowExtentFtraceEvent ext4_ext_show_extent = 173;
-    Ext4FallocateEnterFtraceEvent ext4_fallocate_enter = 174;
-    Ext4FallocateExitFtraceEvent ext4_fallocate_exit = 175;
-    Ext4FindDelallocRangeFtraceEvent ext4_find_delalloc_range = 176;
-    Ext4ForgetFtraceEvent ext4_forget = 177;
-    Ext4FreeBlocksFtraceEvent ext4_free_blocks = 178;
-    Ext4FreeInodeFtraceEvent ext4_free_inode = 179;
-    Ext4GetImpliedClusterAllocExitFtraceEvent
-        ext4_get_implied_cluster_alloc_exit = 180;
-    Ext4GetReservedClusterAllocFtraceEvent ext4_get_reserved_cluster_alloc =
-        181;
-    Ext4IndMapBlocksEnterFtraceEvent ext4_ind_map_blocks_enter = 182;
-    Ext4IndMapBlocksExitFtraceEvent ext4_ind_map_blocks_exit = 183;
-    Ext4InsertRangeFtraceEvent ext4_insert_range = 184;
-    Ext4InvalidatepageFtraceEvent ext4_invalidatepage = 185;
-    Ext4JournalStartFtraceEvent ext4_journal_start = 186;
-    Ext4JournalStartReservedFtraceEvent ext4_journal_start_reserved = 187;
-    Ext4JournalledInvalidatepageFtraceEvent ext4_journalled_invalidatepage =
-        188;
-    Ext4JournalledWriteEndFtraceEvent ext4_journalled_write_end = 189;
-    Ext4LoadInodeFtraceEvent ext4_load_inode = 190;
-    Ext4LoadInodeBitmapFtraceEvent ext4_load_inode_bitmap = 191;
-    Ext4MarkInodeDirtyFtraceEvent ext4_mark_inode_dirty = 192;
-    Ext4MbBitmapLoadFtraceEvent ext4_mb_bitmap_load = 193;
-    Ext4MbBuddyBitmapLoadFtraceEvent ext4_mb_buddy_bitmap_load = 194;
-    Ext4MbDiscardPreallocationsFtraceEvent ext4_mb_discard_preallocations = 195;
-    Ext4MbNewGroupPaFtraceEvent ext4_mb_new_group_pa = 196;
-    Ext4MbNewInodePaFtraceEvent ext4_mb_new_inode_pa = 197;
-    Ext4MbReleaseGroupPaFtraceEvent ext4_mb_release_group_pa = 198;
-    Ext4MbReleaseInodePaFtraceEvent ext4_mb_release_inode_pa = 199;
-    Ext4MballocAllocFtraceEvent ext4_mballoc_alloc = 200;
-    Ext4MballocDiscardFtraceEvent ext4_mballoc_discard = 201;
-    Ext4MballocFreeFtraceEvent ext4_mballoc_free = 202;
-    Ext4MballocPreallocFtraceEvent ext4_mballoc_prealloc = 203;
-    Ext4OtherInodeUpdateTimeFtraceEvent ext4_other_inode_update_time = 204;
-    Ext4PunchHoleFtraceEvent ext4_punch_hole = 205;
-    Ext4ReadBlockBitmapLoadFtraceEvent ext4_read_block_bitmap_load = 206;
-    Ext4ReadpageFtraceEvent ext4_readpage = 207;
-    Ext4ReleasepageFtraceEvent ext4_releasepage = 208;
-    Ext4RemoveBlocksFtraceEvent ext4_remove_blocks = 209;
-    Ext4RequestBlocksFtraceEvent ext4_request_blocks = 210;
-    Ext4RequestInodeFtraceEvent ext4_request_inode = 211;
-    Ext4SyncFsFtraceEvent ext4_sync_fs = 212;
-    Ext4TrimAllFreeFtraceEvent ext4_trim_all_free = 213;
-    Ext4TrimExtentFtraceEvent ext4_trim_extent = 214;
-    Ext4TruncateEnterFtraceEvent ext4_truncate_enter = 215;
-    Ext4TruncateExitFtraceEvent ext4_truncate_exit = 216;
-    Ext4UnlinkEnterFtraceEvent ext4_unlink_enter = 217;
-    Ext4UnlinkExitFtraceEvent ext4_unlink_exit = 218;
-    Ext4WriteBeginFtraceEvent ext4_write_begin = 219;
-    // removed field with id 220;
-    // removed field with id 221;
-    // removed field with id 222;
-    // removed field with id 223;
-    // removed field with id 224;
-    // removed field with id 225;
-    // removed field with id 226;
-    // removed field with id 227;
-    // removed field with id 228;
-    // removed field with id 229;
-    Ext4WriteEndFtraceEvent ext4_write_end = 230;
-    Ext4WritepageFtraceEvent ext4_writepage = 231;
-    Ext4WritepagesFtraceEvent ext4_writepages = 232;
-    Ext4WritepagesResultFtraceEvent ext4_writepages_result = 233;
-    Ext4ZeroRangeFtraceEvent ext4_zero_range = 234;
-    TaskNewtaskFtraceEvent task_newtask = 235;
-    TaskRenameFtraceEvent task_rename = 236;
-    SchedProcessExecFtraceEvent sched_process_exec = 237;
-    SchedProcessExitFtraceEvent sched_process_exit = 238;
-    SchedProcessForkFtraceEvent sched_process_fork = 239;
-    SchedProcessFreeFtraceEvent sched_process_free = 240;
-    SchedProcessHangFtraceEvent sched_process_hang = 241;
-    SchedProcessWaitFtraceEvent sched_process_wait = 242;
-    F2fsDoSubmitBioFtraceEvent f2fs_do_submit_bio = 243;
-    F2fsEvictInodeFtraceEvent f2fs_evict_inode = 244;
-    F2fsFallocateFtraceEvent f2fs_fallocate = 245;
-    F2fsGetDataBlockFtraceEvent f2fs_get_data_block = 246;
-    F2fsGetVictimFtraceEvent f2fs_get_victim = 247;
-    F2fsIgetFtraceEvent f2fs_iget = 248;
-    F2fsIgetExitFtraceEvent f2fs_iget_exit = 249;
-    F2fsNewInodeFtraceEvent f2fs_new_inode = 250;
-    F2fsReadpageFtraceEvent f2fs_readpage = 251;
-    F2fsReserveNewBlockFtraceEvent f2fs_reserve_new_block = 252;
-    F2fsSetPageDirtyFtraceEvent f2fs_set_page_dirty = 253;
-    F2fsSubmitWritePageFtraceEvent f2fs_submit_write_page = 254;
-    F2fsSyncFileEnterFtraceEvent f2fs_sync_file_enter = 255;
-    F2fsSyncFileExitFtraceEvent f2fs_sync_file_exit = 256;
-    F2fsSyncFsFtraceEvent f2fs_sync_fs = 257;
-    F2fsTruncateFtraceEvent f2fs_truncate = 258;
-    F2fsTruncateBlocksEnterFtraceEvent f2fs_truncate_blocks_enter = 259;
-    F2fsTruncateBlocksExitFtraceEvent f2fs_truncate_blocks_exit = 260;
-    F2fsTruncateDataBlocksRangeFtraceEvent f2fs_truncate_data_blocks_range =
-        261;
-    F2fsTruncateInodeBlocksEnterFtraceEvent f2fs_truncate_inode_blocks_enter =
-        262;
-    F2fsTruncateInodeBlocksExitFtraceEvent f2fs_truncate_inode_blocks_exit =
-        263;
-    F2fsTruncateNodeFtraceEvent f2fs_truncate_node = 264;
-    F2fsTruncateNodesEnterFtraceEvent f2fs_truncate_nodes_enter = 265;
-    F2fsTruncateNodesExitFtraceEvent f2fs_truncate_nodes_exit = 266;
-    F2fsTruncatePartialNodesFtraceEvent f2fs_truncate_partial_nodes = 267;
-    F2fsUnlinkEnterFtraceEvent f2fs_unlink_enter = 268;
-    F2fsUnlinkExitFtraceEvent f2fs_unlink_exit = 269;
-    F2fsVmPageMkwriteFtraceEvent f2fs_vm_page_mkwrite = 270;
-    F2fsWriteBeginFtraceEvent f2fs_write_begin = 271;
-    F2fsWriteCheckpointFtraceEvent f2fs_write_checkpoint = 272;
-    F2fsWriteEndFtraceEvent f2fs_write_end = 273;
-    AllocPagesIommuEndFtraceEvent alloc_pages_iommu_end = 274;
-    AllocPagesIommuFailFtraceEvent alloc_pages_iommu_fail = 275;
-    AllocPagesIommuStartFtraceEvent alloc_pages_iommu_start = 276;
-    AllocPagesSysEndFtraceEvent alloc_pages_sys_end = 277;
-    AllocPagesSysFailFtraceEvent alloc_pages_sys_fail = 278;
-    AllocPagesSysStartFtraceEvent alloc_pages_sys_start = 279;
-    DmaAllocContiguousRetryFtraceEvent dma_alloc_contiguous_retry = 280;
-    IommuMapRangeFtraceEvent iommu_map_range = 281;
-    IommuSecPtblMapRangeEndFtraceEvent iommu_sec_ptbl_map_range_end = 282;
-    IommuSecPtblMapRangeStartFtraceEvent iommu_sec_ptbl_map_range_start = 283;
-    IonAllocBufferEndFtraceEvent ion_alloc_buffer_end = 284;
-    IonAllocBufferFailFtraceEvent ion_alloc_buffer_fail = 285;
-    IonAllocBufferFallbackFtraceEvent ion_alloc_buffer_fallback = 286;
-    IonAllocBufferStartFtraceEvent ion_alloc_buffer_start = 287;
-    IonCpAllocRetryFtraceEvent ion_cp_alloc_retry = 288;
-    IonCpSecureBufferEndFtraceEvent ion_cp_secure_buffer_end = 289;
-    IonCpSecureBufferStartFtraceEvent ion_cp_secure_buffer_start = 290;
-    IonPrefetchingFtraceEvent ion_prefetching = 291;
-    IonSecureCmaAddToPoolEndFtraceEvent ion_secure_cma_add_to_pool_end = 292;
-    IonSecureCmaAddToPoolStartFtraceEvent ion_secure_cma_add_to_pool_start =
-        293;
-    IonSecureCmaAllocateEndFtraceEvent ion_secure_cma_allocate_end = 294;
-    IonSecureCmaAllocateStartFtraceEvent ion_secure_cma_allocate_start = 295;
-    IonSecureCmaShrinkPoolEndFtraceEvent ion_secure_cma_shrink_pool_end = 296;
-    IonSecureCmaShrinkPoolStartFtraceEvent ion_secure_cma_shrink_pool_start =
-        297;
-    KfreeFtraceEvent kfree = 298;
-    KmallocFtraceEvent kmalloc = 299;
-    KmallocNodeFtraceEvent kmalloc_node = 300;
-    KmemCacheAllocFtraceEvent kmem_cache_alloc = 301;
-    KmemCacheAllocNodeFtraceEvent kmem_cache_alloc_node = 302;
-    KmemCacheFreeFtraceEvent kmem_cache_free = 303;
-    MigratePagesEndFtraceEvent migrate_pages_end = 304;
-    MigratePagesStartFtraceEvent migrate_pages_start = 305;
-    MigrateRetryFtraceEvent migrate_retry = 306;
-    MmPageAllocFtraceEvent mm_page_alloc = 307;
-    MmPageAllocExtfragFtraceEvent mm_page_alloc_extfrag = 308;
-    MmPageAllocZoneLockedFtraceEvent mm_page_alloc_zone_locked = 309;
-    MmPageFreeFtraceEvent mm_page_free = 310;
-    MmPageFreeBatchedFtraceEvent mm_page_free_batched = 311;
-    MmPagePcpuDrainFtraceEvent mm_page_pcpu_drain = 312;
-    RssStatFtraceEvent rss_stat = 313;
-    IonHeapShrinkFtraceEvent ion_heap_shrink = 314;
-    IonHeapGrowFtraceEvent ion_heap_grow = 315;
-    // removed field with id 316
-    // removed field with id 317
-    // removed field with id 318
-    // removed field with id 319
-    ClkEnableFtraceEvent clk_enable = 320;
-    ClkDisableFtraceEvent clk_disable = 321;
-    ClkSetRateFtraceEvent clk_set_rate = 322;
-    BinderTransactionAllocBufFtraceEvent binder_transaction_alloc_buf = 323;
-    SignalDeliverFtraceEvent signal_deliver = 324;
-    SignalGenerateFtraceEvent signal_generate = 325;
-    // removed field with id 326
-    GenericFtraceEvent generic = 327;
-  }
-}
-
-// End of protos/perfetto/trace/ftrace/ftrace_event.proto
+// End of protos/perfetto/trace/clock_snapshot.proto
 
 // Begin of protos/perfetto/trace/filesystem/inode_file_map.proto
 
@@ -615,166 +209,6 @@
 
 // End of protos/perfetto/trace/filesystem/inode_file_map.proto
 
-// Begin of protos/perfetto/trace/ps/process_stats.proto
-
-// Per-process periodically sampled stats. These samples are wrapped in a
-// dedicated message (as opposite to be fields in process_tree.proto) because
-// they are dumped at a different rate than cmdline and thread list.
-message ProcessStats {
-  // See /proc/[pid]/stats in `man 5 proc` for a description of these fields.
-  message MemCounters {
-    optional int32 pid = 1;
-    optional uint64 vm_size_kb = 2;
-    optional uint64 vm_rss_kb = 3;
-    optional uint64 rss_anon_kb = 4;
-    optional uint64 rss_file_kb = 5;
-    optional uint64 rss_shmem_kb = 6;
-    optional uint64 vm_swap_kb = 7;
-    optional uint64 vm_locked_kb = 8;
-    optional uint64 vm_hwm_kb = 9;
-    // When adding a new field remember to update kProcMemCounterSize in
-    // the trace processor.
-  }
-  repeated MemCounters mem_counters = 1;
-}
-
-// End of protos/perfetto/trace/ps/process_stats.proto
-
-// Begin of protos/perfetto/trace/ps/process_tree.proto
-
-message ProcessTree {
-  // Representation of a thread.
-  message Thread {
-    // The thread id (as per gettid())
-    optional int32 tid = 1;
-
-    // Thread group id (i.e. the PID of the process, == TID of the main thread)
-    optional int32 tgid = 3;
-
-    // The name of the thread.
-    optional string name = 2;
-  }
-
-  // Representation of a process.
-  message Process {
-    // The UNIX process ID, aka thread group ID (as per getpid()).
-    optional int32 pid = 1;
-
-    // The parent process ID, as per getppid().
-    optional int32 ppid = 2;
-
-    // The command line for the process, as per /proc/pid/cmdline.
-    // If it is a kernel thread there will only be one cmdline field
-    // and it will contain /proc/pid/comm.
-    repeated string cmdline = 3;
-
-    // No longer used as of Apr 2018, when the dedicated |threads| field was
-    // introduced in ProcessTree.
-    repeated Thread threads_deprecated = 4 [deprecated = true];
-  }
-
-  // List of processes and threads in the client. These lists are incremental
-  // and not exhaustive. A process and its threads might show up separately in
-  // different ProcessTree messages. A thread might event not show up at all, if
-  // no sched_switch activity was detected, for instance:
-  // #0 { processes: [{pid: 10, ...}], threads: [{pid: 11, tgid: 10}] }
-  // #1 { threads: [{pid: 12, tgid: 10}] }
-  // #2 { processes: [{pid: 20, ...}], threads: [{pid: 13, tgid: 10}] }
-  repeated Process processes = 1;
-  repeated Thread threads = 2;
-}
-
-// End of protos/perfetto/trace/ps/process_tree.proto
-
-// Begin of protos/perfetto/trace/clock_snapshot.proto
-
-// A snapshot of clock readings to allow for trace alignment.
-message ClockSnapshot {
-  message Clock {
-    enum Type {
-      UNKNOWN = 0;
-      REALTIME = 1;
-      REALTIME_COARSE = 2;
-      MONOTONIC = 3;
-      MONOTONIC_COARSE = 4;
-      MONOTONIC_RAW = 5;
-      BOOTTIME = 6;
-      PROCESS_CPUTIME = 7;
-      THREAD_CPUTIME = 8;
-    }
-    optional Type type = 1;
-    optional uint64 timestamp = 2;
-  }
-  repeated Clock clocks = 1;
-}
-
-// End of protos/perfetto/trace/clock_snapshot.proto
-
-// Begin of protos/perfetto/trace/sys_stats/sys_stats.proto
-
-
-// Various Linux system stat counters from /proc.
-// The fields in this message can be reported at different rates and with
-// different granularity. See sys_stats_config.proto.
-message SysStats {
-  // Counters from /proc/meminfo. Values are in KB.
-  message MeminfoValue {
-    optional MeminfoCounters key = 1;
-    optional uint64 value = 2;
-  };
-  repeated MeminfoValue meminfo = 1;
-
-  // Counter from /proc/vmstat. Units are often pages, not KB.
-  message VmstatValue {
-    optional VmstatCounters key = 1;
-    optional uint64 value = 2;
-  };
-  repeated VmstatValue vmstat = 2;
-
-  // Times in each mode, since boot. Unit: nanoseconds.
-  message CpuTimes {
-    optional uint32 cpu_id = 1;
-    optional uint64 user_ns = 2;         // Time spent in user mode.
-    optional uint64 user_ice_ns = 3;     // Time spent in user mode (low prio).
-    optional uint64 system_mode_ns = 4;  // Time spent in system mode.
-    optional uint64 idle_ns = 5;         // Time spent in the idle task.
-    optional uint64 io_wait_ns = 6;      // Time spent waiting for I/O.
-    optional uint64 irq_ns = 7;          // Time spent servicing interrupts.
-    optional uint64 softirq_ns = 8;      // Time spent servicing softirqs.
-  }
-  repeated CpuTimes cpu_stat = 3;  // One entry per cpu.
-
-  // Num processes forked since boot.
-  // Populated only if FORK_COUNT in config.stat_counters.
-  optional uint64 num_forks = 4;
-
-  message InterruptCount {
-    optional int32 irq = 1;
-    optional uint64 count = 2;
-  }
-
-  // Number of interrupts, broken by IRQ number.
-  // Populated only if IRQ_COUNTS in config.stat_counters.
-  optional uint64 num_irq_total = 5;  // Total num of irqs serviced since boot.
-  repeated InterruptCount num_irq = 6;
-
-  // Number of softirqs, broken by softirq number.
-  // Populated only if SOFTIRQ_COUNTS in config.stat_counters.
-  optional uint64 num_softirq_total = 7;    // Total num of softirqs since boot.
-  repeated InterruptCount num_softirq = 8;  // Per-softirq count.
-}
-
-// End of protos/perfetto/trace/sys_stats/sys_stats.proto
-
-// Begin of protos/perfetto/trace/ftrace/print.proto
-
-message PrintFtraceEvent {
-  optional uint64 ip = 1;
-  optional string buf = 2;
-}
-
-// End of protos/perfetto/trace/ftrace/print.proto
-
 // Begin of protos/perfetto/trace/ftrace/binder.proto
 
 message BinderTransactionFtraceEvent {
@@ -2327,6 +1761,26 @@
 
 // End of protos/perfetto/trace/ftrace/ftrace_stats.proto
 
+// Begin of protos/perfetto/trace/ftrace/generic.proto
+
+// This generic proto is used to output events in the trace
+// when a specific proto for that event does not exist.
+message GenericFtraceEvent {
+  message Field {
+    optional string name = 1;
+    oneof value {
+      string str_value = 3;
+      int64 int_value = 4;
+      uint64 uint_value = 5;
+    }
+  }
+
+  optional string event_name = 1;
+  repeated Field field = 2;
+}
+
+// End of protos/perfetto/trace/ftrace/generic.proto
+
 // Begin of protos/perfetto/trace/ftrace/kmem.proto
 
 message AllocPagesIommuEndFtraceEvent {
@@ -2606,15 +2060,6 @@
 
 // End of protos/perfetto/trace/ftrace/power.proto
 
-// Begin of protos/perfetto/trace/ftrace/print.proto
-
-message PrintFtraceEvent {
-  optional uint64 ip = 1;
-  optional string buf = 2;
-}
-
-// End of protos/perfetto/trace/ftrace/print.proto
-
 // Begin of protos/perfetto/trace/ftrace/sched.proto
 
 message SchedSwitchFtraceEvent {
@@ -2746,22 +2191,187 @@
 
 // End of protos/perfetto/trace/ftrace/vmscan.proto
 
-// Begin of protos/perfetto/trace/ftrace/generic.proto
+// Begin of protos/perfetto/trace/ps/process_stats.proto
 
-// This generic proto is used to output events in the trace
-// when a specific proto for that event does not exist.
-message GenericFtraceEvent {
-  message Field {
-    optional string name = 1;
-    oneof value {
-      string str_value = 3;
-      int64 int_value = 4;
-      uint64 uint_value = 5;
-    }
+// Per-process periodically sampled stats. These samples are wrapped in a
+// dedicated message (as opposite to be fields in process_tree.proto) because
+// they are dumped at a different rate than cmdline and thread list.
+message ProcessStats {
+  // See /proc/[pid]/stats in `man 5 proc` for a description of these fields.
+  message MemCounters {
+    optional int32 pid = 1;
+    optional uint64 vm_size_kb = 2;
+    optional uint64 vm_rss_kb = 3;
+    optional uint64 rss_anon_kb = 4;
+    optional uint64 rss_file_kb = 5;
+    optional uint64 rss_shmem_kb = 6;
+    optional uint64 vm_swap_kb = 7;
+    optional uint64 vm_locked_kb = 8;
+    optional uint64 vm_hwm_kb = 9;
+    // When adding a new field remember to update kProcMemCounterSize in
+    // the trace processor.
   }
-
-  optional string event_name = 1;
-  repeated Field field = 2;
+  repeated MemCounters mem_counters = 1;
 }
 
-// End of protos/perfetto/trace/ftrace/generic.proto
+// End of protos/perfetto/trace/ps/process_stats.proto
+
+// Begin of protos/perfetto/trace/ps/process_tree.proto
+
+message ProcessTree {
+  // Representation of a thread.
+  message Thread {
+    // The thread id (as per gettid())
+    optional int32 tid = 1;
+
+    // Thread group id (i.e. the PID of the process, == TID of the main thread)
+    optional int32 tgid = 3;
+
+    // The name of the thread.
+    optional string name = 2;
+  }
+
+  // Representation of a process.
+  message Process {
+    // The UNIX process ID, aka thread group ID (as per getpid()).
+    optional int32 pid = 1;
+
+    // The parent process ID, as per getppid().
+    optional int32 ppid = 2;
+
+    // The command line for the process, as per /proc/pid/cmdline.
+    // If it is a kernel thread there will only be one cmdline field
+    // and it will contain /proc/pid/comm.
+    repeated string cmdline = 3;
+
+    // No longer used as of Apr 2018, when the dedicated |threads| field was
+    // introduced in ProcessTree.
+    repeated Thread threads_deprecated = 4 [deprecated = true];
+  }
+
+  // List of processes and threads in the client. These lists are incremental
+  // and not exhaustive. A process and its threads might show up separately in
+  // different ProcessTree messages. A thread might event not show up at all, if
+  // no sched_switch activity was detected, for instance:
+  // #0 { processes: [{pid: 10, ...}], threads: [{pid: 11, tgid: 10}] }
+  // #1 { threads: [{pid: 12, tgid: 10}] }
+  // #2 { processes: [{pid: 20, ...}], threads: [{pid: 13, tgid: 10}] }
+  repeated Process processes = 1;
+  repeated Thread threads = 2;
+}
+
+// End of protos/perfetto/trace/ps/process_tree.proto
+
+// Begin of protos/perfetto/trace/sys_stats/sys_stats.proto
+
+// Various Linux system stat counters from /proc.
+// The fields in this message can be reported at different rates and with
+// different granularity. See sys_stats_config.proto.
+message SysStats {
+  // Counters from /proc/meminfo. Values are in KB.
+  message MeminfoValue {
+    optional MeminfoCounters key = 1;
+    optional uint64 value = 2;
+  };
+  repeated MeminfoValue meminfo = 1;
+
+  // Counter from /proc/vmstat. Units are often pages, not KB.
+  message VmstatValue {
+    optional VmstatCounters key = 1;
+    optional uint64 value = 2;
+  };
+  repeated VmstatValue vmstat = 2;
+
+  // Times in each mode, since boot. Unit: nanoseconds.
+  message CpuTimes {
+    optional uint32 cpu_id = 1;
+    optional uint64 user_ns = 2;         // Time spent in user mode.
+    optional uint64 user_ice_ns = 3;     // Time spent in user mode (low prio).
+    optional uint64 system_mode_ns = 4;  // Time spent in system mode.
+    optional uint64 idle_ns = 5;         // Time spent in the idle task.
+    optional uint64 io_wait_ns = 6;      // Time spent waiting for I/O.
+    optional uint64 irq_ns = 7;          // Time spent servicing interrupts.
+    optional uint64 softirq_ns = 8;      // Time spent servicing softirqs.
+  }
+  repeated CpuTimes cpu_stat = 3;  // One entry per cpu.
+
+  // Num processes forked since boot.
+  // Populated only if FORK_COUNT in config.stat_counters.
+  optional uint64 num_forks = 4;
+
+  message InterruptCount {
+    optional int32 irq = 1;
+    optional uint64 count = 2;
+  }
+
+  // Number of interrupts, broken by IRQ number.
+  // Populated only if IRQ_COUNTS in config.stat_counters.
+  optional uint64 num_irq_total = 5;  // Total num of irqs serviced since boot.
+  repeated InterruptCount num_irq = 6;
+
+  // Number of softirqs, broken by softirq number.
+  // Populated only if SOFTIRQ_COUNTS in config.stat_counters.
+  optional uint64 num_softirq_total = 7;    // Total num of softirqs since boot.
+  repeated InterruptCount num_softirq = 8;  // Per-softirq count.
+}
+
+// End of protos/perfetto/trace/sys_stats/sys_stats.proto
+
+// Begin of protos/perfetto/trace/trace.proto
+
+message Trace {
+  repeated TracePacket packet = 1;
+
+  // Do NOT add any other field here. This is just a convenience wrapper for
+  // the use case of a trace being saved to a file. There are other cases
+  // (streaming) where TracePacket are directly streamed without being wrapped
+  // in a Trace proto. Nothing should ever rely on the full trace, all the
+  // logic should be based on TracePacket(s).
+}
+
+// End of protos/perfetto/trace/trace.proto
+
+// Begin of protos/perfetto/trace/trace_packet.proto
+
+// The root object emitted by Perfetto. A perfetto trace is just a stream of
+// TracePacket(s).
+//
+// Next id: 10.
+message TracePacket {
+  // TODO: in future we should add a timestamp_clock_domain field to
+  // allow mixing timestamps from different clock domains.
+  optional uint64 timestamp = 8;  // Timestamp [ns].
+
+  oneof data {
+    FtraceEventBundle ftrace_events = 1;
+    ProcessTree process_tree = 2;
+    ProcessStats process_stats = 9;
+    InodeFileMap inode_file_map = 4;
+    // removed field with id 5
+    ClockSnapshot clock_snapshot = 6;
+    SysStats sys_stats = 7;
+
+    // IDs up to 32 are reserved for events that are quite frequent because they
+    // take only one byte to encode their preamble.
+
+    // removed field with id 33
+    FtraceStats ftrace_stats = 34;
+    // removed field with id 35
+    // removed field with id 37
+
+    // This field is emitted at periodic intervals (~10s) and
+    // contains always the binary representation of the UUID
+    // {82477a76-b28d-42ba-81dc-33326d57a079}. This is used to be able to
+    // efficiently partition long traces without having to fully parse them.
+    bytes synchronization_marker = 36;
+
+    // This field is only used for testing.
+    // removed field with id 268435455  // 2^28 - 1, max field id for protos.
+  }
+
+  // Trusted user id of the producer which generated this packet. Keep in sync
+  // with TrustedPacket.trusted_uid.
+  oneof optional_trusted_uid { int32 trusted_uid = 3; };
+}
+
+// End of protos/perfetto/trace/trace_packet.proto
diff --git a/protos/perfetto/trace/sys_stats/sys_stats.proto b/protos/perfetto/trace/sys_stats/sys_stats.proto
index 7b298bf..62ddaa2 100644
--- a/protos/perfetto/trace/sys_stats/sys_stats.proto
+++ b/protos/perfetto/trace/sys_stats/sys_stats.proto
@@ -17,7 +17,6 @@
 syntax = "proto2";
 option optimize_for = LITE_RUNTIME;
 package perfetto.protos;
-
 import "perfetto/common/sys_stats_counters.proto";
 
 // Various Linux system stat counters from /proc.
diff --git a/tools/gen_merged_protos b/tools/gen_merged_protos
index 5f63849..713a5e3 100755
--- a/tools/gen_merged_protos
+++ b/tools/gen_merged_protos
@@ -37,21 +37,8 @@
 
 TRACE_PROTOS = (
   'protos/perfetto/common/sys_stats_counters.proto',
-  'protos/perfetto/trace/trace.proto',
-  'protos/perfetto/trace/trace_packet.proto',
-  'protos/perfetto/trace/ftrace/ftrace_event_bundle.proto',
-  'protos/perfetto/trace/ftrace/ftrace_event.proto',
-  'protos/perfetto/trace/filesystem/inode_file_map.proto',
-  'protos/perfetto/trace/ps/process_stats.proto',
-  'protos/perfetto/trace/ps/process_tree.proto',
   'protos/perfetto/trace/clock_snapshot.proto',
-  'protos/perfetto/trace/sys_stats/sys_stats.proto',
-
-  # Print proto is special: it doesn't have a enable file so is
-  # not present in genfs_contexts.
-  'protos/perfetto/trace/ftrace/print.proto',
-
-  # FTrace events
+  'protos/perfetto/trace/filesystem/inode_file_map.proto',
   'protos/perfetto/trace/ftrace/binder.proto',
   'protos/perfetto/trace/ftrace/block.proto',
   'protos/perfetto/trace/ftrace/clk.proto',
@@ -62,15 +49,19 @@
   'protos/perfetto/trace/ftrace/ftrace_event.proto',
   'protos/perfetto/trace/ftrace/ftrace_event_bundle.proto',
   'protos/perfetto/trace/ftrace/ftrace_stats.proto',
+  'protos/perfetto/trace/ftrace/generic.proto',
   'protos/perfetto/trace/ftrace/kmem.proto',
   'protos/perfetto/trace/ftrace/lowmemorykiller.proto',
   'protos/perfetto/trace/ftrace/power.proto',
-  'protos/perfetto/trace/ftrace/print.proto',
   'protos/perfetto/trace/ftrace/sched.proto',
   'protos/perfetto/trace/ftrace/signal.proto',
   'protos/perfetto/trace/ftrace/task.proto',
   'protos/perfetto/trace/ftrace/vmscan.proto',
-  'protos/perfetto/trace/ftrace/generic.proto',
+  'protos/perfetto/trace/ps/process_stats.proto',
+  'protos/perfetto/trace/ps/process_tree.proto',
+  'protos/perfetto/trace/sys_stats/sys_stats.proto',
+  'protos/perfetto/trace/trace.proto',
+  'protos/perfetto/trace/trace_packet.proto',
 )
 
 MERGED_TRACE_PROTO = 'protos/perfetto/trace/perfetto_trace.proto'