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

Let trace sample callers choose range limits

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent ebf72cba
......@@ -48,6 +48,9 @@ mod viewer;
)]
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
/// Maximum number of process sample rows used for legacy query summaries.
const MAX_MEMORY_SUMMARY_SAMPLES: usize = 200;
/// Starts the trace server on a background thread and returns the store
/// immediately. The WebSocket server runs non-blocking.
pub fn start_turbopack_trace_server(path: PathBuf, port: Option<u16>) -> Arc<StoreContainer> {
......@@ -244,10 +247,9 @@ pub struct SpanInfo {
/// counts non-parked Tokio scheduler workers. `100 ticks = 1 µs`. The
/// offset is within the span.
///
/// The store caps the series at `MAX_MEMORY_SAMPLES`; when more samples
/// exist in the range, consecutive groups are merged: the timestamp and
/// value come from the group's max-memory sample, while pressure,
/// footprint and worker count are each the max over the group.
/// The query caller caps the series at `MAX_MEMORY_SUMMARY_SAMPLES`; groups
/// retain the peak-memory timestamp/value and independent pressure,
/// footprint and worker maxima.
pub memory_samples: Vec<(i64, u64, u8, u64, u64)>,
/// Summary of `memory_samples`. `None` when the span's range holds none.
pub memory_summary: Option<MemorySummary>,
......@@ -522,7 +524,7 @@ fn sort_spans(items: &mut [Located<SpanRef<'_>>], sort: SortMode) {
fn memory_samples_for(store: &store::Store, span: &SpanRef<'_>) -> Vec<(i64, u64, u8, u64, u64)> {
let span_start = *span.start() as i64;
store
.memory_samples_for_range_with_ts(span.start(), span.end())
.memory_samples_for_range_with_ts(span.start(), span.end(), MAX_MEMORY_SUMMARY_SAMPLES)
.into_iter()
.map(|(ts, mem, pressure, footprint, workers)| {
((*ts as i64) - span_start, mem, pressure, footprint, workers)
......@@ -533,12 +535,12 @@ fn memory_samples_for(store: &store::Store, span: &SpanRef<'_>) -> Vec<(i64, u64
fn sample_series_for(store: &store::Store, span: &SpanRef<'_>, limit: usize) -> SpanSampleSeries {
let start = span.start();
let end = span.end();
let samples = store.memory_samples_for_range_with_ts_limit(start, end, limit);
let samples = store.memory_samples_for_range_with_ts(start, end, limit);
SpanSampleSeries {
memory_samples: samples.iter().map(|sample| sample.1).collect(),
memory_pressure_samples: store.memory_pressure_samples_for_range_limit(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(),
concurrency_samples: store.concurrency_samples_for_range_limit(start, end, limit),
concurrency_samples: store.concurrency_samples_for_range(start, end, limit),
}
}
......
......@@ -54,9 +54,11 @@ fn reads_active_workers_and_exposes_them_in_span_queries() {
bytes.len()
);
let samples = store
.read()
.memory_samples_for_range_with_ts(Timestamp::from_micros(10), Timestamp::from_micros(30));
let samples = store.read().memory_samples_for_range_with_ts(
Timestamp::from_micros(10),
Timestamp::from_micros(30),
200,
);
assert_eq!(samples[0].1, 1234);
assert_eq!(samples[0].2, 7);
assert_eq!(samples[0].3, 5555);
......@@ -180,8 +182,11 @@ fn blocking_duration_events_keep_ranges_without_inflating_work() {
assert_eq!(root.corrected_total_time(), Timestamp::from_micros(20));
assert_eq!(root.end(), Timestamp::from_micros(110));
assert_eq!(
store
.concurrency_samples_for_range(Timestamp::from_micros(10), Timestamp::from_micros(100)),
store.concurrency_samples_for_range(
Timestamp::from_micros(10),
Timestamp::from_micros(100),
200
),
vec![0.0; 200]
);
let mut count = 0;
......@@ -232,7 +237,7 @@ fn blocking_events_do_not_change_counted_work_correction() {
assert_eq!(root.total_time(), Timestamp::from_micros(100));
assert_eq!(root.corrected_total_time(), Timestamp::from_micros(100));
assert_eq!(
store.concurrency_samples_for_range(Timestamp::ZERO, Timestamp::from_micros(100)),
store.concurrency_samples_for_range(Timestamp::ZERO, Timestamp::from_micros(100), 200),
vec![1.0; 200]
);
}
......@@ -267,7 +272,11 @@ fn non_blocking_and_legacy_duration_events_still_count() {
assert_eq!(root.total_time(), Timestamp::from_micros(200));
assert!(root.corrected_self_time() < root.self_time());
assert_eq!(
store.concurrency_samples_for_range(Timestamp::from_micros(30), Timestamp::from_micros(80)),
store.concurrency_samples_for_range(
Timestamp::from_micros(30),
Timestamp::from_micros(80),
200
),
vec![3.0; 200]
);
for event in root.children() {
......@@ -336,14 +345,15 @@ fn blocking_entered_spans_ignore_own_work_but_count_children() {
);
assert_eq!(parent.corrected_total_time(), parent.total_time(), "{name}");
assert_eq!(
store.concurrency_samples_for_range(Timestamp::ZERO, Timestamp::from_micros(10)),
store.concurrency_samples_for_range(Timestamp::ZERO, Timestamp::from_micros(10), 200),
vec![if ignored { 0.0 } else { 1.0 }; 200],
"{name}"
);
assert_eq!(
store.concurrency_samples_for_range(
Timestamp::from_micros(10),
Timestamp::from_micros(20)
Timestamp::from_micros(20),
200
),
vec![1.0; 200],
"{name}"
......
......@@ -16,6 +16,11 @@ use crate::{
viewer::{SortMode, Update, ViewLineUpdate, ViewMode, Viewer},
};
/// Maximum number of recorded process samples sent to the viewer.
const MAX_MEMORY_SAMPLES: usize = 200;
/// Maximum number of equal-duration concurrency segments sent to the viewer.
const MAX_CONCURRENCY_SAMPLES: usize = 200;
#[derive(Serialize, Debug)]
#[serde(tag = "type")]
#[serde(rename_all = "kebab-case")]
......@@ -297,19 +302,34 @@ fn handle_connection(
current = parent;
}
path.reverse();
let memory_samples =
store.memory_samples_for_range(span.start(), span.end());
let memory_samples = store.memory_samples_for_range(
span.start(),
span.end(),
MAX_MEMORY_SAMPLES,
);
let memory_pressure_samples = store
.memory_pressure_samples_for_range(span.start(), span.end());
.memory_pressure_samples_for_range(
span.start(),
span.end(),
MAX_MEMORY_SAMPLES,
);
let memory_footprint_samples = store
.memory_footprint_samples_for_range(span.start(), span.end());
.memory_footprint_samples_for_range(
span.start(),
span.end(),
MAX_MEMORY_SAMPLES,
);
let active_worker_threads_samples = store
.active_worker_threads_samples_for_range(
span.start(),
span.end(),
MAX_MEMORY_SAMPLES,
);
let concurrency_samples =
store.concurrency_samples_for_range(span.start(), span.end());
let concurrency_samples = store.concurrency_samples_for_range(
span.start(),
span.end(),
MAX_CONCURRENCY_SAMPLES,
);
ServerToClientMessage::QueryResult {
id,
is_graph,
......
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