Search code examples
jprofiler

Not able to pass the command-file in Jprofiler


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.


Solution

  • 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.