-
Notifications
You must be signed in to change notification settings - Fork 227
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
*: Flamegraph data trimming #2299
Merged
+886
−304
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ad0abc4
Flame graph data trimming
manojVivek 6270df6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 2cf2a66
Merge remote-tracking branch 'origin/main' into flamegraph-trimming
manojVivek f502d12
Merge remote-tracking branch 'origin/main' into flamegraph-trimming
manojVivek f66bdef
Provision to pass the nodeCutOffFraction from the UI
manojVivek 5e1820b
Introduced a user preference hook that supports types other than bool…
manojVivek 14ebaf8
Merge remote-tracking branch 'origin/flamegraph-trimming' into flameg…
manojVivek 880c203
Type-check failures fixed
manojVivek 8741d07
Modified trimming to happen based on the screen size
manojVivek a794316
Merge remote-tracking branch 'origin/main' into flamegraph-trimming
manojVivek 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
Introduced a user preference hook that supports types other than bool…
…ean and hooked in NodeCutOffThreshold prefrence for the query request
commit 5e1820bcaa2cbcca7be81e8faf9f6fa5794a5a5c
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
ui/packages/app/web/src/components/ui/UserPreferences/GraphTrimming.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,37 @@ | ||
// Copyright 2022 The Parca Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import useUserPreference, {USER_PREFERENCES} from '@parca/functions/useUserPreference'; | ||
import UserPreferenceItem from './UserPreferenceItem'; | ||
|
||
const GraphTrimming = () => { | ||
const [disabledTrimming] = useUserPreference<boolean>(USER_PREFERENCES.DISABLE_TRIMMING.key); | ||
|
||
return ( | ||
<div> | ||
<UserPreferenceItem userPreferenceDetails={USER_PREFERENCES.DISABLE_TRIMMING} /> | ||
<div className=""> | ||
<UserPreferenceItem | ||
userPreferenceDetails={USER_PREFERENCES.NODE_TRIM_THRESHOLD} | ||
className="flex-row-reverse w-80" | ||
disabled={disabledTrimming} | ||
/> | ||
<p className="text-xs mt-1 ml-6"> | ||
Nodes that have value less than this percentage will be removed. | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GraphTrimming; |
81 changes: 81 additions & 0 deletions
81
ui/packages/app/web/src/components/ui/UserPreferences/UserPreferenceItem.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,81 @@ | ||
// Copyright 2022 The Parca Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import cx from 'classnames'; | ||
import useUserPreference, {UserPreferenceDetails} from '@parca/functions/useUserPreference'; | ||
|
||
interface GenericInputProps { | ||
id: string; | ||
type: string; | ||
value: any; | ||
onChange: (value: any) => void; | ||
disabled?: boolean; | ||
} | ||
|
||
const GenericInput = ({id, type, value, onChange, disabled = false}: GenericInputProps) => { | ||
switch (type) { | ||
case 'boolean': | ||
return ( | ||
<input | ||
className="bg-inherit border disabled:cursor-not-allowed" | ||
id={id} | ||
type="checkbox" | ||
checked={value} | ||
onChange={e => onChange(e.target.checked)} | ||
disabled={disabled} | ||
/> | ||
); | ||
case 'number': | ||
return ( | ||
<input | ||
className="bg-inherit border p-1 w-20 disabled:cursor-not-allowed rounded-sm" | ||
id={id} | ||
type="number" | ||
value={value} | ||
onChange={e => onChange(Number(e.target.value))} | ||
disabled={disabled} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
interface UserPreferenceItemProps { | ||
userPreferenceDetails: UserPreferenceDetails; | ||
className?: string; | ||
disabled?: boolean; | ||
} | ||
|
||
function UserPreferenceItem<T>({ | ||
userPreferenceDetails, | ||
className = '', | ||
disabled = false, | ||
}: UserPreferenceItemProps) { | ||
const [enabledTrimming, setEnabledTrimming] = useUserPreference<T>(userPreferenceDetails.key); | ||
|
||
return ( | ||
<div | ||
className={cx('flex gap-2 items-center', {[className]: className, 'opacity-50': disabled})} | ||
> | ||
<GenericInput | ||
id={userPreferenceDetails.key} | ||
value={enabledTrimming} | ||
onChange={setEnabledTrimming} | ||
type={userPreferenceDetails.type} | ||
disabled={disabled} | ||
/> | ||
<label htmlFor={userPreferenceDetails.key}>{userPreferenceDetails.name}</label> | ||
</div> | ||
); | ||
} | ||
|
||
export default UserPreferenceItem; |
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
59 changes: 59 additions & 0 deletions
59
ui/packages/shared/functions/src/useUserPreference/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2022 The Parca Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {useLocalStorage} from '@rehooks/local-storage'; | ||
|
||
const USER_PREFERENCES_KEY = 'user-preferences'; | ||
|
||
export interface UserPreferenceDetails { | ||
name: string; | ||
key: string; | ||
type: string; | ||
default: any; | ||
} | ||
|
||
export const USER_PREFERENCES: {[key: string]: UserPreferenceDetails} = { | ||
HIGHTLIGHT_AFTER_FILTERING: { | ||
name: 'Highlight matching nodes after filtering', | ||
key: 'HIGHTLIGHT_AFTER_FILTERING', | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
DISABLE_TRIMMING: { | ||
name: 'Disable trimming of insignificant nodes', | ||
key: 'DISABLE_TRIMMING', | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
NODE_TRIM_THRESHOLD: { | ||
name: 'Node trim threshold', | ||
key: 'NODE_TRIM_THRESHOLD', | ||
type: 'number', | ||
default: 0.5, | ||
}, | ||
} as const; | ||
|
||
export type UserPreference = keyof typeof USER_PREFERENCES; | ||
|
||
const useUserPreference = <T>(preferenceName: UserPreference): [T, (flag: T) => void] => { | ||
const [flags, setFlags] = useLocalStorage<{[flag: string]: any}>(USER_PREFERENCES_KEY, {}); | ||
|
||
const value: T = flags[preferenceName] ?? USER_PREFERENCES[preferenceName].default; | ||
const setFlag = (flag: T): void => { | ||
setFlags({...flags, [preferenceName]: flag}); | ||
}; | ||
|
||
return [value, setFlag]; | ||
}; | ||
|
||
export default useUserPreference; |
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,15 @@ | ||
// Copyright 2022 The Parca Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
export {default} from './src/useUserPreference'; | ||
export * from './src/useUserPreference'; |
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
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.
interesting idea, but I think this would break shareability, if you have a different configuration from me and you share a link with me I will see different data, if we expose this value (which I don't think we should today), then we should make it part of exploring the data (and therefore part of the URL)
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.
Yeah ok, and we can make this a value added to the URL whenever the user is in the ProfileExplorer and the query formed with the value from the URL taking higher precedence over the value from the preference so that the shareability is maintained.
But I would prefer moving this into a separate issue and implement it once #2115 is merged. As it has some nice utilities for dealing with the URL params state. Any concerns?
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.
I would suggest then let's just use a hard-coded value for a start. (I'm not even sure it ever doesn't need to be)
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.
I tried to see if I can implement the URL state without that PR, but it looks like a lot of duplicate work between these two. So, I'll hold it off.
So, if I understand it correctly, meanwhile, you would like this option removed from the user preference and work with just the hardcoded
0.005
cut-off value?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.
This is done.