Fragments (full lines) of source code are printed by perf in annotate mode (man page; relevant part of The Perf Tutorial). Use perf annotate -s=MyFunction
or in perf report
scroll down to the subtree where your MyFunction is root of tree (line where self time is reported; you can use / command to search for it) and then select a button (or Enter then Annotate "MyFunction").
Source code and its lines should be visible near assembly lines in Annotate mode. http://man7.org/linux/man-pages/man1/perf-annotate.1.html
This command reads the input file and displays an annotated version
of the code. If the object file has debug symbols then the source
code will be displayed alongside assembly code.
-l, --print-line
Print matching source lines (may be slow).
--source
Interleave source code with assembly code. Enabled by default,
disable with `--no-source`.
-s, --symbol=<symbol>
Symbol to annotate.
Perf report may use srclines in sorting (--sort=
option) but instructions are unclear. Its man page documents --source
option too, but apparently it is used only in Annotate some_function mode: http://man7.org/linux/man-pages/man1/perf-report.1.html
--source
Interleave source code with assembly code. Enabled by default,
disable with --no-source.