import com.jprofiler.gradle.TestProfile

plugins {
    id 'com.jprofiler' version '16.2.1'
    id 'java'
}

// Execute ../gradlew in this directory to compile and run the custom probe.
// See src/main/java/probe/AWTEventProbe.java for more information.

jprofiler {
    installDir = jprofilerHome
}
defaultTasks 'run'

dependencies {
    // This artifact contains the API for writing the embedded probe, it is also available in the "$JPROFILER_HOME/api" directory
    implementation "com.jprofiler:jprofiler-probe-embedded:$version"
    testImplementation 'junit:junit:4.12'
    // This artifact contains the API for controlling recording, it is only used in the test
    testImplementation "com.jprofiler:jprofiler-controller:$version"
}

/*
Starts the load test that will profile the server and write a snapshot to the "snapshots" directory below the
build directory. The full path of the snapshot will be printed on the console.
Open the snapshot in JProfiler and navigate to the JEE & Probes->Factorial Cache/Factorial Server probes
as well as the CPU call tree view to see the recorded data.
 */
task run(type: TestProfile) {
    outputs.upToDateWhen { false } // always execute test even if nothing has changed

    offline = true
    configFile = file("../common/jprofiler_config.xml")
    sessionId = 80
    // This is the directory where the JProfiler snapshot will be saved
    workingDir = file(findProperty('snapshotsDir') ?: layout.buildDirectory.dir("snapshots").get().asFile)
    workingDir.mkdirs()

    filter {
        includeTestsMatching 'FactorialServerLoadTest'
    }
}