Skip to content

[lldb]Implement LLDB Telemetry #98528

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

Conversation

oontvoo
Copy link
Member

@oontvoo oontvoo commented Jul 11, 2024

Provide some concrete implementation for llvm/Telemetry in lldb/Telemetry

(Dependent on PR/102323

@oontvoo oontvoo requested review from labath and cmtice July 11, 2024 19:36
@oontvoo oontvoo self-assigned this Jul 11, 2024
@nikic
Copy link
Contributor

nikic commented Jul 11, 2024

Why does any part of this need to be in llvm/ at all?

@oontvoo
Copy link
Member Author

oontvoo commented Jul 12, 2024

Why does any part of this need to be in llvm/ at all?

Please see comments on the rfc at https://discourse.llvm.org/t/rfc-lldb-telemetry-metrics/64588/15

TL;DR : A few people feel that Telemetry is not something unique to LLDB and that other tools might be interested in having it too. So rather than having mutliple Telemetry libs doing similar things, it might be good to have at least a common API

@oontvoo oontvoo changed the title [DRAFT][llvm]Added lib/Telemetry [llvm]Added lib/Telemetry Jul 23, 2024
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

I've made one pass over the PR. I think this would be easier to review if it was split into multiple patches:

  • core llvm infrastructure
  • core lldb infrastructure
  • ~one patch per event type

I think the biggest hurdle will be finding someone to approve the addition of the new llvm library (I doubt it's going to be someone from the current reviewer set). I wouldn't be surprised if this ends up needing its own RFC.

@@ -9,10 +9,12 @@
#ifndef LLDB_API_SBDEBUGGER_H
#define LLDB_API_SBDEBUGGER_H

#include <chrono>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this used anywhere?

@@ -245,6 +247,8 @@ class LLDB_API SBDebugger {

lldb::SBTarget GetDummyTarget();

void SendTelemetry(SBStructuredData *entry);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void SendTelemetry(SBStructuredData *entry);
void SendTelemetry(const SBStructuredData &entry);

// Logger configs: LLDB users can also supply their own configs via:
// $HOME/.lldb_telemetry_config
//
// We can propose simple syntax: <field_name><colon><value>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is actual code, it should talk about the (real) syntax, not the proposed one.


auto *ret = new llvm::telemetry::TelemetryConfig{enable_telemetry,
additional_destinations};
#ifdef HAS_VENDOR_TELEMETRY_CONFIG
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd probably do this by providing dummy/empty implementations of these functions when there's no vendor customization.

Copy link
Member Author

Choose a reason for hiding this comment

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

can you clarify what you mean by dummy implementations? (w/o causing either duplicate-symbols errors) I'd tried the weak-def but it wasn't very portable, so I thought this was the simplest.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just meant that we could conditionally provide an empty implementation of the "vendor" function instead of conditionally calling it. So something like:

#if VENDOR
// do something to get the vendor definition
#else
// provide an empty definition ourselves, e.g:
void ApplyVendorSpecificConfigs(...) {}
#endif

Then you don't need the ifdef at the call site.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done - reworked this to use Plugin registry (the default plugin is enabled for test, then vendors can add their own impl as needed)

@oontvoo
Copy link
Member Author

oontvoo commented Aug 7, 2024

I've made one pass over the PR. I think this would be easier to review if it was split into multiple patches:

  • core llvm infrastructure
  • core lldb infrastructure
  • ~one patch per event type

I think the biggest hurdle will be finding someone to approve the addition of the new llvm library (I doubt it's going to be someone from the current reviewer set). I wouldn't be surprised if this ends up needing its own RFC.

Good point - so here's the plane:

  • I'll create a separate PR for the first bullet point (llvm core infra).
  • keep this PR as is - since branching is such a pain (and controversial) in llvm, you can "pretend" to not see the llvm/lib/ changes in this PR . hopefully the diff will disappear once the first PR goes in.

Objective:
  - Provide a common framework in LLVM for collecting various usage metrics
  - Characteristics:
      + Extensible and configurable by:
          * tools in LLVM that want to use it
          * vendors in their downstream codebase
          * tools users (as allowed by vendor)

Background:
The framework was originally proposed only for LLDB, but there were quite a few requests
that it should be moved to llvm/lib given telemetry is a common usage to a lot of tools,
not just LLDB.

See more details on the design and discussions here on the RFC: https://discourse.llvm.org/t/rfc-lldb-telemetry-metrics/64588/20?u=oontvoo
@oontvoo oontvoo changed the title [llvm]Added lib/Telemetry [lldb]Implement LLDB Telemetry Aug 7, 2024
@oontvoo oontvoo marked this pull request as ready for review September 24, 2024 14:33
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

I think it'd be good to separate the general mechanics of creating and managing a telemetry (telemeter) instance from the details of logging individual telemetry entries. I.e. one PR for the general infrastructure (maybe include one simple (startup?) telemetry entry, if you think it's necessary to make a point), and then one PR for each of the entries.

The plugin infrastructure seems very.. baroque. Why do we need the intermediate TelemetryVendor class? And why a whole list of them?

The reason we support registering more than one e.g. SymbolFile plugin is that we can choose which one to use at runtime (based on which file the user opens, etc.). Do we want to do something like that here? What would that even mean?

To create a basic indirection (so that the vendor implementation can be decoupled from the rest of lldb), it sounds to me like all one need is one function pointer (the factory function for the "telemeter"), a way to set it from inside the plugin (PluginManager::SetTelemetryPlugin ?) and then a way to call it (another function?)

@@ -257,8 +257,8 @@ enum StopReason {
};

/// Command Return Status Types.
enum ReturnStatus {
eReturnStatusInvalid,
enum ReturnStatus : int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this relate to the rest of the patch?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed to serialize the ReturnStatus from a command.

static std::string
ExitDescToString(const llvm::telemetry::ExitDescription *desc) {
return ("ExitCode:" + desc->ExitCode) +
(" ExixitDescription: " + desc->Description);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
(" ExixitDescription: " + desc->Description);
(" ExitDescription: " + desc->Description);

Comment on lines 67 to 68
return std::to_string((stats.End.value() - stats.Start).count()) +
"(nanosec)";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return std::to_string((stats.End.value() - stats.Start).count()) +
"(nanosec)";
return llvm::formatv("{0:ns}", stats.End.value() - stats.Start).str();

(or maybe some other unit (ms/us) -- how small do we expect these to get)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants