From f38c358441fbf2bb5e66ea07fe6ed558ce8f11b8 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 24 Apr 2024 13:39:38 +0100 Subject: [PATCH] DRAFT: profiling --- app/gui2/vite.config.ts | 2 +- build.sbt | 6 +++++- .../ydoc-server/src/main/java/module-info.java | 1 + .../src/main/java/org/enso/ydoc/Main.java | 16 ++++++++++++++++ .../enso/ydoc/polyfill/web/WebSocketTest.java | 1 + .../src/main/java/module-info.java | 4 ++++ 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lib/scala/profiling-utils/src/main/java/module-info.java diff --git a/app/gui2/vite.config.ts b/app/gui2/vite.config.ts index 6b9e891379..f4885b8a20 100644 --- a/app/gui2/vite.config.ts +++ b/app/gui2/vite.config.ts @@ -140,7 +140,7 @@ function gatewayServer(): Plugin { buildEnd() { if (ydocServer == null) return - ydocServer.kill(9) + ydocServer.kill('SIGTERM') }, } } diff --git a/build.sbt b/build.sbt index b069f5a491..3449735aa0 100644 --- a/build.sbt +++ b/build.sbt @@ -1184,7 +1184,10 @@ lazy val `ydoc-server` = project shouldContainAll = true ) }, - modulePath += (`syntax-rust-definition` / Compile / productDirectories).value.head, + modulePath ++= Seq( + (`syntax-rust-definition` / Compile / productDirectories).value.head, + (`profiling-utils` / Compile / productDirectories).value.head + ), libraryDependencies ++= Seq( "org.graalvm.polyglot" % "polyglot" % graalMavenPackagesVersion, "org.graalvm.polyglot" % "inspect" % graalMavenPackagesVersion % "runtime", @@ -1198,6 +1201,7 @@ lazy val `ydoc-server` = project ) .dependsOn(`syntax-rust-definition`) .dependsOn(`logging-service-logback`) + .dependsOn(`profiling-utils`) lazy val `persistance` = (project in file("lib/java/persistance")) .settings( diff --git a/lib/java/ydoc-server/src/main/java/module-info.java b/lib/java/ydoc-server/src/main/java/module-info.java index 9137d947a8..a4da021a2a 100644 --- a/lib/java/ydoc-server/src/main/java/module-info.java +++ b/lib/java/ydoc-server/src/main/java/module-info.java @@ -3,6 +3,7 @@ module org.enso.ydoc { requires io.helidon.webclient.websocket; requires io.helidon.webserver; requires io.helidon.webserver.websocket; + requires org.enso.profiling; requires org.enso.syntax; requires org.graalvm.polyglot; requires org.slf4j; diff --git a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java index f47ff04854..ece1af6050 100644 --- a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java +++ b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java @@ -1,7 +1,10 @@ package org.enso.ydoc; +import java.io.File; +import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; +import org.enso.profiling.sampler.OutputStreamSampler; import org.enso.ydoc.polyfill.ParserPolyfill; import org.enso.ydoc.polyfill.web.WebEnvironment; import org.graalvm.polyglot.Source; @@ -10,12 +13,25 @@ import org.graalvm.polyglot.io.IOAccess; public class Main { private static final String YDOC_SERVER_PATH = "/dist/assets/ydocServer.js"; + private static final String SAMPLES_PATH = "/tmp/ydoc-server.out"; private Main() {} public static void main(String[] args) throws Exception { var ydoc = Main.class.getResource(YDOC_SERVER_PATH); var contextBuilder = WebEnvironment.createContext().allowIO(IOAccess.ALL); + var sampler = OutputStreamSampler.ofFile(new File(SAMPLES_PATH)); + sampler.start(); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + sampler.stop(); + } catch (IOException e) { + throw new RuntimeException(e); + } + })); try (var executor = Executors.newSingleThreadExecutor(); var parser = new ParserPolyfill()) { diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/polyfill/web/WebSocketTest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/polyfill/web/WebSocketTest.java index f9cc844d11..3676debdd4 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/polyfill/web/WebSocketTest.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/polyfill/web/WebSocketTest.java @@ -249,6 +249,7 @@ public class WebSocketTest { session.send(buffer, last); } + @Override public void onPing(WsSession session, BufferData buffer) { session.pong(buffer); } diff --git a/lib/scala/profiling-utils/src/main/java/module-info.java b/lib/scala/profiling-utils/src/main/java/module-info.java new file mode 100644 index 0000000000..0e10c27ab3 --- /dev/null +++ b/lib/scala/profiling-utils/src/main/java/module-info.java @@ -0,0 +1,4 @@ +module org.enso.profiling { + exports org.enso.profiling.sampler; + exports org.enso.profiling.events; +}