From e4d4e23530cbab8b057dbbef8184f6872a4be58a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 11 Feb 2026 20:16:07 -0500 Subject: [PATCH] add {thread,process}_sort_index extension + TEF support https://github.com/google/perfetto/pull/3273/changes#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdba allows user to sort threads/processes. --- src/core/core_ext.ml | 4 ++++ src/tef/collector_tef.ml | 15 +++++++++++++++ src/tef/writer.ml | 13 +++++++++++++ src/tef/writer.mli | 2 ++ 4 files changed, 34 insertions(+) diff --git a/src/core/core_ext.ml b/src/core/core_ext.ml index 8a7247a..c961c36 100644 --- a/src/core/core_ext.ml +++ b/src/core/core_ext.ml @@ -8,6 +8,10 @@ open Types type extension_event += | Extension_set_thread_name of string | Extension_set_process_name of string + | Extension_set_thread_sort_index of int + (** https://github.com/google/perfetto/pull/3273/changes#diff-ecec88c33adb7591ee6aa88e29b62ad52ef443611cba5e0f0ecac9b5725afdba + *) + | Extension_set_process_sort_index of int (** Specialized parameters *) type extension_parameter += diff --git a/src/tef/collector_tef.ml b/src/tef/collector_tef.ml index 8660a70..3ab02a9 100644 --- a/src/tef/collector_tef.ml +++ b/src/tef/collector_tef.ml @@ -142,12 +142,27 @@ open struct Writer.emit_name_process ~pid:self.pid ~name buf; self.exporter.on_json buf + let on_thread_sort_index_ (self : st) ~tid i : unit = + let@ buf = Trace_util.Rpool.with_ self.buf_pool in + Writer.emit_thread_sort_index ~pid:self.pid ~tid i buf; + self.exporter.on_json buf + + let on_process_sort_index_ (self : st) i : unit = + let@ buf = Trace_util.Rpool.with_ self.buf_pool in + Writer.emit_process_sort_index ~pid:self.pid i buf; + self.exporter.on_json buf + let extension (self : st) ~level:_ ev = match ev with | Core_ext.Extension_set_thread_name name -> let tid = Trace_util.Mock_.get_tid () in on_name_thread_ self ~tid name | Core_ext.Extension_set_process_name name -> on_name_process_ self name + | Core_ext.Extension_set_process_sort_index idx -> + on_process_sort_index_ self idx + | Core_ext.Extension_set_thread_sort_index idx -> + let tid = Trace_util.Mock_.get_tid () in + on_thread_sort_index_ self ~tid idx | _ -> () end diff --git a/src/tef/writer.ml b/src/tef/writer.ml index ea2b75b..934f624 100644 --- a/src/tef/writer.ml +++ b/src/tef/writer.ml @@ -75,6 +75,19 @@ let emit_name_thread ~pid ~tid ~name buf : unit = (emit_args_o_ pp_user_data_) [ "name", `String name ] +let emit_process_sort_index ~pid i buf : unit = + Printf.bprintf buf + {json|{"pid":%d,"name":"process_sort_index","ph":"M"%a}|json} pid + (emit_args_o_ pp_user_data_) + [ "sort_index", `Int i ] + +let emit_thread_sort_index ~pid ~tid i buf : unit = + Printf.bprintf buf + {json|{"pid":%d,"tid": %d,"name":"thread_sort_index","ph":"M"%a}|json} pid + tid + (emit_args_o_ pp_user_data_) + [ "sort_index", `Int i ] + let emit_name_process ~pid ~name buf : unit = Printf.bprintf buf {json|{"pid":%d,"name":"process_name","ph":"M"%a}|json} pid (emit_args_o_ pp_user_data_) diff --git a/src/tef/writer.mli b/src/tef/writer.mli index 34a7461..06dfc9c 100644 --- a/src/tef/writer.mli +++ b/src/tef/writer.mli @@ -46,6 +46,8 @@ val emit_instant_event : val emit_name_thread : pid:int -> tid:int -> name:string -> Buffer.t -> unit val emit_name_process : pid:int -> name:string -> Buffer.t -> unit +val emit_process_sort_index : pid:int -> int -> Buffer.t -> unit +val emit_thread_sort_index : pid:int -> tid:int -> int -> Buffer.t -> unit val emit_counter : pid:int -> tid:int -> name:string -> ts:float -> Buffer.t -> float -> unit