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 tree view for recent $/memoryUsage feature in clangd. #86

Merged
merged 5 commits into from
Oct 22, 2020
Merged

Conversation

sam-mccall
Copy link
Member

No description provided.

Copy link
Member

@kadircet kadircet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, LGTM

.filter(x => !x.startsWith('_'))
.map(e => convert(m[e] as WireTree, e))
.sort((x, y) => x.total - y.total)
.reverse(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not sort in the other way directly? (or why not sort based on title)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The intention was to sort by [total, title] but I messed it up.

The code to sort by a compound key is awkward in JS, but sort() is stable, so we sort the titles first and then the totals.

interface WireTree {
_self: number;
_total: number;
[child: string]: WireTree|number|string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my typescript isnt so strong, but why can this be anything but WireTree ? isn't it enough to handle _self and _total explicitly? (and even if that's not enough, where does the string come from)

Copy link
Member Author

@sam-mccall sam-mccall Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_self and _total have to conform to this constraint too, unfortunately. I couldn't find a way to more precisely express the type. This is one of the reasons for mapping quickly to another type :-)

(There's a workaround involving intersection types, but they must be type rather than interface and types can't be recursive as they're just aliases).

string is a mistake (leftover from an intermediate version where I added _title)

item.tooltip = `self=${node.self} total=${node.total}`;
if (node.isFile)
item.iconPath = new vscode.ThemeIcon('symbol-file');
else if (!node.children.length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we intentionally not set any icons for non-leaf (and non-file) nodes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This is subjective, but I couldn't find an icon that seemed to add signal rather than just visual noise.

src/memory-usage.ts Outdated Show resolved Hide resolved
src/memory-usage.ts Outdated Show resolved Hide resolved
src/memory-usage.ts Outdated Show resolved Hide resolved
@sam-mccall sam-mccall merged commit 0b171de into master Oct 22, 2020
@sam-mccall sam-mccall deleted the memory branch October 22, 2020 08:04
@hokein
Copy link
Collaborator

hokein commented Oct 22, 2020

might be worth to mention this in https://clangd.llvm.org/extensions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants