Skip to content

Commit

Permalink
Added decoding/trace writing tests for sampling extra events
Browse files Browse the repository at this point in the history
The goal of this PR is to allow support to sample other events from perf, e.g.
`branch-misses`, `cache-misses`. Although this is a nice feature, the goal is
also to already have support for processing these events through sampling, so
that when we have PEBS-via-PT available, we can also have these events in the
processor trace stream.

Now the user can pass `-events` along with a comma separated list of either
names like `branch-misses` or sexps which allow the user to control the event
period. These will then show up on separate tracks along with the actual trace
as arrows representing every sample.

I also drafted a [new wiki
page](https://github.com/Lamoreauxaj/magic-trace/wiki/Sampling-extra-events) and
referenced in the help docs for `-events` which would need to be updated along
with this PR.

This commit solely adds new tests which include both branch-misses and
cache-misses as well as the Intel PT stream or a stacktrace sampled stream.

Signed-off-by: Aaron Lamoreaux <alamoreaux@janestreet.com>
  • Loading branch information
lamoreauxaj committed Jul 6, 2022
1 parent 3df6b91 commit 5e2a9a4
Show file tree
Hide file tree
Showing 10 changed files with 58,850 additions and 41,318 deletions.
1,056 changes: 528 additions & 528 deletions test/c_demo_sampling.ml

Large diffs are not rendered by default.

1,056 changes: 528 additions & 528 deletions test/c_demo_sampling.perf

Large diffs are not rendered by default.

27,176 changes: 27,176 additions & 0 deletions test/demo_extra_events.ml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/demo_extra_events.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(*_ This signature deliberately left empty. *)
9,985 changes: 9,985 additions & 0 deletions test/demo_sampling_with_branch_misses_and_cache_misses.perf

Large diffs are not rendered by default.

10,003 changes: 10,003 additions & 0 deletions test/demo_with_branch_misses.perf

Large diffs are not rendered by default.

10,001 changes: 10,001 additions & 0 deletions test/demo_with_branch_misses_and_cache_misses.perf

Large diffs are not rendered by default.

26,142 changes: 310 additions & 25,832 deletions test/ocaml_demo_sampling.ml

Large diffs are not rendered by default.

14,721 changes: 303 additions & 14,418 deletions test/ocaml_demo_sampling.perf

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions test/perf_script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ let run ?(debug = false) ?ocaml_exception_info ~trace_scope file =
;;

let write_duration_begin ~args:_ ~thread:_ ~name ~time : unit =
printf "-> %8s BEGIN %s\n" (Time_ns.Span.to_string_hum time) name
if not String.(name = "branch-misses" || name = "cache-misses")
then printf "-> %8s BEGIN %s\n" (Time_ns.Span.to_string_hum time) name
;;

let write_duration_end ~args:_ ~thread:_ ~name ~time : unit =
printf "-> %8s END %s\n" (Time_ns.Span.to_string_hum time) name
if not String.(name = "branch-misses" || name = "cache-misses")
then printf "-> %8s END %s\n" (Time_ns.Span.to_string_hum time) name
;;

let write_duration_complete ~args ~thread ~name ~time ~time_end : unit =
Expand Down Expand Up @@ -86,17 +88,18 @@ let run ?(debug = false) ?ocaml_exception_info ~trace_scope file =
in
List.iter split_lines ~f:(fun lines ->
let event =
Perf_decode.For_testing.to_event lines
|> Option.value_exn
|> adjust_event_time
Perf_decode.For_testing.to_event lines |> Option.map ~f:adjust_event_time
in
if should_print_perf_line event
then (
match lines with
| [ line ] -> printf "%s\n" line
| lines -> print_s [%message (lines : string list)]);
let event = Event.With_write_info.create ~should_write:true event in
Trace_writer.write_event trace_writer event);
match event with
| Some event ->
if should_print_perf_line event
then (
match lines with
| [ line ] -> printf "%s\n" line
| lines -> print_s [%message (lines : string list)]);
let event = Event.With_write_info.create ~should_write:true event in
Trace_writer.write_event trace_writer event
| None -> ());
printf "END\n";
Trace_writer.end_of_trace trace_writer)
;;

0 comments on commit 5e2a9a4

Please sign in to comment.