Profile Operations
open()
Load a profile from a file.Path to profile file. Supports:
- JFR:
.jfr,.jfr.gz - pprof:
.pb,.pb.gz - Collapsed text: any other extension
- Stdin: use
"-"
Event type to load:
"cpu", "wall", "alloc", or "lock". For formats without event metadata (collapsed text), this is used as the label.JFR only. Window start time. Go duration syntax:
"5s", "1m30s". Times are relative to recording start.JFR only. Window end time. Go duration syntax.
Filter to stacks with thread names containing this substring.
Profile object.
Examples:
diff()
Compare two profiles by self%.First profile (“before”).
Second profile (“after”).
Minimum percentage point change to include in results.
Limit entries per category (regressions, improvements, etc.).
0 = unlimited.Use fully-qualified names. Changes aggregation granularity.
Diff object with:
.regressions- Methods with increased self% (sorted by delta descending).improvements- Methods with decreased self% (sorted by delta ascending).added- Methods only in second profile.removed- Methods only in first profile.all- All entries sorted by absolute delta descending
list[DiffEntry] where each entry has:
.name- Method name (string).fqn- Fully-qualified name (string).before- Self% in first profile (float).after- Self% in second profile (float).delta- Change in percentage points (float)
Output Functions
emit()
Write a single stack in collapsed format to stdout.Stack to emit.
[thread];frame1;frame2;... count
ap-query hot for visualization:
emit_all()
Write all stacks from a profile in collapsed format.Profile to emit.
fail()
Print message to stderr and exit with code 1.Error message to print.
warn()
Print message to stderr and continue.Warning message to print.
String Functions
round()
Round a float to specified decimal places.Number to round.
Number of decimal places (0-15).
Starlark’s
%f format specifier doesn’t support precision modifiers like %.2f. Use round() instead.ljust()
Left-justify a value with spaces (pad right).Value to justify. Automatically converted to string.
Minimum width in characters. If value is already wider, returned unchanged.
rjust()
Right-justify a value with spaces (pad left).Value to justify. Automatically converted to string.
Minimum width in characters.
Utility Functions
match()
Match a string against a regular expression (RE2 syntax).String to test.
RE2 regex pattern.
For simple substring matching, use Python’s
in operator or stack.has():Duration Parsing
Duration strings use Go syntax:"5s"- 5 seconds"1m30s"- 1 minute 30 seconds"2h"- 2 hours"500ms"- 500 milliseconds
open(start=..., end=...)timeline(resolution=...)split([...])
Built-in Functions
Starlark provides these built-ins (no import needed):len(x)- Length of list/dict/stringsorted(list, key=None, reverse=False)- Sort a listenumerate(list)- Iterate with index:for i, item in enumerate(list)range(n)/range(start, end, step)- Generate numeric rangesstr(x),int(x),float(x)- Type conversionslist(x),dict(x)- Create collectionstype(x)- Get type name as stringhasattr(obj, name)- Check if attribute existsmin(...),max(...),abs(x)- Numeric operationszip(a, b)- Iterate pairsany(list),all(list)- Boolean aggregatesrepr(x)- Representation stringreversed(list)- Reverse iteration