Skip to content

Commit

Permalink
Add tracy support to timing
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Oct 5, 2023
1 parent 093eb5e commit 2925170
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/goblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ let main () =
allocated = true;
count = true;
tef = true;
tracy = false;
};
Timing.Program.start {
cputime = false;
walltime = false;
allocated = false;
count = false;
tef = true;
tracy = true;
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/util/timing/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
(library
(name goblint_timing)
(public_name goblint.timing)
(libraries catapult catapult-file))
(libraries catapult catapult-file tracy-client))
16 changes: 14 additions & 2 deletions src/util/timing/goblint_timing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let dummy_options: options = {
allocated = false;
count = false;
tef = false;
tracy = false;
}

(** TEF process ID for the next {!Make}.
Expand Down Expand Up @@ -41,6 +42,7 @@ struct
start_walltime: float; (** Wall time at the beginning of the frame. *)
start_allocated: float; (** Allocated memory at the beginning of the frame. *)
(* No need for count, because it always gets incremented by 1. *)
tracy_span: Tracy_client.span;
}

let current_cputime (): float =
Expand All @@ -60,6 +62,7 @@ struct
start_cputime = if !options.cputime then current_cputime () else 0.0;
start_walltime = if !options.walltime then current_walltime () else 0.0;
start_allocated = if !options.allocated then current_allocated () else 0.0;
tracy_span = -1;
}

(** Stack of currently active timing frames. *)
Expand Down Expand Up @@ -108,7 +111,14 @@ struct
in
loop tree.children
in
Stack.push (create_frame tree) current;
let frame = create_frame tree in
let frame =
if !options.tracy then
{frame with tracy_span = Tracy_client.enter ~__FILE__ ~__LINE__ name}
else
frame
in
Stack.push frame current;
if !options.tef then
Catapult.Tracing.begin' ~pid:tef_pid ?args name

Expand All @@ -134,7 +144,9 @@ struct
assert (tree.name = name);
add_frame_to_tree frame tree;
if !options.tef then
Catapult.Tracing.exit' ~pid:tef_pid name
Catapult.Tracing.exit' ~pid:tef_pid name;
if !options.tracy then
Tracy_client.exit frame.tracy_span

let wrap ?args name f x =
enter ?args name;
Expand Down
1 change: 1 addition & 0 deletions src/util/timing/goblint_timing_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type options = {
allocated: bool; (** Measure allocated memory. *)
count: bool; (** Count calls. *)
tef: bool; (** Output a TEF track. *)
tracy: bool;
}

(** Timing tree node. *)
Expand Down

0 comments on commit 2925170

Please sign in to comment.