From 6920c3341a0a71028c991fa534d146681296fae6 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 17 Sep 2024 10:36:49 -0400 Subject: [PATCH] refactor: use `trace.subscriber` instead of a separate library --- .github/workflows/gh-pages.yml | 4 ++-- .github/workflows/main.yml | 10 ++++----- dune-project | 15 ++----------- src/subscriber/dune | 11 ++++++++-- src/subscriber/thread_.dummy.ml | 1 + src/subscriber/thread_.mli | 2 ++ src/subscriber/thread_.real.ml | 1 + src/subscriber/time_.dummy.ml | 1 + src/subscriber/time_.mli | 1 + src/subscriber/time_.mtime.ml | 3 +++ src/subscriber/trace_subscriber.ml | 2 +- src/tef-tldrs/dune | 2 +- src/tef/dune | 2 +- trace-subscriber.opam | 34 ------------------------------ 14 files changed, 30 insertions(+), 59 deletions(-) create mode 100644 src/subscriber/thread_.dummy.ml create mode 100644 src/subscriber/thread_.mli create mode 100644 src/subscriber/thread_.real.ml create mode 100644 src/subscriber/time_.dummy.ml create mode 100644 src/subscriber/time_.mli create mode 100644 src/subscriber/time_.mtime.ml delete mode 100644 trace-subscriber.opam diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 6ee8aab..35a149d 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -22,10 +22,10 @@ jobs: - run: opam pin odoc 2.2.2 -y -n # crash with 2.4, see https://github.com/ocaml/odoc/issues/1066 - name: Deps - run: opam install odig trace trace-tef trace-fuchsia trace-subscriber ppx_trace + run: opam install odig trace trace-tef trace-fuchsia ppx_trace - name: Build - run: opam exec -- odig odoc --cache-dir=_doc/ trace trace-tef trace-fuchsia trace-subscriber ppx_trace + run: opam exec -- odig odoc --cache-dir=_doc/ trace trace-tef trace-fuchsia ppx_trace - name: Deploy uses: peaceiris/actions-gh-pages@v3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30e09cf..eba351b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,17 +32,17 @@ jobs: dune-cache: true allow-prerelease-opam: true - - run: opam install -t trace trace-subscriber trace-tef trace-fuchsia --deps-only + - run: opam install -t trace trace-tef trace-fuchsia --deps-only - run: opam install ppx_trace --deps-only # no tests if: matrix.ocaml-compiler != '4.08.x' - - run: opam exec -- dune build '@install' -p trace,trace-subscriber,trace-tef,trace-fuchsia + - run: opam exec -- dune build '@install' -p trace,trace-tef,trace-fuchsia - run: opam exec -- dune build '@install' -p ppx_trace if: matrix.ocaml-compiler != '4.08.x' - run: opam exec -- dune runtest -p trace - run: opam install trace - - run: opam exec -- dune runtest -p trace-subscriber,trace-tef,trace-fuchsia + - run: opam exec -- dune runtest -p trace-tef,trace-fuchsia # with depopts - - run: opam install hmap - - run: opam exec -- dune build '@install' -p trace,trace-subscriber,trace-tef,trace-fuchsia + - run: opam install hmap mtime + - run: opam exec -- dune build '@install' -p trace,trace-tef,trace-fuchsia diff --git a/dune-project b/dune-project index 858ed66..e8df28d 100644 --- a/dune-project +++ b/dune-project @@ -47,22 +47,11 @@ (= :version) :with-test)) dune) + (depopts + (mtime (>= 2.0))) (tags (trace ppx))) -(package - (name trace-subscriber) - (synopsis "Generic subscriber system for `trace`") - (depends - (ocaml - (>= 4.08)) - (trace - (= :version)) - (mtime - (>= 2.0))) - (tags - (trace subscriber))) - (package (name trace-tef) (synopsis diff --git a/src/subscriber/dune b/src/subscriber/dune index a76b0fd..657c53f 100644 --- a/src/subscriber/dune +++ b/src/subscriber/dune @@ -1,6 +1,13 @@ (library (name trace_subscriber) - (public_name trace-subscriber) - (libraries (re_export trace.core) mtime mtime.clock.os threads)) + (public_name trace.subscriber) + (libraries (re_export trace.core) + (select thread_.ml from + (threads -> thread_.real.ml) + ( -> thread_.dummy.ml)) + (select time_.ml from + (mtime mtime.clock.os -> time_.mtime.ml) + (mtime mtime.clock.jsoo -> time_.mtime.ml) + ( -> time_.dummy.ml)))) diff --git a/src/subscriber/thread_.dummy.ml b/src/subscriber/thread_.dummy.ml new file mode 100644 index 0000000..29ea74d --- /dev/null +++ b/src/subscriber/thread_.dummy.ml @@ -0,0 +1 @@ +let[@inline] get_tid () = 0 diff --git a/src/subscriber/thread_.mli b/src/subscriber/thread_.mli new file mode 100644 index 0000000..08e8ea1 --- /dev/null +++ b/src/subscriber/thread_.mli @@ -0,0 +1,2 @@ +val get_tid : unit -> int +(** Get current thread ID *) diff --git a/src/subscriber/thread_.real.ml b/src/subscriber/thread_.real.ml new file mode 100644 index 0000000..51a172c --- /dev/null +++ b/src/subscriber/thread_.real.ml @@ -0,0 +1 @@ +let[@inline] get_tid () = Thread.id @@ Thread.self () diff --git a/src/subscriber/time_.dummy.ml b/src/subscriber/time_.dummy.ml new file mode 100644 index 0000000..c727752 --- /dev/null +++ b/src/subscriber/time_.dummy.ml @@ -0,0 +1 @@ +let[@inline] get_time_ns () : float = 0. diff --git a/src/subscriber/time_.mli b/src/subscriber/time_.mli new file mode 100644 index 0000000..ee1a9f4 --- /dev/null +++ b/src/subscriber/time_.mli @@ -0,0 +1 @@ +val get_time_ns : unit -> float diff --git a/src/subscriber/time_.mtime.ml b/src/subscriber/time_.mtime.ml new file mode 100644 index 0000000..89c80d1 --- /dev/null +++ b/src/subscriber/time_.mtime.ml @@ -0,0 +1,3 @@ +let get_time_ns () : float = + let t = Mtime_clock.now () in + Int64.to_float (Mtime.to_uint64_ns t) diff --git a/src/subscriber/trace_subscriber.ml b/src/subscriber/trace_subscriber.ml index f600d47..bbe4626 100644 --- a/src/subscriber/trace_subscriber.ml +++ b/src/subscriber/trace_subscriber.ml @@ -20,7 +20,7 @@ module Private_ = struct let[@inline] tid_ () : int = match !get_tid_ with | Some f -> f () - | None -> Thread.id (Thread.self ()) + | None -> Thread_.get_tid () end open struct diff --git a/src/tef-tldrs/dune b/src/tef-tldrs/dune index 7bd7fab..37fa81d 100644 --- a/src/tef-tldrs/dune +++ b/src/tef-tldrs/dune @@ -5,7 +5,7 @@ (libraries trace.core trace.private.util - trace-subscriber + trace.subscriber trace-tef unix threads)) diff --git a/src/tef/dune b/src/tef/dune index b1bac7c..2e036f9 100644 --- a/src/tef/dune +++ b/src/tef/dune @@ -6,7 +6,7 @@ (libraries trace.core trace.private.util - trace-subscriber + trace.subscriber mtime mtime.clock.os unix diff --git a/trace-subscriber.opam b/trace-subscriber.opam deleted file mode 100644 index 254d443..0000000 --- a/trace-subscriber.opam +++ /dev/null @@ -1,34 +0,0 @@ -# This file is generated by dune, edit dune-project instead -opam-version: "2.0" -version: "0.7" -synopsis: "Generic subscriber system for `trace`" -maintainer: ["Simon Cruanes"] -authors: ["Simon Cruanes"] -license: "MIT" -tags: ["trace" "subscriber"] -homepage: "https://github.com/c-cube/ocaml-trace" -bug-reports: "https://github.com/c-cube/ocaml-trace/issues" -depends: [ - "dune" {>= "2.9"} - "ocaml" {>= "4.08"} - "trace" {= version} - "mtime" {>= "2.0"} - "odoc" {with-doc} -] -build: [ - ["dune" "subst"] {dev} - [ - "dune" - "build" - "-p" - name - "-j" - jobs - "--promote-install-files=false" - "@install" - "@runtest" {with-test} - "@doc" {with-doc} - ] - ["dune" "install" "-p" name "--create-install-files" name] -] -dev-repo: "git+https://github.com/c-cube/ocaml-trace.git"