# Could the Profile.print() tree view sort in the other order?

**URL:** <https://discourse.julialang.org/t/could-the-profile-print-tree-view-sort-in-the-other-order/63881>\
**Category:** Performance\
**Tags:** profiling\
**Created:** [July 1, 2021, 10:28am UTC](https://discourse.julialang.org/t/could-the-profile-print-tree-view-sort-in-the-other-order/63881 "2021-07-01T10:28:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gleyland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gleyland/32/15339_2.png) [@gleyland](https://discourse.julialang.org/u/gleyland)\
**Post date:** [July 1, 2021, 10:28am UTC](https://discourse.julialang.org/t/could-the-profile-print-tree-view-sort-in-the-other-order/63881/1 "2021-07-01T10:28:42Z")

</div>

Hi,

I’m aware there are other ways of viewing profile output, but Profile.print() is pretty handy in a pinch. It would be _even handier_ if the tree was sorted by count.

The docs say that `sortedby` “Controls the order in `:flat` format”. But I think the code says that the tree view also respects `sortedby` (Profile.jl 762-764):

```julia
        if fmt.sortedby === :count
            counts = collect(frame.count for frame in nexts)
            p = sortperm(counts)

```

BUT, it looks like (and the output also looks like) when the tree view sorts by `:count` it does it in _ascending_ order of counts. It would be much easier to read the profile output if it was in _descending_ order.

Have I interpreted this correctly? Anything that can be done about it?

Thanks!  
Geoff

---

<div class="post-metadata">

**Author:** ![gleyland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gleyland/32/15339_2.png) [@gleyland](https://discourse.julialang.org/u/gleyland)\
**Post date:** [July 1, 2021, 10:59am UTC](https://discourse.julialang.org/t/could-the-profile-print-tree-view-sort-in-the-other-order/63881/2 "2021-07-01T10:59:43Z")

</div>

I’ll reply to myself. Profile.jl line 775 is:

```julia
        for i in reverse(p)

```

Which means I read the code wrong, I think this _should_ do what I asked above. But the output I get puts counts at the same level in ascending order.

If I change line 764 of Profile.jl to:

```julia
        p = sortperm(counts, rev=true)

```

then I get output from `Profile.print()` that I find much easier to use. Looking at the code, as I said above, this is the opposite of what I expect, so I’m a little confused, but also, I have something that works for me.

(BTW, since Profile is in stdlib, changing the “real” Profile.jl didn’t make any difference, I just copied the module locally, renamed it and changed it. Is there a better way of testing changes to stdlib?)
