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: theScriptContextbelow, a per-script state store that survives across invocations.clazz: theClassof 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 andObjectotherwise. Add application JARs withrecordingConfig.advanced.scriptClassPathto 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 name | Kind | File |
|---|---|---|
com.jprofiler.agent.scripts.ComplexityScript | interface | ComplexityScript |
com.jprofiler.agent.scripts.ExpandParameter | annotation | ExpandParameter |
com.jprofiler.agent.scripts.ProbeScript | interface | ProbeScript |
com.jprofiler.agent.scripts.SplitScript | interface | SplitScript |
com.jprofiler.api.agent.ScriptContext | interface | ScriptContext |
Package com.jprofiler.agent.scripts
ComplexityScript
Import: import com.jprofiler.agent.scripts.ComplexityScript;
interface ComplexityScript
Methods
| Signature | Returns | Description |
|---|---|---|
enter(ScriptContext, Class, Object, Object, Object, Object, Object, Object) | long | |
enter(ScriptContext, Class, Object, Object[]) | long |
##### 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
| Signature | Returns | Description |
|---|---|---|
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
| Signature | Returns | Description |
|---|---|---|
enter(ScriptContext, Class, Object, Object, Object, Object, Object, Object) | String | |
enter(ScriptContext, Class, Object, Object[]) | String |
##### 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
| Signature | Returns | Description |
|---|---|---|
getObject(Object) | Object | Returns the value for the specified key in the script context. |
putObject(Object, Object) | Object | Store a key-value pair in the script context. |
getLong(Object) | long | Returns the long value for the specified key in the script context. |
putLong(Object, long) | long | Store a key-value pair of value type long in the script context. |
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 keyvalue— the value
Returns: the value that was previously associated with the specified key, or null if there was no mapping for the key.
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
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 keyvalue— the long value
Returns: the value that was previously associated with the specified key, or 0 if there was no mapping for the key.