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

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 01:05:29 PST 2024


================
@@ -0,0 +1,132 @@
+//===- llvm/Telemetry/Telemetry.h - Telemetry -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file provides the basic framework for Telemetry
+/// Refer to its documentation at llvm/docs/Telemetry.rst for more details.
+//===---------------------------------------------------------------------===//
+
+#ifndef LLVM_TELEMETRY_TELEMETRY_H
+#define LLVM_TELEMETRY_TELEMETRY_H
+
+#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 init() = 0;
+  virtual void write(StringRef KeyName, bool Value) = 0;
+  virtual void write(StringRef KeyName, int Value) = 0;
+  virtual void write(StringRef KeyName, size_t Value) = 0;
----------------
jh7370 wrote:

int64_t and uint64_t are just typedefs for fundamental types. Just provide the fundamental types like `long long` and `unsigned long long` and it'll be fine. More generally the fundamental types we support downstream are:
```
int
unsigned int
long
unsigned long
long long
unsigned long long
double
bool
```
We've not bothered with overloads for `float`, `char` variants, or `short`, because there's never been a need for them. We also have first-class support for `const char *`, `std::string_view` (which covers the `std::string` case), `std::chrono::system_clock::time_point`, since these needed special treatment in the json that everything ultimately got converted to. If we can have those, that would be great from our point of view.

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


More information about the llvm-commits mailing list