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

Include RSS footprint in trace query samples and summaries

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 456f30f0
...@@ -143,20 +143,22 @@ pub struct TraceSpanInfo { ...@@ -143,20 +143,22 @@ pub struct TraceSpanInfo {
/// independently of whether or how many sample values are requested. /// independently of whether or how many sample values are requested.
pub memory_summary: Option<TraceMemorySummary>, pub memory_summary: Option<TraceMemorySummary>,
/// Requested value arrays; absent unless `samples` was supplied. /// Requested value arrays; absent unless `samples` was supplied.
/// MCP flattens this internal object to the four optional value arrays. /// MCP flattens this internal object to the five optional value arrays.
pub sample_series: Option<TraceSpanSampleSeries>, pub sample_series: Option<TraceSpanSampleSeries>,
/// Descendants of this span, populated only when `depth > 1`. /// Descendants of this span, populated only when `depth > 1`.
pub children: Vec<TraceSpanInfo>, pub children: Vec<TraceSpanInfo>,
} }
/// Requested process/global value series. Captured memory/pressure/workers /// Requested process/global value series. Captured memory/pressure/footprint/workers
/// are grouped by recorded timestamps; concurrency uses equal-time segments. /// are grouped by recorded timestamps; concurrency uses equal-time segments.
/// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte, /// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
/// and workers are non-parked Tokio scheduler workers (not the blocking pool). /// Footprint is process RSS bytes (0 = not reported); workers are non-parked
/// Tokio scheduler workers (not the blocking pool).
#[napi(object)] #[napi(object)]
pub struct TraceSpanSampleSeries { pub struct TraceSpanSampleSeries {
pub memory_samples: Vec<i64>, pub memory_samples: Vec<i64>,
pub memory_pressure_samples: Vec<u8>, pub memory_pressure_samples: Vec<u8>,
pub memory_footprint_samples: Vec<i64>,
pub active_worker_threads_samples: Vec<i64>, pub active_worker_threads_samples: Vec<i64>,
pub concurrency_samples: Vec<f64>, pub concurrency_samples: Vec<f64>,
} }
...@@ -228,7 +230,6 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo { ...@@ -228,7 +230,6 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo {
self_deallocations: s.self_deallocations as i64, self_deallocations: s.self_deallocations as i64,
self_persistent_allocations: s.self_persistent_allocations as i64, self_persistent_allocations: s.self_persistent_allocations as i64,
self_allocation_count: s.self_allocation_count as i64, self_allocation_count: s.self_allocation_count as i64,
memory_summary: s.memory_summary.map(|m| TraceMemorySummary { memory_summary: s.memory_summary.map(|m| TraceMemorySummary {
count: m.count as i64, count: m.count as i64,
start: m.start as i64, start: m.start as i64,
...@@ -245,6 +246,11 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo { ...@@ -245,6 +246,11 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo {
.map(|value| value as i64) .map(|value| value as i64)
.collect(), .collect(),
memory_pressure_samples: series.memory_pressure_samples, memory_pressure_samples: series.memory_pressure_samples,
memory_footprint_samples: series
.memory_footprint_samples
.into_iter()
.map(|value| value as i64)
.collect(),
active_worker_threads_samples: series active_worker_threads_samples: series
.active_worker_threads_samples .active_worker_threads_samples
.into_iter() .into_iter()
......
...@@ -856,7 +856,7 @@ internal ...@@ -856,7 +856,7 @@ internal
.addOption( .addOption(
new Option( new Option(
'--samples <N>', '--samples <N>',
'Include up to N memory, pressure, active Tokio worker, and concurrency values per span. Omit for summaries only; 0 returns empty arrays.' 'Include up to N memory, pressure, RSS footprint, active Tokio worker, and concurrency values per span. Omit for summaries only; 0 returns empty arrays.'
).argParser((value: string) => { ).argParser((value: string) => {
const count = Number(value) const count = Number(value)
if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < 0) { if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < 0) {
......
...@@ -970,7 +970,7 @@ export interface TraceSpanInfo { ...@@ -970,7 +970,7 @@ export interface TraceSpanInfo {
memorySummary?: TraceMemorySummary memorySummary?: TraceMemorySummary
/** /**
* Requested value arrays; absent unless `samples` was supplied. * Requested value arrays; absent unless `samples` was supplied.
* MCP flattens this internal object to the four optional value arrays. * MCP flattens this internal object to the five optional value arrays.
*/ */
sampleSeries?: TraceSpanSampleSeries sampleSeries?: TraceSpanSampleSeries
/** Descendants of this span, populated only when `depth > 1`. */ /** Descendants of this span, populated only when `depth > 1`. */
...@@ -978,14 +978,16 @@ export interface TraceSpanInfo { ...@@ -978,14 +978,16 @@ export interface TraceSpanInfo {
} }
/** /**
* Requested process/global value series. Captured memory/pressure/workers * Requested process/global value series. Captured memory/pressure/footprint/workers
* are grouped by recorded timestamps; concurrency uses equal-time segments. * are grouped by recorded timestamps; concurrency uses equal-time segments.
* Memory is TurboMalloc live bytes, pressure is the recorded pressure byte, * Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
* and workers are non-parked Tokio scheduler workers (not the blocking pool). * Footprint is process RSS bytes (0 = not reported); workers are non-parked
* Tokio scheduler workers (not the blocking pool).
*/ */
export interface TraceSpanSampleSeries { export interface TraceSpanSampleSeries {
memorySamples: Array<number> memorySamples: Array<number>
memoryPressureSamples: Array<number> memoryPressureSamples: Array<number>
memoryFootprintSamples: Array<number>
activeWorkerThreadsSamples: Array<number> activeWorkerThreadsSamples: Array<number>
concurrencySamples: Array<number> concurrencySamples: Array<number>
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* CLI client for querying a running turbopack trace server via its MCP endpoint. * CLI client for querying a running turbopack trace server via its MCP endpoint.
* Sends a JSON-RPC `tools/call` request and prints the response to stdout. * Sends a JSON-RPC `tools/call` request and prints the response to stdout.
* Use --json for machine-readable JSON output (default: markdown). * Use --json for machine-readable JSON output (default: markdown).
* Use --samples=N to opt into memory, pressure, worker and concurrency values; * Use --samples=N to opt into memory, pressure, RSS footprint, worker and concurrency values;
* otherwise only the existing summaries are reported. * otherwise only the existing summaries are reported.
* *
* Usage: next internal query-trace [options] * Usage: next internal query-trace [options]
......
...@@ -24,10 +24,16 @@ export function renderMemorySummary( ...@@ -24,10 +24,16 @@ export function renderMemorySummary(
if (!summary) return null if (!summary) return null
const delta = summary.end - summary.start const delta = summary.end - summary.start
const deltaSign = delta >= 0 ? '+' : '-' const deltaSign = delta >= 0 ? '+' : '-'
// Zero means the platform did not report RSS.
const footprint =
summary.maxFootprint > 0
? `, maxFootprint=${formatBytes(summary.maxFootprint)}`
: ''
return ( return (
`samples=${summary.count}, peak=${formatBytes(summary.peak)}, min=${formatBytes(summary.min)}, ` + `samples=${summary.count}, peak=${formatBytes(summary.peak)}, min=${formatBytes(summary.min)}, ` +
`start=${formatBytes(summary.start)}, end=${formatBytes(summary.end)}, ` + `start=${formatBytes(summary.start)}, end=${formatBytes(summary.end)}, ` +
`Δ=${deltaSign}${formatBytes(Math.abs(delta))}, maxPressure=${summary.maxPressure}` `Δ=${deltaSign}${formatBytes(Math.abs(delta))}, maxPressure=${summary.maxPressure}` +
footprint
) )
} }
...@@ -43,6 +49,7 @@ export function renderSampleSeriesMarkdown( ...@@ -43,6 +49,7 @@ export function renderSampleSeriesMarkdown(
const metrics: [string, number[], (value: number) => string][] = [ const metrics: [string, number[], (value: number) => string][] = [
['Memory (TurboMalloc live bytes)', series.memorySamples, formatBytes], ['Memory (TurboMalloc live bytes)', series.memorySamples, formatBytes],
['Memory pressure', series.memoryPressureSamples, (value) => `${value}%`], ['Memory pressure', series.memoryPressureSamples, (value) => `${value}%`],
['Memory footprint (RSS)', series.memoryFootprintSamples, formatBytes],
['Active Tokio workers', series.activeWorkerThreadsSamples, String], ['Active Tokio workers', series.activeWorkerThreadsSamples, String],
['Concurrency', series.concurrencySamples, (value) => value.toFixed(2)], ['Concurrency', series.concurrencySamples, (value) => value.toFixed(2)],
] ]
......
...@@ -219,7 +219,7 @@ export async function startTurboTraceServerCli( ...@@ -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.', '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 compact formatted sample lines. `memorySummary.count` counts all captured readings in the span range, without downsampling.", "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), `memoryFootprintSamples` (process RSS bytes, 0 = not reported), `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 five fields; `samples: 0` includes five empty arrays. Memory uses each recorded group's peak-memory sample; pressure, RSS and workers independently use 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'), ].join('\n'),
inputSchema: { inputSchema: {
parent: z parent: z
...@@ -270,7 +270,7 @@ export async function startTurboTraceServerCli( ...@@ -270,7 +270,7 @@ export async function startTurboTraceServerCli(
.max(Number.MAX_SAFE_INTEGER) .max(Number.MAX_SAFE_INTEGER)
.optional() .optional()
.describe( .describe(
'Maximum values per memory, pressure, active-worker and concurrency series per span. Omit for summaries only; 0 returns empty arrays. Supports counts above 200. Larger values increase response/query cost.' 'Maximum values per memory, pressure, RSS footprint, active-worker and concurrency series per span. Omit for summaries only; 0 returns empty arrays. Supports counts above 200. Larger values increase response/query cost.'
), ),
outputType: z outputType: z
.enum(['markdown', 'json']) .enum(['markdown', 'json'])
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
const series = { const series = {
memorySamples: [1024, 2048], memorySamples: [1024, 2048],
memoryPressureSamples: [7, 80], memoryPressureSamples: [7, 80],
memoryFootprintSamples: [4096, 8192],
activeWorkerThreadsSamples: [2, 1], activeWorkerThreadsSamples: [2, 1],
concurrencySamples: [1.25, 0], concurrencySamples: [1.25, 0],
} }
...@@ -41,6 +42,7 @@ function span(overrides: Partial<TraceSpanInfo> = {}): TraceSpanInfo { ...@@ -41,6 +42,7 @@ function span(overrides: Partial<TraceSpanInfo> = {}): TraceSpanInfo {
min: 1024, min: 1024,
peak: 1024, peak: 1024,
maxPressure: 7, maxPressure: 7,
maxFootprint: 0,
}, },
children: [], children: [],
...overrides, ...overrides,
...@@ -50,6 +52,7 @@ function span(overrides: Partial<TraceSpanInfo> = {}): TraceSpanInfo { ...@@ -50,6 +52,7 @@ function span(overrides: Partial<TraceSpanInfo> = {}): TraceSpanInfo {
const emptySeries = { const emptySeries = {
memorySamples: [], memorySamples: [],
memoryPressureSamples: [], memoryPressureSamples: [],
memoryFootprintSamples: [],
activeWorkerThreadsSamples: [], activeWorkerThreadsSamples: [],
concurrencySamples: [], concurrencySamples: [],
} }
...@@ -202,7 +205,7 @@ describe('query-trace samples', () => { ...@@ -202,7 +205,7 @@ describe('query-trace samples', () => {
expect(result.firstSpanId).toBe('1') expect(result.firstSpanId).toBe('1')
}) })
it('returns four empty arrays for zero while keeping the memory summary', () => { it('returns five empty arrays for zero while keeping the memory summary', () => {
expect( expect(
serializeTraceSpan(span({ sampleSeries: emptySeries })) serializeTraceSpan(span({ sampleSeries: emptySeries }))
).toMatchObject({ ).toMatchObject({
...@@ -222,6 +225,24 @@ describe('query-trace samples', () => { ...@@ -222,6 +225,24 @@ describe('query-trace samples', () => {
expect(summary).not.toContain('activeWorkerThreads') expect(summary).not.toContain('activeWorkerThreads')
}) })
it('prints positive RSS in the full summary but omits unreported zero', () => {
const summary = span().memorySummary!
expect(
renderMemorySummary({ ...summary, maxFootprint: 8192 }, String)
).toContain(', maxFootprint=8192')
expect(renderMemorySummary(summary, String)).not.toContain('maxFootprint')
})
it('retains zero RSS readings in requested output', () => {
const samples = { ...emptySeries, memoryFootprintSamples: [0] }
expect(
serializeTraceSpan(span({ sampleSeries: samples })).memoryFootprintSamples
).toEqual([0])
expect(renderSampleSeriesMarkdown(samples, String)).toContain(
'Memory footprint (RSS) samples: 0\n'
)
})
it('omits the memory summary when no readings are available', () => { it('omits the memory summary when no readings are available', () => {
expect(renderMemorySummary(undefined, String)).toBeNull() expect(renderMemorySummary(undefined, String)).toBeNull()
}) })
...@@ -235,6 +256,7 @@ describe('query-trace samples', () => { ...@@ -235,6 +256,7 @@ describe('query-trace samples', () => {
'\nSample indices are not shared timestamps.\n' + '\nSample indices are not shared timestamps.\n' +
'Memory (TurboMalloc live bytes) samples: 1 KB 2 KB\n' + 'Memory (TurboMalloc live bytes) samples: 1 KB 2 KB\n' +
'Memory pressure samples: 7% 80%\n' + 'Memory pressure samples: 7% 80%\n' +
'Memory footprint (RSS) samples: 4 KB 8 KB\n' +
'Active Tokio workers samples: 2 1\n' + 'Active Tokio workers samples: 2 1\n' +
'Concurrency samples: 1.25 0.00\n' 'Concurrency samples: 1.25 0.00\n'
) )
...@@ -251,6 +273,7 @@ describe('query-trace samples', () => { ...@@ -251,6 +273,7 @@ describe('query-trace samples', () => {
'\nSample indices are not shared timestamps.\n' + '\nSample indices are not shared timestamps.\n' +
'Memory (TurboMalloc live bytes) samples: none\n' + 'Memory (TurboMalloc live bytes) samples: none\n' +
'Memory pressure samples: none\n' + 'Memory pressure samples: none\n' +
'Memory footprint (RSS) samples: none\n' +
'Active Tokio workers samples: none\n' + 'Active Tokio workers samples: none\n' +
'Concurrency samples: 2.75\n' 'Concurrency samples: 2.75\n'
) )
......
...@@ -129,10 +129,12 @@ pub struct QueryOptions { ...@@ -129,10 +129,12 @@ pub struct QueryOptions {
/// Requested value series for a span's elapsed range. Captured samples and /// Requested value series for a span's elapsed range. Captured samples and
/// equal-duration concurrency segments do not share a timestamp grid. /// equal-duration concurrency segments do not share a timestamp grid.
/// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte, /// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
/// and workers are non-parked Tokio scheduler workers (not the blocking pool). /// Footprint is process RSS bytes (0 = not reported); workers are non-parked
/// Tokio scheduler workers (not the blocking pool).
pub struct SpanSampleSeries { pub struct SpanSampleSeries {
pub memory_samples: Vec<u64>, pub memory_samples: Vec<u64>,
pub memory_pressure_samples: Vec<u8>, pub memory_pressure_samples: Vec<u8>,
pub memory_footprint_samples: Vec<u64>,
pub active_worker_threads_samples: Vec<u64>, pub active_worker_threads_samples: Vec<u64>,
pub concurrency_samples: Vec<f64>, pub concurrency_samples: Vec<f64>,
} }
...@@ -521,7 +523,8 @@ fn sample_series_for(store: &store::Store, span: &SpanRef<'_>, limit: usize) -> ...@@ -521,7 +523,8 @@ fn sample_series_for(store: &store::Store, span: &SpanRef<'_>, limit: usize) ->
SpanSampleSeries { SpanSampleSeries {
memory_samples: samples.iter().map(|sample| sample.1).collect(), memory_samples: samples.iter().map(|sample| sample.1).collect(),
memory_pressure_samples: store.memory_pressure_samples_for_range(start, end, limit), memory_pressure_samples: store.memory_pressure_samples_for_range(start, end, limit),
active_worker_threads_samples: samples.iter().map(|sample| sample.3).collect(), memory_footprint_samples: samples.iter().map(|sample| sample.3).collect(),
active_worker_threads_samples: samples.iter().map(|sample| sample.4).collect(),
concurrency_samples: store.concurrency_samples_for_range(start, end, limit), concurrency_samples: store.concurrency_samples_for_range(start, end, limit),
} }
} }
...@@ -1032,6 +1035,7 @@ mod tests { ...@@ -1032,6 +1035,7 @@ mod tests {
Timestamp::from_value(i), Timestamp::from_value(i),
i, i,
if i == 1 { 100 } else { (i % 100) as u8 }, if i == 1 { 100 } else { (i % 100) as u8 },
if i == 2 { 9999 } else { i * 10 },
i % 8, i % 8,
); );
} }
...@@ -1059,6 +1063,7 @@ mod tests { ...@@ -1059,6 +1063,7 @@ mod tests {
min: 0, min: 0,
peak: 599, peak: 599,
max_pressure: 100, max_pressure: 100,
max_footprint: 9999,
}; };
assert_eq!(first.memory_summary, Some(expected_summary)); assert_eq!(first.memory_summary, Some(expected_summary));
let child = &first.children[0]; let child = &first.children[0];
...@@ -1069,6 +1074,7 @@ mod tests { ...@@ -1069,6 +1074,7 @@ mod tests {
for length in [ for length in [
series.memory_samples.len(), series.memory_samples.len(),
series.memory_pressure_samples.len(), series.memory_pressure_samples.len(),
series.memory_footprint_samples.len(),
series.active_worker_threads_samples.len(), series.active_worker_threads_samples.len(),
series.concurrency_samples.len(), series.concurrency_samples.len(),
] { ] {
...@@ -1080,13 +1086,18 @@ mod tests { ...@@ -1080,13 +1086,18 @@ mod tests {
assert_eq!(series.concurrency_samples.len(), limit.min(elapsed)); assert_eq!(series.concurrency_samples.len(), limit.min(elapsed));
if limit > 0 { if limit > 0 {
assert_eq!(series.memory_samples.last(), Some(&599)); assert_eq!(series.memory_samples.last(), Some(&599));
assert_eq!( assert_eq!(series.active_worker_threads_samples.last(), Some(&7));
series.active_worker_threads_samples.last(),
Some(&(599 % 8))
);
} }
} }
if limit == 1 { if limit == 1 {
assert_eq!(
first
.sample_series
.as_ref()
.unwrap()
.memory_footprint_samples,
vec![9999]
);
assert_eq!( assert_eq!(
first.sample_series.as_ref().unwrap().concurrency_samples, first.sample_series.as_ref().unwrap().concurrency_samples,
vec![1.6] vec![1.6]
...@@ -1465,7 +1476,8 @@ mod tests { ...@@ -1465,7 +1476,8 @@ mod tests {
assert_eq!(summary.peak, 900); assert_eq!(summary.peak, 900);
assert_eq!(summary.max_pressure, 3); assert_eq!(summary.max_pressure, 3);
// Footprint is maxed independently of the memory peak. // Footprint is maxed independently of the memory peak.
assert_eq!(summary.max_footprint, 7000); assert!( assert_eq!(summary.max_footprint, 7000);
assert!(
MemorySummary::for_range(&store, Timestamp::from_micros(3), Timestamp::from_micros(4)) MemorySummary::for_range(&store, Timestamp::from_micros(3), Timestamp::from_micros(4))
.is_none() .is_none()
); );
......
...@@ -99,11 +99,13 @@ fn reads_active_workers_and_exposes_them_in_span_queries() { ...@@ -99,11 +99,13 @@ fn reads_active_workers_and_exposes_them_in_span_queries() {
if limit == 0 { if limit == 0 {
assert!(series.memory_samples.is_empty()); assert!(series.memory_samples.is_empty());
assert!(series.memory_pressure_samples.is_empty()); assert!(series.memory_pressure_samples.is_empty());
assert!(series.memory_footprint_samples.is_empty());
assert!(series.active_worker_threads_samples.is_empty()); assert!(series.active_worker_threads_samples.is_empty());
assert!(series.concurrency_samples.is_empty()); assert!(series.concurrency_samples.is_empty());
} else { } else {
assert_eq!(series.memory_samples, vec![1234]); assert_eq!(series.memory_samples, vec![1234]);
assert_eq!(series.memory_pressure_samples, vec![7]); assert_eq!(series.memory_pressure_samples, vec![7]);
assert_eq!(series.memory_footprint_samples, vec![5555]);
assert_eq!(series.active_worker_threads_samples, vec![2]); assert_eq!(series.active_worker_threads_samples, vec![2]);
assert_eq!(series.concurrency_samples, vec![1.0]); assert_eq!(series.concurrency_samples, vec![1.0]);
} }
......
...@@ -677,13 +677,14 @@ mod tests { ...@@ -677,13 +677,14 @@ mod tests {
let start = Timestamp::ZERO; let start = Timestamp::ZERO;
let end = Timestamp::from_value(599); let end = Timestamp::from_value(599);
for i in 0..600 { for i in 0..600 {
store.add_memory_sample(Timestamp::from_value(i), i, (i % 100) as u8, 0, i % 8); store.add_memory_sample(Timestamp::from_value(i), i, (i % 100) as u8, i * 10, i % 8);
} }
for limit in [0, 1, 200, 300, 1000] { for limit in [0, 1, 200, 300, 1000] {
let samples = store.memory_samples_for_range_with_ts(start, end, limit); let samples = store.memory_samples_for_range_with_ts(start, end, limit);
let memory = store.memory_samples_for_range(start, end, limit); let memory = store.memory_samples_for_range(start, end, limit);
let pressure = store.memory_pressure_samples_for_range(start, end, limit); let pressure = store.memory_pressure_samples_for_range(start, end, limit);
let workers = store.active_worker_threads_samples_for_range(start, end, limit); let workers = store.active_worker_threads_samples_for_range(start, end, limit);
let footprint = store.memory_footprint_samples_for_range(start, end, limit);
assert!(samples.len() <= limit); assert!(samples.len() <= limit);
assert_eq!(pressure.len(), samples.len()); assert_eq!(pressure.len(), samples.len());
assert_eq!( assert_eq!(
...@@ -692,6 +693,10 @@ mod tests { ...@@ -692,6 +693,10 @@ mod tests {
); );
assert_eq!( assert_eq!(
workers, workers,
samples.iter().map(|sample| sample.4).collect::<Vec<_>>()
);
assert_eq!(
footprint,
samples.iter().map(|sample| sample.3).collect::<Vec<_>>() samples.iter().map(|sample| sample.3).collect::<Vec<_>>()
); );
if limit > 0 { if limit > 0 {
...@@ -733,14 +738,25 @@ mod tests { ...@@ -733,14 +738,25 @@ mod tests {
} }
#[test] #[test]
fn pressure_and_workers_keep_the_viewer_reduction_semantics() { fn pressure_footprint_and_workers_keep_the_viewer_reduction_semantics() {
let mut store = Store::new(); let mut store = Store::new();
let start = Timestamp::ZERO; let start = Timestamp::ZERO;
let end = Timestamp::from_value(10); let end = Timestamp::from_value(10);
store.add_memory_sample(start, 100, 80, 1000, 7); store.add_memory_sample(Timestamp::from_value(2), 200, 80, 200, 1);
store.add_memory_sample(Timestamp::from_value(4), 300, 2, 1000, 1);
store.add_memory_sample(Timestamp::from_value(6), 400, 2, 200, 7);
store.add_memory_sample(start, 100, 1, 200, 1);
store.add_memory_sample(end, 900, 2, 200, 1); store.add_memory_sample(end, 900, 2, 200, 1);
let samples = store.memory_samples_for_range_with_ts(start, end, 1); let samples = store.memory_samples_for_range_with_ts(start, end, 1);
assert_eq!(samples, vec![(end, 900, 80, 1000, 7)]); assert_eq!(samples, vec![(end, 900, 80, 1000, 7)]);
assert_eq!(
store.memory_footprint_samples_for_range(start, end, 1),
vec![1000]
);
assert_eq!(
store.active_worker_threads_samples_for_range(start, end, 1),
vec![7]
);
assert_eq!( assert_eq!(
store.memory_pressure_samples_for_range(start, end, 1), store.memory_pressure_samples_for_range(start, end, 1),
vec![80] vec![80]
...@@ -993,7 +1009,7 @@ mod tests { ...@@ -993,7 +1009,7 @@ mod tests {
for i in 0..10u64 { for i in 0..10u64 {
store.add_memory_sample(Timestamp::from_micros(i), i * 10, i as u8, i * 100, i); store.add_memory_sample(Timestamp::from_micros(i), i * 10, i as u8, i * 100, i);
} }
let samples = store.memory_samples_for_range_with_ts(Timestamp::ZERO, Timestamp::MAX); let samples = store.memory_samples_for_range_with_ts(Timestamp::ZERO, Timestamp::MAX, 200);
assert_eq!(samples.len(), 10); assert_eq!(samples.len(), 10);
for (i, (ts, mem, pressure, footprint, workers)) in samples.into_iter().enumerate() { for (i, (ts, mem, pressure, footprint, workers)) in samples.into_iter().enumerate() {
let i = i as u64; let i = i as u64;
...@@ -1008,9 +1024,10 @@ mod tests { ...@@ -1008,9 +1024,10 @@ mod tests {
#[test] #[test]
fn downsampled_memory_samples_use_column_max_for_pressure_footprint_and_workers() { fn downsampled_memory_samples_use_column_max_for_pressure_footprint_and_workers() {
let mut store = Store::new(); let mut store = Store::new();
let limit = 200;
// Two samples per group: the first has the higher TurboMalloc memory, // Two samples per group: the first has the higher TurboMalloc memory,
// the second has the higher pressure, footprint and worker count. // the second has the higher pressure, footprint and worker count.
for group in 0..MAX_MEMORY_SAMPLES as u64 { for group in 0..limit as u64 {
store.add_memory_sample(Timestamp::from_micros(group * 2), 1000 + group, 1, 10, 1); store.add_memory_sample(Timestamp::from_micros(group * 2), 1000 + group, 1, 10, 1);
store.add_memory_sample( store.add_memory_sample(
Timestamp::from_micros(group * 2 + 1), Timestamp::from_micros(group * 2 + 1),
...@@ -1022,17 +1039,17 @@ mod tests { ...@@ -1022,17 +1039,17 @@ mod tests {
} }
let (start, end) = (Timestamp::ZERO, Timestamp::MAX); let (start, end) = (Timestamp::ZERO, Timestamp::MAX);
let with_ts = store.memory_samples_for_range_with_ts(start, end); let with_ts = store.memory_samples_for_range_with_ts(start, end, limit);
let memory = store.memory_samples_for_range(start, end); let memory = store.memory_samples_for_range(start, end, limit);
let pressure = store.memory_pressure_samples_for_range(start, end); let pressure = store.memory_pressure_samples_for_range(start, end, limit);
let footprint = store.memory_footprint_samples_for_range(start, end); let footprint = store.memory_footprint_samples_for_range(start, end, limit);
let workers = store.active_worker_threads_samples_for_range(start, end); let workers = store.active_worker_threads_samples_for_range(start, end, limit);
assert_eq!(with_ts.len(), MAX_MEMORY_SAMPLES); assert_eq!(with_ts.len(), limit);
assert_eq!(memory.len(), MAX_MEMORY_SAMPLES); assert_eq!(memory.len(), limit);
assert_eq!(pressure.len(), MAX_MEMORY_SAMPLES); assert_eq!(pressure.len(), limit);
assert_eq!(footprint.len(), MAX_MEMORY_SAMPLES); assert_eq!(footprint.len(), limit);
assert_eq!(workers.len(), MAX_MEMORY_SAMPLES); assert_eq!(workers.len(), limit);
for (i, (ts, mem, p, f, w)) in with_ts.into_iter().enumerate() { for (i, (ts, mem, p, f, w)) in with_ts.into_iter().enumerate() {
let group = i as u64; let group = i as u64;
......
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