[llvm] [llvm]Add a simple Telemetry framework (PR #102323)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 01:38:26 PDT 2024
================
@@ -0,0 +1,107 @@
+//===- 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
+//
+//===----------------------------------------------------------------------===//
+
+#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"
+
+namespace llvm {
+namespace telemetry {
+
+using SteadyTimePoint = std::chrono::time_point<std::chrono::steady_clock>;
+
+struct TelemetryConfig {
+ // If true, telemetry will be enabled.
+ bool enable_telemetry;
+
+ // Additional destinations to send the logged entries.
+ // Could be stdout, stderr, or some local paths.
+ // Note: these are destinations are __in addition to__ whatever the default
+ // destination(s) are, as implemented by vendors.
+ std::vector<std::string> additional_destinations;
----------------
jh7370 wrote:
I don't feel like a vector of strings will appropriately capture where data should be sent. For example, short of hard-coding it, how would you go from `"stdout"` to actually writing to `stdout`? Having this as a vector of streams might well make more sense, but ownership probably doesn't belong in this class.
Another issue is that different kinds of destinations will require data written in different ways. For example, in our downstream telemetry library, we usually write data as JSON to a file, but we also have the ability to write it into a dictionary-like type, which doesn't go anywhere near any sort of string-writing code.
https://github.com/llvm/llvm-project/pull/102323
More information about the llvm-commits
mailing list