Giter Site home page Giter Site logo

flightmemory's Introduction

FlightMemory

A java flight recording helper

Helper class for production profiling using java flight recorder (JFR)

FlightMemory.recordingAsZip(Duration.ofSeconds(10));

Returns a CompletableFuture<InputStream> to a zipfile which contains:

  • profile-XXX.jfr
  • stacks-XXX.folded
  • _coroutinesDump.txt
    • A kotlin coroutines dump. Debug probes must be installed beforehand (at start), with DebugProbes.install() available in . If debug probes are not installed the file is empty.

Requires the app to run in a JVM with flight recorder classes available (jdk.jfr package), for example java8u262 or higher (jdk not jre) or java11

Depend on it in gradle or maven

repositories {
    ...
    maven { url 'https://jitpack.io' }
}
implementation 'com.github.rrva:flightmemory:0.1.0'

Example usage in a spring boot application:

Here we do a ten second profiling, so we record and return the recording synchronously. For long recordings you might get a HTTP timeout so it might be better to return immediately with a link where the finished recording can be fetched.

Java usage:

import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import io.github.rrva.flightmemory.FlightMemory;
import java.time.LocalDateTime;
import java.time.Duration;
import java.util.concurrent.ExecutionException;


@RestController
public class FlightRecordingController {

    @GetMapping("/profile.jfr.zip")
    public ResponseEntity<InputStreamResource> flightRecorder() throws ExecutionException, InterruptedException {
        LocalDateTime now = LocalDateTime.now();
        InputStreamResource inputStreamResource = 
                new InputStreamResource(FlightMemory.recordingAsZip(Duration.ofSeconds(10)).get());
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);

        httpHeaders.set("Content-Disposition", "attachment; filename=index-profile-"+now+".zip");

        return new ResponseEntity<InputStreamResource>(inputStreamResource, httpHeaders, HttpStatus.OK);
    }
}

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.