• Stars
    star
    103
  • Rank 322,651 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A monadic java profiler

mjprof

mjprof is a command line monadic java profiler.

Introduction

mjprof is a monadic thread dump analysis tool set. It is a fancy way to say it analyzes jstack output using a series of simple composable building blocks (monads).

Motivation

So, You are out there in the wild vs a production machine. All you have in hand is the "poor man's profiler" jstack. You take one, two, three jstack thread dumps and then you need to look at them manually inside an editor, vi, less, etc.... If you have done it enough times, you probably know that it is a lot of manual work. Especially when you have thousands of threads in your process.

Running mjprof

mjprof reads thread dumps from one or more data sources and writes to the standard output. An example of a data source can be the standard input.

The following will filter out all the threads which are not in RUNNABLE state:
jstack -l pid | ./mjprof.sh contains/state,RUNNABLE/

The commands passed to mjprof consists of several building blocks, monads from now on, concatenated with , (comma) While the monads are relatively simple, mixing and matching them can yield a very thorough analysis, while still allowing you to focus on the data you need. Monad parameters are wrapped with / (instead of () {} or [] which are special chars in the shell) and seperated by ,

Monads

Data Sources

Data sources generate thread dumps and feed them into mjprof. The default data source is stdin. When no data source is specified stdin will be used. When more than one data source is specified the thread dumps generated by all of them will be fed into mjprof.

  • jmx/host:port|MainClass|pid,[count],[sleep],[username],[passwd]/ - Generate dumps via JMX
  • jmxc/host:port|MainClass|pid,[count],[sleep],[username],[passwd]/ - Generate thread dumps via JMX and collect sper thread CPU
  • path/path/ - Read thread dump from file
  • stdin - Read thread dumps from standard input
  • visualvm/path/ - Read profiling session from xml export of VisualVM

Output

  • gui/[title],[maxInvocations]/ - Display current thread dump in a GUI window
  • snapshot/[filename]/ - Write to a file
  • stdout - Writes current stream of thread dumps to stdout

Filters

  • contains/attr,value/ - Returns only threads which contain the string in certain attribute (regexp not supported)
  • -contains/attr,value/ - Returns only threads which do not contain the string (regexp not supported)

Single thread mappers

  • -at - Eliminates the 'at' from the beginning of stack frames
  • bottom/int/ - Returns at most n bottom stack frames of the stack
  • -fn - Eliminates file name and line from stack frames
  • frame/string/ - Eliminates stack frames from all stacks which do not contain string.
  • -frame/string/ - Eliminates stack frames from all stacks which contain string.
  • -namesuffix - Trim the last number from thread names helps to group thread pool threads together
  • noop - Does nothing
  • -pkg - Eliminates package name from stack frames
  • -prop/attr/ - Removes a certain attribute e.g. eliminate/stack/
  • top/int/ - Returns at most n top stack frames of the stack
  • trimbelow/string/ - Trim all stack frames below the first occurrence of string

Full dump mappers:

  • group/[attr]/ - Group a single thread dump by an attribute. If not attribute is specified all dump is merged
  • merge/attribute/ - Combine all dumps to a single one merge based on thread id attribute
  • sort/attr/ - Sorts based on an attribute
  • -sort/string/ - Sorts based on an attribute (descending order)

Terminals:

  • count - counts number of threads

  • ctree - combine all stack traces with colors (UNIX Terminal)

  • flat - Shows flat histogram of the profiles

  • list - lists the possible stack trace attributes

  • tree - combine all stack traces

  • help -Prints this message

Macros:

  • blocked - contains/state,BLOCKED/
  • jvm - ncontains/stack,at/
  • -jvm - contains/stack,at/.ncontains/name,RMI TCP /.ncontains/name,Reference Handle/.ncontains/name,Finalizer/.ncontains/name,JMX server connection timeout/.ncontains/name,RMI Scheduler/
  • locks - stackkeep/- /
  • -locks - stackelim/- /
  • parking - contains/state,TIMED_WAITING/.contains/stack,sun.misc.Unsafe.park/
  • running - contains/state,RUNNABLE/
  • sleeping - contains/state,TIMED_WAITING/
  • waiting - contains/state,WAITING/
  • withstack - contains/stack,at/

