# Does anybody use \`--track-allocations\`

**URL:** <https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570>\
**Category:** General Usage\
**Created:** [January 5, 2023, 7:38pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570 "2023-01-05T19:38:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [January 5, 2023, 7:38pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/1 "2023-01-05T19:38:58Z")

</div>

Would anyone mind if we removed support for `julia --track-allocations` in favor of the more reliable [allocation profiler](https://docs.julialang.org/en/v1/manual/profile/#Allocation-Profiler) ~~`@allocations` and `@allocated` macros?~~ ([RFC: Remove `--track-allocation` by vchuravy · Pull Request #48070 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/48070))

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [January 9, 2023, 5:50pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/2 "2023-01-09T17:50:54Z")

</div>

I’m assuming that `@allocations` refers to the recently merged PR [#47367](https://github.com/JuliaLang/julia/pull/47367). I understand that like `@allocated` it returns a single number. With `--track-allocations` one can identify the lines in the code where the allocations happen. I find this quite useful. How would one do that with one of the macros?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 9, 2023, 6:04pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/3 "2023-01-09T18:04:25Z")

</div>

No, this is about the [allocation profiler](https://docs.julialang.org/en/v1/manual/profile/#Allocation-Profiler)

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [January 9, 2023, 8:14pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/4 "2023-01-09T20:14:44Z")

</div>

`--track-allocations` is the only way I have successfully debugged spurious allocations. Sure, the macros you are describing are probably very convenient for people that are comfortable juggling the various “descending in the call graph” tools, but `--track-allocations` is simply easier for me, even if it requires reading through a ton of files. Similarly, the two or three times I tried to make the allocation profiler work, I failed in the first few minutes (the reported data seemed nonsensical) and simply switched back to `--track-allocations`.

However, there is probably a better workflow than mine. I would be grateful if someone writes a few detailed blog posts on such a better workflow. (I am referring to a workflow that uses the macros. There are already good blog posts about the profiler.)

**Edit: thinking more about it, my negative knee-jerk reaction comes almost certainly from the fact that I could not make the profiler work in vscode on my first couple of tries. If the profiler is the only option, I am sure I will learn to love it.**

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 9, 2023, 8:17pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/5 "2023-01-09T20:17:42Z")

</div>

The TLDR is that with the allocation profiler, profiling allocations becomes exactly the same as profiling runtime. Just `Allocs@profile my_func()` and it will take a trace of all the allocations.

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [January 9, 2023, 10:29pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/6 "2023-01-09T22:29:36Z")

</div>

I’m trying this out. I’m looking at the results with [PProf.jl](https://github.com/JuliaPerf/PProf.jl). Some questions I have:

1. PProf.jl pulls in a lot of packages, mostly for graphics, I guess. Is there a more light-weight, text-based interface that produces human-readable output?

2. At my present level of understanding, I find it hard to read the output I get. After saying `Profile.Allocs@profile my_func()` and `PProf.Allocs.pprof()`, I don’t even see a function `my_func` in the output. (I’ve tried out various views in the web interface.) Am I missing any documentation here?

3. If everything works, will there be a way to track down allocations to a specific line in the code I’ve written? I find this more helpful than just knowing the function in which the allocation occurs. In the diagrams I’ve seen there were no line numbers.

Thanks in advance for any clarification!

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [January 12, 2023, 2:23am UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/7 "2023-01-12T02:23:45Z")

</div>

OK, to address the original question: I would prefer `--track-allocation` to stay.

Firstly, it appears to be much more lightweight than the allocation profiler. To read the profiler output, one seems to need `PProf.jl`. On my machine, that package pulled in 5GB of artifacts!

Secondly, `--track-allocation` seems to be easier to use for casual users, at least with the current state of the documentation. In a test case where I try to locate allocations in a function with just three lines, I end up with a graph having close to 70 nodes, and it’s not obvious to me how they are related to my three lines. I’m sure there is a way to understand that, but I prefer the self-explanatory output of `--track-allocation`. Other non-expert users might do so, too.

---

<div class="post-metadata">

**Author:** ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Post date:** [January 12, 2023, 3:13am UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/8 "2023-01-12T03:13:16Z")

</div>

I would use the `--track-allocations` to narrow down where allocations were happening at a rough level but to drill down and get specific repeatable results on allocations I’d used `@allocated`. I say more repeatable because in the past I got seemingly inconsistent results using the `--track-allocations` method.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [January 12, 2023, 3:52am UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/9 "2023-01-12T03:52:53Z")

</div>

The new profiler has the momentous advantage of greater flexibility, but no one has yet been motivated to make friendly postprocessing tools. The PProf recommendation seems insane. But `Profile.Allocs.fetch` yields a vector of simple structs with stacktraces and sizes, and crunching it for a particular investigation is really not that hard.

Apparently an example is in order.

```julia
using LinearAlgebra
using Profile

function eigen_allocs()
    A = rand(100,100)

    eigen(A) # in case we need to compile anything
    @time eigen(A) # for reference
    Profile.Allocs.@profile sample_rate=1.0 eigen(A)

    results = Profile.Allocs.fetch()
    allocs = results.allocs
    t = 0
    for r in allocs
        st = r.stacktrace
        for s in st
            fn = string(s.file)
            if occursin("LinearAlgebra", fn)
                println("$(basename(fn)):$(s.line) $(r.size)")
                t += r.size
                break
            end
        end
    end
    println("total: $t")
end

eigen_allocs()

```

```julia
0.008760 seconds (21 allocations: 422.469 KiB)
LinearAlgebra.jl:377 80000
LinearAlgebra.jl:377 40
lapack.jl:2048 848
...
eigen.jl:169 32
total: 431968

```

Exercise for the reader: fix the logic to select the _most useful_ stacktrace entries.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 12, 2023, 3:56am UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/10 "2023-01-12T03:56:04Z")

</div>

Yeah, there’s a pretty easy PR to add allocation profiling support to ProfileView which is a lot lighter weight.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [January 12, 2023, 8:04am UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/11 "2023-01-12T08:04:11Z")

</div>

> [@Ralph\_Smith](#):
>
> The new profiler has the momentous advantage of greater flexibility, but no one has yet been motivated to make friendly postprocessing tools.

I generally agree with the statement, but note that in VSCode (with the Julia extension) you get the same visualizations as for regular (time) profiling. For example, it highlights the code lines in the editor that have the most / the largest allocations.

 ![Screenshot 2023-01-12 at 09.07.48](https://global.discourse-cdn.com/julialang/original/3X/4/9/49757d2a282f2210ca19aa580fe05db000106652.jpeg)

(Note how the three lines, where A,B,C are defined, are highlighted. Since I selected `size`, the C line has the tallest bar because its size is the largest.)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [March 1, 2023, 6:42pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/12 "2023-03-01T18:42:34Z")

</div>

> [@Krastanov](#):
>
> the only way I have successfully debugged spurious allocations.

First, I believe it’s not the only way, and second, I want a way to guarantee no allocations.

Some languages, at least D, has such a way, to mark a function `@nogc`. Such a function can only call similarly marked (or I think if proven to not allocate). You could test and see there are no allocations, and that’s often enough, but also might be only be the case for your code-path, with no guarantee at runtime… I could also foresee the macro/marking not just for applying to the function, as with `@inline`, but also as with it, possible to use it in the caller.

> [@matthias314](#):
>
> one seems to need `PProf.jl`. On my machine, that package pulled in 5GB of artifacts!

Probably something that could be done better. Would you miss the feature until then, or would it be ok to just use it in an older version of Julia? I guess it’s simple to drop the feature from Julia, not sure what is the great benefit, in startup cost or sysimage size etc. I’ve never used that feature (and not sure most even know of it), so feel free to drop it on my account! I’m neural though, unless there’s any such downside, then I want it gone in 1.9.

---

<div class="post-metadata">

**Author:** ![matthias314](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Post date:** [March 1, 2023, 8:53pm UTC](https://discourse.julialang.org/t/does-anybody-use-track-allocations/92570/13 "2023-03-01T20:53:36Z")

</div>

> [@Palli](#):
>
> Would you miss the feature until then, or would it be ok to just use it in an older version of Julia?

It’s not “mission-critical” for me; in this sense I could do without in the latest Julia version. However, if it goes, I would hope to see a lightweight and easy-to-use replacement in the near future.
