forked from ivoanjo/gvl-tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide when possible the thread name and gem name
gvl-tracing handles properly thread name for basic usage like: ```ruby Thread.new do Thread.current.name = "thread name end ``` But on more complicated with external libraries it is not able to properly handles thread name. Jean had a good idea in ivoanjo#9 about using `Thread.list`. This commit does this: - Store as list of json line, events we want to monitor - Store `Thread.list` before stopping saving event related to the GVL - Iterate of events store in json file and modify entries where we can find the name of the thread - Go a little bit further when we can provide the gem name This is a very naive approach and probably not super efficient. But this is a first try.
- Loading branch information
Showing
5 changed files
with
71 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"ph":"M","pid":81742,"tid":0,"name":"thread_name","args":{"name":null}},{"ph":"E","pid":81742,"tid":0,"ts":0.0},{"ph":"B","pid":81742,"tid":0,"ts":0.0,"name":"started_tracing"},{"ph":"M","pid":81742,"tid":1,"name":"thread_name","args":{"name":"worker-1 from concurrent-ruby"}},{"ph":"E","pid":81742,"tid":1,"ts":62.0},{"ph":"B","pid":81742,"tid":1,"ts":62.0,"name":"started"},{"ph":"E","pid":81742,"tid":1,"ts":65.0},{"ph":"B","pid":81742,"tid":1,"ts":65.0,"name":"wants_gvl"},{"ph":"M","pid":81742,"tid":2,"name":"thread_name","args":{"name":"worker-2 from concurrent-ruby"}},{"ph":"E","pid":81742,"tid":2,"ts":76.0},{"ph":"B","pid":81742,"tid":2,"ts":76.0,"name":"started"},{"ph":"E","pid":81742,"tid":2,"ts":78.0},{"ph":"B","pid":81742,"tid":2,"ts":78.0,"name":"wants_gvl"},{"ph":"M","pid":81742,"tid":3,"name":"thread_name","args":{"name":"worker-3 from concurrent-ruby"}},{"ph":"E","pid":81742,"tid":3,"ts":88.0},{"ph":"B","pid":81742,"tid":3,"ts":88.0,"name":"started"},{"ph":"E","pid":81742,"tid":3,"ts":89.0},{"ph":"B","pid":81742,"tid":3,"ts":89.0,"name":"wants_gvl"},{"ph":"M","pid":81742,"tid":4,"name":"thread_name","args":{"name":"worker-4 from concurrent-ruby"}},{"ph":"E","pid":81742,"tid":4,"ts":97.0},{"ph":"B","pid":81742,"tid":4,"ts":97.0,"name":"started"},{"ph":"E","pid":81742,"tid":4,"ts":98.0},{"ph":"B","pid":81742,"tid":4,"ts":98.0,"name":"wants_gvl"},{"ph":"M","pid":81742,"tid":5,"name":"thread_name","args":{"name":"worker-5 from concurrent-ruby"}},{"ph":"E","pid":81742,"tid":5,"ts":106.0},{"ph":"B","pid":81742,"tid":5,"ts":106.0,"name":"started"},{"ph":"E","pid":81742,"tid":5,"ts":107.0},{"ph":"B","pid":81742,"tid":5,"ts":107.0,"name":"wants_gvl"},{"ph":"E","pid":81742,"tid":0,"ts":146.0},{"ph":"B","pid":81742,"tid":0,"ts":146.0,"name":"stopped_tracing"}] |
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,18 @@ | ||
# conrrent-ruby needs to be installed | ||
require "concurrent" | ||
require "gvl-tracing" | ||
|
||
def fib(n) | ||
return n if n <= 1 | ||
fib(n - 1) + fib(n - 2) | ||
end | ||
|
||
GvlTracing.start("examples/thread_name_with_extension.json") | ||
pool = Concurrent::FixedThreadPool.new(5) | ||
|
||
40.times do | ||
pool.post do | ||
p fib(30) | ||
end | ||
end | ||
GvlTracing.stop |
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