Skip to content
Snippets Groups Projects
Commit efe96a69 authored by David Bühler's avatar David Bühler
Browse files

[Ivette] Eva flamegraph: new function for the info text about a node.

parent 1ac04020
No related branches found
No related tags found
No related merge requests found
...@@ -70,13 +70,28 @@ interface EvaFlamegraphProps { ...@@ -70,13 +70,28 @@ interface EvaFlamegraphProps {
size: Size size: Size
} }
/* Round f to at most [decimal] decimals. */
function round(f: number, decimal: number): number {
const factor = 10 ** decimal;
return Math.round(f * factor) / factor;
}
/* Returns text to be shown about a node in a flamegraph. */
function nodeInfoText(flameGraph:Flamegraph, node:Flamegraph): string {
const percentage = round(100 * node.value / flameGraph.value, 1);
const value = round(node.value, 2);
const infos = node.name + " : " + value + "s : " + percentage + "%";
return infos;
}
function EvaFlamegraph(props: EvaFlamegraphProps): JSX.Element { function EvaFlamegraph(props: EvaFlamegraphProps): JSX.Element {
const { useScope, flameGraph, size } = props; const { useScope, flameGraph, size } = props;
const { width, height } = size; const { width, height } = size;
const [ nodeInfos, setNodeInfos ] = React.useState(""); const [ nodeInfos, setNodeInfos ] = React.useState("");
const changeScope = (f: Flamegraph): void => { /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
States.setCurrentScope(f.kfKey as Ast.decl); const changeScope = (node:any): void => {
if (useScope) States.setCurrentScope(node.source.kfKey as Ast.decl);
}; };
return ( return (
...@@ -85,18 +100,9 @@ function EvaFlamegraph(props: EvaFlamegraphProps): JSX.Element { ...@@ -85,18 +100,9 @@ function EvaFlamegraph(props: EvaFlamegraphProps): JSX.Element {
data={flameGraph} data={flameGraph}
height={height} height={height}
width={width} width={width}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ onChange={changeScope}
onChange={(node:any) => { onMouseOver={(_e:Event, node:Flamegraph) => {
if(useScope) changeScope(node.source); setNodeInfos(nodeInfoText(flameGraph, node));
}}
onMouseOver={(_e:Event, nodeInfos:Flamegraph) => {
const percentage = Math.round(
10*(nodeInfos.value * 100)/flameGraph.value)/10;
const value = Math.round(nodeInfos.value*100)/100;
const infos = (
nodeInfos.name+" : "+value+"s : "+percentage+"%"
);
setNodeInfos(infos);
}} }}
onMouseOut={() => { setNodeInfos(""); }} onMouseOut={() => { setNodeInfos(""); }}
/> />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment