diff --git a/README.md b/README.md index ed3bfe1..b97c92b 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,19 @@ public class Main { } } ``` -* run it with (adjust paths): +Requirements +* java22 +* rust + +Start rest service ``` bash cd api; RUST_LOG=info cargo run ``` +Start your java with ``` -java22 -javaagent:$EXCEPTIONAL_PROJECT/exceptional/agent/target/exceptional-agent-1.0-SNAPSHOT.jar --enable-preview -classpath $YOUR_CLASSPATH Main +java22 -javaagent:$EXCEPTIONAL_PROJECT/exceptional/agent/target/exceptional-agent-1.0-SNAPSHOT.jar +-Dagentlib="$EXCEPTIONAL_PROJECT/rustlib/target/debug/librustlib.dylib" +--enable-preview --enable-native-access=ALL-UNNAMED +-classpath $YOUR_CLASSPATH YourMain ``` diff --git a/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java b/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java index 937b5af..bc26025 100644 --- a/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java +++ b/lib/src/main/java/com/github/shautvast/exceptional/CircularBufferWriter.java @@ -38,7 +38,12 @@ public class CircularBufferWriter implements AutoCloseable { arena = Arena.ofConfined(); linker = Linker.nativeLinker(); //TODO relative path, or configurable - rustlib = SymbolLookup.libraryLookup(System.getProperty("agentlib"), arena); + String agentlibPath = System.getProperty("agentlib"); + if (agentlibPath == null) { + System.err.println("Please specify an agent library with -Dagentlib="); + System.exit(-1); + } + rustlib = SymbolLookup.libraryLookup(agentlibPath, arena); MemorySegment create = rustlib.find("buffer_updated").orElseThrow(); var updateHandle = linker.downcallHandle(create, FunctionDescriptor.ofVoid( ValueLayout.ADDRESS diff --git a/lib/src/test/java/com/github/shautvast/exceptional/ExceptionLoggerTest.java b/lib/src/test/java/com/github/shautvast/exceptional/ExceptionLoggerTest.java index f8d6370..527e0a8 100644 --- a/lib/src/test/java/com/github/shautvast/exceptional/ExceptionLoggerTest.java +++ b/lib/src/test/java/com/github/shautvast/exceptional/ExceptionLoggerTest.java @@ -2,19 +2,11 @@ package com.github.shautvast.exceptional; import org.junit.jupiter.api.Test; -import java.util.concurrent.TimeUnit; - class ExceptionLoggerTest { @Test - void test() throws InterruptedException { - long t0 = System.currentTimeMillis(); - for (int i = 0; i < 1_000; i++) { - ExceptionLogger.log(new Throwable()); - TimeUnit.MILLISECONDS.sleep(1); - } - System.out.println(System.currentTimeMillis() - t0); - Thread.sleep(10000); + void test() { + ExceptionLogger.log(new Throwable()); } } \ No newline at end of file diff --git a/rustlib/Cargo.lock b/rustlib/Cargo.lock index 61ae06e..b64fd83 100644 --- a/rustlib/Cargo.lock +++ b/rustlib/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -137,31 +146,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" - [[package]] name = "encoding_rs" version = "0.8.34" @@ -492,6 +476,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" @@ -510,6 +500,15 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -559,6 +558,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -627,6 +636,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -689,6 +704,50 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "reqwest" version = "0.12.5" @@ -773,8 +832,9 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", - "crossbeam-deque", "reqwest", + "tracing", + "tracing-subscriber", ] [[package]] @@ -898,6 +958,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.9" @@ -985,6 +1054,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.6.1" @@ -1083,9 +1162,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -1093,6 +1184,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1139,6 +1260,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1236,6 +1363,28 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" diff --git a/rustlib/Cargo.toml b/rustlib/Cargo.toml index d4a0c8c..0f0dcad 100644 --- a/rustlib/Cargo.toml +++ b/rustlib/Cargo.toml @@ -11,4 +11,5 @@ bench = false anyhow = "1.0" chrono = "0.4" reqwest = { version = "0.12", features = ["blocking"]} -crossbeam-deque = "0.8" \ No newline at end of file +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/rustlib/src/lib.rs b/rustlib/src/lib.rs index de44d57..3f67226 100644 --- a/rustlib/src/lib.rs +++ b/rustlib/src/lib.rs @@ -3,6 +3,7 @@ use std::ffi::c_char; use std::slice; use reqwest::blocking::Client; +use tracing::error; // same value, but different meanings // TODO find a way to set the buffer size from java. @@ -42,10 +43,9 @@ pub extern "C" fn buffer_updated(buffer: *mut c_char) { if len <= remaining { unsafe { let result = std::str::from_utf8_unchecked(slice::from_raw_parts(buffer.offset(read_pos).cast::(), len as usize)); - client.post("http://localhost:3000/api/stacktraces") + _ = client.post("http://localhost:3000/api/stacktraces") .body(result) .send() - .unwrap(); } read_pos += len; } else { @@ -55,10 +55,9 @@ pub extern "C" fn buffer_updated(buffer: *mut c_char) { let mut s = String::with_capacity(len as usize); s.push_str(s1); s.push_str(s2); - client.post("http://localhost:3000/api/stacktraces") + _ = client.post("http://localhost:3000/api/stacktraces") .body(s) .send() - .unwrap(); } read_pos = len - remaining; }