Skip to content
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

add "c" shortcut to slice a profile #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Once a profile has loaded, the main view is split into two: the top area is the
* `n`: Go to next profile/thread if one is available
* `p`: Go to previous profile/thread if one is available
* `t`: Open the profile/thread selector if available
* `c`: Slice the profile by the current selecting in "Time Order" view
* `Cmd+F`/`Ctrl+F`: to open search. While open, `Enter` and `Shift+Enter` cycle through results

## Contributing
Expand Down
27 changes: 27 additions & 0 deletions src/lib/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,33 @@ export class Profile {
return flattenedProfile
}

getProfileSlice(start: number, end: number): Profile {
const builder = new CallTreeProfileBuilder()

let lastValue = 0

function openFrame(node: CallTreeNode, value: number) {
builder.enterFrame(
node.frame,
(lastValue = value >= end || value < start ? lastValue : value - start),
)
}
function closeFrame(node: CallTreeNode, value: number) {
builder.leaveFrame(
node.frame,
(lastValue = value >= end || value < start ? lastValue : value - start),
)
}

this.forEachCall(openFrame, closeFrame)

const slice = builder.build()
slice.name = this.name
slice.valueFormatter = this.valueFormatter

return slice
}

getInvertedProfileForCallersOf(focalFrameInfo: FrameInfo): Profile {
const focalFrame = Frame.getOrInsert(this.frames, focalFrameInfo)
const builder = new StackListProfileBuilder()
Expand Down
11 changes: 11 additions & 0 deletions src/views/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ export class Application extends StatelessComponent<ApplicationProps> {
if (activeProfileState) {
this.props.setProfileIndexToView(activeProfileState.index - 1)
}
} else if (ev.key === 'c') {
const {activeProfileState, profileGroup, setProfileGroup} = this.props
if (activeProfileState && profileGroup) {
const start = activeProfileState.chronoViewState.configSpaceViewportRect.origin.x
const end = start + activeProfileState.chronoViewState.configSpaceViewportRect.size.x
setProfileGroup({
name: profileGroup.name,
indexToView: 0,
profiles: [activeProfileState.profile.getProfileSlice(start, end)],
})
}
}
}

Expand Down