sample as long as you want, ctrl-C when you've had enough can also --call-graph dwarf for more accurate stack traces but will take a lot more memory & storage
sudo perf record -e cycles,instructions -c 1000000 -a --call-graph fp
get the stacks
sudo perf script > stacks.out