From e915f84388d5d441914dd89009c055fad9d6af15 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Tue, 9 Jan 2024 18:45:17 -0500 Subject: [PATCH] Do not display extremely long commandline arguments Otherwise, the trace writer will raise because we're violating the Perfetto trace file format. I opted to not show the arguments at all because it was slightly simpler, and it is unlikely the 60-something characters Perfetto would display in the UI would be particularly enlightening for a commandline that's longer than 32 KiB. Signed-off-by: Tudor Brindus --- src/trace_writer.ml | 5 ++++- vendor/tracing/zero/writer.ml | 6 ++++-- vendor/tracing/zero/writer.mli | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/trace_writer.ml b/src/trace_writer.ml index 6bedadcec..4574196d6 100644 --- a/src/trace_writer.ml +++ b/src/trace_writer.ml @@ -522,7 +522,10 @@ let create_thread t event = | None -> default_name | Some cmdline -> let concat_cmdline = String.concat ~sep:" " cmdline in - [%string "%{concat_cmdline} %{default_name}"]) + let name = [%string "%{concat_cmdline} %{default_name}"] in + if String.length name > Tracing_zero.Writer.max_interned_string_length + then default_name + else name) in let track_group_id = allocate_pid t ~name in let thread = allocate_thread t ~pid:track_group_id ~name:"main" in diff --git a/vendor/tracing/zero/writer.ml b/vendor/tracing/zero/writer.ml index d0da652c9..e088c167b 100644 --- a/vendor/tracing/zero/writer.ml +++ b/vendor/tracing/zero/writer.ml @@ -149,10 +149,12 @@ module String_id = struct let max_number_of_temp_string_slots = max_value - first_temp + 1 end +(* maximum string length defined in spec, somewhat less than 2**15 *) +let max_interned_string_length = 32000 - 1 + let set_string_slot t ~string_id s = let str_len = String.length s in - (* maximum string length defined in spec, somewhat less than 2**15 *) - if str_len >= 32000 + if str_len > max_interned_string_length then failwithf "string too long for FTF trace: %i is over the limit of 32kb" str_len (); (* String record *) let rtype = 2 in diff --git a/vendor/tracing/zero/writer.mli b/vendor/tracing/zero/writer.mli index f754446af..36da5c9e2 100644 --- a/vendor/tracing/zero/writer.mli +++ b/vendor/tracing/zero/writer.mli @@ -29,6 +29,8 @@ module String_id : sig val max_number_of_temp_string_slots : int end +val max_interned_string_length : int + (** Intern a string into the trace so that it can be referred to with very low cost. Note that this does not check if the string has already been interned, see [intern_string_cached].