diff --git a/README.md b/README.md index ec2f361..09a1d2b 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ *** https://www.markdownguide.org/basic-syntax/#reference-style-links -->
-

Project Name

+

jVaidhiyar

- A template for Java maven projects. + A library for retrieving JVM related resource usage and configuration information.
- Report Bug/Request Feature + Report Bug/Request Feature

[![Contributors][contributors-shield]][contributors-url] @@ -19,15 +19,15 @@ [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![Apache License][license-shield]][license-url]
-![Maven build - Ubuntu latest](https://github.com/padaiyal/jMavenProjectTemplate/workflows/Maven%20build%20-%20Ubuntu%20latest/badge.svg?branch=main) -![Maven build - Windows latest](https://github.com/padaiyal/jMavenProjectTemplate/workflows/Maven%20build%20-%20Windows%20latest/badge.svg?branch=main) -![Maven build - MacOS latest](https://github.com/padaiyal/jMavenProjectTemplate/workflows/Maven%20build%20-%20MacOS%20latest/badge.svg?branch=main) -![Publish to GitHub packages](https://github.com/padaiyal/jMavenProjectTemplate/workflows/Publish%20to%20GitHub%20packages/badge.svg) +![Maven build - Ubuntu latest](https://github.com/padaiyal/jVaidhiyar/workflows/Maven%20build%20-%20Ubuntu%20latest/badge.svg?branch=main) +![Maven build - Windows latest](https://github.com/padaiyal/jVaidhiyar/workflows/Maven%20build%20-%20Windows%20latest/badge.svg?branch=main) +![Maven build - MacOS latest](https://github.com/padaiyal/jVaidhiyar/workflows/Maven%20build%20-%20MacOS%20latest/badge.svg?branch=main) +![Publish to GitHub packages](https://github.com/padaiyal/jVaidhiyar/workflows/Publish%20to%20GitHub%20packages/badge.svg)
@@ -54,15 +54,74 @@ ## About The Project -Describe the project. +This library retrieves the following JVM related information: + - Thread Information (Name, Priority, ID, Stack, CPU usage etc) + - Heap usage information + - Non heap usage information + - VM options + - Heap dump ## Usage -Specify the steps to set up and use the project. +This project is to be used as a dependency to other projects. +Adding this project as a dependency is as follows: + 1. Download the latest jar for this project from [GitHub packages](https://github.com/orgs/padaiyal/packages?repo_name=jVaidhiyar) and place it within + the dependant project. + 2. Add the following dependency tag to the pom.xml of the dependant project: + ``` + + org.java.padaiyal.utilities + vaidhiyar + 2021.02.09 + system + ${basedir}/ + + ``` + NOTE: Refer the [GitHub packages](https://github.com/orgs/padaiyal/packages?repo_name=jVaidhiyar) + / [releases](https://github.com/padaiyal/jVaidhiyar/releases) section for this repo to know + the latest released version of this project. + +Here's a sample snippet showing the usage of JvmUtility: +``` +// Get the heap or non heap memory info. +ExtendedMemoryUsage extendedMemoryUsage = JvmUtility.getHeapMemoryUsage(); // Or JvmUtility.getNonHeapMemoryUsage() +double memoryUsagePercentage = extendedMemoryUsage.getMemoryUsagePercentage(); +long initMemoryInBytes = extendedMemoryUsage.getInit(); +long committedMemoryInBytes = extendedMemoryUsage.getCommitted(); +long maxMemoryInBytes = extendedMemoryUsage.getMax(); + +// Get the configured VM options. +JsonArray vmOptions = JvmUtility.getAllVmOptions(); + +// Information on the most recent garbage collection. +GarbageCollectionInfo[] gcInfos = JvmUtility.getGarbageCollectionInfo(); + +// IDs of all threads running in the JVM. +long[] threadIds = JvmUtility.getAllThreadsId(); + +// Get information on JVM threads. +int threadStackDepth = 10; +ExtendedThreadInfo[] extendedThreadInfos = JvmUtility.getAllExtendedThreadInfo(threadStackDepth); +double threadCpuUsage = extendedThreadInfos[0].getCpuUsage(); +ThreadInfo threadInfo = extendedThreadInfos[0].getThreadInfo(); +long threadMemoryAllocatedInBytes = extendedThreadInfos[0].getMemoryAllocatedInBytes(); + +// Generate a heap dump. +Path destinationDirectory = ...; +String heapDumpFileName = "heapDump.hprof"; +boolean dumpOnlyLiveObjects = false; +JvmUtility.generateHeapDump( + destinationDirectory, + heapDumpFileName, + dumpOnlyLiveObjects +); +... +``` +For more such examples, checkout [JvmUtilityTest](https://github.com/padaiyal/jVaidhiyar/tree/main/src/test/java/org/padaiyal/utilities/vaidhiyar/JvmUtilityTest.java) ## Roadmap -See the [open issues](https://github.com/padaiyal/jMavenProjectTemplate/issues) for a list of proposed features (and known issues). +See the [open issues](https://github.com/padaiyal/jVaidhiyar/issues) for a list of proposed features (and known issues). ## Contributing @@ -77,18 +136,18 @@ Contributions are what make the open source community such an amazing place to b ## License -Distributed under the Apache License. See [`LICENSE`](https://github.com/padaiyal/jMavenProjectTemplate/blob/main/LICENSE) for more information. +Distributed under the Apache License. See [`LICENSE`](https://github.com/padaiyal/jVaidhiyar/blob/main/LICENSE) for more information. -[contributors-shield]: https://img.shields.io/github/contributors/padaiyal/jMavenProjectTemplate.svg?style=for-the-badge -[contributors-url]: https://github.com/padaiyal/jMavenProjectTemplate/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/padaiyal/jMavenProjectTemplate.svg?style=for-the-badge -[forks-url]: https://github.com/padaiyal/jMavenProjectTemplate/network/members -[stars-shield]: https://img.shields.io/github/stars/padaiyal/jMavenProjectTemplate.svg?style=for-the-badge -[stars-url]: https://github.com/padaiyal/jMavenProjectTemplate/stargazers -[issues-shield]: https://img.shields.io/github/issues/padaiyal/jMavenProjectTemplate.svg?style=for-the-badge -[issues-url]: https://github.com/padaiyal/jMavenProjectTemplate/issues -[license-shield]: https://img.shields.io/github/license/padaiyal/jMavenProjectTemplate.svg?style=for-the-badge -[license-url]: https://github.com/padaiyal/jMavenProjectTemplate/blob/master/LICENSE +[contributors-shield]: https://img.shields.io/github/contributors/padaiyal/jVaidhiyar.svg?style=for-the-badge +[contributors-url]: https://github.com/padaiyal/jVaidhiyar/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/padaiyal/jVaidhiyar.svg?style=for-the-badge +[forks-url]: https://github.com/padaiyal/jVaidhiyar/network/members +[stars-shield]: https://img.shields.io/github/stars/padaiyal/jVaidhiyar.svg?style=for-the-badge +[stars-url]: https://github.com/padaiyal/jVaidhiyar/stargazers +[issues-shield]: https://img.shields.io/github/issues/padaiyal/jVaidhiyar.svg?style=for-the-badge +[issues-url]: https://github.com/padaiyal/jVaidhiyar/issues +[license-shield]: https://img.shields.io/github/license/padaiyal/jVaidhiyar.svg?style=for-the-badge +[license-url]: https://github.com/padaiyal/jVaidhiyar/blob/master/LICENSE