-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(FlameGraph): Keep focus whenever the profile data changes #325
Open
grafakus
wants to merge
8
commits into
main
Choose a base branch
from
grafakus/fg-keeps-focused
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3941bf
feat(FlameGraph): Keep focus whenever the profile data changes
grafakus 54fca79
feat: Keep sandwhich
grafakus efa05d6
fix: Keep item focused at all times + cosmetic UI changes
grafakus 9078f02
fix: Prevent too many renders
grafakus b3bb997
feat: Add tooltip on focus pill
grafakus 29d3650
fix(FlameGraph): Fix fatal runtime error when in sandwich view
grafakus 2d4a91a
fix: Keep sandwich view
grafakus 56d07b6
fix: Edge case with sandwich view
grafakus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { css } from '@emotion/css'; | ||
import { createTheme, GrafanaTheme2, LoadingState, TimeRange } from '@grafana/data'; | ||
import { FlameGraph } from '@grafana/flamegraph'; | ||
import { SceneComponentProps, SceneObjectBase, SceneObjectState, SceneQueryRunner } from '@grafana/scenes'; | ||
import { Spinner, useStyles2, useTheme2 } from '@grafana/ui'; | ||
import { displayWarning } from '@shared/domain/displayStatus'; | ||
|
@@ -14,6 +13,7 @@ import { PyroscopeLogo } from '@shared/ui/PyroscopeLogo'; | |
import React, { useEffect, useMemo } from 'react'; | ||
import { Unsubscribable } from 'rxjs'; | ||
|
||
import { FlameGraph } from '../../../../tmp/grafana-flamegraph/src/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS was complaining when I tried aliasing |
||
import { useBuildPyroscopeQuery } from '../../domain/useBuildPyroscopeQuery'; | ||
import { getSceneVariableValue } from '../../helpers/getSceneVariableValue'; | ||
import { buildFlameGraphQueryRunner } from '../../infrastructure/flame-graph/buildFlameGraphQueryRunner'; | ||
|
@@ -201,6 +201,7 @@ export class SceneFlameGraph extends SceneObjectBase<SceneFlameGraphState> { | |
timeRange={data.export.timeRange} | ||
/> | ||
} | ||
keepFocusOnDataChange | ||
/> | ||
</Panel> | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...loreServiceFlameGraph/components/SceneFunctionDetailsPanel/domain/useGitHubIntegration.ts
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
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,9 @@ | ||
{ | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"react/react-in-jsx-scope": "off", | ||
"@grafana/no-border-radius-literal": "off", | ||
"sonarjs/cognitive-complexity": "off", | ||
"sonarjs/no-collapsible-if": "off" | ||
} | ||
} |
212 changes: 212 additions & 0 deletions
212
src/tmp/grafana-flamegraph/src/FlameGraph/FlameGraph.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,212 @@ | ||
// This component is based on logic from the flamebearer project | ||
// https://github.com/mapbox/flamebearer | ||
// ISC License | ||
// Copyright (c) 2018, Mapbox | ||
// Permission to use, copy, modify, and/or distribute this software for any purpose | ||
// with or without fee is hereby granted, provided that the above copyright notice | ||
// and this permission notice appear in all copies. | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
// THIS SOFTWARE. | ||
import * as React from 'react'; | ||
import { css, cx } from '@emotion/css'; | ||
import { Icon } from '@grafana/ui'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { PIXELS_PER_LEVEL } from '../constants'; | ||
import { ClickedItemData, ColorScheme, ColorSchemeDiff, SelectedView, TextAlign } from '../types'; | ||
import { CollapsedMap, FlameGraphDataContainer, LevelItem } from './dataTransform'; | ||
import FlameGraphCanvas from './FlameGraphCanvas'; | ||
import { GetExtraContextMenuButtonsFunction } from './FlameGraphContextMenu'; | ||
import FlameGraphMetadata from './FlameGraphMetadata'; | ||
|
||
type Props = { | ||
data: FlameGraphDataContainer; | ||
rangeMin: number; | ||
rangeMax: number; | ||
matchedLabels?: Set<string>; | ||
setRangeMin: (range: number) => void; | ||
setRangeMax: (range: number) => void; | ||
style?: React.CSSProperties; | ||
onItemFocused: (data: ClickedItemData) => void; | ||
focusedItemData?: ClickedItemData; | ||
textAlign: TextAlign; | ||
sandwichItem?: string; | ||
onSandwich: (label: string) => void; | ||
onFocusPillClick: () => void; | ||
onSandwichPillClick: () => void; | ||
colorScheme: ColorScheme | ColorSchemeDiff; | ||
showFlameGraphOnly?: boolean; | ||
getExtraContextMenuButtons?: GetExtraContextMenuButtonsFunction; | ||
collapsing?: boolean; | ||
selectedView: SelectedView; | ||
search: string; | ||
collapsedMap: CollapsedMap; | ||
setCollapsedMap: (collapsedMap: CollapsedMap) => void; | ||
}; | ||
|
||
const FlameGraph = ({ | ||
data, | ||
rangeMin, | ||
rangeMax, | ||
matchedLabels, | ||
setRangeMin, | ||
setRangeMax, | ||
onItemFocused, | ||
focusedItemData, | ||
textAlign, | ||
onSandwich, | ||
sandwichItem, | ||
onFocusPillClick, | ||
onSandwichPillClick, | ||
colorScheme, | ||
showFlameGraphOnly, | ||
getExtraContextMenuButtons, | ||
collapsing, | ||
selectedView, | ||
search, | ||
collapsedMap, | ||
setCollapsedMap, | ||
}: Props) => { | ||
const styles = getStyles(); | ||
|
||
const [levels, setLevels] = useState<LevelItem[][]>(); | ||
const [levelsCallers, setLevelsCallers] = useState<LevelItem[][]>(); | ||
const [totalProfileTicks, setTotalProfileTicks] = useState<number>(0); | ||
const [totalProfileTicksRight, setTotalProfileTicksRight] = useState<number>(); | ||
const [totalViewTicks, setTotalViewTicks] = useState<number>(0); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
let levels = data.getLevels(); | ||
let totalProfileTicks = levels.length ? levels[0][0].value : 0; | ||
let totalProfileTicksRight = levels.length ? levels[0][0].valueRight : undefined; | ||
let totalViewTicks = totalProfileTicks; | ||
let levelsCallers = undefined; | ||
|
||
if (sandwichItem) { | ||
const [callers, callees] = data.getSandwichLevels(sandwichItem); | ||
levels = callees; | ||
levelsCallers = callers; | ||
// We need this separate as in case of diff profile we want to compute diff colors based on the original ticks. | ||
totalViewTicks = callees[0]?.[0]?.value ?? 0; | ||
} | ||
setLevels(levels); | ||
setLevelsCallers(levelsCallers); | ||
setTotalProfileTicks(totalProfileTicks); | ||
setTotalProfileTicksRight(totalProfileTicksRight); | ||
setTotalViewTicks(totalViewTicks); | ||
} | ||
}, [data, sandwichItem]); | ||
|
||
if (!levels) { | ||
return null; | ||
} | ||
|
||
const commonCanvasProps = { | ||
data, | ||
rangeMin, | ||
rangeMax, | ||
matchedLabels, | ||
setRangeMin, | ||
setRangeMax, | ||
onItemFocused, | ||
focusedItemData, | ||
textAlign, | ||
onSandwich, | ||
colorScheme, | ||
totalProfileTicks, | ||
totalProfileTicksRight, | ||
totalViewTicks, | ||
showFlameGraphOnly, | ||
collapsedMap, | ||
setCollapsedMap, | ||
getExtraContextMenuButtons, | ||
collapsing, | ||
search, | ||
selectedView, | ||
}; | ||
const canvas = levelsCallers?.length ? ( | ||
grafakus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<> | ||
<div className={styles.sandwichCanvasWrapper}> | ||
<div className={styles.sandwichMarker}> | ||
Callers | ||
<Icon className={styles.sandwichMarkerIcon} name={'arrow-down'} /> | ||
</div> | ||
<FlameGraphCanvas | ||
{...commonCanvasProps} | ||
root={levelsCallers[levelsCallers.length - 1][0]} | ||
depth={levelsCallers.length} | ||
direction={'parents'} | ||
// We do not support collapsing in sandwich view for now. | ||
collapsing={false} | ||
/> | ||
</div> | ||
|
||
<div className={styles.sandwichCanvasWrapper}> | ||
<div className={cx(styles.sandwichMarker, styles.sandwichMarkerCalees)}> | ||
<Icon className={styles.sandwichMarkerIcon} name={'arrow-up'} /> | ||
Callees | ||
</div> | ||
<FlameGraphCanvas | ||
{...commonCanvasProps} | ||
root={levels[0][0]} | ||
depth={levels.length} | ||
direction={'children'} | ||
collapsing={false} | ||
/> | ||
</div> | ||
</> | ||
) : ( | ||
<FlameGraphCanvas {...commonCanvasProps} root={levels[0][0]} depth={levels.length} direction={'children'} /> | ||
); | ||
|
||
return ( | ||
<div className={styles.graph}> | ||
<FlameGraphMetadata | ||
data={data} | ||
focusedItem={focusedItemData} | ||
sandwichedLabel={sandwichItem} | ||
totalTicks={totalViewTicks} | ||
onFocusPillClick={onFocusPillClick} | ||
onSandwichPillClick={onSandwichPillClick} | ||
/> | ||
{canvas} | ||
</div> | ||
); | ||
}; | ||
|
||
const getStyles = () => ({ | ||
graph: css({ | ||
label: 'graph', | ||
overflow: 'auto', | ||
flexGrow: 1, | ||
flexBasis: '50%', | ||
}), | ||
sandwichCanvasWrapper: css({ | ||
label: 'sandwichCanvasWrapper', | ||
display: 'flex', | ||
marginBottom: `${PIXELS_PER_LEVEL / window.devicePixelRatio}px`, | ||
}), | ||
sandwichMarker: css({ | ||
label: 'sandwichMarker', | ||
writingMode: 'vertical-lr', | ||
transform: 'rotate(180deg)', | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
}), | ||
sandwichMarkerCalees: css({ | ||
label: 'sandwichMarkerCalees', | ||
textAlign: 'right', | ||
}), | ||
sandwichMarkerIcon: css({ | ||
label: 'sandwichMarkerIcon', | ||
verticalAlign: 'baseline', | ||
}), | ||
}); | ||
|
||
export default FlameGraph; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed and added all its dependencies instead.