Properties

Properties may change from one dump to another and the can also be eliminated by mjstack. Following is the list of usual properties

  • status - The status of the thread
  • nid - Native thread id ( a number)
  • name - Name of thread
  • state - State of thread
  • los - The locked ownable synchronizers part of the stack trace
  • daemon - Whether the thread is a daemon or not
  • tid - The thread id (a number)
  • prio - Thread priority, a number
  • stack - The actual stack trace
  • cpu_ns - cpu consumed in nano seconds
  • wall_ms - wall time in ms for the time frame cpu was recorded
  • %cpu - %cpu of the thread info

You can also get the actual list of properties bu using the list monad.
jstack -l pid | ./mjprof list

Examples

jstack Original output:
jstack -l 38515 > mystack.txt
Keep only thread which their names contain ISCREAM:
jstack -l 38515 | mjprof contains/name,ISCREAM/
Sort them by state
cat mystack.txt | mjprof contains/name,ISCREAM/.sort/state/
Eliminate the Locked Ownable Synchronizers Section
jstack -l 38515 | mjprof contains/name,ISCREAM/.sort/state/.eliminate/los/
Shorten stack traces to include only 10 last stack frames
mjprof jstack/MyAppMainClass/.contains/name,ISCREAM/.sort/state/.eliminate/los/.keeptop/10/
Count threads
mjprof jstack/38515/.contains/name,ISCREAM/.sort/state/.eliminate/los/.keeptop/10/.count

Building MJProf

mjprof uses maven for compilation. In order to build mjprof use the following command line:
mvn clean package This will create a zip file in target/mjprof1.0-bin.zip which contains everything you need.

Writing a plugin

mjprof monadic capabilities can be extended with plugins. If you feel something is missing you can write your own plugin. We will appreciate if you will contribute it back to the community. A plugin is a Java class which is annotated with the com.performizeit.mjprof.plugin.Plugin. The annotation accepts three parameters. "name" the plugin name (must be unique) paramTypes the expected parameter types in the plugin. description one liner that will be used for synopsis. For example:

import com.performizeit.mjprof.api.Plugin;

@Plugin(name="group", paramTypes={String.class},description="Group by an attribute")

There are several plugin types mappers filters terminals etc... for each type you will need to implement a different interface.

Mapper

Implement JStackMapper interface which includes a single method ThreadInfo map(ThreadInfo stck)

Filter

Implement JStackFilter interface which includes a single method boolean filter(ThreadIndo stck)

Terminal

Implement JStackFilter interface which includes a single method void addStackDump(JStackDump jsd)

Comparator

Implement JStackComparator interface which includes a single method int compare(ThreadInfo o1, ThreadInfo o2)

Installing a plugin

In order to install the plugin just drop your jar which contains plugin implementation into the 'plugins' directory inside mjprof installation directory.

More Repositories

1

jitwatch

Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.
Java
2,980
star
2

homebrew-openjdk

AdoptOpenJDK HomeBrew Tap
Ruby
1,828
star
3

openjdk-docker

Scripts for creating Docker images of OpenJDK binaries.
Slim
423
star
4

openjdk-jdk8u

JDK8u mirror from mercurial
Java
350
star
5

openjdk8-binaries

The new home for releases and nightlies for all OpenJDK8 variants and platforms
328
star
6

jdk9-jigsaw

Examples and exercises based on some of the features of jigsaw in JDK9/Jigsaw (Early Access builds)
Java
284
star
7

openjdk-jdk11

Mirror of the jdk/jdk11 Mercurial forest at OpenJDK
Java
242
star
8

jdk-api-diff

Creates a report of all API changes two JDK versions
Java
237
star
9

IcedTea-Web

The new home for IcedTea-Web
Java
211
star
10

openjdk11-binaries

The new home for releases and nightlies for all OpenJDK11 variants and platforms
197
star
11

openjdk8-upstream-binaries

Archived release scripts/releases of OpenJDK 8u project builds. Superseded by Eclipse Temurin releases.
Batchfile
153
star
12

