To compare stack traces of a program Brendan Gregg suggested the so called Differential Flamegraph, but actually it might no be so straight forward to use it.
Brendan Gregg diff flamegraph
On his diff alg, Brendan G, the difference of the two profiles is highlighted using a color scheme. Basically, it takes the first profile and put the colors using a delta from the second profile! This delta might cause an issue for comparing since we would need to wonder which one of the frames is which.
TraceCompare Flamegraph
Francois Doray’s TraceCompare developed another differential flamegraph comparing the first and the second groups in the javascript.
When faced with the same problem, he talks about two solutions: use 3 flamegraphs (input 1, input 2 and output) or use a new black/white solution, which adds a region for missing code paths in white. Basically highlighting a Venn diagram solution of the result would be the first tree, and inside of it the difference of the second.
A problem with this approach is that some code paths present in the A profile may be missing entirely in the B profile, and so will be missing from the final visualization. This could be misleading.
Differential flame graph used in my masters implementation
To simplify the question I developed a diff flamegraph that basically used three colors for each stack using the average of it.
Reference
[1] http://cacm.acm.org/magazines/2016/6/202665-the-flame-graph/fulltext#R2