fix local fingerprints check; pprof bin debug

This commit is contained in:
akvlad
2024-10-24 14:24:37 +03:00
parent 3360e4fa4c
commit 5d642c1cac
4 changed files with 44 additions and 16 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ node_modules
/wasm_parts/wasm_parts.iml /wasm_parts/wasm_parts.iml
/test/qryn_test_env/clickhouse/_data/ /test/qryn_test_env/clickhouse/_data/
/test/qryn_test_env/grafana/_data/ /test/qryn_test_env/grafana/_data/
/test/qryn_test_cluster_env/grafana/_data/

View File

@ -445,7 +445,7 @@ module.exports.preJoinLabels = (token, query, dist) => {
dist = dist || '' dist = dist || ''
const timeSeriesReq = new Sql.Select() const timeSeriesReq = new Sql.Select()
.select('fingerprint', 'labels') .select('fingerprint', 'labels')
.from([`${DATABASE_NAME()}.time_series${dist}`, 'time_series']) .from([`${DATABASE_NAME()}.time_series`, 'time_series'])
.where(new Sql.And( .where(new Sql.And(
new Sql.In('time_series.fingerprint', 'in', inRightSide), new Sql.In('time_series.fingerprint', 'in', inRightSide),
Sql.Gte(new Sql.Raw('date'), sqlFrom), Sql.Gte(new Sql.Raw('date'), sqlFrom),

View File

@ -15,7 +15,7 @@ use pprof_pb::querier::v1::FlameGraphDiff;
use pprof_pb::querier::v1::Level; use pprof_pb::querier::v1::Level;
use pprof_pb::querier::v1::SelectMergeStacktracesResponse; use pprof_pb::querier::v1::SelectMergeStacktracesResponse;
use prost::Message; use prost::Message;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet, VecDeque};
use std::io::Read; use std::io::Read;
use std::panic; use std::panic;
use std::sync::Arc; 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.right_ticks = t2.total()[0];
res.total = res.left_ticks + res.right_ticks; res.total = res.left_ticks + res.right_ticks;
let mut left_nodes = vec![Arc::new(TreeNodeV2 { let mut left_nodes: VecDeque<Arc<TreeNodeV2>> = VecDeque::new();
left_nodes.push_back(Arc::new(TreeNodeV2 {
fn_id: 0, fn_id: 0,
node_id: 0, node_id: 0,
slf: vec![0], slf: vec![0],
total: vec![res.left_ticks], total: vec![res.left_ticks],
})]; }));
let mut right_nodes = vec![Arc::new(TreeNodeV2 { let mut right_nodes: VecDeque<Arc<TreeNodeV2>> = VecDeque::new();
right_nodes.push_back(Arc::new(TreeNodeV2 {
fn_id: 0, fn_id: 0,
node_id: 0, node_id: 0,
slf: vec![0], slf: vec![0],
total: vec![res.right_ticks], total: vec![res.right_ticks],
})]; }));
let mut levels = vec![0]; let mut levels = vec![0];
let mut x_left_offsets = vec![0]; let mut x_left_offsets: VecDeque<i64> = VecDeque::new();
let mut x_right_offsets = vec![0]; 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<String, i64> = HashMap::new(); let mut name_location_cache: HashMap<String, i64> = HashMap::new();
while let (Some(left), Some(right)) = (left_nodes.pop(), right_nodes.pop()) { while let (Some(left), Some(right)) =
let x_left_offset = x_left_offsets.pop().unwrap(); (left_nodes.pop_back(), right_nodes.pop_back()) {
let x_right_offset = x_right_offsets.pop().unwrap(); 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 level = levels.pop().unwrap();
let name = if left.fn_id == 0 { 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()); 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(&[ res.levels[level].values.extend_from_slice(&[
x_left_offset, x_left_offset,
left.total[0], left.total[0],
@ -708,15 +720,30 @@ fn compute_flame_graph_diff(t1: &Tree, t2: &Tree) -> FlameGraphDiff {
let empty_vec = Vec::new(); let empty_vec = Vec::new();
let children_right = t2.nodes.get(&right.node_id).unwrap_or(&empty_vec); 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()) { for (child_left, child_right) in children_left.iter().zip(children_right.iter()) {
left_nodes.push(child_left.clone()); left_nodes.push_front(child_left.clone());
right_nodes.push(child_right.clone()); right_nodes.push_front(child_right.clone());
x_left_offsets.push(x_left_offset + child_left.total[0]); x_left_offsets.push_front(x_left_offset.clone());
x_right_offsets.push(x_right_offset + child_right.total[0]); x_right_offsets.push_front(x_right_offset.clone());
levels.push(level + 1); 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 res
} }