================ @@ -0,0 +1,619 @@ + +//===-- 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 <stdbool.h> +#include <sys/auxv.h> + +#include <memory> + +#include <chrono> +#include <cstdlib> +#include <ctime> +#include <fstream> +#include <iostream> +#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/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/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/LineIterator.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/RandomNumberGenerator.h" +#include "llvm/Telemetry/Telemetry.h" + +#ifdef HAS_VENDOR_TELEMETRY_PLUGINS +// TODO: could make this path a build-variable rather than hard-coded +#include "lldb/Core/VendorTelemetryPlugin.h" + +// This must include definitions for these functions +extern void ApplyVendorSpecificConfigs( + llvm::telemetry::TelemetryConfig *config) /* __attribute__((weak))*/; +extern std::shared_ptr<llvm::telemetry::TelemetryInfo> SanitizeSensitiveFields( + const llvm::telemetry::TelemetryInfo *entry) /*__attribute__((weak))*/; +extern std::shared_ptr<lldb_private::LldbTelemeter> +CreateVendorSpecificTelemeter( + llvm::telemetry::TelemetryConfig *config) /*__attribute__((weak))*/; +#endif + +namespace lldb_private { + +static std::string GetDuration(const TelemetryEventStats &stats) { + if (stats.m_end.has_value()) + return std::to_string((stats.m_end.value() - stats.m_start).count()) + + "(nanosec)"; + return "<NONE>"; +} + +std::string DebuggerTelemetryInfo::ToString() const { + std::string duration_desc = + (exit_description.has_value() ? " lldb session duration: " + : " lldb startup duration: ") + + std::to_string((stats.m_end.value() - stats.m_start).count()) + + "(nanosec)\n"; + + return TelemetryInfo::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"; +} + +std::string ClientTelemetryInfo::ToString() const { + return TelemetryInfo::ToString() + "\n" + ("[DapRequestInfoEntry]\n") + + (" request_name: " + request_name + "\n") + + (" request_duration: " + GetDuration(stats) + "(nanosec)\n") + + (" error_msg: " + error_msg + "\n"); +} + +std::string TargetTelemetryInfo::ToString() const { + std::string exit_or_load_desc; + if (exit_description.has_value()) { + // If this entry was emitted for an exit + exit_or_load_desc = " process_duration: " + GetDuration(stats) + + " exit: " + exit_description->ToString() + "\n"; + } else { + // This was emitted for a load event. + // See if it was the start-load or end-load entry + if (stats.m_end.has_value()) { + exit_or_load_desc = + " startup_init_duration: " + GetDuration(stats) + "\n"; + } else { + exit_or_load_desc = " startup_init_start\n"; + } + } + return TelemetryInfo::ToString() + "\n" + ("[TargetTelemetryInfo]\n") + + (" target_uuid: " + target_uuid + "\n") + + (" file_format: " + file_format + "\n") + + (" binary_path: " + binary_path + "\n") + + (" binary_size: " + std::to_string(binary_size) + "\n") + + exit_or_load_desc; +} + +static std::string StatusToString(CommandReturnObject *result) { + std::string msg; + switch (result->GetStatus()) { + case lldb::eReturnStatusInvalid: + msg = "invalid"; + break; + case lldb::eReturnStatusSuccessFinishNoResult: + msg = "success_finish_no_result"; + break; + case lldb::eReturnStatusSuccessFinishResult: + msg = "success_finish_result"; + break; + case lldb::eReturnStatusSuccessContinuingNoResult: + msg = "success_continuing_no_result"; + break; + case lldb::eReturnStatusSuccessContinuingResult: + msg = "success_continuing_result"; + break; + case lldb::eReturnStatusStarted: + msg = "started"; + break; + case lldb::eReturnStatusFailed: + msg = "failed"; + break; + case lldb::eReturnStatusQuit: + msg = "quit"; + break; + } ---------------- oontvoo wrote:
(added this as an additional field only for the command (because this ExitDescription is used for both the commands and the tool) https://github.com/llvm/llvm-project/pull/98528 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits