diff --git a/src/plugins/profiling/server/routes/flamegraph.ts b/src/plugins/profiling/server/routes/flamegraph.ts new file mode 100644 index 00000000000000..4e9376ca84df82 --- /dev/null +++ b/src/plugins/profiling/server/routes/flamegraph.ts @@ -0,0 +1,37 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export class FlameGraph { + constructor(events, totalEvents, stackTraces, stackFrames) { + this.events = events; + this.totalEvents = totalEvents; + this.stacktraces = stackTraces; + this.stackframes = stackFrames; + } + + toElastic() { + let facts = []; + for (const trace of this.stacktraces) { + if (trace.found) { + const pairs = ['root'].concat(trace._source.FrameID).map((item, i) => [i, item]); + const fact = { + id: trace._source.FrameID[trace._source.FrameID.length - 1], + value: 1, + depth: trace._source.FrameID.length, + layers: Object.fromEntries(pairs), + }; + facts.push(fact); + } + } + return { facts }; + } + + toPixi() { + return {}; + } +} diff --git a/src/plugins/profiling/server/routes/search_flameChart.ts b/src/plugins/profiling/server/routes/search_flameChart.ts index f60919652a511c..6a59f419d7ae46 100644 --- a/src/plugins/profiling/server/routes/search_flameChart.ts +++ b/src/plugins/profiling/server/routes/search_flameChart.ts @@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema'; import type { DataRequestHandlerContext } from '../../../data/server'; import type { IRouter } from '../../../../core/server'; import { getRemoteRoutePaths } from '../../common'; +import { FlameGraph } from './flamegraph'; export function registerFlameChartSearchRoute(router: IRouter) { const paths = getRemoteRoutePaths(); @@ -150,13 +151,15 @@ export function registerFlameChartSearchRoute(router: IRouter