diff --git a/.gitignore b/.gitignore index e23f35f9..5732e78e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ node_modules /wasm_parts/wasm_parts.iml /test/qryn_test_env/clickhouse/_data/ /test/qryn_test_env/grafana/_data/ +/test/qryn_test_cluster_env/grafana/_data/ diff --git a/parser/registry/common.js b/parser/registry/common.js index 0f0273ca..80fd2384 100644 --- a/parser/registry/common.js +++ b/parser/registry/common.js @@ -445,7 +445,7 @@ module.exports.preJoinLabels = (token, query, dist) => { dist = dist || '' const timeSeriesReq = new Sql.Select() .select('fingerprint', 'labels') - .from([`${DATABASE_NAME()}.time_series${dist}`, 'time_series']) + .from([`${DATABASE_NAME()}.time_series`, 'time_series']) .where(new Sql.And( new Sql.In('time_series.fingerprint', 'in', inRightSide), Sql.Gte(new Sql.Raw('date'), sqlFrom), diff --git a/pyroscope/pprof-bin/pkg/pprof_bin_bg.wasm b/pyroscope/pprof-bin/pkg/pprof_bin_bg.wasm index 74d12654..0ee3ff45 100644 Binary files a/pyroscope/pprof-bin/pkg/pprof_bin_bg.wasm and b/pyroscope/pprof-bin/pkg/pprof_bin_bg.wasm differ diff --git a/pyroscope/pprof-bin/src/lib.rs b/pyroscope/pprof-bin/src/lib.rs index 7f397658..a6f264f7 100644 --- a/pyroscope/pprof-bin/src/lib.rs +++ b/pyroscope/pprof-bin/src/lib.rs @@ -15,7 +15,7 @@ use pprof_pb::querier::v1::FlameGraphDiff; use pprof_pb::querier::v1::Level; use pprof_pb::querier::v1::SelectMergeStacktracesResponse; use prost::Message; -use std::collections::{HashMap, HashSet}; +use std::collections::{HashMap, HashSet, VecDeque}; use std::io::Read; use std::panic; use std::sync::Arc; @@ -655,28 +655,33 @@ fn compute_flame_graph_diff(t1: &Tree, t2: &Tree) -> FlameGraphDiff { res.right_ticks = t2.total()[0]; res.total = res.left_ticks + res.right_ticks; - let mut left_nodes = vec![Arc::new(TreeNodeV2 { + let mut left_nodes: VecDeque> = VecDeque::new(); + left_nodes.push_back(Arc::new(TreeNodeV2 { fn_id: 0, node_id: 0, slf: vec![0], total: vec![res.left_ticks], - })]; + })); - let mut right_nodes = vec![Arc::new(TreeNodeV2 { + let mut right_nodes: VecDeque> = VecDeque::new(); + right_nodes.push_back(Arc::new(TreeNodeV2 { fn_id: 0, node_id: 0, slf: vec![0], total: vec![res.right_ticks], - })]; + })); let mut levels = vec![0]; - let mut x_left_offsets = vec![0]; - let mut x_right_offsets = vec![0]; + let mut x_left_offsets: VecDeque = VecDeque::new(); + x_left_offsets.push_back(0); + let mut x_right_offsets = VecDeque::new(); + x_right_offsets.push_back(0); let mut name_location_cache: HashMap = HashMap::new(); - while let (Some(left), Some(right)) = (left_nodes.pop(), right_nodes.pop()) { - let x_left_offset = x_left_offsets.pop().unwrap(); - let x_right_offset = x_right_offsets.pop().unwrap(); + while let (Some(left), Some(right)) = + (left_nodes.pop_back(), right_nodes.pop_back()) { + let mut x_left_offset = x_left_offsets.pop_back().unwrap().clone(); + let mut x_right_offset = x_right_offsets.pop_back().unwrap().clone(); let level = levels.pop().unwrap(); let name = if left.fn_id == 0 { @@ -694,6 +699,13 @@ fn compute_flame_graph_diff(t1: &Tree, t2: &Tree) -> FlameGraphDiff { res.levels.push(Level::default()); } + if res.max_self < left.slf[0] { + res.max_self = left.slf[0]; + } + if res.max_self < right.slf[0] { + res.max_self = right.slf[0]; + } + res.levels[level].values.extend_from_slice(&[ x_left_offset, left.total[0], @@ -708,15 +720,30 @@ fn compute_flame_graph_diff(t1: &Tree, t2: &Tree) -> FlameGraphDiff { let empty_vec = Vec::new(); let children_right = t2.nodes.get(&right.node_id).unwrap_or(&empty_vec); for (child_left, child_right) in children_left.iter().zip(children_right.iter()) { - left_nodes.push(child_left.clone()); - right_nodes.push(child_right.clone()); - x_left_offsets.push(x_left_offset + child_left.total[0]); - x_right_offsets.push(x_right_offset + child_right.total[0]); - levels.push(level + 1); + left_nodes.push_front(child_left.clone()); + right_nodes.push_front(child_right.clone()); + x_left_offsets.push_front(x_left_offset.clone()); + x_right_offsets.push_front(x_right_offset.clone()); + x_left_offset += child_left.total[0].clone(); + x_right_offset += child_right.total[0].clone(); + levels.insert(0,level + 1); } } } + for i in 0..res.levels.len() { + let mut j = 0; + let mut prev0 = 0i64; + let mut prev3 = 0i64; + while j < res.levels[i].values.len() { + res.levels[i].values[j] -= prev0; + prev0 += res.levels[i].values[j] + res.levels[i].values[j+1]; + res.levels[i].values[j+3] -= prev3; + prev3 += res.levels[i].values[j+3] + res.levels[i].values[j+4]; + j += 7; + } + } + res }