Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(flamegraph): don't convert to graphviz format unnecessarily (#1834)
* perf(flamegraph): don't convert to graphviz data unnecessarily
- Loading branch information
Showing
4 changed files
with
121 additions
and
115 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
packages/pyroscope-flamegraph/src/FlameGraph/FlameGraphComponent/GraphVizPane.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { Flamebearer } from '@pyroscope/models/src'; | ||
import React, { useMemo } from 'react'; | ||
import toGraphviz from '../../convert/toGraphviz'; | ||
import styles from './GraphVizPanel.module.scss'; | ||
|
||
// this is to make sure that graphviz-react is not used in node.js | ||
let Graphviz = (obj: IGraphvizProps) => { | ||
if (obj) { | ||
return null; | ||
} | ||
return null; | ||
}; | ||
interface IGraphvizProps { | ||
dot: string; | ||
options?: object; | ||
className?: string; | ||
} | ||
|
||
if (typeof process === 'undefined') { | ||
/* eslint-disable global-require */ | ||
Graphviz = require('graphviz-react').Graphviz; | ||
} | ||
|
||
interface GraphVizPaneProps { | ||
flamebearer: Flamebearer; | ||
} | ||
export function GraphVizPane({ flamebearer }: GraphVizPaneProps) { | ||
// TODO(@petethepig): I don't understand what's going on with types here | ||
// need to fix at some point | ||
const fb = flamebearer as ShamefulAny; | ||
|
||
// flamebearer | ||
const dot = fb.metadata?.format && fb.flamebearer?.levels; | ||
|
||
// Graphviz doesn't update position and scale value on rerender | ||
// so image sometimes moves out of the screen | ||
// to fix it we remounting graphViz component by updating key | ||
const key = `graphviz-pane-${fb?.appName || String(new Date().valueOf())}`; | ||
const dotValue = useMemo(() => { | ||
return toGraphviz(fb); | ||
}, [JSON.stringify(fb)]); | ||
|
||
return ( | ||
<div className={styles.graphVizPane} key={key}> | ||
{dot ? ( | ||
<Graphviz | ||
// options https://github.com/magjac/d3-graphviz#supported-options | ||
options={{ | ||
zoom: true, | ||
width: '150%', | ||
height: '100%', | ||
scale: 1, | ||
// 'true' by default, but causes warning | ||
// https://github.com/magjac/d3-graphviz/blob/master/README.md#defining-the-hpcc-jswasm-script-tag | ||
useWorker: false, | ||
}} | ||
dot={dotValue} | ||
/> | ||
) : ( | ||
<div>NO DATA</div> | ||
)} | ||
</div> | ||
); | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/pyroscope-flamegraph/src/FlameGraph/FlameGraphComponent/GraphVizPanel.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.graphVizPane { | ||
display: flex; | ||
flex: 1; | ||
|
||
// hacky better than !important | ||
&#{&} { | ||
margin-right: 0; | ||
border: 1px solid var(--ps-ui-border); | ||
} | ||
|
||
div[id^='graphviz'] { | ||
width: 100%; | ||
overflow: hidden; | ||
|
||
:global { | ||
.graph > polygon { | ||
// graphviz overlay | ||
fill: none; | ||
} | ||
|
||
.node { | ||
polygon { | ||
// node box | ||
// stroke: var(--ps-fl-toolbar-btn-bg); | ||
} | ||
|
||
text[text-anchor='middle'] { | ||
// node caption | ||
// fill: var(--ps-toolbar-icon-color); | ||
} | ||
} | ||
|
||
.edge { | ||
text[text-anchor='middle'] { | ||
// edge caption | ||
fill: var(--ps-toolbar-icon-color); | ||
// fill: red; | ||
} | ||
|
||
a { | ||
path { | ||
// arrow body | ||
// stroke: var(--ps-fl-toolbar-btn-bg); | ||
} | ||
|
||
polygon { | ||
// arrow head | ||
// stroke: var(--ps-fl-toolbar-btn-bg); | ||
// fill: var(--ps-fl-toolbar-btn-bg); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters