# Gantt chart for profiling multi threaded code?

**URL:** https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672
**Category:** General Usage
**Tags:** question
**Created:** [September 4, 2021, 1:25am UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672 "2021-09-04T01:25:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [September 4, 2021, 1:25am UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672/1 "2021-09-04T01:25:36Z")

</div>

Investigating the bottleneck in a parallel program preventing it from scaling linearly like its C++ counterpart. The program includes I/O and uses CodeZlib (which has `ccall`). Trying to see how threads are spending time.

Maybe this is already a profiling package?

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [September 4, 2021, 7:42pm UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672/2 "2021-09-04T19:42:29Z")

</div>

I don’t know of a Gantt chart library for plain multithreaded Julia code; that would require a thread-safe timing library, similar to TimerOutputs (which itself is not thread-safe), so that you can collect the relevant events into different groups for display.

I would like to point out that Dagger.jl has a built-in Gantt chart, which I’m in the process of overhauling to be more efficient (the PR will be available in the next few days). If you’re interested in porting your code to Dagger, I could help you setup Dagger’s Gantt chart and expose custom events to it.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [September 4, 2021, 8:13pm UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672/3 "2021-09-04T20:13:58Z")

</div>

> [@jpsamaroo](#):
>
> thread-safe timing library

is `time()` not thread-safe? someone tried some hacky stuff: [https://github.com/aminnj/ThreadGantt.jl/blob/678093b4587408303020b36b4fccc044e7d5b280/src/main.jl#L3](https://github.com/aminnj/ThreadGantt.jl/blob/678093b4587408303020b36b4fccc044e7d5b280/src/main.jl#L3) and seems got qualitatively useful visualization

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [September 4, 2021, 8:19pm UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672/4 "2021-09-04T20:19:44Z")

</div>

Sure, `@time` is technically thread-safe (all it’s doing is making two system calls and doing a subtraction to get the time), but collecting all `@time`-d information from every thread requires considerations to be realistically thread-safe. I can’t tell if the `ThreadGantt.jl` package is data race-free, so I can’t make any comments on whether using it will work for you.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [September 5, 2021, 7:07am UTC](https://discourse.julialang.org/t/gantt-chart-for-profiling-multi-threaded-code/67672/5 "2021-09-05T07:07:42Z")

</div>

Here’s something I played with a bit: [Gallery · EventTracker](https://tkf.github.io/EventTracker.jl/dev/gallery/)

![image](https://global.discourse-cdn.com/julialang/original/3X/5/b/5b0be0e8095c9d851cc66fe466c9221372903307.png)

If you want conventional profiling, you can use the stdlib profiler in the nightly build. Better threading support was added a few days ago: [https://github.com/JuliaLang/julia/pull/41742](https://github.com/JuliaLang/julia/pull/41742)
