mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 17:23:59 +00:00
Show server CPU and heap use in the studio status bar
The bridge sends a usage event every second and when a studio connects: CPU with 100 per busy thread, like top, and the Java heap in use. The status bar shows both beside the cursor and turns each warning-coloured at 80%. v3: e1e158364 11e4ba0b1 268e72b9c 275b5965b
This commit is contained in:
1 parent
d28b9d13cc
commit
723764a782
10 files changed
+243
-8
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package art.arcane.iris.core.studio.bridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerUsageTest {
|
||||
@Test
|
||||
public void cpuCountsAHundredPercentPerBusyThread() {
|
||||
ServerUsage usage = ServerUsage.of(0.25D, 8, 1L, 2L);
|
||||
|
||||
assertEquals(200D, usage.cpuPercent(), 1e-9D);
|
||||
assertEquals(8, usage.threads());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyThreadBusyReachesAHundredPerThread() {
|
||||
assertEquals(1600D, ServerUsage.of(1D, 16, 1L, 2L).cpuPercent(), 1e-9D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnknownCpuLoadIsLeftOut() {
|
||||
assertNull(ServerUsage.of(-1D, 8, 1L, 2L).cpuPercent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSampleHoldsTheHeapInUseWithinItsMaximum() {
|
||||
ServerUsage usage = ServerUsage.sample();
|
||||
|
||||
assertNotNull(usage);
|
||||
assertTrue(usage.threads() >= 1);
|
||||
assertTrue(usage.heapUsedBytes() > 0L);
|
||||
assertTrue(usage.heapUsedBytes() <= usage.heapMaxBytes());
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,24 @@ public class StudioBridgeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aNewListenerHearsTheServersUsageRightAway() throws Exception {
|
||||
HttpResponse<InputStream> events = http.send(authorized("events"), HttpResponse.BodyHandlers.ofInputStream());
|
||||
|
||||
try (BufferedReader lines = new BufferedReader(new InputStreamReader(events.body(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
do {
|
||||
line = lines.readLine();
|
||||
} while (line != null && !line.equals("event: usage"));
|
||||
assertEquals("event: usage", line);
|
||||
JsonObject usage = JsonParser.parseString(lines.readLine().substring("data: ".length())).getAsJsonObject();
|
||||
assertTrue(usage.get("threads").getAsInt() >= 1);
|
||||
assertTrue(usage.get("heapUsedBytes").getAsLong() > 0L);
|
||||
assertTrue(usage.get("heapMaxBytes").getAsLong() >= usage.get("heapUsedBytes").getAsLong());
|
||||
assertTrue(usage.has("cpuPercent"));
|
||||
}
|
||||
}
|
||||
|
||||
private HttpResponse<String> get(String endpoint) throws Exception {
|
||||
return http.send(authorized(endpoint), HttpResponse.BodyHandlers.ofString());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user