Skip to content

[lldb] Add/change options in statistics dump to control what sections are dumped #95075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 19, 2024

Conversation

royitaqi
Copy link
Contributor

@royitaqi royitaqi commented Jun 11, 2024

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).

Build Bot

https://lab.llvm.org/buildbot/#/changes/928

@royitaqi royitaqi requested a review from JDevlieghere as a code owner June 11, 2024 04:50
@llvmbot llvmbot added the lldb label Jun 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2024

@llvm/pr-subscribers-lldb

Author: None (royitaqi)

Changes

Add options

The following options are added to the statistics dump command:

  • --targets: Dumps the targets section.
  • --modules: Dumps the modules section.

When both options are given, the field moduleIdentifiers will be dumped for each target in the targets section.

Split options into groups

We are splitting the section-selecting options into the following groups.

  • Group 1: --summary. This dumps only the summary.
  • Group 2: --targets, --modules, --transcript. This dumps both the summary and any of the specified sections.

There is also an implicit Group 0, i.e. when none of the above options are given by the user. This dumps all sections.

Other horizontal options (--all-targets and --load-all-debug-info) are accessible from all groups.

Tests

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

A new test case test_sections_existence is added to verify that different sections are dumped/not dumped when different options are given.


Full diff: https://github.com/llvm/llvm-project/pull/95075.diff

5 Files Affected:

  • (modified) lldb/include/lldb/Target/Statistics.h (+2)
  • (modified) lldb/source/Commands/CommandObjectStats.cpp (+6)
  • (modified) lldb/source/Commands/Options.td (+13-3)
  • (modified) lldb/source/Target/Statistics.cpp (+23-10)
  • (modified) lldb/test/API/commands/statistics/basic/TestStats.py (+96-6)
diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
       case 'f':
         m_stats_options.load_all_debug_info = true;
         break;
+      case 'r':
+        m_stats_options.include_targets = true;
+        break;
+      case 'm':
+        m_stats_options.include_modules = true;
+        break;
       case 't':
         m_stats_options.include_transcript = true;
         break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
     Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
     Desc<"Dump only high-level summary statistics. "
          "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>,
     Desc<"Dump the total possible debug info statistics. "
     "Force loading all the debug information if not yet loaded, and collect "
     "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+    Desc<"Dump statistics for the targets, including breakpoints, expression "
+    "evaluations, frame variables, etc. "
+    "If both the '--targets' and the '--modules' options are specified, a "
+    "list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+    Desc<"Dump statistics for the modules, including time and size of various "
+    "aspects of the module and debug information, type system, path, etc. "
+    "If both the '--targets' and the '--modules' options are specified, a "
+    "list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
     Desc<"If the setting interpreter.save-transcript is enabled and this "
     "option is specified, include a JSON array with all commands the user and/"
     "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..15c7dfe07ac87 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -108,6 +108,10 @@ TargetStats::ToJSON(Target &target,
   json::Object target_metrics_json;
   ProcessSP process_sp = target.GetProcessSP();
   const bool summary_only = options.summary_only;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
