================ @@ -0,0 +1,620 @@ + +//===-- 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 <memory> +#include <stdbool.h> +#include <sys/auxv.h> + +#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 "third_party/llvm/llvm-project/llvm/include/llvm/ADT/StringRef.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/Chrono.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 "clang/Basic/Version.h" + +namespace lldb_private { + +std::string BaseTelemetryEntry::ToString() const { + return "[BaseTelemetryEntry]\n" + (" session_uuid:" + session_uuid + "\n") + + (" start timestamp: " + + std::to_string(stats.m_start.time_since_epoch().count()) + "\n") + + (" counter: " + std::to_string(counter)); +} + +std::string DebuggerInfoEntry::ToString() const { + auto duration = stats.Duration(); + return BaseTelemetryEntry::ToString() + "\n" + ("[DebuggerInfoEntry]\n") + + (" username: " + username + "\n") + + (" lldb_git_sha: " + lldb_git_sha + "\n") + + (" lldb_path: " + lldb_path + "\n") + (" cwd: " + cwd + "\n") + + (" lldb startup/session duration: " + + (duration.has_value() ? std::to_string(duration->count()) + : "<empty>") + + "(nanosec)\n") + + (lldb_exit.has_value() + ? ("lldb_exit_code: " + std::to_string(lldb_exit->exit_code) + + ", lldb_exit_description: " + lldb_exit->description + "\n ") + : ("")); +} + +std::string ClientTelemetryEntry::ToString() const { + return BaseTelemetryEntry::ToString() + "\n" + ("[DapRequestInfoEntry]\n") + + (" request_name: " + request_name + "\n") + + (" request_duration: " + std::to_string(stats.Duration()->count()) + + "(nanosec)\n") + + (" error_msg: " + error_msg + "\n"); +} + +std::string TargetInfoEntry::ToString() const { + std::string exit_or_load_desc; + if (process_exit.has_value()) { + // If this entry was emitted for an exit + exit_or_load_desc = + " process_duration: " + std::to_string(stats.Duration()->count()) + + "(nanosec)" + + "\n" + " exit_code: " + + std::to_string(process_exit->exit_code) + + ", exit description: " + process_exit->description + "\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: " + + std::to_string(stats.Duration()->count()) + + "(nanosec)" + "\n"; + } else { + exit_or_load_desc = " startup_init_start\n"; + } + } + return BaseTelemetryEntry::ToString() + "\n" + ("[TargetInfoEntry]\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) { + // TODO: surely there's a better way to translate status to text??? + std::string msg; + switch (result->GetStatus()) { ---------------- bulbazord wrote:
`llvm::StringSwitch` might be a good idea here. https://github.com/llvm/llvm-project/pull/87815 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits