An exploration for running analytics on JDK Flight Recorder recordings

Overview

JFR Analytics

An exploration for running analytics on JDK Flight Recorder recordings.

There's two areas of interest:

  • Pull-based SQL queries on JFR recording files, using Apache Calcite (work in progress)
  • Streaming queries on realtime JFR event streams (implementation tbd., e.g. via Apache Flink or Akka Streams; not started yet)

Running SQL Queries on JFR Recordings

Each JFR event type gets mapped to a table named after the type, e.g. jdk.ObjectAllocationSample, jdk.ClassLoad, etc. Each event attribute gets mapped to a table column. These tables can be queried programmatically using JDBC or ad-hoc using SQLLine. See here for a list of all built-in JFR event types and their attributes.

Running Queries Via JDBC

Queries against a JFR file can be run using standard JDBC like shown below (this query retrieves the ten top allocating stacktraces):

Path jfrFile = ...; // path to some-recording.jfr

Properties properties = new Properties();
properties.put("model", JfrSchemaFactory.INLINE_MODEL.formatted(jfrFile));

try (Connection connection = DriverManager.getConnection("jdbc:calcite:", properties)) {
    PreparedStatement statement = connection.prepareStatement("""
            SELECT TRUNCATE_STACKTRACE("stackTrace", 40), SUM("weight")
            FROM "jfr"."jdk.ObjectAllocationSample"
            GROUP BY TRUNCATE_STACKTRACE("stackTrace", 40)
            ORDER BY SUM("weight") DESC
            LIMIT 10
            """);

    try (ResultSet rs = statement.executeQuery()) {
        while (rs.next()) {
            System.out.printlne("Trace : " + rs.getString(1));
            System.out.printlne("Weight: " + rs.getSLong(2));
        }
    }
}

Running Queries Using SQLLine

Using SQLLine, you can run ad-hoc SQL queries against a given JFR file. First build the project using the sqlline profile, which will copy SQLLine and all the project dependencies into the target/lib folder. Then run SQLLine as shown below:

mvn clean verify -Psqlline -Dquick
java --class-path "target/lib/*:target/jfr-analytics-1.0.0-SNAPSHOT.jar" sqlline.SqlLine

Within SQLLine, you can "connect" to a given JFR recording file like so:

(SELECT "startTime" FROM "jfrunit.Reset") GROUP BY TRUNCATE_STACKTRACE("stackTrace", 40) ORDER BY SUM("weight") DESC LIMIT 10;">
!connect jdbc:calcite:schemaFactory=org.moditect.jfranalytics.JfrSchemaFactory;schema.file=src/test/resources/object-allocations.jfr dummy dummy

!tables # shows all tables (i.e. JFR event types)
!columns "jdk.ObjectAllocationSample" # shows all columns (i.e. JFR event attributes)

!outputformat vertical

SELECT TRUNCATE_STACKTRACE("stackTrace", 40), SUM("weight")
FROM "jdk.ObjectAllocationSample"
WHERE "startTime" > (SELECT "startTime" FROM "jfrunit.Reset")
GROUP BY TRUNCATE_STACKTRACE("stackTrace", 40)
ORDER BY SUM("weight") DESC
LIMIT 10;

Built-in Functions

There's a set of functions for working with JFR attribute types such as jdk.jfr.consumer.RecordedClass and jdk.jfr.consumer.RecordedStackTrace.

Function Description
VARCHAR CLASS_NAME(RecordedClass) Obtains the fully-qualified class name from the given jdk.jfr.consumer.RecordedClass
VARCHAR TRUNCATE_STACKTRACE(RecordedStackTrace, INT) Truncates the stacktrace of the given jdk.jfr.consumer.RecordedStackTrace to the given depth

Build

Run the following command to build this project:

mvn clean verify

Pass the -Dquick option to skip all non-essential plug-ins and create the output artifact as quickly as possible:

mvn clean verify -Dquick

Run the following command to format the source code and organize the imports as per the project's conventions:

mvn process-sources

License

This code base is available under the Apache License, version 2.

You might also like...

Simple animated PNG and GIF screen recorder

Simple animated PNG and GIF screen recorder

Japagoge (PNG and GIF screen recorder) Warning In Linux. If you get black screen as grabbing result, then it is bug JDK-8269245. You can switch your s

Sep 5, 2022

Apache Druid: a high performance real-time analytics database.

Apache Druid: a high performance real-time analytics database.

Website | Documentation | Developer Mailing List | User Mailing List | Slack | Twitter | Download Apache Druid Druid is a high performance real-time a

Jan 1, 2023

Apache Spark - A unified analytics engine for large-scale data processing