openjdk-jdk11u

Mirror of the jdk-updates/jdk11u Mercurial forest at OpenJDK
Java
145
star
13

openjdk-website

Website source
Handlebars
121
star
14

openjdk-jdk

JDK TIP mirror from https://github.com/openjdk/jdk
Java
109
star
15

lambda-tutorial

Exercises to learn lambda syntax + the Streams API from the upcoming JDK 8 release
Java
108
star
16

openjdk11-upstream-binaries

Archived release scripts/releases of OpenJDK 11u project builds. Superseded by Eclipse Temurin releases.
Batchfile
92
star
17

TSC

The AdoptOpenJDK Technical Steering Committee - Also acts as the knowledge portal for the Adopt OpenJDK GitHub projects
70
star
18

openjdk-jdk-legacy-hg-clone

Mirror of the jdk/jdk Mercurial forest at OpenJDK
Java
62
star
19

adoptopenjdk-getting-started-kit

A one stop guide for developers of all levels, you start with simple and basic know-how and dive deep into the realms of OpenJDK. Know what the Adopt OpenJDK program is about.
Shell
47
star
20

openjdk8-releases

AdoptOpenJDK main binary releases for OpenJDK 8 with HotSpot
47
star
21

jlink.online

Build optimized Java runtimes in your browser!
Go
46
star
22

jheappo

A Heap Dump Analyzer
Java
39
star
23

openjdk-jdk12u

Mirror of http://hg.openjdk.java.net/jdk-updates/jdk12u/
Java
38
star
24

openjdk-api-v3

AdoptOpenJDK API V3 🚀
Kotlin
34
star
25

openjdk16-binaries

The home for releases and nightlies for all AdoptOpenJDK16 variants and platforms
26
star
26

openjdk-jdk9

OpenJDK jdk9 source mirror
Java
24
star
27

jsplitpkgscan

JDK 9+ split package analysis tool
Java
23
star
28

openjdk17-binaries

The home for releases and nightlies for all AdoptOpenJDK17 variants and platforms
18
star
29

openjdk-jdk8u-backup

OpenJDK jdk8u source mirror on master, with selective patches on branch 'dev'.
Java
17
star
30

openjdk12-binaries

The new home for releases and nightlies for all OpenJDK12 variants and platforms
16
star
31

openjdk-api

DEPRECATED and replaced by of https://github.com/AdoptOpenJDK/openjdk-api-v3 - See README
JavaScript
15
star
32

openjdk-aarch64-jdk8u

Mirror of aarch64 jdk8u mercurial forest at OpenJDK
Java
14
star
33

PatchReview

A repo to push patches to for reviewing
Shell
14
star
34

openjdk13-binaries

The new home for releases and nightlies for all OpenJDK13 variants and platforms
13
star
35

openjdk14-binaries

The new home for releases and nightlies for all OpenJDK14 variants and platforms
13
star
36

openjdk-virtual-images

Virtual Images for the Adopt OpenJDK programme
Ruby
11
star
37

install-jdk

Github action that installs SDKs served up by the AdoptOpenJDK API
TypeScript
11
star
38

openjdk-jdk13u

Mirror of the jdk-updates/jdk13u Mercurial forest at OpenJDK
Java
11
star
39

openjdk15-binaries

The new home for releases and nightlies for all OpenJDK15 variants and platforms
9
star
40

ForkJoinPoolMonitor

A ForkJoinPool Monitor prototype for possible inclusion into OpenJDK
Java
9
star
41

openjdk9-openj9-releases

AdoptOpenJDK main binary releases for OpenJDK 9 with Eclipse OpenJ9
9
star
42

openjdk8-openj9-releases

AdoptOpenJDK main binary releases for OpenJDK 8 with Eclipse OpenJ9
9
star
43

openjdk-docker-build-tools

Shell
9
star
44

NashornHackDay

A repo for build instructions & materials related to Nashorn HackDays
JavaScript
9
star
45

openjdk-aarch64-jdk8u-old

Mirror of aarch64 jdk8u mercurial forest at OpenJDK
Java
9
star
46

BuildHelpers

A list of helper scripts for building openjdk.
Shell
8
star
47

openjdk-jdk-old

JDK tip mirror from https://github.com/openjdk/jdk
Java
8
star
48

openjdk-jdk16

JDK16 mirror from https://github.com/openjdk/jdk16
Java
8
star
49

openjdk-jdk16u

JDK16u mirror from https://github.com/openjdk/jdk16u
Java
7
star
50

openjdk10-binaries

The new home for releases and nightlies for all OpenJDK10 variants and platforms
7
star
51

openjdk-jdk8u-backup-31-oct-2018

AdoptOpenJDK GitHub clone of the OpenJDK jdk8u Mercurial forest
Java
6
star
52

adopt-openjdk-kiss-vagrant

Shell
6
star
53

openjdk-jdk14u

JDK14u mirror from https://github.com/openjdk/jdk14u
Java
6
star
54

openjdk9-binaries

The new home for releases and nightlies for all OpenJDK9 variants and platforms
6
star
55

openjdk9-releases

AdoptOpenJDK main binary releases for OpenJDK 9 with HotSpot
5
star
56

openjdk-jdk15

JDK15 mirror from https://github.com/openjdk/jdk15
Java
5
star
57

openjdk-jdk-archived

Mirror of the jdk/jdk Mercurial forest at OpenJDK
Java
5
star
58

semeru17-binaries

4
star
59

TDA

Thread Dump Analysis
Java
4
star
60

openjdk10-releases

AdoptOpenJDK main binary releases for OpenJDK 10 with HotSpot
4
star
61

JavadocUpdaterTool

This is a community copy of Oracle's JavadocUpdaterTool to address a security vulnerability http://www.oracle.com/technetwork/java/javase/downloads/java-doc-updater-tool-1955731.html
Java
4
star
62

openjdk-jdk10u

Mirror of the jdkupdates/jdk10u Mercurial forest at OpenJDK
Java
4
star
63

openjdk-aarch32-jdk8u

Mirror of aarch32 jdk8u mercurial forest at OpenJDK
Java
4
star
64

jsplitpkgscan-maven-plugin

A Maven plugin wrapper for the jsplitpkgscan utility
Java
3
star
65

openjdk-jdk14

JDK14 mirror from https://github.com/openjdk/jdk14
Java
3
star
66

openjdk-aarch32-jdk8u-old

Mirror of aarch32 jdk8u mercurial forest at OpenJDK
Java
3
star
67

openjdk-jdk9u

AdoptOpenJDK GitHub clone of the OpenJDK jdk9u Mercurial forest
Java
3
star
68

website-adoptium

Repo for new Adoptium website
Java
2
star
69

openjdk-jdk15u

JDK15u mirror from https://github.com/openjdk/jdk15u
Java
2
star
70

openjdk-api-java-client

A Java wrapper around the AdoptOpenJDK REST API
Java
2
star
71

semeru8-binaries

2
star
72

openjdk-portola

Mirror of https://github.com/openjdk/portola
Java
2
star
73

blog

The blog of AdoptOpenJDK
JavaScript
2
star
74

semeru11-binaries

2
star
75

openjdk10-nightly

AdoptOpenJDK nightly binary releases for OpenJDK 10 with HotSpot
1
star
76

openjdk-dashboard-v2

The next gen download dashboard
JavaScript
1
star
77

openjdk-amber

The AdoptOpen GitHub clone of http://openjdk.java.net/projects/amber/
Java
1
star
78

openjdk9-openj9-nightly

AdoptOpenJDK nightly binary releases for OpenJDK 9 with Eclipse OpenJ9
1
star
79

openjdk10-openj9-releases

1
star
80

openjdk8-nightly

AdoptOpenJDK nightly binary releases for OpenJDK 8 with HotSpot
1
star
81

openjdk8-dragonwell-binaries

Alibaba Dragonwell8 builds
1
star
82

openjdk-website-next

the next generation adoptopenjdk website 🚀
TypeScript
1
star
83

openjdk-jdk8u-backup-06-sep-2018

OpenJDK jdk8u source mirror on master, with selective patches on branch 'dev'. https://adoptopenjdk.net
Java
1
star