Skip to content

Commit 4e54145

Browse files
committed
Reduce noise when OCaml exception tracking gets confused
We're not going to be able to address all the corner cases any time soon, so in the meantime output exception tracking warnings at most once per trace. Signed-off-by: Tudor Brindus <[email protected]>
1 parent d3a25d3 commit 4e54145

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/trace_writer.ml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ type 'thread inner =
144144
; trace : (module Trace with type thread = 'thread)
145145
; annotate_inferred_start_times : bool
146146
; mutable in_filtered_region : bool
147+
; suppressed_errors : Hash_set.M(Source_code_position).t
147148
}
148149

149150
type t = T : 'thread inner -> t
@@ -154,6 +155,13 @@ let sexp_of_inner inner =
154155

155156
let sexp_of_t (T inner) = sexp_of_inner inner
156157

158+
let eprint_s_once t here sexp =
159+
if not (Hash_set.mem t.suppressed_errors here)
160+
then (
161+
Hash_set.add t.suppressed_errors here;
162+
eprint_s sexp)
163+
;;
164+
157165
let allocate_pid (type thread) (t : thread inner) ~name : int =
158166
let module T = (val t.trace) in
159167
T.allocate_pid ~name
@@ -312,6 +320,7 @@ let create_expert
312320
; trace
313321
; annotate_inferred_start_times
314322
; in_filtered_region = true
323+
; suppressed_errors = Hash_set.create (module Source_code_position)
315324
}
316325
in
317326
write_hits t hits;
@@ -831,12 +840,20 @@ end = struct
831840
some data. *)
832841
if Callstack.depth thread_info.callstack <> 1
833842
then
834-
eprintf
835-
"Warning: expected callstack depth to be the same going into a [try] \
836-
block as when leaving it, but it wasn't (off by %d). Did Intel \
837-
Processor Trace drop some data? Will attempt to recover.\n\
838-
%!"
839-
(Callstack.depth thread_info.callstack - 1)
843+
(* Conditional on happening once, this is likely to happen again... don't
844+
spam the user's terminal. *)
845+
eprint_s_once
846+
t
847+
[%here]
848+
[%message
849+
"WARNING: expected callstack depth to be the same going into a \
850+
[try] block as when leaving it, but it wasn't. Did Intel Processor \
851+
Trace drop some data? Will attempt to recover. Further errors will \
852+
be suppressed.\n"
853+
~depth:(Callstack.depth thread_info.callstack - 1 : int)
854+
(src : Event.Location.t)
855+
(dst : Event.Location.t)
856+
(last_known_instruction_pointer : Int64.Hex.t)]
840857
else (
841858
(* Only pop the exception callstack if we're at the same callstack
842859
depth as we were when we saw [Pushtrap]. This should let us recover

0 commit comments

Comments
 (0)