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


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):

        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?


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

        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:

        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?)

1 Like