Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 2f7b01b

Browse files
authored
Merge pull request #2 from jonathan-spruce/pull-image
Pull language server image from DockerHub
2 parents bd7bd29 + dae8fef commit 2f7b01b

5 files changed

Lines changed: 70 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
client/server
44
.vscode-test
55
**/.DS_Store
6+
*.vsix

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Codewind Java Profiler
22

3-
Annotates your Java code with code highlighting for your hottest methods in your Codewind projects.
3+
Annotates your Java code with code highlighting for your hottest methods in your Eclipse Codewind projects.
44

55
![platforms](https://img.shields.io/badge/runtime-Java-yellow.svg)
66
[![Eclipse License](https://img.shields.io/badge/license-Eclipse-brightgreen.svg)](https://github.com/eclipse/codewind-java-profiler/blob/master/LICENSE)
77

8-
This extension provides code highlighting showing relative time spent in Java methods based on profiling data gathered through Codewind Load Testing.
8+
This extension provides code highlighting showing relative time spent in Java methods based on profiling data gathered through Codewind's load testing feature.
99

1010
## Usage
1111

12+
### Prerequisites
13+
14+
- The Eclipse Codewind extension (available [here](https://marketplace.visualstudio.com/items?itemName=IBM.codewind)) installed in Visual Studio Code.
15+
- A Java Liberty project bound to Codewind.
16+
1217
With Visual Studio Code:
1318

14-
- Open .
15-
- This will create profiling data in a `load-test/[timestamp]/xxxx.hcd` file in your Codewind project.
19+
- Open your Java Liberty Project's Performance Dashboard by right-clicking on the project in the Codewind section of Visual Studio Code and selecting `Open Performance Dashboard`.
20+
- Once the Performance Dashboard opens, click `Run Load Test`.
21+
- Once the test has completed, it will create profiling data in a `load-test/[timestamp]/xxxx.hcd` file in your Codewind project.
1622
- In Visual Studio Code open a Java file in your project.
1723
- The extension will highlight any methods which were found in the profiling data and annotate them to show the percentage of time they were running on the CPU during profiling.
1824

client/src/extension.ts

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import * as ip from 'ip';
1818

1919
const docker = new Docker();
2020
const clientPort: number = 3333;
21-
const dockerImage: string = 'java-ls';
21+
const dockerRepo: string = 'ibmcom';
22+
const dockerImage: string = 'codewind-java-profiler-language-server';
23+
const dockerTag: string = 'latest';
2224
let clientServer: net.Server;
2325
let client: LanguageClient;
2426
let serverConnected = false;
@@ -60,45 +62,18 @@ export async function activate(context: ExtensionContext) {
6062
}
6163

6264
async function startServerDockerContainer(dockerBinds: string[]) {
63-
if(!process.env.REMOTE_SERVER) {
64-
let originalContainer: Docker.Container;
65-
try {
66-
originalContainer = await docker.getContainer(dockerImage);
67-
try {
68-
await originalContainer.stop();
69-
} catch (error) {
70-
// don't care if already stopped
71-
}
72-
await originalContainer.remove();
73-
} catch (error) {
74-
// if it doesn't exist then try to build it
75-
// TODO: host image and try to pull instead
76-
const pack = tarfs.pack(path.join(__dirname, '../..', 'server'));
77-
78-
const stream = await docker.buildImage(pack, {t: dockerImage});
79-
// wait for the build to finish
80-
await new Promise((resolve, reject) => {
81-
docker.modem.followProgress(stream, (err: any, res: {} | PromiseLike<{}>) => err ? reject(err) : resolve(res), (event) => {
82-
// console.log(event.stream);
83-
});
84-
});
85-
}
86-
87-
const container = await docker.createContainer({
88-
Image: dockerImage,
89-
name: dockerImage,
90-
Env: [`CLIENT_PORT=${clientPort}`, `CLIENT_HOST=${ip.address()}`, `BINDS="${dockerBinds}"`],
91-
HostConfig: {
92-
Binds: dockerBinds
93-
}
94-
});
95-
96-
container.start();
65+
try {
66+
await pullDockerImage();
67+
console.log('Pull completed!');
68+
} catch (error) {
69+
console.log('Pull failed, building from local Dockerfile');
70+
await buildLocalDockerImage();
9771
}
72+
await startContainer(dockerBinds);
9873

9974
setupConnectionListeners();
100-
10175
const serverSocket = await waitForServerConnection();
76+
10277
// Connect to language server via socket
10378
let result: StreamInfo = {
10479
writer: serverSocket,
@@ -128,6 +103,52 @@ function waitForServerConnection() {
128103
});
129104
}
130105

106+
async function pullDockerImage() {
107+
await removeExistingContainer();
108+
await docker.pull(`${dockerRepo}/${dockerImage}:${dockerTag}`, {});
109+
}
110+
111+
async function buildLocalDockerImage() {
112+
try {
113+
await removeExistingContainer();
114+
} catch (error) {
115+
// if it doesn't exist then try to build it
116+
// TODO: host image and try to pull instead
117+
const pack = tarfs.pack(path.join(__dirname, '../..', 'server'));
118+
119+
const stream = await docker.buildImage(pack, {t: dockerImage});
120+
// wait for the build to finish
121+
await new Promise((resolve, reject) => {
122+
docker.modem.followProgress(stream, (err: any, res: {} | PromiseLike<{}>) => err ? reject(err) : resolve(res), (event) => {
123+
// console.log(event.stream);
124+
});
125+
});
126+
}
127+
}
128+
129+
async function removeExistingContainer() {
130+
let originalContainer: Docker.Container;
131+
originalContainer = await docker.getContainer(dockerImage);
132+
try {
133+
await originalContainer.stop();
134+
} catch (error) {
135+
// don't care if already stopped
136+
}
137+
await originalContainer.remove();
138+
}
139+
140+
async function startContainer(dockerBinds: string[]) {
141+
const container = await docker.createContainer({
142+
Image: dockerImage,
143+
name: dockerImage,
144+
Env: [`CLIENT_PORT=${clientPort}`, `CLIENT_HOST=${ip.address()}`, `BINDS="${dockerBinds}"`],
145+
HostConfig: {
146+
Binds: dockerBinds
147+
}
148+
});
149+
150+
container.start();
151+
}
131152
function setupConnectionListeners() {
132153
// wait for the language server to connect
133154
clientServer.setMaxListeners(1);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codewind-java-profiler",
33
"displayName": "Codewind Java Profiler",
4-
"description": "Code Highlighting for Codewind's Java Load Testing",
4+
"description": "Code Highlighting for Eclipse Codewind's Java Load Testing",
55
"version": "19.6.0",
66
"author": "IBM",
77
"publisher": "IBM",
@@ -16,7 +16,7 @@
1616
"Profiling",
1717
"Java",
1818
"Load",
19-
"IBM"
19+
"Eclipse"
2020
],
2121
"icon": "res/img/codewind-logo.png",
2222
"homepage": "https://www.eclipse.org/codewind/",

res/img/codewind-logo.png

-697 Bytes
Loading

0 commit comments

Comments
 (0)