Skip to content

Commit ce3b42e

Browse files
committed
Improve alias generation
1 parent a462f98 commit ce3b42e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ Please do not create GitHub issues for security-related doubts or problems.
304304

305305
## Changelog
306306

307+
### Snapshot
308+
- Added `cf java generate-alias-script` to generate a script that can be used via `source script.sh`,
309+
adding commands like `vm-info` (with optional pid argument) to your shell
310+
307311
### 4.0.0-rc
308312

309313
- Profiling and JCMD related features

cf_cli_java_plugin.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ var commands = []Command{
153153
Description: "Generate a heap dump from a running Java application",
154154
GenerateFiles: true,
155155
FileExtension: ".hprof",
156+
RequiredTools: []string{"jmap", "jvmmon"},
156157
/*
157-
If there is not enough space on the filesystem to write the dump, jmap will create a file
158+
If there is not enough space on the filesystem to write the dump, jmap will create a file
158159
with size 0, output something about not enough space left on the device, and exit with status code 0.
159160
Because YOLO.
160161
@@ -180,17 +181,16 @@ SIZE=-1; OLD_SIZE=$(stat -c '%s' "${HEAP_DUMP_NAME}"); while [ ${SIZE} != ${OLD_
180181
if [ ! -s "${HEAP_DUMP_NAME}" ]; then echo >&2 ${OUTPUT}; $$EXIT 1; fi
181182
if [ ${STATUS_CODE:-0} -gt 0 ]; then echo >&2 ${OUTPUT}; exit ${STATUS_CODE}; fi
182183
fi`,
184+
AliasCommand: "$JMAP_COMMAND -dump:format=b,file=$$FILE_NAME $$PIDOF_JAVA_APP",
183185
FileLabel: "heap dump",
184186
FileNamePart: "heapdump",
185-
OmitAlias: true,
186187
},
187188
{
188189
Name: "thread-dump",
189190
Description: "Generate a thread dump from a running Java application",
190191
RequiredTools: []string{"jstack", "jvmmon"},
191192
GenerateFiles: false,
192-
SshCommand: "${JSTACK_COMMAND} $$PIDOF_JAVA_APP; ${JVMMON_COMMAND} -pid $$PIDOF_JAVA_APP -c \"print stacktrace\"",
193-
OmitAlias: true,
193+
SshCommand: "${JSTACK_COMMAND} $$PIDOF_JAVA_APP; ${JVMMON_COMMAND} -pid $$PIDOF_JAVA_APP -c \"print stacktrace\" 2> /dev/null",
194194
},
195195
{
196196
Name: "vm-info",
@@ -404,7 +404,7 @@ func toSentenceCase(input string) string {
404404

405405
func generateRequiredToolCommand(requiredTool string) []string {
406406
uppercase := strings.ToUpper(requiredTool)
407-
var ret = []string{fmt.Sprintf(`%s_COMMAND=$(which %s 2>/dev/null || command -v %s 2>/dev/null)
407+
var ret = []string{fmt.Sprintf(`%s_COMMAND=$(which %s 2>/dev/null || command -v %s 2>/dev/null || echo '___NOT_FOUND___')
408408
if [ -z "${%s_COMMAND}" ]; then
409409
if [ -n "$JAVA_HOME" ]; then
410410
%s_COMMAND=$(find "$JAVA_HOME/bin" -name %s -type f -executable 2>/dev/null | head -1)
@@ -415,7 +415,8 @@ fi`, uppercase, requiredTool, requiredTool, uppercase, uppercase, requiredTool)}
415415
ret = append(ret, fmt.Sprintf(`ASPROF_COMMAND=$(which asprof 2>/dev/null || command -v asprof 2>/dev/null)
416416
if [ -n "${ASPROF_COMMAND}" ]; then
417417
JCMD_COMMAND="${ASPROF_COMMAND} jcmd"
418-
fi`))
418+
fi
419+
`))
419420
}
420421
return ret
421422
}

0 commit comments

Comments
 (0)