llvm-project/lldb/source/API/SBStatisticsOptions.cpp
royitaqi 70f41a8c30
[lldb] Add/change options in statistics dump to control what sections are dumped (#95075)
# Added/changed options

The following options are **added** to the `statistics dump` command:
* `--targets=bool`: Boolean. Dumps the `targets` section.
* `--modules=bool`: Boolean. Dumps the `modules` section.
When both options are given, the field `moduleIdentifiers` will be
dumped for each target in the `targets` section.

The following options are **changed**:
* `--transcript=bool`: Changed to a boolean. Dumps the `transcript`
section.

# Behavior of `statistics dump` with various options

The behavior is **backward compatible**:
- When no options are provided, `statistics dump` dumps all sections.
- When `--summary` is provided, only dumps the summary info.

**New** behavior:
- `--targets=bool`, `--modules=bool`, `--transcript=bool` overrides the
above "default".

For **example**:
- `statistics dump --modules=false` dumps summary + targets +
transcript. No modules.
- `statistics dump --summary --targets=true --transcript=true` dumps
summary + targets (in summary mode) + transcript.


# Added options into public API

In `SBStatisticsOptions`, add:
* `Set/GetIncludeTargets`
* `Set/GetIncludeModules`
* `Set/GetIncludeTranscript`

**Alternative considered**: Thought about adding
`Set/GetIncludeSections(string sections_spec)`, which receives a
comma-separated list of section names to be included ("targets",
"modules", "transcript"). The **benefit** of this approach is that the
API is more future-proof when it comes to possible adding/changing of
section names. **However**, I feel the section names are likely to
remain unchanged for a while - it's not like we plan to make big changes
to the output of `statistics dump` any time soon. The **downsides** of
this approach are: 1\ the readability of the API is worse (requires
reading doc to understand what string can be accepted), 2\ string input
are more prone to human error (e.g. typo "target" instead of expected
"targets").


# Tests

```
bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/commands/statistics/basic/TestStats.py
```

```
./tools/lldb/unittests/Interpreter/InterpreterTests
```

New test cases have been added to verify:
* Different sections are dumped/not dumped when different
`StatisticsOptions` are given through command line (CLI or
`HandleCommand`; see `test_sections_existence_through_command`) or API
(see `test_sections_existence_through_api`).
* The order in which the options are given in command line does not
matter (see `test_order_of_options_do_not_matter`).

---------

Co-authored-by: Roy Shi <royshi@meta.com>
2024-06-18 17:21:20 -07:00

83 lines
2.1 KiB
C++

//===-- SBStatisticsOptions.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBStatisticsOptions.h"
#include "lldb/Target/Statistics.h"
#include "lldb/Utility/Instrumentation.h"
#include "Utils.h"
using namespace lldb;
using namespace lldb_private;
SBStatisticsOptions::SBStatisticsOptions()
: m_opaque_up(new StatisticsOptions()) {
LLDB_INSTRUMENT_VA(this);
}
SBStatisticsOptions::SBStatisticsOptions(const SBStatisticsOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
m_opaque_up = clone(rhs.m_opaque_up);
}
SBStatisticsOptions::~SBStatisticsOptions() = default;
const SBStatisticsOptions &
SBStatisticsOptions::operator=(const SBStatisticsOptions &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
if (this != &rhs)
m_opaque_up = clone(rhs.m_opaque_up);
return *this;
}
void SBStatisticsOptions::SetSummaryOnly(bool b) {
m_opaque_up->SetSummaryOnly(b);
}
bool SBStatisticsOptions::GetSummaryOnly() {
return m_opaque_up->GetSummaryOnly();
}
void SBStatisticsOptions::SetIncludeTargets(bool b) {
m_opaque_up->SetIncludeTargets(b);
}
bool SBStatisticsOptions::GetIncludeTargets() const {
return m_opaque_up->GetIncludeTargets();
}
void SBStatisticsOptions::SetIncludeModules(bool b) {
m_opaque_up->SetIncludeModules(b);
}
bool SBStatisticsOptions::GetIncludeModules() const {
return m_opaque_up->GetIncludeModules();
}
void SBStatisticsOptions::SetIncludeTranscript(bool b) {
m_opaque_up->SetIncludeTranscript(b);
}
bool SBStatisticsOptions::GetIncludeTranscript() const {
return m_opaque_up->GetIncludeTranscript();
}
void SBStatisticsOptions::SetReportAllAvailableDebugInfo(bool b) {
m_opaque_up->SetLoadAllDebugInfo(b);
}
bool SBStatisticsOptions::GetReportAllAvailableDebugInfo() {
return m_opaque_up->GetLoadAllDebugInfo();
}
const lldb_private::StatisticsOptions &SBStatisticsOptions::ref() const {
return *m_opaque_up;
}