Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
os:
- ubuntu_x64_8_cores
ocaml-version:
- 4.14.0
- '5.2.0+ox'

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -21,19 +21,20 @@ jobs:
- uses: actions/cache@v4
with:
path: ~/.opam
key: ${{ matrix.os }}-opam-${{ matrix.ocaml-version }}-flambda-musl-v6
key: ${{ matrix.os }}-opam-${{ matrix.ocaml-version }}-1

- name: Install musl-compatible kernel headers
run: |
mkdir musl-kernel
curl -L https://github.com/sabotage-linux/kernel-headers/archive/refs/tags/v4.19.88-1.tar.gz | \
tar -xz -C musl-kernel --strip-components=1
echo "C_INCLUDE_PATH=$(pwd)/musl-kernel/x86/include" >> "$GITHUB_ENV"
echo "CC=musl-gcc" >> "$GITHUB_ENV"

- name: "Install apt packages"
run: |
sudo apt-get update
sudo apt-get install bubblewrap musl-tools libucl1
sudo apt-get install -y bubblewrap musl musl-tools libucl1 rsync

- name: Install upx
run: |
Expand All @@ -50,7 +51,7 @@ jobs:
CC=musl-gcc ./configure --libdir=/usr/lib/x86_64-linux-musl --includedir=/usr/include/x86_64-linux-musl
make -j$(nproc)
sudo make install

- name: Build zstd with musl
run: |
mkdir musl-zstd
Expand All @@ -62,7 +63,7 @@ jobs:

- name: Use OCaml ${{ matrix.ocaml-version }}
run: |
sudo wget -O /usr/local/bin/opam https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-x86_64-linux
sudo wget -O /usr/local/bin/opam https://github.com/ocaml/opam/releases/download/2.5.0/opam-2.5.0-x86_64-linux
sudo chmod a+x /usr/local/bin/opam

export OPAMYES=1
Expand All @@ -71,13 +72,28 @@ jobs:
echo "OPAMJOBS=$OPAMJOBS" >> "$GITHUB_ENV"

opam init --bare -yav https://github.com/ocaml/opam-repository.git
opam switch set ${{ matrix.ocaml-version }}-flambda-musl 2>/dev/null || \
opam switch create ${{ matrix.ocaml-version }}-flambda-musl \
--packages=ocaml-variants.${{ matrix.ocaml-version }}+options,ocaml-option-flambda,ocaml-option-musl
opam switch set ${{ matrix.ocaml-version }} 2>/dev/null || \
opam switch create ${{ matrix.ocaml-version }} --repos ox=git+https://github.com/oxcaml/opam-repository.git,default

- name: Vendor Basement
run: |
mkdir ../basement
curl -L 'https://github.com/janestreet/basement/archive/c657898128a97dcdfbe4b25d79fd0de2e1e5218f.tar.gz' | \
tar -C ../basement -xz --strip-components=1
git -C ../basement apply $PWD/vendor/basement-semaphore-bug-fix.patch
opam pin basement ../basement

- name: Vendor Core_unix
run: |
mkdir ../core_unix
curl -L 'https://github.com/janestreet/core_unix/archive/63390a3f75376156e77ed49d6cc07ca48a90dd53.tar.gz' | \
tar -C ../core_unix -xz --strip-components=1
git -C ../core_unix apply $PWD/vendor/core-unix-musl-compatibility.patch
opam pin core_unix ../core_unix

- run: opam install ./magic-trace.opam --deps-only

- run: opam install ocamlformat.0.26.2
- run: opam install ocamlformat
- run: opam exec -- dune build @fmt

- run: opam exec -- make PROFILE=static
Expand Down
1 change: 0 additions & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
version=0.26.2
profile=janestreet
20 changes: 10 additions & 10 deletions lib/magic_trace/src/magic_trace.mli
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(** The magic-trace tool can work with any binary, but using these functions
allows you to easily mark places in your code to take a snapshot, and enables
additional features like passing a value and marking the start of a duration. *)
(** The magic-trace tool can work with any binary, but using these functions allows you to
easily mark places in your code to take a snapshot, and enables additional features
like passing a value and marking the start of a duration. *)

(** This is the default symbol that the magic-trace command will attach to and use to
take a snapshot. Use it if you want to take a snapshot based on custom logic, and it
will save you the step of selecting the symbol you want to stop on.
(** This is the default symbol that the magic-trace command will attach to and use to take
a snapshot. Use it if you want to take a snapshot based on custom logic, and it will
save you the step of selecting the symbol you want to stop on.

It's an external C function that does nothing and should be very fast to call. It's
only a C function to ensure it has a stable and exact symbol. *)
Expand All @@ -31,11 +31,11 @@ val mark_start : unit -> unit
;;
]}

which allows capturing only unusually long executions without adding the
~10us breakpoint overhead on every run while magic-trace is attached.
which allows capturing only unusually long executions without adding the ~10us
breakpoint overhead on every run while magic-trace is attached.

See also the [-duration-thresh] flag for use in combination with this or
instead of it if you can tolerate a 10us pause on every call. *)
See also the [-duration-thresh] flag for use in combination with this or instead of it
if you can tolerate a 10us pause on every call. *)
module Min_duration : sig
type t

Expand Down
1 change: 1 addition & 0 deletions magic-trace.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build: [
]
depends: [
"ocaml" {>= "4.14"}
"ocaml_intrinsics"
"async"
"camlzip"
"cohttp"
Expand Down
8 changes: 4 additions & 4 deletions src/backend_intf.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(** Backends, which do the trace recording, present this unified interface in
order to be exposed as commands which can generate traces. *)
(** Backends, which do the trace recording, present this unified interface in order to be
exposed as commands which can generate traces. *)

open! Core
open! Async
Expand Down Expand Up @@ -48,8 +48,8 @@ module type S = sig
function. Default [true]. *)
-> debug_print_perf_commands:bool
-> recording_data:Recording.Data.t option
(** This parameter is passed to allow [decode_events] to depend
on information or configuration from [attach_and_record]. *)
(** This parameter is passed to allow [decode_events] to depend on information or
configuration from [attach_and_record]. *)
-> record_dir:string
-> collection_mode:Collection_mode.t
-> Decode_opts.t
Expand Down
13 changes: 6 additions & 7 deletions src/demangle_ocaml_symbols.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
open! Core

(** The logic for this function is derived from perf [0].
This function is used to change the symbols in the application
executable from a mangled form to a demangled form in ocaml. Now
when running [magic-trace run -trigger] the symbols will appear in
their demangled form. Will return None if the symbol is not
recognized as an OCaml symbol.
(** The logic for this function is derived from perf [0]. This function is used to change
the symbols in the application executable from a mangled form to a demangled form in
ocaml. Now when running [magic-trace run -trigger] the symbols will appear in their
demangled form. Will return None if the symbol is not recognized as an OCaml symbol.

[0]: https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/tools/perf/util/demangle-ocaml.c *)
[0]:
https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/tools/perf/util/demangle-ocaml.c *)
val demangle : string -> string option
6 changes: 3 additions & 3 deletions src/elf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ let find_selection t name : Selection.t option =
Some desired_filename, maybe_int_of_string desired_line, None
| _ -> None, None, None
in
let%bind.Option desired_filename = desired_filename in
let%bind.Option desired_line = desired_line in
let%bind.Option desired_filename in
let%bind.Option desired_line in
let cols = ref [] in
traverse_debug_line
~f:(fun header state ->
Expand Down Expand Up @@ -405,7 +405,7 @@ module Symbol_resolver = struct
, (value symb |> Int64.to_int_exn) - normal_offset + t.loaded_offset
, size_in_bytes symb |> Int64.to_int_exn ))
in
let%bind name = name in
let%bind name in
return { name; start_addr; end_addr = start_addr + size }
;;
end
64 changes: 31 additions & 33 deletions src/ocaml_exception_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let iter_pushtraps_and_poptraps_in_range =
let addr, _ = t.(i) in
addr
in
let first_index_greater_than_or_equal_to t x =
let first_index_greater_than_or_equal_to t x = exclave_
Binary_search.binary_search
t.pushtrap_and_poptrap_addresses
~length:Array.length
Expand All @@ -41,7 +41,7 @@ let iter_pushtraps_and_poptraps_in_range =
`First_greater_than_or_equal_to
x
in
let last_index_less_than_or_equal_to t x =
let last_index_less_than_or_equal_to t x = exclave_
Binary_search.binary_search
t.pushtrap_and_poptrap_addresses
~length:Array.length
Expand All @@ -63,41 +63,39 @@ let iter_pushtraps_and_poptraps_in_range =

let is_entertrap t ~addr = Set.mem t.entertrap_addresses addr

let%test_module _ =
(module struct
open Core
module%test _ = struct
open Core

let iter_and_print ~from ~to_ t =
let range = ref [] in
iter_pushtraps_and_poptraps_in_range ~from ~to_ ~f:(fun r -> range := r :: !range) t;
let range = !range |> List.rev in
Core.print_s
[%message "" (from : int64) (to_ : int64) (range : (int64 * Kind.t) list)]
;;
let iter_and_print ~from ~to_ t =
let range = ref [] in
iter_pushtraps_and_poptraps_in_range ~from ~to_ ~f:(fun r -> range := r :: !range) t;
let range = !range |> List.rev in
Core.print_s
[%message "" (from : int64) (to_ : int64) (range : (int64 * Kind.t) list)]
;;

let%expect_test "basic range classification tests" =
let t =
create ~pushtraps:[| 0L; 5L; 10L |] ~poptraps:[| 2L; 100L |] ~entertraps:[| 50L |]
in
iter_and_print ~from:0L ~to_:1L t;
[%expect {|
let%expect_test "basic range classification tests" =
let t =
create ~pushtraps:[| 0L; 5L; 10L |] ~poptraps:[| 2L; 100L |] ~entertraps:[| 50L |]
in
iter_and_print ~from:0L ~to_:1L t;
[%expect {|
((from 0) (to_ 1) (range ((0 Pushtrap)))) |}];
iter_and_print ~from:0L ~to_:4L t;
[%expect {|
iter_and_print ~from:0L ~to_:4L t;
[%expect {|
((from 0) (to_ 4) (range ((0 Pushtrap) (2 Poptrap)))) |}];
iter_and_print ~from:3L ~to_:7L t;
[%expect {|
iter_and_print ~from:3L ~to_:7L t;
[%expect {|
((from 3) (to_ 7) (range ((5 Pushtrap)))) |}];
iter_and_print ~from:49L ~to_:100L t;
[%expect {|
iter_and_print ~from:49L ~to_:100L t;
[%expect {|
((from 49) (to_ 100) (range ((100 Poptrap)))) |}];
iter_and_print ~from:75L ~to_:101L t;
[%expect {|
iter_and_print ~from:75L ~to_:101L t;
[%expect {|
((from 75) (to_ 101) (range ((100 Poptrap)))) |}];
iter_and_print ~from:75L ~to_:80L t;
[%expect {| ((from 75) (to_ 80) (range ())) |}];
iter_and_print ~from:150L ~to_:200L t;
[%expect {| ((from 150) (to_ 200) (range ())) |}]
;;
end)
;;
iter_and_print ~from:75L ~to_:80L t;
[%expect {| ((from 75) (to_ 80) (range ())) |}];
iter_and_print ~from:150L ~to_:200L t;
[%expect {| ((from 150) (to_ 200) (range ())) |}]
;;
end
4 changes: 2 additions & 2 deletions src/perf_ctlfd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ let create () =
;;

let close_perf_side_fds t =
Option.iter t.ctl_rx ~f:(Core_unix.close ~restart:true);
Option.iter t.ctl_rx ~f:Core_unix.close;
t.ctl_rx <- None;
Option.iter t.ack_tx ~f:(Core_unix.close ~restart:true);
Option.iter t.ack_tx ~f:Core_unix.close;
t.ack_tx <- None
;;

Expand Down
Loading