Giter Club home page Giter Club logo

jstackseries.sh's Introduction

jstackSeries.sh

Bash jstack script for capturing a series of thread dumps from a Java process on Linux.

Just run it like this:

sudo -u java-process-user-id sh jstackSeries.sh pid [[count] delay]

For example: sudo -u javauser sh jstackSeries.sh 1234 10 3

  • javauser is the user that owns the java process
  • 1234 is the pid of the Java process
  • 10 is how many thread dumps to take
  • 3 is the delay between each dump

Note:

  • The script must run as the user that owns the java process.
  • The top output has the native thread id in decimal format while the jstack output has the "nid" in hexadecimal. You can match the thread id (PID) from the top output to the jstack output by converting the thread id to hexadecimal. This provides CPU profiling at the Java thread level.

jstackSeriesAEM.sh

Bash jstack script for capturing a series of thread dumps from an Adobe Experience Manager Java process on Linux.

Make these modifications to the script:

  • Update the JAVA_HOME variable to point to the path of where java is installed.
  • Update the AEM_HOME variable to point to the path of where AEM is installed.

Just run it like this:

sudo -u aem-process-user-id sh jstackSeriesAEM.sh [[count] delay]

For example: sudo -u aemuser sh jstackSeriesAEM.sh 10 3

  • aemuser is the user that owns the java process that runs AEM
  • 10 is how many thread dumps to take
  • 3 is the delay between each dump

Note:

  • The script will automatically try to get the AEM process' PID. It will first look for ${AEM_HOME}/crx-quickstart/conf/cq.pid, if that file is non-existent or empty it would fail over to "ps -aux | grep $AEM_JAR" where variable $AEM_JAR is the name of the jar file. If it fails with both of those it would report an error.
  • Thread dumps and top output would automatically be generated under crx-quickstart/logs/threaddumps in a subfolder with the PID and a timestamp in the name.

MS Windows - Powershell Script

NOTE - Makes the assumption that jstack is on the Windows Environmental Variables PATH

Usage

Command:

jstackSeries_powershell.ps1 <pid> <num_threads> <time_between_threads_seconds>

Step 1

Provide the script the location of jstack.exe via one of the following methods:

  1. Add the JDK bin folder to the windows Path and reopen the powershell.
  2. Set the JAVA_HOME environment variable to the JDK home directory and reopen the powershell.
  3. Or modify the jstackSeries_powershell.ps1 script and set the script:jstackbin variable to the full path of jstack.exe.

The "TOP" output is not similar to the Linux top output and there's some things to understand.

Regular expressions to match "long" running threads.

CPUTime \(Sec\)        : ([0-9]{2,}\.[0-9]{1,}) 
CPUTime \(Sec\)        : ([0-9]{3,}\.[0-9]{1,})

$ProcessThread.TotalProcessorTime

A TimeSpan that indicates the amount of time that the associated process has spent utilizing the CPU. This value is the sum of the UserProcessorTime and the PrivilegedProcessorTime.

$ProcessThread.UserProcessorTime

User CPUTime (%)

A TimeSpan that indicates the amount of time that the associated process has spent running code inside the application portion of the process (not inside the operating system core).

$ProcessThread.privilegedProcessorTime

System CPUTime (%)

A TimeSpan that indicates the amount of time that the process has spent running code inside the operating system core.

jstackseries.sh's People

Contributors

andrewmkhoury avatar johnb4 avatar kalyanar avatar somarc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jstackseries.sh's Issues

Cannot convert 'System.Object[]' to the type 'System.String

Hello, I was trying to use your ps script but it throw error:

Out-File : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported.
At line:1 char:66

  • ... e -append -Encoding ascii -filepath .\jstack.17044.1.1602071301,79466
  •                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Out-File], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.OutFileCommand

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.