@@ -119,6 +119,9 @@ type Command struct {
119119 FileExtension string
120120 FileLabel string
121121 FileNamePart string
122+ // Run the command in a subfolder of the container
123+ GenerateArbitraryFiles bool
124+ GenerateArbitraryFilesFolderName string
122125}
123126
124127var commands = []Command {
215218 OnlyOnRecentSapMachine : true ,
216219 RequiredTools : []string {"asprof" },
217220 GenerateFiles : false ,
221+ GenerateArbitraryFiles : true ,
222+ GenerateArbitraryFilesFolderName : "asprof" ,
218223 SshCommand : `$ASPROF_COMMAND $(pidof java) $$ARGS` ,
219224 },
220225 {
244249 NeedsFileName : true ,
245250 FileExtension : ".jfr" ,
246251 FileNamePart : "asprof" ,
247- SshCommand : `$ASPROF_COMMAND start $$ARGS -f $$FILE_NAME -e ctimer $(pidof java)` ,
252+ SshCommand : `$ASPROF_COMMAND start $$ARGS -f $$FILE_NAME -e cpu $(pidof java)` ,
248253 },
249254 {
250255 Name : "start-asprof-wall-clock-profile" ,
@@ -352,7 +357,7 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
352357 }
353358
354359 command := commands [index ]
355- if ! command .GenerateFiles {
360+ if ! command .GenerateFiles && ! command . GenerateArbitraryFiles {
356361 for _ , flag := range fileFlags {
357362 if commandFlags .IsSet (flag ) {
358363 return "" , & InvalidUsageError {message : fmt .Sprintf ("The flag %q is not supported for %s" , flag , command .Name )}
@@ -382,10 +387,10 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
382387
383388 for _ , requiredTool := range command .RequiredTools {
384389 uppercase := strings .ToUpper (requiredTool )
385- var toolCommand = fmt .Sprintf ("%s_COMMAND=$(find -executable -name %s | head -1 | tr -d [:space:]); if [ -z \" ${%s_COMMAND}\" ]; then echo \" %s not found\" ; exit 1; fi" , uppercase , requiredTool , uppercase , requiredTool )
390+ var toolCommand = fmt .Sprintf ("%s_COMMAND=$(realpath $( find -executable -name %s | head -1 | tr -d [:space:]) ); if [ -z \" ${%s_COMMAND}\" ]; then echo \" %s not found\" ; exit 1; fi" , uppercase , requiredTool , uppercase , requiredTool )
386391 if requiredTool == "jcmd" {
387392 // add code that first checks whether asprof is present and if so use `asprof jcmd` instead of `jcmd`
388- remoteCommandTokens = append (remoteCommandTokens , toolCommand , "ASPROF_COMMAND=$(find -executable -name asprof | head -1 | tr -d [:space:]); if [ -n \" ${ASPROF_COMMAND}\" ]; then JCMD_COMMAND=\" ${ASPROF_COMMAND} jcmd\" ; fi" )
393+ remoteCommandTokens = append (remoteCommandTokens , toolCommand , "ASPROF_COMMAND=$(realpath $( find -executable -name asprof | head -1 | tr -d [:space:]) ); if [ -n \" ${ASPROF_COMMAND}\" ]; then JCMD_COMMAND=\" ${ASPROF_COMMAND} jcmd\" ; fi" )
389394 } else {
390395 remoteCommandTokens = append (remoteCommandTokens , toolCommand )
391396 }
@@ -398,15 +403,23 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
398403 "$$APP_NAME" : applicationName ,
399404 }
400405
401- if command .GenerateFiles || command .NeedsFileName {
406+ if command .GenerateFiles || command .NeedsFileName || command . GenerateArbitraryFiles {
402407 fspath , err = util .GetAvailablePath (applicationName , remoteDir )
403408 if err != nil {
404409 return "" , err
405410 }
411+ if command .GenerateArbitraryFiles {
412+ fspath = fspath + "/" + command .GenerateArbitraryFilesFolderName
413+ }
406414
407415 fileName = fspath + "/" + applicationName + "-" + command .FileNamePart + "-" + uuidGenerator .Generate () + command .FileExtension
408416 replacements ["$$FILE_NAME" ] = fileName
409417 replacements ["$$FSPATH" ] = fspath
418+ if command .GenerateArbitraryFiles {
419+ // prepend 'mkdir -p $$FSPATH' to the command to create the directory if it does not exist
420+ remoteCommandTokens = append ([]string {"mkdir -p " + fspath }, remoteCommandTokens ... )
421+ remoteCommandTokens = append (remoteCommandTokens , "cd " + fspath )
422+ }
410423 }
411424
412425 var commandText = command .SshCommand
@@ -472,6 +485,34 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
472485 fmt .Println (toSentenceCase (command .FileLabel ) + " file deleted in app container" )
473486 }
474487 }
488+ if command .GenerateArbitraryFiles {
489+ // download all files in the generic folder
490+ files , err := util .ListFiles (cfSSHArguments , fspath )
491+ if err != nil {
492+ return "" , err
493+ }
494+ if copyToLocal {
495+ for _ , file := range files {
496+ localFileFullPath := localDir + "/" + file
497+ err = util .CopyOverCat (cfSSHArguments , fspath + "/" + file , localFileFullPath )
498+ if err == nil {
499+ fmt .Printf ("File %s saved to: %s\n " , file , localFileFullPath )
500+ } else {
501+ return "" , err
502+ }
503+ }
504+ } else {
505+ fmt .Println (toSentenceCase (command .FileLabel ) + " will not be copied as parameter `local-dir` was not set" )
506+ }
507+
508+ if ! keepAfterDownload {
509+ err = util .DeleteRemoteFile (cfSSHArguments , fspath )
510+ if err != nil {
511+ return "" , err
512+ }
513+ fmt .Println ("File folder deleted in app container" )
514+ }
515+ }
475516 // We keep this around to make the compiler happy, but commandExecutor.Execute will cause an os.Exit
476517 return strings .Join (output , "\n " ), err
477518}
0 commit comments