Skip to content

Commit 92360de

Browse files
committed
small fix
1 parent a86406c commit 92360de

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
import {useRef} from "react";
2-
1+
import {useEffect, useRef, useState} from "react";
32

43

54
const Instruction = ({data, selectionState, onInstrClick}) => {
6-
const selBackgroundColor=selectionState(data)
5+
const selBackgroundColor = data.loc&&selectionState.includes(data.loc) ? "yellow" : "transparent"
76
return (<div id={data.id} onClick={(e) => {
87
e.stopPropagation();
98
onInstrClick(data)
10-
}} style={{backgroundColor:`rgba(255,0,0,${data.localPercentage/100*10})`}}>
11-
<div style={{minWidth:80, display:"inline-block"}}>{data.localPercentage>0.05?`${data.localPercentage.toFixed(1)}%`:""}</div><div style={{backgroundColor: selBackgroundColor==="white"? `none`: selBackgroundColor,display:"inline", fontFamily:"monospace", textDecoration: data.loc?"underline":"default", }}>{data.asm}</div>
9+
}} style={{backgroundColor: `rgba(255,0,0,${data.localPercentage / 100 * 10})`}}>
10+
<div style={{
11+
minWidth: 80,
12+
display: "inline-block"
13+
}}>{data.localPercentage > 0.05 ? `${data.localPercentage.toFixed(1)}%` : ""}</div>
14+
<div style={{
15+
backgroundColor: selBackgroundColor,
16+
display: "inline",
17+
fontFamily: "monospace",
18+
textDecoration: data.loc ? "underline" : "default",
19+
}}>{data.asm}</div>
1220
</div>)
1321

1422
}
1523

1624
const Func = ({data, selectionState, onInstrClick}) => {
17-
let totalFuncEvents=data.assembly.reduce((a, c)=>a+c.samples,0)
25+
let totalFuncEvents = data.assembly.reduce((a, c) => a + c.samples, 0)
1826

1927
return (<div style={{display: "inline"}}>
2028
{data.func}
2129
<div style={{paddingLeft: "10px"}}>
2230
{data.assembly.map((child, index) => {
23-
return (<Instruction data={{...child,localPercentage:child.samples/totalFuncEvents*100}} selectionState={selectionState} onInstrClick={onInstrClick}></Instruction>)
31+
return (<Instruction data={{...child, localPercentage: child.samples / totalFuncEvents * 100}}
32+
selectionState={selectionState} onInstrClick={onInstrClick}></Instruction>)
2433
})}
2534
</div>
2635
</div>)
2736
}
2837

2938

30-
export const PerfAsmViewer = ({data, selectedOps, width, height, onInstrClick,selectedLLVMOps}) => {
39+
export const PerfAsmViewer = ({data, selectedOps, width, height, onInstrClick, selectedLLVMOps}) => {
3140
const scrollableDivRef = useRef(null);
32-
const getBackground = (data) => {
33-
if (data.loc && selectedLLVMOps.includes(data.loc)) {
34-
return "yellow"
35-
}
36-
return "white"
37-
}
41+
42+
3843

3944
return (<div ref={scrollableDivRef} style={{maxWidth: width, maxHeight: height, overflow: "auto"}}>
4045
{
41-
data.map((f)=><Func data={f} selectionState={getBackground} onInstrClick={onInstrClick}/> )
46+
data.map((f) => <Func data={f} selectionState={selectedLLVMOps} onInstrClick={onInstrClick}/>)
4247
}
4348
</div>)
4449
}

0 commit comments

Comments
 (0)