D45547 added a while ago the skeleton for some target stats, along with a command to enable, disable, and dump them. However, it seems it wasn't further developed.
My team is in need of a bunch of other target stats so that we can fix some bottlenecks. Some of these stats are related to expressions (e.g. # of expr eval that trigger global lookups, time per expr eval), and some others are are related to modules (e.g. amount of debug info parsed, time spent indexing dwarf, etc.).
In order to collect this metrics, I'm proposing improving the existing code and create a TargetStats class, that can keep track of them.
Some things to consider:
- I think it's useful to have colletion enabled by default. You might encounter some perf issues and you might want to dump the stats right away, instead of rerunning the debug session but this time with collection enabled.
- The information that is very cheap to collect, should be collected on the fly, e.g. # of failed frame vars.
- The information that is expensive to collect, should be collected at retrieval time (e.g. when invoking ToJSON or Dump). That way the collection can be enabled by default without paying any noticeable penalty.
As an interesting case, I added a metric for the amount of time spent indexing dwarf per module, which is not as trivial as the other existing metrics because the Target is not available there. However, it was easy to implement and can be extended to all symbol files. This metric is collected at retrieval time. This doesn't account for cases in which a dynamic library is unloaded at runtime, but I'm just making the current changes just for demonstration purposes.
Btw, the code is not really polished, but it's fully functional.
Example:
(lldb) statistics dump Number of expr evaluation successes: 0 Number of expr evaluation failures: 0 Number of frame var successes: 0 Number of frame var failures: 0 Modules: /home/wallace/a.out: Symbol loading time in seconds: 2.500064272 /lib64/libc.so.6: Symbol loading time in seconds: not loaded /lib64/libgcc_s.so.1: Symbol loading time in seconds: not loaded /lib64/libm.so.6: Symbol loading time in seconds: not loaded /lib64/libstdc++.so.6: Symbol loading time in seconds: not loaded /usr/lib64/ld-2.28.so: Symbol loading time in seconds: not loaded [vdso]: Symbol loading time in seconds: not loaded (lldb) statistics dump --json { "exprEval": { "failures": 0, "successes": 0 }, "frameVal": { "failures": 0, "successes": 0 }, "modules": { "/home/wallace/a.out": { "symbolLoadingTimeInSec:": "2.500064272" }, "/lib64/libc.so.6": { "symbolLoadingTimeInSec:": null }, "/lib64/libgcc_s.so.1": { "symbolLoadingTimeInSec:": null }, "/lib64/libm.so.6": { "symbolLoadingTimeInSec:": null }, "/lib64/libstdc++.so.6": { "symbolLoadingTimeInSec:": null }, "/usr/lib64/ld-2.28.so": { "symbolLoadingTimeInSec:": null }, "[vdso]": { "symbolLoadingTimeInSec:": null } } }
clang-tidy: error: 'lldb/Core/PluginInterface.h' file not found [clang-diagnostic-error]
not useful