Method script API

A resource document of the JProfiler MCP server. Back to the tool and resource reference.

For agent consumption, this page is also available as raw Markdown.

Content of the MCP resource jprofiler://api/method-scripts of the JProfiler MCP server, see the tool and resource reference for the full list of tools and resources.

API reference for the scripts of recordingConfig.advanced.splitMethods, recordingConfig.advanced.complexityMethods and recordingConfig.advanced.scriptProbes: the script text is compiled as the body of the script interface method - SplitScript.enter returns the split key string (null leaves the invocation unsplit), ComplexityScript.enter returns the input size of the invocation as a long, ProbeScript.getPayload returns the payload string of a script probe event (null records no payload).

Available parameters:

  • scriptContext: the ScriptContext below, a per-script state store that survives across invocations.
  • clazz: the Class of the declaring class of the instrumented method.
  • currentObject: the instance the method is invoked on, null for static methods.
  • param0, param1, ...: the declared method parameters in order, statically typed when their classes are on the compile classpath and Object otherwise. Add application JARs with recordingConfig.advanced.scriptClassPath to get static typing.

The script runs on every invocation of the method, so keep it cheap and do not instrument extremely hot methods.

Types

Flat alphabetical index of every type in the API. Use this when you know the qualified name and want to skip package navigation.

Qualified nameKindFile
com.jprofiler.agent.scripts.ComplexityScriptinterfaceComplexityScript
com.jprofiler.agent.scripts.ExpandParameterannotationExpandParameter
com.jprofiler.agent.scripts.ProbeScriptinterfaceProbeScript
com.jprofiler.agent.scripts.SplitScriptinterfaceSplitScript
com.jprofiler.api.agent.ScriptContextinterfaceScriptContext

Package com.jprofiler.agent.scripts

ComplexityScript

Import: import com.jprofiler.agent.scripts.ComplexityScript;

interface ComplexityScript

Methods

##### enter(ScriptContext, Class, Object, Object, Object, Object, Object, Object)

long enter(ScriptContext scriptContext, Class clazz, Object object, Object p0, Object p1, Object p2, Object p3, Object p4) throws Exception

##### enter(ScriptContext, Class, Object, Object[])

long enter(ScriptContext scriptContext, Class clazz, Object object, Object[] parameters) throws Exception

ExpandParameter

Import: import com.jprofiler.agent.scripts.ExpandParameter;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface ExpandParameter implements Annotation

ProbeScript

Import: import com.jprofiler.agent.scripts.ProbeScript;

@ExpandParameter
interface ProbeScript

Methods

SignatureReturnsDescription
getPayload(ScriptContext, Class<?>, Object, Object[])String

##### getPayload(ScriptContext, Class<?>, Object, Object[])

String getPayload(ScriptContext scriptContext, Class<?> declaringClass, Object instance, Object[] arguments) throws Exception

SplitScript

Import: import com.jprofiler.agent.scripts.SplitScript;

interface SplitScript

Methods

##### enter(ScriptContext, Class, Object, Object, Object, Object, Object, Object)

String enter(ScriptContext scriptContext, Class clazz, Object object, Object p0, Object p1, Object p2, Object p3, Object p4) throws Exception

##### enter(ScriptContext, Class, Object, Object[])

String enter(ScriptContext scriptContext, Class clazz, Object object, Object[] parameters) throws Exception

Package com.jprofiler.api.agent

ScriptContext

Import: import com.jprofiler.api.agent.ScriptContext;

interface ScriptContext

Context object that is passed to all scripts and provides ways to store key-value pairs for all subsequent invocations of any custom script.

For example, if you need to calculate the change of an observed numeric value between script invocations, you can use the context as follows:

    long previousValue = scriptContext.getLong("myValue");
    long currentValue = ...;
    long delta = currentValue - previousValue;
    // Use delta
    scriptContext.putLong("myValue", currentValue); // for the next invocation of the script

Methods

SignatureReturnsDescription
getObject(Object)ObjectReturns the value for the specified key in the script context.
putObject(Object, Object)ObjectStore a key-value pair in the script context.
getLong(Object)longReturns the long value for the specified key in the script context.
putLong(Object, long)longStore a key-value pair of value type long in the script context.

##### getObject(Object)

Object getObject(Object key)

Returns the value for the specified key in the script context.

Parameters:

  • key — the key

Returns: the value, or null if there was no mapping for the key.

##### putObject(Object, Object)

Object putObject(Object key, Object value)

Store a key-value pair in the script context. An existing mapping is overwritten.

Parameters:

  • key — the key
  • value — the value

Returns: the value that was previously associated with the specified key, or null if there was no mapping for the key.

##### getLong(Object)

long getLong(Object key)

Returns the long value for the specified key in the script context.

Parameters:

  • key — the key

Returns: the long value, or 0 if there was no mapping

##### putLong(Object, long)

long putLong(Object key, long value)

Store a key-value pair of value type long in the script context. An existing mapping is overwritten.

Parameters:

  • key — the key
  • value — the long value

Returns: the value that was previously associated with the specified key, or 0 if there was no mapping for the key.