[Lldb-commits] [lldb] [llvm] [lldb]Implement LLDB Telemetry (PR #98528)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 25 06:56:59 PDT 2024
================
@@ -0,0 +1,273 @@
+
+//===-- Telemetry.cpp -----------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#include "lldb/Core/Telemetry.h"
+
+#include <chrono>
+#include <cstdlib>
+#include <ctime>
+#include <fstream>
+#include <memory>
+#include <string>
+#include <typeinfo>
+#include <utility>
+#include <vector>
+
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/TelemetryVendor.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Statistics.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/UUID.h"
+#include "lldb/Version/Version.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/RandomNumberGenerator.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+namespace lldb_private {
+
+using ::llvm::telemetry::Destination;
+using ::llvm::telemetry::EventStats;
+using ::llvm::telemetry::ExitDescription;
+using ::llvm::telemetry::SteadyTimePoint;
+using ::llvm::telemetry::TelemetryInfo;
+
+static std::string
+ExitDescToString(const llvm::telemetry::ExitDescription *desc) {
+ return ("ExitCode:" + desc->ExitCode) +
+ (" ExixitDescription: " + desc->Description);
+}
+
+static std::string GetDuration(const EventStats &stats) {
+ if (stats.End.has_value())
+ return std::to_string((stats.End.value() - stats.Start).count()) +
+ "(nanosec)";
+ return "<NONE>";
+}
+
+std::string LldbBaseTelemetryInfo::ToString() const {
+ return ("[LldbBaseTelemetryInfo]\n") + (" SessionId: " + SessionId + "\n");
+}
+
+std::string DebuggerTelemetryInfo::ToString() const {
+ std::string duration_desc =
+ (ExitDesc.has_value() ? " lldb session duration: "
+ : " lldb startup duration: ") +
+ std::to_string((Stats.End.value() - Stats.Start).count()) + "(nanosec)\n";
+
+ return LldbBaseTelemetryInfo::ToString() + "\n" +
+ ("[DebuggerTelemetryInfo]\n") + (" username: " + username + "\n") +
+ (" lldb_git_sha: " + lldb_git_sha + "\n") +
+ (" lldb_path: " + lldb_path + "\n") + (" cwd: " + cwd + "\n") +
+ duration_desc + "\n";
+}
+
+static size_t ToNanosecOrZero(const std::optional<SteadyTimePoint> &Point) {
+ if (!Point.has_value())
+ return 0;
+
+ return Point.value().time_since_epoch().count();
+}
+
+llvm::json::Object DebuggerTelemetryInfo::serializeToJson() const {
+ return llvm::json::Object{
+ {"DebuggerInfo",
+ {
+ {"SessionId", SessionId},
+ {"username", username},
+ {"lldb_git_sha", lldb_git_sha},
+ {"lldb_path", lldb_path},
+ {"cwd", cwd},
+ {
+ "EventStats",
+ {
+ {"Start", Stats.Start.time_since_epoch().count()},
+ {"End", ToNanosecOrZero(Stats.End)},
+ },
+ },
+ // TODO: fill in more?
+ }}};
+}
+
+std::string ClientTelemetryInfo::ToString() const {
+ return LldbBaseTelemetryInfo::ToString() + "\n" +
+ ("[DapRequestInfoEntry]\n") +
----------------
labath wrote:
I don't think we should assume this request comes from lldb-dap.
https://github.com/llvm/llvm-project/pull/98528
More information about the lldb-commits
mailing list