================
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   ///     A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
----------------
clayborg wrote:

This violates our public API policy where we can't take away or change a 
previously available public API function. So we must:
- keep the old function around
- add a new function with extra parameters

If we are going to possibly add more options to GetStatistics in the future, we 
don't want to have to keep overloading this function with new values since we 
would need to keep adding overloads. The way we fix this in the API is to 
create a SBStatisticsOptions class that has accessors. This way we can keep 
adding more features in the future as it is ok to add new methods to any 
existing classes. So this code should look like:
```
  /// Returns a dump of the collected statistics.
  ///
  /// \return
  ///     A SBStructuredData with the statistics collected.
  lldb::SBStructuredData GetStatistics();

  /// Returns a dump of the collected statistics.
  ///
  /// \param[in] options
  ///   An objects object that contains all options for the statistics dumping.
  ///
  /// \return
  ///     A SBStructuredData with the statistics collected.
  lldb::SBStructuredData GetStatistics(SBStatisticsOptions options);
```
Then we need to create a simple public API class for `SBStatisticsOptions`:
```
class SBStatisticsOptions {
public:
  SBStatisticsOptions();
  bool GetSummaryOnly();
  void SetSummaryOnly(bool b);
};
```
And if later we might want to add another bool option, we can just add the new 
methods to this class. Lets say later we want to only emit target stats for a 
specific target, instead of all targets, we could add new functions to 
`SBStatisticsOptions`:
```
class SBStatisticsOptions {
public:
  SBStatisticsOptions();
  bool GetSummaryOnly();
  void SetSummaryOnly(bool b);
  /// Limit statistics data for only 1 target instead of all targets
  void SetTarget(SBTarget target);
};
```
And we can still use our `lldb::SBStructuredData 
GetStatistics(SBStatisticsOptions options);` function because the signature 
didn't change!

https://github.com/llvm/llvm-project/pull/80745
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to