Skip to content

Commit 1c3c4b8

Browse files
committed
ADAP-216: added MemeoryProfile
1 parent feac2d3 commit 1c3c4b8

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

191 KB
Binary file not shown.

release/profile.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
java -Xmx100m -Xms100m -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.3-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.2.2.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.MemoryProfile
2+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.openfin.desktop.demo;
2+
3+
import com.openfin.desktop.*;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.util.concurrent.CountDownLatch;
8+
import java.util.concurrent.TimeUnit;
9+
import java.util.concurrent.atomic.AtomicBoolean;
10+
import java.util.concurrent.atomic.AtomicInteger;
11+
12+
13+
/**
14+
* This class can be used to profile memory usage of Java Adapter for communicating with Runtime. The initial version
15+
* just keeps calling getMachineId API. It can easily extended to test other APIs.
16+
*
17+
* VisualVM, available from https://visualvm.github.io/, can be used to monitor memory usgage while this code is running
18+
*/
19+
20+
public class MemoryProfile {
21+
private final static Logger logger = LoggerFactory.getLogger(MemoryProfile.class.getName());
22+
23+
public static void main(String[] args) {
24+
RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration();
25+
String connectionUuid = MemoryProfile.class.getName();
26+
String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version");
27+
if (desktopVersion == null) {
28+
desktopVersion = "stable";
29+
}
30+
runtimeConfiguration.setRuntimeVersion(desktopVersion);
31+
try {
32+
final DesktopConnection desktopConnection = new DesktopConnection(connectionUuid);
33+
DesktopStateListener listener = new DesktopStateListener() {
34+
@Override
35+
public void onReady() {
36+
launchThread(desktopConnection);
37+
}
38+
@Override
39+
public void onClose(String error) {
40+
41+
}
42+
@Override
43+
public void onError(String reason) {
44+
logger.error(String.format("onError %s", reason));
45+
}
46+
47+
@Override
48+
public void onMessage(String message) {
49+
}
50+
@Override
51+
public void onOutgoingMessage(String message) {
52+
}
53+
};
54+
desktopConnection.connect(runtimeConfiguration, listener, 50);
55+
} catch (Exception e) {
56+
logger.error("", e);
57+
}
58+
}
59+
60+
private static void launchThread(DesktopConnection desktopConnection) {
61+
Thread t = new Thread() {
62+
@Override
63+
public void run() {
64+
OpenFinRuntime openfinSystem = new OpenFinRuntime(desktopConnection);
65+
AtomicInteger callCount = new AtomicInteger();
66+
AtomicBoolean shouldRun = new AtomicBoolean(true);
67+
while (shouldRun.get()) {
68+
try {
69+
CountDownLatch latch = new CountDownLatch(1);
70+
openfinSystem.getMachineId(new AckListener() {
71+
@Override
72+
public void onSuccess(Ack ack) {
73+
if (ack.isSuccessful()) {
74+
logger.info(String.format("API call count %d", callCount.incrementAndGet()));
75+
latch.countDown();
76+
} else {
77+
logger.error(String.format("API failed %s", ack.getReason()));
78+
shouldRun.set(false);
79+
}
80+
}
81+
@Override
82+
public void onError(Ack ack) {
83+
logger.error(String.format("API failed %s", ack.getReason()));
84+
shouldRun.set(false);
85+
}
86+
});
87+
latch.await(1, TimeUnit.SECONDS);
88+
} catch (Exception ex) {
89+
ex.printStackTrace();
90+
}
91+
}
92+
}
93+
};
94+
t.start();
95+
}
96+
}

0 commit comments

Comments
 (0)