I've run some sample code through perf
, and get the following top hotspot:
- 63.93% 0.10% bonds libc.so.6 [.] __GI___fstatat64
63.82% __GI___fstatat64
- 63.82% 63.82% bonds [unknown] [k] 0xffffffffa90001a2
__GI___fstatat64
+ 5.32% 0.00% bonds [unknown] [.] 0000000000000000
From this, I can see that the majority of the time is spent in the __GI___fstatat64
function inside glibc. I'm now using gdb
to debug this code to see what code paths lead to this area of the code. As you can see, perf
only shows me a very shallow call stack, i.e one function, where as gdb gives me the full backtrace:
(gdb) bt
#0 __GI___fstatat64 (fd=fd@entry=-100, file=file@entry=0x7ffff59bb46b "/etc/localtime", buf=buf@entry=0x7fffffffd440, flag=flag@entry=0)
at ../sysdeps/unix/sysv/linux/fstatat64.c:154
#1 0x00007ffff591d706 in __GI___stat64 (file=file@entry=0x7ffff59bb46b "/etc/localtime", buf=buf@entry=0x7fffffffd440)
at ../sysdeps/unix/sysv/linux/stat64.c:29
#2 0x00007ffff58eb174 in __tzfile_read (file=file@entry=0x7ffff59bb46b "/etc/localtime", extra=extra@entry=0, extrap=extrap@entry=0x0) at tzfile.c:159
#3 0x00007ffff58ead24 in tzset_internal (always=<optimized out>) at tzset.c:405
#4 0x00007ffff58eaf23 in __tz_convert (timer=1681057207, use_localtime=1, tp=0x7ffff59fd660 <_tmbuf>) at tzset.c:577
#5 0x00007ffff6da62ae in QuantLib::Date::todaysDate () at /mnt/hdd1/sandbox/temp/QuantLib/ql/time/date.cpp:770
#6 0x00007ffff67e4a35 in QuantLib::Settings::DateProxy::operator QuantLib::Date (
this=0x7ffff7e238a0 <QuantLib::Singleton<QuantLib::Settings, std::integral_constant<bool, false> >::instance()::instance>)
at /mnt/hdd1/sandbox/temp/QuantLib/ql/settings.hpp:136
#7 QuantLib::Bond::isExpired (this=0x7fffffffda00) at /mnt/hdd1/sandbox/temp/QuantLib/ql/instruments/bond.cpp:107
#8 0x000000000040eb9c in QuantLib::Instrument::calculate (this=0x7fffffffda00) at /usr/local/include/ql/instrument.hpp:148
#9 0x00000000004103fa in QuantLib::Instrument::NPV (this=this@entry=0x7fffffffda00) at /usr/local/include/ql/instrument.hpp:185
#10 0x000000000040e272 in go () at /mnt/hdd1/sandbox/work/cpp/quantlib/bonds.cpp:93
Show I not be able to see an equally rich call stack in perf
? I'm invoking perf
like so with code compiled with -Og -ggdb3
:
perf record -g ./bonds
perf report -g