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

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 01:29:35 PST 2024


================
@@ -8,71 +8,68 @@
 ///
 /// \file
 /// This file provides the basic framework for Telemetry
-///
-/// It comprises of three important structs/classes:
-///
-/// - Telemeter: The class responsible for collecting and forwarding
-///              telemery data.
-/// - TelemetryInfo: data courier
-/// - TelemetryConfig: this stores configurations on Telemeter.
-///
 /// Refer to its documentation at llvm/docs/Telemetry.rst for more details.
 //===---------------------------------------------------------------------===//
 
 #ifndef LLVM_TELEMETRY_TELEMETRY_H
 #define LLVM_TELEMETRY_TELEMETRY_H
 
-#include <chrono>
-#include <ctime>
-#include <memory>
-#include <optional>
-#include <string>
-
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/JSON.h"
+#include <memory>
+#include <optional>
+#include <string>
 
 namespace llvm {
 namespace telemetry {
 
+class Serializer {
+public:
+  virtual llvm::Error start() = 0;
+  virtual void writeBool(StringRef KeyName, bool Value) = 0;
----------------
jh7370 wrote:

FWIW, in our downstream interface, everything is simply called `write` and function overloading is used. I'm somewhat ambivalent whether that's done here, but it does mean everything is serialized by calling the same-named function (which I find aesthetically pleasing), at the cost of needing to cast or similar if a different function is wanted to the one that is actually used (I've not had a concrete case where that's actually been needed).

We also have `write` methods for all fundamental types, plus a few other special cases like `std::chrono::system_clock::time_point` and iterable types. In some implementations, under the hood these may result in the same function being called, but it also provides the maximum flexibility for implementations to do things differently. For example, a serializer that simply wants to copy the value can do so without loss of type/precision this way.

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


More information about the llvm-commits mailing list