2

I tried to automate the JProfiler in offline mode to connect to a running JVM using below batch script. I am not able to pass command-file which would take the inputs to the JProfiler. I am still unsure what format do I need to pass to the JProfiler. I tried passing as text and File formats but no luck.

BatchScript.bat

@echo off
TITLE "Profiling an application using JPofiler"

echo ***********Running JProfiler in non-interactive mode*****************

set "JPROFILER_HOME=C:\dev\jprofiler11"
set JPROFILER_CONFIG_FILE_LOCATION=C:\dev\profiler_start_script\config.xml

"%JPROFILER_HOME%"\bin\jpenable.exe --offline --id=116 --config=%JPROFILER_CONFIG_FILE_LOCATION%

if %ERRORLEVEL% NEQ 0 (
    set ERROR= Jpenable is not able to profile the selected JVM, check JPROFILER_HOME and JPROFILER_CONFIG_FILE_LOCATION is set to correct location.
    goto endError)

set /p PID=Enter the process id of the JVM:

SET "JPCONTRL=%JPROFILER_HOME%\bin\jpcontroller.exe"

"%JPCONTRL%" -n --non-interactive -f **--command-file=C:\dev\profiler_start_script\commands** %PID%

goto end
:endError
echo Error: %ERROR%

:end
endlocal

Commands

startCPURecording true
saveSnapshot C:\dev\build\trunk\WBScheduler\snapshot.jps
stopCPURecording

Can anyone tell me what format do i need to send the inputs file to the JProfiler? I am using Jprofiler 11+ version.

1 Answers1

1

The arguments to jpcontroller.exe should be

-n --non-interactive -f C:\dev\profiler_start_script\commands %PID%

Also, the commands should include a sleep, otherwise there will be no data in the snapshot:

startCPURecording true
sleep 10
stopCPURecording
saveSnapshot C:\dev\build\trunk\WBScheduler\snapshot.jps

Just tested this with JProfiler 11.1.4. If your problem persists, please include the error message. Also try to invoke the commands manually.

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
  • 1
    It worked. Shouldn't add the "--command-file=". Thank you so much @Ingo Kegel – Naresh kumar vadakatta Jun 29 '21 at 05:53
  • Can I get the commands to record probes like jdbc and cpu at the same time? Is there any documentation about the commands that can be passed?. https://www.ej-technologies.com/resources/jprofiler/help/doc/commandLine/profilingExecutables.html I checked this page no commands are described there. Any help would be helpful. – Naresh kumar vadakatta Jun 29 '21 at 05:59
  • 1
    Each probe recording has to be started separately. The available commands are the method names of the remote controller MBean: https://www.ej-technologies.com/resources/jprofiler/help/api/javadoc/com/jprofiler/api/agent/mbean/RemoteControllerMBean.html – Ingo Kegel Jun 29 '21 at 07:49
  • 1
    Had to use the commands like below and it worked: startCPURecording true startProbeRecording builtin.JdbcProbe true false sleep 15 saveSnapshot snapshot.jps stopCPURecording stopProbeRecording builtin.JdbcProbe – Naresh kumar vadakatta Jun 30 '21 at 13:52