Apache Spark Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, and an op

Jan 2, 2023

Apache Druid: a high performance real-time analytics database.

Apache Druid: a high performance real-time analytics database.

Website | Documentation | Developer Mailing List | User Mailing List | Slack | Twitter | Download Apache Druid Druid is a high performance real-time a

Jan 2, 2023

Web-based notebook that enables data-driven, interactive data analytics and collaborative documents with SQL, Scala and more.

Apache Zeppelin Documentation: User Guide Mailing Lists: User and Dev mailing list Continuous Integration: Contributing: Contribution Guide Issue Trac

Jan 8, 2023

Apache Druid: a high performance real-time analytics database.

Apache Druid: a high performance real-time analytics database.

Website | Documentation | Developer Mailing List | User Mailing List | Slack | Twitter | Download Apache Druid Druid is a high performance real-time a

Jan 9, 2023

:elephant: Elasticsearch real-time search and analytics natively integrated with Hadoop

Elasticsearch Hadoop Elasticsearch real-time search and analytics natively integrated with Hadoop. Supports Map/Reduce, Apache Hive, Apache Pig, Apach

Dec 22, 2022

FLiP: StreamNative: Cloud-Native: Streaming Analytics Using Apache Flink SQL on Apache Pulsar

FLiP: StreamNative: Cloud-Native: Streaming Analytics Using Apache Flink SQL on Apache Pulsar

StreamingAnalyticsUsingFlinkSQL FLiP: StreamNative: Cloud-Native: Streaming Analytics Using Apache Flink SQL on Apache Pulsar Running on NVIDIA XAVIER

Dec 19, 2021

Scalable Time Series Data Analytics

Scalable Time Series Data Analytics

Time Series Data Analytics Working with time series is difficult due to the high dimensionality of the data, erroneous or extraneous data, and large d

Dec 7, 2022

A Spigot plugin that tracks statistics with InfluxDB for timescale analytics.

A Spigot plugin that tracks statistics with InfluxDB for timescale analytics.

RiceStats I made this plugin for my SMP server. It's able to track statistics and send it to InfluxDB where it can be processed by an analytics progra

Dec 24, 2022

DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API.

DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API. It has been deliberately developed with no 3rd party jars with the goal of being a lean, reliable and scalable solution.

Dec 16, 2022

Provides additional date-time classes that complement those in JDK 8

ThreeTen-Extra ThreeTen-Extra provides additional date-time classes that complement those in JDK 8. Not every piece of date/time logic is destined for

Jan 8, 2023

JCTools - Concurrency tools currently missing from the JDK.

JCTools Java Concurrency Tools for the JVM. This project aims to offer some concurrent data structures currently missing from the JDK: SPSC/MPSC/SPMC/

Dec 28, 2022

Alibaba Dragonwell8 JDK

Alibaba Dragonwell8 JDK

Alibaba Dragonwell8 User Guide Alibaba Dragonwell8 Release Notes Introduction Over the years, Java has proliferated in Alibaba. Many applications are

Dec 30, 2022

Automon combines the power of AOP (AspectJ) with monitoring or logging tools you already use to declaratively monitor your Java code, the JDK, and 3rd party libraries.

Automon combines the power of AOP (AspectJ) with monitoring or logging tools you already use to declaratively monitor your Java code, the JDK, and 3rd party libraries.

Automon Automon combines the power of AOP (AspectJ) with monitoring tools or logging tools that you already use to declaratively monitor the following

Nov 27, 2022

JDK 17 development

Welcome to the JDK! For build instructions please see the online documentation, or either of these files: doc/building.html (html version) doc/buildin

Dec 8, 2022

JDK main-line development

Welcome to the JDK! For build instructions please see the online documentation, or either of these files: doc/building.html (html version) doc/buildin

Dec 29, 2022

JDKMon - A little tool written in JavaFX that monitors your installed JDK's and inform you about updates

JDKMon - A little tool written in JavaFX that monitors your installed JDK's and inform you about updates

JDKMon JDKMon Home JDKMon is a little tool written in JavaFX that tries to detect all JDK's installed on your machine and will inform you about new up

Jan 3, 2023
Comments
  • Different newlines on Windows

    Different newlines on Windows

    Summary

    WIndows has trouble with newlines and I'm not sure how you want to proceed.

    Failure

    When I run JfrSchemaFactoryTest.canRunSimpleSelectFromClassLoad on Windows, it fails on column 2 because the newlines are different:

    assertThat(rs.getString(2)).isEqualTo("""
            {
              classLoader = null
              name = "java/lang/Throwable"
              package = {
                name = "java/lang"
                module = {
                  name = "java.base"
                  version = "17"
                  location = "jrt:/java.base"
                  classLoader = null
                }
                exported = true
              }
              modifiers = 33
              hidden = false
            }
            """);
    

    Cause

    JfrSchema.getConverter is using the following converter:

    else if (field.getTypeName().equals("java.lang.Class")) {
        LOGGER.log(INFO, "| -> java.lang.Class");
        return event -> event.getClass(field.getName());
    }
    

    I believe when the testcase calls rs.getString(), this is calling RecordedClass.toString() which ultimately uses StructuredWriter.lineSeparator which is initialized to String.format("%n"), and this differs by platform.

    Possible solutions

    Should we return the java.lang.Class in this case, rather than the RecordedClass object? The Class.toString() method should produce the same result on all platforms.

    opened by prdoyle 2
  • Support all the JFR event attribute types

    Support all the JFR event attribute types

    • [x] boolean
    • [x] char
    • [x] byte
    • [x] short
    • [x] int
    • [x] long
    • [x] float
    • [x] double
    • [x] String
    • [ ] Thread
    • [x] Class
    • [x] ClassLoader
    • [x] StackTrace
    • [ ] jdk.ReservedStackActivation::method: jdk.types.Method
    • [ ] jdk.GCHeapSummary::heapSpace: jdk.types.VirtualSpace
    • [ ] jdk.MetaspaceSummary::metaspace: jdk.types.MetaspaceSizes
    • [ ] jdk.PSHeapSummary::oldObjectSpace: jdk.types.ObjectSpace
    • [ ] jdk.G1EvacuationYoungStatistics::statistics: jdk.types.G1EvacuationStatistics
    • [ ] jdk.PromotionFailed::promotionFailed: jdk.types.CopyFailed
    • [ ] jdk.CompilerInlining::callee: jdk.types.CalleeMethod
    • [ ] jdk.OldObjectSample::object: jdk.types.OldObject
    • [ ] jdk.OldObjectSample::root: jdk.types.OldObjectGcRoot
    • [ ] jdk.ModuleRequire::source: jdk.types.Module
    • [ ] jdk.ModuleExport::exportedPackage: jdk.types.Package
    opened by gunnarmorling 0
Owner
ModiTect
A family of open-source projects related to Java Modules, Flight Recorder, and more
ModiTect
Get Method Sampling from Java Flight Recorder Dump and convert to FlameGraph compatible format.

Note: Travis has removed the support for Oracle JDK 8. Therefore the build status is removed temporarily. Converting JFR Method Profiling Samples to F

M. Isuru Tharanga Chrishantha Perera 248 Dec 16, 2022
Tool for creating reports from Java Flight Recorder dumps

jfr-report-tool Tool for creating reports from Java Flight Recorder dumps. Influenced by https://github.com/chrishantha/jfr-flame-graph . Kudos to @ch

Lari Hotari 50 Oct 28, 2022
Generate flame graph in HTML format from jfr(Java Flight Recorder) file

jfr-flamegraph-generator Generate Flame Graph from .jfr file. Get Started Executable jar and executable binary for Linux, Windows and macOS are provid

Lawrence Ching 3 Sep 22, 2022
Simple, Scalable. Trace-Recorder is a trace recorder.

Trace-Recorder It's Scalable. Simple, Scalable, High-Powered. Trace-Recorder is a trace recorder, mainly in order to better record the source code flo

WangCai 40 Dec 24, 2022
Halo plug-in capacity experimental exploration.

Halo plugin experimental Halo 博客插件化的功能性探索。 简介 插件管理能力位于 extensions 目录下 plugins 目录下为插件示例 在插件和 Halo 主应用共用 ApplicationContext 还是 插件使用独立的 ApplicationContex

guqing 8 Jul 17, 2022
Docker-compose-integration-tstst - An exploration of how to run integration tests against an application that has inconvenient external dependencies (e.g. a SQL database).

Tstst? it was supposed to be docker-compose-integration-tests but i was too lazy to fix it at the outset, and now im trying to convince myself its fun

null 1 Jan 4, 2022
A Java Virtual Machine - running on a Java Virtual Machine - running on a (jk).

Javaception A Java Virtual Machine - running on a Java Virtual Machine - running on a (jk). Goals JVMS compliant Java Virtual Machine Somewhat fast Re

null 33 Oct 10, 2022
Dual Camera, IMU, and GPS data recorder for Android

Visual-Inertial Recorder (VIRec) Record camera frames at ~30fps from one or two camera sensors, Inertial Measurement Unit (IMU) measurements at ~100Hz

AUT 3D Vision 17 Oct 24, 2022