Skip to content

Creating guides for profiling. #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/assets/resources/yourkit/mvn-profiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# You can set the env variable here instead of exporting it globally.
YOURKIT_MONITOR=$HOME/.youmonitor
LD_LIBRARY_PATH=$YOURKIT_MONITOR/current/32:$YOURKIT_MONITOR/current/64:$LD_LIBRARY_PATH

echo Preparing to execute Maven with profiler
echo "Searching for projects in $YOURKIT_MONITOR"

declare -a PROJECTS

for f in `find $YOURKIT_MONITOR -type f -name repository.json -print `; do
PROJECT_ID=`jq -r '.guid' $f`
PROJECT_NAME=`jq -r '.displayName' $f`
echo " - Found project($PROJECT_ID): $PROJECT_NAME"
PROJECTS+=("$PROJECT_ID" "$PROJECT_NAME")
done

if [[ ${#PROJECTS[@]} -eq "0" ]]; then
echo "No projects found in $YOURKIT_MONITOR. Exiting!"
exit 1
fi

# Avoid redirection issues when running script in different terminal context.
TERMINAL=$(tty)
SELECTED_PROJECT=$(dialog --backtitle "YourKit YouMonitor Project Select" --title "Choose" --menu "" 15 80 4 "${PROJECTS[@]}" 2>&1 >$TERMINAL)

clear

if [[ -z "$SELECTED_PROJECT" ]]; then
echo "Nothing selected - exiting..."
exit 0
fi

echo "Starting build using YouMonitor project: $SELECTED_PROJECT"

MAVEN_OPTS="$MAVEN_OPTS -agentlib:youmonitor=repository=$YOURKIT_MONITOR/repositories/$SELECTED_PROJECT"

set -x
env LD_LIBRARY_PATH="$LD_LIBRARY_PATH" MAVEN_OPTS="$MAVEN_OPTS" MAVEN_DEBUG_OPTS="$MAVEN_DEBUG_OPTS" mvn "$@"
Binary file added docs/assets/screenshots/yourkit/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/screenshots/yourkit/02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/screenshots/yourkit/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions docs/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ body > .md-container {
}

.md-typeset code, .md-typeset pre {
/*background-color: hsl(199, 19%, 39%);*/
background-color: hsl(207, 24%, 18%);
background-color: hsl(207, 24%, 17%);
color: #f7f7f7;
}

.md-typeset code {
padding: .25em .5em;
}

.md-typeset .codehilitetable .linenos, .md-typeset .highlighttable .linenos {
background-color: rgb(35, 47, 57);
}
Expand Down
96 changes: 96 additions & 0 deletions docs/developer-guide/yourkit/yourkit-java-profiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# YourKit Java Profiler

## Intro

Having a fast running application requires a lot of efforts to find the cause of memory leaks, high CPU
usage and do overall application profiling. We would like to thank [YourKit][yourkit-link] for sponsoring us and
making our lives much easier!

[![][yourkit-logo]][yourkit-link]

[YourKit][yourkit-link] supports open source projects with innovative and intelligent tools for monitoring and
profiling Java and .NET applications. YourKit is the creator of [YourKit Java Profiler][yourkit-profiler-link],
[YourKit .NET Profiler][yourkit-dotnet-profiler-link] and [YourKit YouMonitor][yourkit-monitor-link].


## Pre-requisites

* JDK 8
* [Running Strongbox instance](../building-strongbox-using-strongbox-instance.md)
* [YourKit Java Profiler][yourkit-profiler-link]
* `YOURKIT_PROFILER` environment variable pointing to the installation path.
* `YOURKIT_PROFILER_AGENT` environment variable pointing to the correct agent

## YourKit Java Profiler

There are a two ways to start profiling:

1. By automatically attaching profiler with an agent (preferred)
2. By manually attaching the profiler to a running JVM ([limitations][yourkit-profiler-manual-attach-limits])

### Agents

All possible OS agents can be found at [YourKit Java Profiler Help page][yourkit-profiler-agnets].

OS | Platform | Agent
------- | ---------------- | -----
Linux | x86, 64-bit Java | `-agentpath:$YOURKIT_PROFILER/bin/linux-x86-64/libyjpagent.so`
macOS | n/a | `-agentpath:$YOURKIT_PROFILER/bin/mac/libyjpagent.dylib`
Windows | x86, 64-bit Java | `-agentpath:%YOURKIT_PROFILER%\bin\win64\yjpagent.dll`

### Start profiling

1. Start [YourKit Java Profiler][yourkit-profiler-link]
1. Set an environment variable with the agent corresponding to your OS:

=== "Linux"
```
YOURKIT_PROFILER_AGENT=-agentpath:$YOURKIT_PROFILER/bin/linux-x86-64/libyjpagent.so
```
=== "MacOS"
```
YOURKIT_PROFILER_AGENT=-agentpath:$YOURKIT_PROFILER/bin/mac/libyjpagent.dylib
```
=== "Windows"
```
set YOURKIT_PROFILER_AGENT=-agentpath:%YOURKIT_PROFILER%\bin\win64\yjpagent.dll
```

2. Start a Strongbox instance

=== "Linux/Mac"
```
For spring-boot:run:
JAVA_TOOL_OPTIONS=$YOURKIT_PROFILER_AGENT mvn spring-boot:run

For strongbox-distribution:
JAVA_TOOL_OPTIONS=$YOURKIT_PROFILER_AGENT ./bin/strongbox start
```

=== "Windows"
```
For spring-boot:run:
set JAVA_TOOL_OPTIONS=%YOURKIT_PROFILER_AGENT%
mvn spring-boot:run

For strongbox-distribution:
set JAVA_TOOL_OPTIONS=%YOURKIT_PROFILER_AGENT%
./bin/strongbox start
```

3. Select `StrongboxSpringBootApplication` in the profiler

## See also

* [YourKit Java Profiler: Help](https://www.yourkit.com/docs/java/help/)
* [YourKit Java Profiler: Local Profiling](https://www.yourkit.com/docs/java/help/local_profiling.jsp)
* [YourKit Java Profiler: Enabling profiling manually](https://www.yourkit.com/docs/java/help/agent.jsp)


[yourkit-logo]: https://www.yourkit.com/images/yk_logo.png
[yourkit-link]: https://www.yourkit.com
[yourkit-profiler-link]: https://www.yourkit.com/java/profiler
[yourkit-dotnet-profiler-link]: https://www.yourkit.com/.net/profiler
[yourkit-monitor-link]: https://www.yourkit.com/youmonitor/
[yourkit-profiler-manual-attach-limits]: https://www.yourkit.com/docs/java/help/attach_agent.jsp#limitations
[yourkit-profiler-agnets]: https://www.yourkit.com/docs/java/help/agent.jsp
108 changes: 108 additions & 0 deletions docs/developer-guide/yourkit/yourkit-youmonitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# YourKit YouMonitor

## Intro

Having a fast running application requires a lot of efforts to find the cause of memory leaks, high CPU
usage and do overall application profiling. In addition to [YourKit Java Profiler][yourkit-profiler-link] we are also
using [YourKit YouMonitor][yourkit-monitor-link] to keep our build times as fast as possible and pin-point slow tests.

[![][yourkit-logo]][yourkit-link]

[YourKit][yourkit-link] supports open source projects with innovative and intelligent tools for monitoring and
profiling Java and .NET applications. YourKit is the creator of [YourKit Java Profiler][yourkit-profiler-link],
[YourKit .NET Profiler][yourkit-dotnet-profiler-link] and [YourKit YouMonitor][yourkit-monitor-link].


## Pre-requisites

* JDK 8
* [Running Strongbox instance](../building-strongbox-using-strongbox-instance.md)
* `YOURKIT_MONITOR` environment variable pointing to the installation path.
* `dialog` (if you use `mvn-profiler.sh`)

## YourKit YouMonitor

### Repository setup

1. When you start [YouMonitor][yourkit-monitor-link] you will see the `Get Started with YouMonitor` screen:

1. Monitor Builds in IDE or Command line
2. Monitor builds on continuous integration server

Since we are using the free version, we are going to be using only be monitoring builds through IDE or command line.
Selecting it will popup a new window - choose `Command Line`

![][yourkit-monitor-welcome-screen]

2. You will be prompted to setup a "repository" - this is where [YouMonitor][yourkit-monitor-link] will
keep the build history. Enter a `(Project) Name` and leave the `Location` as it is.

!!! note
The `Location` points to `$HOME/.youmonitor/repositories/[random-string]` by default.
The same pattern is used later in the [mvn-profiler] bash script.

3. Click `Open Instructions` which will give you instructions on how to `run` a maven build with
[YouMonitor][yourkit-monitor-link]. The instruction will ask you to create a script called `xmvn.sh` with some env vars
exported. Although this works fine, but it fast becomes annoying and error-prone. Continue to the next section for guidance on
automating this.

### mvn-profiler

In order for [YouMonitor][yourkit-monitor-link] to record and keep track of build performance you need to export
`LD_LIBRARY_PATH` and `MAVEN_OPTS` pointing to the correct YouMonitor repository and `LD_LIBRARY`. This quickly becomes
annoying and error-prone when you need to switch between multiple project within Strongbox.

In an attempt to ease this pain, we have created a [mvn-profiler] bash script which does this automatically and allows
you to select existing YouMonitor repositories from `$HOME/.youmonitor/repositories` before starting the maven build.
To install:

1. Download `mvn-profiler.sh`

```
curl -o mvn-profiler \
{{resources}}/yourkit/mvn-profiler.sh
```

2. Install into `/usr/local/bin`
```
sudo mv mvn-profiler /usr/local/bin/mvn-profiler
```

!!! warn
Obviously, this script works only for Linux/MacOS and won't work on Windows.
Pull requests are more than welcome.

## Build Profiling

1. Start YouMonitor

2. Execute
* If you are using `mvn-profiler.sh`:
```
mvn-profiler clean install
```
* If you are using the `xmvn.sh` (as suggested in the instructions):
```
xmvn.sh clean install
```

3. Monitor the build in YouMonitor.

![][yourkit-monitor-monitor-02]
![][yourkit-monitor-monitor-03]


## See also

* [YourKit YouMonitor: Help](https://www.yourkit.com/docs/youmonitor/help/)

[yourkit-logo]: https://www.yourkit.com/images/yk_logo.png
[yourkit-link]: https://www.yourkit.com
[yourkit-profiler-link]: https://www.yourkit.com/java/profiler
[yourkit-dotnet-profiler-link]: https://www.yourkit.com/.net/profiler
[yourkit-monitor-link]: https://www.yourkit.com/youmonitor/
[yourkit-monitor-welcome-screen]: ../../assets/screenshots/yourkit/01.png
[yourkit-monitor-monitor-02]: ../../assets/screenshots/yourkit/02.png
[yourkit-monitor-monitor-03]: ../../assets/screenshots/yourkit/03.png
[mvn-profiler]: #mvn-profiler
[mvn-profiler-link]: {{resources}}/yourkit/mvn-profiler.sh
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ nav:
- AssertJ: developer-guide/assertj-user-guide.md
- Web Form Tests: developer-guide/writing-web-form-tests.md
- Web Integration Tests: developer-guide/writing-web-integration-tests.md
- Performance:
- YourKit Java Profiler: developer-guide/yourkit/yourkit-java-profiler.md
- YourKit YouMonitor: developer-guide/yourkit/yourkit-youmonitor.md
- Using Git:
- Rebasing vs Merging: developer-guide/git/rebase-vs-merge.md
- How To Gather Requirements: developer-guide/how-to-gather-requirements.md
Expand Down