diff --git a/CHANGELOG.md b/CHANGELOG.md index d33048e..f2427cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,4 @@ - `btrace-extension-authoring` skill for designing a new extension against a target library. - `jafar-perf` `compare` skill covers the `jfr_compare` significance rules and thin-data results that follow jafar `v0.29.0`. - `btrace-observability` MCP server runs BTrace `3.0.0-RC1` from Maven Central instead of the 3.0.0 snapshot. +- `jafar-perf` skills say how the pinned jfr-mcp `0.29.0` attributes samples to threads, reads `jfr_use`/`jfr_tsa` time windows and counts multi-chunk results, and what changes from the first release after it (btraceio/jafar #204, #206, #248). diff --git a/plugins/jafar-perf/agents/concurrency-analyst.md b/plugins/jafar-perf/agents/concurrency-analyst.md index 6799379..17d7697 100644 --- a/plugins/jafar-perf/agents/concurrency-analyst.md +++ b/plugins/jafar-perf/agents/concurrency-analyst.md @@ -1,7 +1,7 @@ --- name: concurrency-analyst description: Specialist for thread and contention analysis of a JFR recording — thread states, monitor contention, parking, executor queue saturation, and per-endpoint latency attribution. Dispatch when triage shows threads blocked or waiting rather than running, or when the complaint is p99 latency rather than throughput. -tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_tsa, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_stackprofile, mcp__plugin_jafar-perf_jafar__pprof_tsa, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_tsa, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_flamegraph, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_stackprofile, mcp__plugin_jafar-perf_jafar__pprof_tsa, Read, Grep, Glob skills: latency, report model: sonnet --- @@ -13,7 +13,10 @@ If you were not given an open session id, open the artifact yourself and close i Run `jfr_tsa` with `correlateBlocking=true` first and read `stateDistribution` before anything else — if the recording is RUNNABLE-dominated this is a CPU question and you -should say so rather than manufacturing a contention story. +should say so rather than manufacturing a contention story. If one thread named `unknown` +holds every sample, the result came from the pinned jfr-mcp 0.29.0. That release cannot +attribute `jdk.ExecutionSample` samples to threads, so report no per-thread findings or +`totalThreads` from it (see the `latency` skill). Keep `jdk.JavaMonitorEnter` (blocked acquiring) separate from `jdk.JavaMonitorWait` (waiting on a condition); they mean different things. Rank monitors by summed duration @@ -22,5 +25,6 @@ first-class: queued work cannot be recovered by faster methods. Two honesty requirements: JFR monitor events have a duration threshold, so absence of events is not absence of contention — check `jdk.ActiveSetting` if it matters. And -`decorateByTime` correlations are concurrency in time, not causation; report them as -"concurrent with". +`jfr_tsa` correlations are concurrency in time, not causation; report them as +"concurrent with". Find contending code from the monitor and park events' own stack traces, +not by joining execution samples with `decorateByTime`, as the `latency` skill explains. diff --git a/plugins/jafar-perf/skills/cpu/SKILL.md b/plugins/jafar-perf/skills/cpu/SKILL.md index f3513be..2af42ab 100644 --- a/plugins/jafar-perf/skills/cpu/SKILL.md +++ b/plugins/jafar-perf/skills/cpu/SKILL.md @@ -57,7 +57,10 @@ A frame is worth reporting when all three hold: present in one bucket out of ten is an event, not a hotspot. The `steady-hotspot` category means it persisted. 3. It is not an artifact of one thread doing something unrepresentative. Check - `threadCounts{}` in the same output. + `threadCounts{}` in the same output. Its keys are thread names. jfr-mcp 0.29.0, which this + plugin pins, prefers the OS name to the Java name. From the first release after 0.29.0, + the Java name of the sampled thread comes first, as in `jfr_tsa`. Do not match thread + labels across output from the two versions. ``` jfr_stackprofile buckets=10 minPct=1.0 @@ -72,8 +75,10 @@ them using event decoration: jfr_query query="events/jdk.ExecutionSample | decorateByKey(datadog.Endpoint, key=localRootSpanId, decoratorKey=localRootSpanId, fields=endpoint) | groupBy($decorator.endpoint)" ``` -For time-overlap correlation instead of a key join, use `decorateByTime` — see the -`latency` skill for the same technique applied to locks. +For time-overlap correlation instead of a key join, `decorateByTime` matches events that +overlap **on the same thread**. Execution samples carry their thread in `sampledThread`, not +`eventThread`, so the thread path matters: see the `jfrpath` skill before joining samples +this way, and expect matches only with events recorded on the sampled threads themselves. ## Mapping frames to source diff --git a/plugins/jafar-perf/skills/gc/SKILL.md b/plugins/jafar-perf/skills/gc/SKILL.md index dab0c81..f881745 100644 --- a/plugins/jafar-perf/skills/gc/SKILL.md +++ b/plugins/jafar-perf/skills/gc/SKILL.md @@ -93,14 +93,25 @@ jfr_flamegraph eventType=jdk.ObjectAllocationSample direction=bottom-up format=f not the bytes of that one object. Report it as an estimated rate (MB/s), never as an exact total. -## 5. What is running during GC +## 5. Collector cost versus application cost + +Execution samples cannot show what the collector costs. JFR samples Java threads only, so GC +worker threads never appear in `jdk.ExecutionSample`, and a stop-the-world pause stops the +Java threads it would sample. Do not join samples with GC phase events through +`decorateByTime`: it matches events on the same thread, and GC phases are recorded on GC +threads, so almost nothing matches. + +Read the collector's CPU time from `jdk.GCCPUTime` (present in JDK 21 recordings) when `jfr_list_types` +shows it: ``` -jfr_query query="events/jdk.ExecutionSample | decorateByTime(jdk.GCPhase, fields=name) | groupBy($decorator.name, agg=count)" +jfr_query query="events/jdk.GCCPUTime | stats(userTime)" +jfr_query query="events/jdk.GCCPUTime | stats(systemTime)" ``` -Useful for separating application cost from collector cost when a profile looks unexpectedly -hot in JVM-internal frames. +The pause share of wall clock from step 1 covers the time application threads lost. A +profile hot in JVM-internal frames on application threads is usually allocation slow paths: +read it with the allocation flame graph in step 4. ## Recommendations worth making diff --git a/plugins/jafar-perf/skills/jfrpath/SKILL.md b/plugins/jafar-perf/skills/jfrpath/SKILL.md index d6a49d0..ecad87b 100644 --- a/plugins/jafar-perf/skills/jfrpath/SKILL.md +++ b/plugins/jafar-perf/skills/jfrpath/SKILL.md @@ -77,11 +77,12 @@ events/jdk.JavaMonitorEnter[startTime>= and duration>10ms] read in the server's local timezone — write the offset when the hour matters. These are JfrPath filters on epoch time. The `startTime` and `endTime` *parameters* of -`jfr_use` and `jfr_tsa` are a different thing — nanoseconds from the recording's start; the -`latency` skill covers them. +`jfr_use` and `jfr_tsa` are read differently depending on the server version. The `latency` +skill covers them. -**What a query costs on a large recording.** Two choices decide it, and neither changes the -result: +**What a query costs on a large recording.** From the first release after 0.29.0, two +choices decide it. Neither changes the result, and both are harmless on the pinned +jfr-mcp 0.29.0, which decodes every event of every chunk whatever the query: - **Name the event type.** Only the event types a query names are decoded, so a query for one rare type does not pay for decoding the common ones. @@ -124,12 +125,27 @@ events/jdk.FileRead | select(path, formatDuration(duration) as dur) | sortBy(dur ### Correlation ``` -decorateByTime(, fields=f1,f2 [, threadPath=] [, decoratorThreadPath=]) +decorateByTime(, [threadPath=,] [decoratorThreadPath=,] fields=f1,f2) decorateByKey(, key=, decoratorKey=, fields=f1,f2) ``` -`decorateByTime` matches events overlapping in time **on the same thread** (thread path -defaults to `eventThread/javaThreadId`). `decorateByKey` joins on a shared correlation id — +`decorateByTime` matches events overlapping in time **on the same thread**. How the thread +is found when `threadPath`/`decoratorThreadPath` are omitted depends on the server version: + +- **jfr-mcp 0.29.0, which this plugin pins:** `eventThread/javaThreadId` on both sides. + `jdk.ExecutionSample` and `jdk.NativeMethodSample` have no `eventThread`; their thread is + `sampledThread`. With these samples as either side, nothing matches unless you name the + path, e.g. `threadPath=sampledThread/javaThreadId`. On 0.29.0, put every named parameter + **before** `fields=`. A parameter after `fields=` is read as one more field name. +- **From the first release after 0.29.0:** each event's own thread, `sampledThread` for + samples, else `eventThread`, and a named parameter after `fields=` parses. + +The same rule applies to filters and grouping. `sampledThread/javaName` and +`sampledThread/javaThreadId` are the thread of a sample, and `eventThread/…` is null for +every `jdk.ExecutionSample` and `jdk.NativeMethodSample`. Other events, including +`datadog.ExecutionSample`, carry `eventThread`. + +`decorateByKey` joins on a shared correlation id — prefer it when one exists, as it is exact and cheaper. Decorated fields are read with the `$decorator.` prefix and work in `groupBy`, `select` and filters. diff --git a/plugins/jafar-perf/skills/latency/SKILL.md b/plugins/jafar-perf/skills/latency/SKILL.md index 55b318e..22a3b02 100644 --- a/plugins/jafar-perf/skills/latency/SKILL.md +++ b/plugins/jafar-perf/skills/latency/SKILL.md @@ -1,7 +1,7 @@ --- name: latency description: Investigate response-time problems that are not CPU-bound — lock contention, thread parking, executor queue saturation, blocking I/O, and per-endpoint latency attribution. Use when the user reports slow requests, p99 spikes, timeouts, deadlock suspicion, or when triage shows threads blocked rather than running. -allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_tsa mcp__plugin_jafar-perf_jafar__jfr_use mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__jfr_stackprofile mcp__plugin_jafar-perf_jafar__pprof_tsa +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_tsa mcp__plugin_jafar-perf_jafar__jfr_use mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_flamegraph mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__jfr_stackprofile mcp__plugin_jafar-perf_jafar__pprof_tsa --- # Latency analysis @@ -26,6 +26,18 @@ Thread State Analysis returns: Read `stateDistribution` first. If most time is `RUNNABLE`, this is a CPU problem — switch to the `cpu` skill. If it is dominated by blocked, waiting or parked states, continue here. +Check the thread attribution before reading the per-thread fields. jfr-mcp 0.29.0, the +version this plugin pins, reads each sample's thread from `eventThread`, which +`jdk.ExecutionSample` and `jdk.NativeMethodSample` do not have. On a recording with those +samples it files every sample under one thread named `unknown`, so `threadProfiles`, +`topThreadsByState` and `totalThreads` describe that one pseudo-thread, and the active-thread +count of `jfr_use` is wrong for the same reason. `stateDistribution` is still usable, because +it does not depend on the thread. Recordings whose samples carry `eventThread`, such as +`datadog.ExecutionSample`, are not affected. From the first release after 0.29.0, samples are +attributed to their `sampledThread`; events without one, such as `jdk.JavaMonitorEnter` in +`correlations`, still use `eventThread`. A single `unknown` thread holding all the samples +therefore identifies a 0.29.0 result: do not report its per-thread findings. + ## 2. Which resource is saturated? ``` @@ -43,25 +55,32 @@ Narrow the window when the recording spans a mix of load levels. `jfr_use` and ` take the same two optional bounds: ``` -jfr_use startTime= endTime= resources=threads -jfr_tsa startTime= endTime= correlateBlocking=true +jfr_use startTime= endTime= resources=threads +jfr_tsa startTime= endTime= correlateBlocking=true ``` -`startTime` and `endTime` are nanoseconds from the recording's start. An epoch-nanosecond -timestamp — the `startTime` of an event, copied from a query result — is also accepted, so -the events that bracket a spike can be used as the bounds directly. The window selects -events by their start time. +Pass epoch-nanosecond bounds: the `startTime` of an event, copied from a query result, such +as the events that bracket a spike. The window selects events by their start time. How a +bound is read depends on the server version: + +- **jfr-mcp 0.29.0, which this plugin pins,** compares the bounds directly with event start + times, which are epoch nanoseconds. Epoch bounds therefore work. An offset from the + recording's start does not: as `startTime` it excludes nothing, and as `endTime` it + excludes every event. +- **From the first release after 0.29.0,** `startTime` and `endTime` are nanoseconds from the + recording's start, and a value at or after the recording's start is read as an epoch + timestamp. Epoch bounds therefore work on both versions. -Confirm the window before reading the metrics. The result's `timeWindow` repeats -`startTime` and `endTime` as given and adds `recordingStartEpochNanos`, -`startTimeEpochNanos` and `endTimeEpochNanos`, which show how the bounds were interpreted. -Check that they cover the interval you meant, and quote them in the report. +Confirm the window before reading the metrics, and quote it in the report. From the first +release after 0.29.0, the result's `timeWindow` repeats `startTime` and `endTime` as given +and adds `recordingStartEpochNanos`, `startTimeEpochNanos` and `endTimeEpochNanos`, which +show how the bounds were read. Check that the last two cover the interval you meant. -- A `timeWindow` without those three fields comes from a server that predates this contract. - It compares the bounds with epoch timestamps as given, so offsets from the recording's - start select nothing. Do not report such a result as windowed. -- If the recording's start cannot be read, the call fails rather than guessing. Report the - failure; do not substitute the whole-recording result. +- A `timeWindow` with only `startTime` and `endTime` comes from 0.29.0. The window was + applied as given, so it is right only if both bounds were epoch nanoseconds from this + recording. A result for offset bounds is not windowed: do not report it as such. +- From the first release after 0.29.0, if the recording's start cannot be read, the call fails + rather than guessing. Report the failure; do not substitute the whole-recording result. - `jfr_tsa` answering with only a `message` that no execution samples fell in the window means the window is empty, not that the threads were idle. @@ -82,17 +101,26 @@ them. jfr_query query="events/jdk.JavaMonitorEnter | groupBy(monitorClass, agg=sum, value=duration) | top(10, by=value)" ``` -To find *what code* was contending, correlate execution samples with the wait window on the -same thread: +To find *what code* was contending, read the stack traces of the monitor events themselves. +Each event records the stack of the thread that blocked or waited. Build one graph per event +type and keep them apart, as above: ``` -jfr_query query="events/jdk.ExecutionSample | decorateByTime(jdk.JavaMonitorWait, fields=monitorClass,duration) | groupBy($decorator.monitorClass, agg=count) | top(10, by=count)" +jfr_flamegraph eventType=jdk.JavaMonitorEnter direction=bottom-up format=folded +jfr_flamegraph eventType=jdk.JavaMonitorWait direction=bottom-up format=folded ``` -`decorateByTime` joins events that overlap in time **on the same thread** (thread path -defaults to `eventThread/javaThreadId`). Rows where `$decorator.monitorClass` is null were -sampled outside any wait — that is the uncontended baseline, and it belongs in the report -as the comparison. +The first shows where threads blocked acquiring a monitor, the second where they waited on a +condition. `java.util.concurrent` locks and queues do neither; their waiting is +`jdk.ThreadPark`, covered next, and `jfr_flamegraph eventType=jdk.ThreadPark` gives its code +paths the same way. + +Do not use `jdk.ExecutionSample | decorateByTime(jdk.JavaMonitorWait, …)` for this. +`decorateByTime` joins events that overlap in time **on the same thread**, and JFR takes no +execution sample of a thread while it waits, so almost every row comes back undecorated. +Those rows do not show an uncontended baseline. On jfr-mcp 0.29.0 the default thread paths +are `eventThread/javaThreadId` on both sides, and execution samples have no `eventThread`, so +that join decorates no sample at all. ## 4. Parking and sleeping diff --git a/plugins/jafar-perf/skills/report/SKILL.md b/plugins/jafar-perf/skills/report/SKILL.md index 3faf85e..0379d9f 100644 --- a/plugins/jafar-perf/skills/report/SKILL.md +++ b/plugins/jafar-perf/skills/report/SKILL.md @@ -85,6 +85,13 @@ jfr_query query="events/jdk.JavaMonitorEnter | groupBy(monitorClass, agg=sum, va For a regression claim, both artifacts and the comparison call are the reproduction — see the `compare` skill. +Name the jfr-mcp version in the reproduction. On a recording with more than one chunk, the +pinned jfr-mcp 0.29.0 can return short results that differ from run to run: in `jfr_query`, +`count()`, `sum`, `stats`, `groupBy`, row listings and `flamegraph()`, and the output of +`jfr_flamegraph`, which runs the same query engine. From the first release after 0.29.0 they +are exact and repeatable. A small difference between two runs on +0.29.0 is therefore this defect, not a property of the recording. + ## What a recommendation must contain Not "reduce allocations" but: the file and line, the change, and the expected effect with diff --git a/plugins/jafar-perf/skills/triage/SKILL.md b/plugins/jafar-perf/skills/triage/SKILL.md index ba3826b..6947778 100644 --- a/plugins/jafar-perf/skills/triage/SKILL.md +++ b/plugins/jafar-perf/skills/triage/SKILL.md @@ -47,7 +47,10 @@ jfr_diagnose Returns `findings[]` and `recommendations[]`, and runs the USE and TSA analyses in-process so the resource and thread-state picture arrives with the first call. Treat its output as a *routing decision*, not a conclusion — it applies fixed thresholds and knows nothing about -your service's normal behaviour. +your service's normal behaviour. On the pinned jfr-mcp 0.29.0, the TSA pass files every +`jdk.ExecutionSample` under one thread named `unknown`, so a finding about a single +problematic thread is not evidence about any real thread. The `latency` skill explains how +to recognise this. Read `capabilityGaps` before you believe a negative result. "ALLOCATION PROFILING: Not enabled in this recording" means you cannot conclude anything about allocation, not that