+  const bool include_transcript = options.include_transcript;
+  const bool include_default_sections = !summary_only && !include_targets && !include_modules && !include_transcript;
   if (!summary_only) {
     CollectStats(target);
 
@@ -117,8 +121,9 @@ TargetStats::ToJSON(Target &target,
 
     target_metrics_json.try_emplace(m_expr_eval.name, m_expr_eval.ToJSON());
     target_metrics_json.try_emplace(m_frame_var.name, m_frame_var.ToJSON());
-    target_metrics_json.try_emplace("moduleIdentifiers",
-                                    std::move(json_module_uuid_array));
+    if (include_default_sections || include_modules)
+      target_metrics_json.try_emplace("moduleIdentifiers",
+                                      std::move(json_module_uuid_array));
 
     if (m_launch_or_attach_time && m_first_private_stop_time) {
       double elapsed_time =
@@ -226,7 +231,10 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
+  const bool include_default_sections = !summary_only && !include_targets && !include_modules && !include_transcript;
 
   json::Array json_targets;
   json::Array json_modules;
@@ -314,7 +322,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
     if (module_stat.debug_info_had_incomplete_types)
       ++num_modules_with_incomplete_types;
 
-    if (!summary_only) {
+    if (include_default_sections || include_modules) {
       module_stat.identifier = (intptr_t)module;
       module_stat.path = module->GetFileSpec().GetPath();
       if (ConstString object_name = module->GetObjectName()) {
@@ -347,13 +355,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
       {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-    json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-    for (const auto &target : debugger.GetTargetList().Targets())
+  if (include_default_sections || include_targets) {
+    if (target) {
       json_targets.emplace_back(target->ReportStatistics(options));
+    } else {
+      for (const auto &target : debugger.GetTargetList().Targets())
+        json_targets.emplace_back(target->ReportStatistics(options));
+    }
+    global_stats.try_emplace("targets", std::move(json_targets));
   }
-  global_stats.try_emplace("targets", std::move(json_targets));
 
   ConstStringStats const_string_stats;
   json::Object json_memory{
@@ -362,11 +372,14 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   global_stats.try_emplace("memory", std::move(json_memory));
   if (!summary_only) {
     json::Value cmd_stats = debugger.GetCommandInterpreter().GetStatistics();
-    global_stats.try_emplace("modules", std::move(json_modules));
     global_stats.try_emplace("commands", std::move(cmd_stats));
   }
 
-  if (include_transcript) {
+  if (include_default_sections || include_modules) {
+    global_stats.try_emplace("modules", std::move(json_modules));
+  }
+
+  if (include_default_sections || include_transcript) {
     // When transcript is available, add it to the to-be-returned statistics.
     //
     // NOTE:
diff --git a/lldb/test/API/commands/statistics/basic/TestStats.py b/lldb/test/API/commands/statistics/basic/TestStats.py
index ebe6166eb45e5..2132d2df03b4b 100644
--- a/lldb/test/API/commands/statistics/basic/TestStats.py
+++ b/lldb/test/API/commands/statistics/basic/TestStats.py
@@ -657,16 +657,106 @@ def test_transcript_happy_path(self):
         # The second "statistics dump" in the transcript should have no output
         self.assertNotIn("output", transcript[2])
 
-    def test_transcript_should_not_exist_when_not_asked_for(self):
+    def test_sections_existence(self):
         """
-        Test "statistics dump" and the transcript information.
+        Test "statistics dump" and the existence of sections when different
+        options are given.
         """
         self.build()
         exe = self.getBuildArtifact("a.out")
         target = self.createTestTarget(file_path=exe)
         self.runCmd("settings set interpreter.save-transcript true")
-        self.runCmd("version")
 
-        # Verify the output of a first "statistics dump"
-        debug_stats = self.get_stats()  # Not with "--transcript"
-        self.assertNotIn("transcript", debug_stats)
+        test_cases = [
+            {   # statistics dump
+                "options": "",
+                "expect": {
+                    "commands": True,
+                    "targets": True,
+                    "targets.moduleIdentifiers": True,
+                    "targets.breakpoints": True,
+                    "modules": True,
+                    "transcript": True,
+                },
+            },
+            {   # statistics dump --summary
+                "options": " --summary",
+                "expect": {
+                    "commands": False,
+                    "targets": False,
+                    "targets.moduleIdentifiers": False,
+                    "targets.breakpoints": False,
+                    "modules": False,
+                    "transcript": False,
+                },
+            },
+            {   # statistics dump --targets
+                "options": " --targets",
+                "expect": {
+                    "commands": True,
+                    "targets": True,
+                    "targets.moduleIdentifiers": False,
+                    "targets.breakpoints": True,
+                    "modules": False,
+                    "transcript": False,
+                },
+            },
+            {   # statistics dump --modules
+                "options": " --modules",
+                "expect": {
+                    "commands": True,
+                    "targets": False,
+                    "targets.moduleIdentifiers": False,
+                    "targets.breakpoints": False,
+                    "modules": True,
+                    "transcript": False,
+                },
+            },
+            {   # statistics dump --targets --modules
+                "options": " --targets --modules",
+                "expect": {
+                    "commands": True,
+                    "targets": True,
+                    "targets.moduleIdentifiers": True,
+                    "targets.breakpoints": True,
+                    "modules": True,
+                    "transcript": False,
+                },
+            },
+            {   # statistics dump --transcript
+                "options": " --transcript",
+                "expect": {
+                    "commands": True,
+                    "targets": False,
+                    "targets.moduleIdentifiers": False,
+                    "targets.breakpoints": False,
+                    "modules": False,
+                    "transcript": True,
+                },
+            },
+        ]
+
+        for test_case in test_cases:
+            options = test_case["options"]
+            debug_stats = self.get_stats(options)
+            # The following fields should always exist
+            self.assertIn("totalDebugInfoEnabled", debug_stats, "Global stats should always exist")
+            self.assertIn("memory", debug_stats, "'memory' should always exist")
+            # The following fields should exist/not exist depending on the test case
+            for field_name in test_case["expect"]:
+                idx = field_name.find(".")
+                if idx == -1:
+                    # `field` is a top-level field
+                    exists = field_name in debug_stats
+                    should_exist = test_case["expect"][field_name]
+                    should_exist_string = "" if should_exist else "not "
+                    self.assertEqual(exists, should_exist, f"'{field_name}' should {should_exist_string}exist for 'statistics dump{options}'")
+                else:
+                    # `field` is a string of "<top-level field>.<second-level field>"
+                    top_level_field_name = field_name[0:idx]
+                    second_level_field_name = field_name[idx+1:]
+                    for top_level_field in debug_stats[top_level_field_name] if top_level_field_name in debug_stats else []:
+                        exists = second_level_field_name in top_level_field
+                        should_exist = test_case["expect"][field_name]
+                        should_exist_string = "" if should_exist else "not "
+                        self.assertEqual(exists, should_exist, f"'{field_name}' should {should_exist_string}exist for 'statistics dump{options}'")

@royitaqi
Copy link
Contributor Author

cc @kusmour, @clayborg , @jeffreytan81

Copy link

github-actions bot commented Jun 11, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link

github-actions bot commented Jun 11, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these new options the default statistics dump changes the output from what is was before. I might suggest that we set the defaults so it does what it used to do by default, and then let users opt out of the targets and modules in each output. This means that the --targets and --modules would need to take a bool variable, or be switched to --no-targets and --no-modules.

@nikic nikic changed the title Add options to "statistics dump" to control what sections are dumped [lldb] Add options to "statistics dump" to control what sections are dumped Jun 14, 2024
Copy link
Contributor

@hawkinsw hawkinsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this work! I hope that these little bits help!

@royitaqi royitaqi changed the title [lldb] Add options to "statistics dump" to control what sections are dumped [lldb] Add/change options in "statistics dump" to control what sections are dumped Jun 17, 2024
@royitaqi royitaqi changed the title [lldb] Add/change options in "statistics dump" to control what sections are dumped [lldb] Add/change options in statistics dump to control what sections are dumped Jun 17, 2024
@clayborg clayborg merged commit 70f41a8 into llvm:main Jun 19, 2024
4 of 5 checks passed
kusmour pushed a commit that referenced this pull request Jun 28, 2024
# Change

#95075 accidentally removed the
`targets` section from `statistics dump --summary`. Adding it back, by
setting the default value to `true` in
`StatisticsOptions::GetIncludeTargets()`.

Updated the description for the options.
Updated tests.


# Verification

Manually verified the fix by running `statist dump --summary` and
comparing three versions of LLDB (in commit order):
1. Before #95075
2. After #95075
3. After this fix

The expected result is that 1 and 3 give the same sections, while 2 is
missing the `targets` section when in summary mode. The output (see
Appendix) matches the expectation.


# Appendix: Manual Test Output

## `statistics dump --summary` of 1

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 724992,
      "bytesUnused": 714547,
      "bytesUsed": 10445
    }
  },
  "targets": [
    {
      "sourceMapDeduceCount": 0,
      "totalSharedLibraryEventHitCount": 0
    }
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.00070699999999999995,
  "totalDebugInfoParseTime": 2.5999999999999998e-05,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.000223,
  "totalSymbolTableParseTime": 0.00025799999999999998,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 3

Should be the same as above.

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 516096,
      "bytesUnused": 510353,
      "bytesUsed": 5743
    }
  },
  "targets": [
    {
      "sourceMapDeduceCount": 0,
      "totalSharedLibraryEventHitCount": 0
    }
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.0022139999999999998,
  "totalDebugInfoParseTime": 0.00031700000000000001,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.0014499999999999999,
  "totalSymbolTableParseTime": 0.001848,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 2

Should be missing the `targets` section.

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 716800,
      "bytesUnused": 705887,
      "bytesUsed": 10913
    }
  },
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.001374,
  "totalDebugInfoParseTime": 0.000174,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.00068300000000000001,
  "totalSymbolTableParseTime": 0.0010139999999999999,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

Co-authored-by: royshi <[email protected]>
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
…97004)

# Change

llvm#95075 accidentally removed the
`targets` section from `statistics dump --summary`. Adding it back, by
setting the default value to `true` in
`StatisticsOptions::GetIncludeTargets()`.

Updated the description for the options.
Updated tests.


# Verification

Manually verified the fix by running `statist dump --summary` and
comparing three versions of LLDB (in commit order):
1. Before llvm#95075
2. After llvm#95075
3. After this fix

The expected result is that 1 and 3 give the same sections, while 2 is
missing the `targets` section when in summary mode. The output (see
Appendix) matches the expectation.


# Appendix: Manual Test Output

## `statistics dump --summary` of 1

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 724992,
      "bytesUnused": 714547,
      "bytesUsed": 10445
    }
  },
  "targets": [
    {
      "sourceMapDeduceCount": 0,
      "totalSharedLibraryEventHitCount": 0
    }
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.00070699999999999995,
  "totalDebugInfoParseTime": 2.5999999999999998e-05,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.000223,
  "totalSymbolTableParseTime": 0.00025799999999999998,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 3

Should be the same as above.

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 516096,
      "bytesUnused": 510353,
      "bytesUsed": 5743
    }
  },
  "targets": [
    {
      "sourceMapDeduceCount": 0,
      "totalSharedLibraryEventHitCount": 0
    }
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.0022139999999999998,
  "totalDebugInfoParseTime": 0.00031700000000000001,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.0014499999999999999,
  "totalSymbolTableParseTime": 0.001848,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 2

Should be missing the `targets` section.

```
(lldb) statistics dump --summary
{
  "memory": {
    "strings": {
      "bytesTotal": 716800,
      "bytesUnused": 705887,
      "bytesUsed": 10913
    }
  },
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.001374,
  "totalDebugInfoParseTime": 0.000174,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.00068300000000000001,
  "totalSymbolTableParseTime": 0.0010139999999999999,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

Co-authored-by: royshi <[email protected]>
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…ns are dumped (llvm#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 <[email protected]>
kevinfrei pushed a commit to kevinfrei/llvm that referenced this pull request Sep 25, 2024
Summary:
This is to temporarily fix the test `TestVSCode`, before [PR llvm#97004](llvm#97004) can be upstreamed and pulled into `toolchain/llvm-sand/main`.

The bug was that a previous PR ([llvm#95075](llvm#95075)) accidentally removed the `targets` section from `statistics dump --summary`, which this test relies on.

The fix in [PR llvm#97004](llvm#97004) reverts that behavior, while the temporary fix in this diff just explicitly adds an option to make sure that the `targets` section is generated.

This diff *can (but doesn't have to)* be reverted after [PR llvm#97004](llvm#97004) has been merged and pulled into `llvm-sand`.

Test Plan: Manually tested after applying this diff on top of the release candidate that I'm working on.

Reviewers: jeffreytan, #lldb_team

Subscribers: gclayton, #lldb_team

Differential Revision: https://phabricator.intern.facebook.com/D59139567
@royitaqi royitaqi deleted the statistics-dump-sections branch October 24, 2024 21:49
Jlalond pushed a commit to Jlalond/llvm-project that referenced this pull request Apr 23, 2025
Summary:
This is to temporarily fix the test `TestVSCode`, before [PR llvm#97004](llvm#97004) can be upstreamed and pulled into `toolchain/llvm-sand/main`.

The bug was that a previous PR ([llvm#95075](llvm#95075)) accidentally removed the `targets` section from `statistics dump --summary`, which this test relies on.

The fix in [PR llvm#97004](llvm#97004) reverts that behavior, while the temporary fix in this diff just explicitly adds an option to make sure that the `targets` section is generated.

This diff *can (but doesn't have to)* be reverted after [PR llvm#97004](llvm#97004) has been merged and pulled into `llvm-sand`.

Test Plan: Manually tested after applying this diff on top of the release candidate that I'm working on.

Reviewers: jeffreytan, #lldb_team

Subscribers: gclayton, #lldb_team

Differential Revision: https://phabricator.intern.facebook.com/D59139567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants