Unverified Commit 456f30f0 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Summarize raw trace memory and compact sample output

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent bc26003c
......@@ -139,8 +139,8 @@ pub struct TraceSpanInfo {
/// matter what each allocated. Rank concurrent work by allocation fields;
/// `peak` is the figure to quote for memory actually in use.
///
/// Computed from at most 200 temporary peak-memory rows, independently
/// of whether or how many sample values are requested.
/// Computed directly from all captured readings in the span's range,
/// independently of whether or how many sample values are requested.
pub memory_summary: Option<TraceMemorySummary>,
/// Requested value arrays; absent unless `samples` was supplied.
/// MCP flattens this internal object to the four optional value arrays.
......@@ -164,8 +164,8 @@ pub struct TraceSpanSampleSeries {
/// Aggregate view of a span's TurboMalloc memory samples.
#[napi(object)]
pub struct TraceMemorySummary {
/// Number of samples in the span's range, after downsampling.
pub count: u32,
/// Number of captured readings in the span's range, without downsampling.
pub count: i64,
/// Live bytes at the first sample in the range.
pub start: i64,
/// Live bytes at the last sample in the range.
......@@ -230,7 +230,7 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo {
self_allocation_count: s.self_allocation_count as i64,
memory_summary: s.memory_summary.map(|m| TraceMemorySummary {
count: m.count as u32,
count: m.count as i64,
start: m.start as i64,
end: m.end as i64,
min: m.min as i64,
......
......@@ -779,7 +779,7 @@ export declare function teardownTraceSubscriber(
/** Aggregate view of a span's TurboMalloc memory samples. */
export interface TraceMemorySummary {
/** Number of samples in the span's range, after downsampling. */
/** Number of captured readings in the span's range, without downsampling. */
count: number
/** Live bytes at the first sample in the range. */
start: number
......@@ -964,8 +964,8 @@ export interface TraceSpanInfo {
* matter what each allocated. Rank concurrent work by allocation fields;
* `peak` is the figure to quote for memory actually in use.
*
* Computed from at most 200 temporary peak-memory rows, independently
* of whether or how many sample values are requested.
* Computed directly from all captured readings in the span's range,
* independently of whether or how many sample values are requested.
*/
memorySummary?: TraceMemorySummary
/**
......
......@@ -39,8 +39,7 @@ export function renderSampleSeriesMarkdown(
return ''
}
let md =
'\n**Sample values:** Memory/pressure/workers use recorded sample groups; concurrency uses equal-time segments. Indices are not shared timestamps.\n'
let md = '\nSample indices are not shared timestamps.\n'
const metrics: [string, number[], (value: number) => string][] = [
['Memory (TurboMalloc live bytes)', series.memorySamples, formatBytes],
['Memory pressure', series.memoryPressureSamples, (value) => `${value}%`],
......@@ -48,15 +47,7 @@ export function renderSampleSeriesMarkdown(
['Concurrency', series.concurrencySamples, (value) => value.toFixed(2)],
]
for (const [name, values, format] of metrics) {
md += `\n**${name}:**\n\n`
if (values.length === 0) {
md += '_No samples._\n'
continue
}
md += '| Sample | Value |\n| ---: | ---: |\n'
for (const [index, value] of values.entries()) {
md += `| ${index + 1} | ${format(value)} |\n`
}
md += `${name} samples: ${values.length ? values.map(format).join(' ') : 'none'}\n`
}
return md
}
......@@ -211,7 +211,7 @@ export async function startTurboTraceServerCli(
'',
'Allocations: `allocations` / `deallocations` / `allocationCount` and `persistentAllocations`, each with a `self*` counterpart excluding children. Comparing a total to its `self` shows whether a span allocates directly or only through descendants.',
'',
'`persistentAllocations` ranks allocators; it is NOT retained memory. It is allocated-minus-freed per TurboMalloc counters, which never see turbo-tasks cell or cache drops, so a total far above real peak RSS is expected rather than a leak. For absolute memory use `memorySummary` (count/start/end/min/peak/maxPressure/maxFootprint, precomputed from the legacy, at-most-200 max-memory rows, independent of requested sample details; maxFootprint is the process RSS peak, 0 = not reported).',
'`persistentAllocations` ranks allocators; it is NOT retained memory. It is allocated-minus-freed per TurboMalloc counters, which never see turbo-tasks cell or cache drops, so a total far above real peak RSS is expected rather than a leak. For absolute memory use `memorySummary` (count/start/end/min/peak/maxPressure/maxFootprint, computed directly from all captured readings in the span range, independent of requested sample details; maxFootprint is process RSS bytes, 0 = not reported).',
'',
"But live heap is process-wide: a span's samples are just the global series sliced to its time range, so concurrent spans report identical memory however much each allocated. Rank concurrent work by the allocation fields, never by memory.",
'',
......@@ -219,7 +219,7 @@ export async function startTurboTraceServerCli(
'',
'For aggregated groups every allocation field is a group total, while `cpuDuration`, `correctedDuration`, `memorySummary` and requested samples describe the example span only. `firstSpanId` is first in execution order; use `heaviestSpanId` to reach the member holding the most bytes.',
'',
"Set `samples: N` (a nonnegative safe integer, including values above 200) to include up to N values per series: `memorySamples` (TurboMalloc live bytes, not RSS), `memoryPressureSamples` (percent), `activeWorkerThreadsSamples` (non-parked scheduler workers, excluding blocking-pool threads), and `concurrencySamples` (global average self-time concurrency, rounded to hundredths; blocking=true spans do not contribute their own time). Without `samples`, JSON omits all four fields; `samples: 0` includes four empty arrays. Memory/worker rows use each recorded group's peak-memory sample; pressure uses each group's maximum. Concurrency uses equal-time segments, so indices are not shared timestamps. JSON returns number arrays (not the previous timestamped tuples); markdown includes formatted sample tables. `memorySummary.count` still counts its independent at-most-200 summary rows.",
"Set `samples: N` (a nonnegative safe integer, including values above 200) to include up to N values per series: `memorySamples` (TurboMalloc live bytes, not RSS), `memoryPressureSamples` (percent), `activeWorkerThreadsSamples` (non-parked scheduler workers, excluding blocking-pool threads), and `concurrencySamples` (global average self-time concurrency, rounded to hundredths; blocking=true spans do not contribute their own time). Without `samples`, JSON omits all four fields; `samples: 0` includes four empty arrays. Memory/worker rows use each recorded group's peak-memory sample; pressure uses each group's maximum. Concurrency uses equal-time segments, so indices are not shared timestamps. JSON returns number arrays (not the previous timestamped tuples); markdown includes compact formatted sample lines. `memorySummary.count` counts all captured readings in the span range, without downsampling.",
].join('\n'),
inputSchema: {
parent: z
......
......@@ -231,16 +231,42 @@ describe('query-trace samples', () => {
series,
(value) => `${value / 1024} KB`
)
expect(md).toContain('| 1 | 1 KB |')
expect(md).toContain('| 2 | 80% |')
expect(md).toContain('| 1 | 2 |')
expect(md).toContain('| 1 | 1.25 |')
expect(md).toContain('| 2 | 0.00 |')
expect(md).toContain('Indices are not shared timestamps')
expect(md).toContain('Active Tokio workers')
expect(md).toBe(
'\nSample indices are not shared timestamps.\n' +
'Memory (TurboMalloc live bytes) samples: 1 KB 2 KB\n' +
'Memory pressure samples: 7% 80%\n' +
'Active Tokio workers samples: 2 1\n' +
'Concurrency samples: 1.25 0.00\n'
)
expect(md).not.toContain('|')
})
it('prints none for empty metrics when another metric has values', () => {
expect(
renderSampleSeriesMarkdown(
{ ...emptySeries, concurrencySamples: [2.75] },
String
)
).toBe(
'\nSample indices are not shared timestamps.\n' +
'Memory (TurboMalloc live bytes) samples: none\n' +
'Memory pressure samples: none\n' +
'Active Tokio workers samples: none\n' +
'Concurrency samples: 2.75\n'
)
})
it('prints every returned value without an extra presentation cap', () => {
const values = Array.from({ length: 300 }, (_, index) => index)
expect(
renderSampleSeriesMarkdown(
{ ...emptySeries, activeWorkerThreadsSamples: values },
String
)
).toContain(`Active Tokio workers samples: ${values.join(' ')}\n`)
})
it('does not print sample tables for omitted or zero details', () => {
it('does not print sample lines for omitted or zero details', () => {
expect(renderSampleSeriesMarkdown(undefined, String)).toBe('')
expect(renderSampleSeriesMarkdown(emptySeries, String)).toBe('')
})
......
......@@ -524,7 +524,7 @@ impl Store {
})
}
fn memory_samples_slice(&self, start: Timestamp, end: Timestamp) -> &[MemorySample] {
pub(crate) fn memory_samples_slice(&self, start: Timestamp, end: Timestamp) -> &[MemorySample] {
// Binary search for the first sample >= start
let lo = self.memory_samples.partition_point(|(ts, ..)| *ts < start);
// Binary search for the first sample > end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment