This is an archive of the discontinued LLVM Phabricator instance.

[rfc] target stats
AbandonedPublic

Authored by wallace on Aug 3 2021, 4:06 PM.

Details

Reviewers
clayborg
jingham
Summary

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
    }
  }
}

Diff Detail

Event Timeline

wallace created this revision.Aug 3 2021, 4:06 PM
wallace requested review of this revision.Aug 3 2021, 4:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2021, 4:06 PM
wallace edited the summary of this revision. (Show Details)Aug 3 2021, 4:07 PM
wallace edited the summary of this revision. (Show Details)Aug 3 2021, 4:07 PM
wallace edited the summary of this revision. (Show Details)
clayborg requested changes to this revision.Aug 3 2021, 4:52 PM
clayborg added inline comments.
lldb/include/lldb/Symbol/SymbolFile.h
302–305

I would add an instance variable to this base class and then return it here. Then subclasses can just access the ivar, and clients can use this accessor to access it and no need to be virtual

lldb/include/lldb/Target/TargetStats.h
43

Does this belong here? It seems like this is something we should gather at the time the stats are asked to be returned. If it does belong here, what is this saying? Total symbol parsing time?

lldb/source/API/SBTarget.cpp
213–226

We can't replace this if this was doing something before. Was this doing nothing previously? Or are we doing everything this used to do and more?

228–230

We can't change this if it did something valid prior to this diff? Or are we doing everything this used to do and more?

234

We can't change this if it did something valid prior to this diff? Or are we doing everything this used to do and more?

lldb/source/Commands/CommandObjectStats.cpp
16

We should leave this command in place. Not a good idea to remote a command, if we do, it might make some lldb command files fail in the middle or parsing them and change people's script behavior.

40

We should leave this command in place. Not a good idea to remote a command, if we do, it might make some lldb command files fail in the middle or parsing them and change people's script behavior.

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
26–38

Maybe use a scope C++ class to help get the time of the index here and avoid making the Index() and DoIndex() calls? The "ScopedTimer" class would be something like:

class ScopedTimer {
  llvm::Optional<std::chrono::duration<double>> &m_opt_time;
  std::chrono::duration<double>m_start;
public:
  ScopedTimer (llvm::Optional<std::chrono::duration<double>> &opt_time) : m_opt_time(opt_time) {
    m_start = std::chrono::steady_clock::now().time_since_epoch();
  }
  ~ScopedTimer() {
    m_opt_time = std::chrono::steady_clock::now().time_since_epoch() - m_start;
  }
}

And we should probably put this in a header file so it can be reused elsewhere.

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
58

Remove, see comment in DWARFIndex.h

72

Remove and see "ScopedTimer" comment

86

This should be in base class.

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
517–522

Remove this and just set the SymbolFile::m_index_time directly after indexing

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
323–324

Remove, see comment in SymbolFile.h

This revision now requires changes to proceed.Aug 3 2021, 4:52 PM
wallace abandoned this revision.Oct 19 2021, 1:02 PM