[llvm] [llvm]Add a simple Telemetry framework (PR #102323)

Vy Nguyen via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 07:25:39 PST 2024


================
@@ -70,120 +69,168 @@ Key components
 
 The framework consists of four important classes:
 
-* `llvm::telemetry::Telemeter`: The class responsible for collecting and
+* ``llvm::telemetry::Manager``: The class responsible for collecting and
   transmitting telemetry data. This is the main point of interaction between the
-  framework and any tool that wants to enable telemery.
-* `llvm::telemetry::TelemetryInfo`: Data courier
-* `llvm::telemetry::Destination`: Data sink to which the Telemetry framework
+  framework and any tool that wants to enable telemetry.
+* ``llvm::telemetry::TelemetryInfo``: Data courier
+* ``llvm::telemetry::Destination``: Data sink to which the Telemetry framework
   sends data.
   Its implementation is transparent to the framework.
   It is up to the vendor to decide which pieces of data to forward and where
-  to forward them to their final storage.
-* `llvm::telemetry::Config`: Configurations on the `Telemeter`.
+  to forward them to for their final storage.
+* ``llvm::telemetry::Config``: Configurations for the ``Manager``.
   
 .. image:: llvm_telemetry_design.png
 
 How to implement and interact with the API
 ------------------------------------------
 
-To use Telemetry in your tool, you need to provide a concrete implementation of the `Telemeter` class and `Destination`.
+To use Telemetry in your tool, you need to provide a concrete implementation of the ``Manager`` class and ``Destination``.
 
-1) Define a custom `Telemeter` and `Destination`
+1) Define a custom ``Serializer``, ``Manager``, ``Destination`` and optionally a subclass of ``TelemetryInfo``
 
 .. code-block:: c++
 
-    // This destination just prints the given entry to a stdout.
-    // In "real life", this would be where you forward the data to your
-    // custom data storage.
-    class MyStdoutDestination : public llvm::telemetry::Destination {
-    public:
-      Error emitEntry(const TelemetryInfo* Entry) override {
-         return sendToBlackBox(Entry);
-         
-      }
-      
-    private:
-      Error sendToBlackBox(const TelemetryInfo* Entry) {
-          // This could send the data anywhere.
-          // But we're simply sending it to stdout for the example.
-          llvm::outs() << entryToString(Entry) << "\n";
-          return llvm::success();
-      }
-      
-      std::string entryToString(const TelemetryInfo* Entry) {
-        // make a string-representation of the given entry.
+  class JsonSerializer : public Serializer {
+  public:
+    json::Object *getOutputObject() { return object.get(); }
+
+    llvm::Error start() override {
----------------
oontvoo wrote:

done

https://github.com/llvm/llvm-project/pull/102323


More information about the llvm-commits mailing list