-
Notifications
You must be signed in to change notification settings - Fork 23
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
Pretty thread names based on best-effort parsing of Thread#inspect output #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ def initialize(ruby_thread_id, profile, categorizer, name:, tid:, samples:, weig | |
@profile = profile | ||
@categorizer = categorizer | ||
@tid = tid | ||
@name = name | ||
@name = pretty_name(name) | ||
|
||
timestamps ||= [0] * samples.size | ||
@samples, @weights, @timestamps = samples, weights, timestamps | ||
|
@@ -385,6 +385,24 @@ def string_table | |
|
||
private | ||
|
||
def pretty_name(name) | ||
if name.empty? | ||
begin | ||
tr = ObjectSpace._id2ref(@ruby_thread_id) | ||
name = tr.inspect if tr | ||
rescue RangeError | ||
# Thread was already GC'd | ||
end | ||
end | ||
return name unless name.start_with?("#<Thread") | ||
pretty = [] | ||
obj_address = name[/Thread:(0x\d+)/,1] | ||
best_id = name[/\#<Thread:0x\w+@?\s?(.*)\s+\S+>/,1] | ||
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. i originally wanted to do this just splitting on whitespace, but realized that this could get complicated very fast:
So instead, I try to just anchor on what we know will be present at the start ( If the thread was named, then the match for |
||
pretty << best_id unless best_id.empty? | ||
pretty << "(#{obj_address})" | ||
pretty.join(' ') | ||
end | ||
|
||
def gc_category | ||
@categorizer.get_category("GC") | ||
end | ||
|
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.
case to cover "retained memory" name set for
:retained
mode, or if we ever got another name somehow. Also if we couldn't get any inspect output, no sense in doing the parsing below.