-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][telemetry] Implement LLDB Telemetry (part 1) #119716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7216d7
fca4674
549e44f
157b5e4
ec5a661
5e19b7e
75dbb9e
c534405
e76c216
5bc42c0
4275ec5
507e562
aa9c9c7
9e584b5
8675094
8c7c82c
38d0cec
387a38c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===-- Telemetry.h -------------------------------------------------------===// | ||
// | ||
// 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 LLDB_CORE_TELEMETRY_H | ||
#define LLDB_CORE_TELEMETRY_H | ||
|
||
#include "lldb/Core/StructuredDataImpl.h" | ||
#include "lldb/Interpreter/CommandReturnObject.h" | ||
#include "lldb/Utility/StructuredData.h" | ||
#include "lldb/lldb-forward.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/JSON.h" | ||
#include "llvm/Telemetry/Telemetry.h" | ||
#include <chrono> | ||
#include <ctime> | ||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace lldb_private { | ||
namespace telemetry { | ||
|
||
struct LLDBEntryKind : public ::llvm::telemetry::EntryKind { | ||
static const llvm::telemetry::KindType BaseInfo = 0b11000; | ||
}; | ||
|
||
/// Defines a convenient type for timestamp of various events. | ||
using SteadyTimePoint = std::chrono::time_point<std::chrono::steady_clock, | ||
std::chrono::nanoseconds>; | ||
struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo { | ||
/// Start time of an event | ||
SteadyTimePoint start_time; | ||
/// End time of an event - may be empty if not meaningful. | ||
std::optional<SteadyTimePoint> end_time; | ||
// TBD: could add some memory stats here too? | ||
|
||
Debugger *debugger; | ||
|
||
// For dyn_cast, isa, etc operations. | ||
llvm::telemetry::KindType getKind() const override { | ||
return LLDBEntryKind::BaseInfo; | ||
} | ||
|
||
static bool classof(const llvm::telemetry::TelemetryInfo *t) { | ||
// Subclasses of this is also acceptable. | ||
return (t->getKind() & LLDBEntryKind::BaseInfo) == LLDBEntryKind::BaseInfo; | ||
} | ||
|
||
void serialize(llvm::telemetry::Serializer &serializer) const override; | ||
}; | ||
|
||
/// The base Telemetry manager instance in LLDB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing period. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
/// This class declares additional instrumentation points | ||
/// applicable to LLDB. | ||
class TelemetryManager : public llvm::telemetry::Manager { | ||
public: | ||
TelemetryManager(std::unique_ptr<llvm::telemetry::Config> config); | ||
|
||
llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override; | ||
|
||
private: | ||
std::unique_ptr<llvm::telemetry::Config> m_config; | ||
}; | ||
|
||
} // namespace telemetry | ||
} // namespace lldb_private | ||
#endif // LLDB_CORE_TELEMETRY_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//===-- 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" | ||
labath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "lldb/Core/Debugger.h" | ||
#include "lldb/Utility/LLDBLog.h" | ||
#include "lldb/Utility/UUID.h" | ||
#include "lldb/lldb-enumerations.h" | ||
#include "lldb/lldb-forward.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/RandomNumberGenerator.h" | ||
#include "llvm/Telemetry/Telemetry.h" | ||
#include <chrono> | ||
#include <cstdlib> | ||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
|
||
namespace lldb_private { | ||
namespace telemetry { | ||
|
||
using ::llvm::Error; | ||
using ::llvm::telemetry::Destination; | ||
using ::llvm::telemetry::Serializer; | ||
using ::llvm::telemetry::TelemetryInfo; | ||
|
||
static uint64_t ToNanosec(const SteadyTimePoint Point) { | ||
return std::chrono::nanoseconds(Point.time_since_epoch()).count(); | ||
} | ||
|
||
void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) const { | ||
serializer.write("entry_kind", getKind()); | ||
serializer.write("session_id", SessionId); | ||
serializer.write("start_time", ToNanosec(start_time)); | ||
if (end_time.has_value()) | ||
serializer.write("end_time", ToNanosec(end_time.value())); | ||
} | ||
|
||
static std::string MakeUUID(lldb_private::Debugger *debugger) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (all addressed in #126757) |
||
uint8_t random_bytes[16]; | ||
if (auto ec = llvm::getRandomBytes(random_bytes, 16)) { | ||
LLDB_LOG(GetLog(LLDBLog::Object), | ||
"Failed to generate random bytes for UUID: {0}", ec.message()); | ||
// fallback to using timestamp + debugger ID. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return llvm::formatv( | ||
"{0}_{1}", std::chrono::steady_clock::now().time_since_epoch().count(), | ||
debugger->GetID()); | ||
} | ||
return lldb_private::UUID(random_bytes).GetAsString(); | ||
} | ||
|
||
TelemetryManager::TelemetryManager( | ||
std::unique_ptr<llvm::telemetry::Config> config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
: m_config(std::move(config)) {} | ||
|
||
llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) { | ||
// Do nothing for now. | ||
// In up-coming patch, this would be where the manager | ||
// attach the session_uuid to the entry. | ||
return Error::success(); | ||
} | ||
|
||
} // namespace telemetry | ||
} // namespace lldb_private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere else we use
/// LLVM RTTI support.