If I were in vgrippa's place, I would have not produced flamegraphs, but treemaps. It's the far superior choice for visualising profiling/query plans and the like, no matter along which property one would measure.
Munging the mysql output into something that is delectable as input to kcachegrind is straight-forward. Screenshots: https://ddg.gg/?q=%21i+kcachegrind
Thanks for the suggestion. Actually I received some feedback to produce something like flamescope from netflix https://github.com/Netflix/flamescope
I will take a look at the treemaps and try to incorporate.