Skip to content

Commit

Permalink
Flamegraph: Reduce JSON data for mget + measure data processing
Browse files Browse the repository at this point in the history
  • Loading branch information
rockdaboot committed Jun 8, 2022
1 parent d9c3da2 commit 1737335
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/plugins/profiling/server/routes/flamechart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async function queryFlameGraph(
],
},
aggs: {
sum_count: {
count: {
sum: {
field: 'Count',
},
Expand All @@ -157,18 +157,23 @@ async function queryFlameGraph(
// It reduces the query time by avoiding unneeded searches.
querystring: {
pre_filter_shard_size: 1,
filter_path:
'aggregations.group_by.buckets.key,aggregations.group_by.buckets.count,aggregations.total_count,_shards.failures',
},
}
);
}
);

let totalCount: number = resEvents.body.aggregations?.total_count.value;

const stackTraceEvents = new Map<StackTraceID, number>();
resEvents.body.aggregations?.group_by.buckets.forEach((item: any) => {
const traceid: StackTraceID = item.key.traceid;
stackTraceEvents.set(traceid, item.sum_count.value);
let stackTraceEvents: Map<StackTraceID, number>;

await logExecutionLatency(logger, 'processing events data', async () => {
stackTraceEvents = new Map<StackTraceID, number>();
resEvents.body.aggregations?.group_by.buckets.forEach((item: any) => {
const traceid: StackTraceID = item.key.traceid;
stackTraceEvents.set(traceid, item.count.value);
});
});
logger.info('events total count: ' + totalCount);
logger.info('unique stacktraces: ' + stackTraceEvents.size);
Expand All @@ -177,7 +182,9 @@ async function queryFlameGraph(
if (totalCount > sampleSize * 1.1) {
const p = sampleSize / totalCount;
logger.info('downsampling events with p=' + p);
totalCount = downsampleEventsRandomly(stackTraceEvents, p, filter.toString());
await logExecutionLatency(logger, 'downsampling events', async () => {
totalCount = downsampleEventsRandomly(stackTraceEvents, p, filter.toString());
});
logger.info('downsampled total count: ' + totalCount);
logger.info('unique downsampled stacktraces: ' + stackTraceEvents.size);
}
Expand Down

0 comments on commit 1737335

Please sign in to comment.