Skip to content

[llvm][telemetry]Change Telemetry-disabling mechanism. #128534

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

Merged
merged 19 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lldb/source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ if (LLDB_ENABLE_CURSES)
endif()
endif()

if (LLVM_BUILD_TELEMETRY)
set(TELEMETRY_DEPS Telemetry)
endif()

# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
add_lldb_library(lldbCore
Address.cpp
Expand Down Expand Up @@ -84,7 +80,7 @@ add_lldb_library(lldbCore
Support
Demangle
TargetParser
${TELEMETRY_DEPS}
Telemetry
)

add_dependencies(lldbCore
Expand Down
13 changes: 5 additions & 8 deletions lldb/source/Core/Telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/Config/llvm-config.h"

#ifdef LLVM_BUILD_TELEMETRY

#include "lldb/Core/Telemetry.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Utility/LLDBLog.h"
Expand Down Expand Up @@ -67,13 +62,15 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
}

std::unique_ptr<TelemetryManager> TelemetryManager::g_instance = nullptr;
TelemetryManager *TelemetryManager::GetInstance() { return g_instance.get(); }
TelemetryManager *TelemetryManager::GetInstance() {
if (!Config::BuildTimeEnableTelemetry)
return nullptr;
return g_instance.get();
}

void TelemetryManager::SetInstance(std::unique_ptr<TelemetryManager> manager) {
g_instance = std::move(manager);
}

} // namespace telemetry
} // namespace lldb_private

#endif // LLVM_BUILD_TELEMETRY
5 changes: 1 addition & 4 deletions lldb/unittests/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
if (LLVM_BUILD_TELEMETRY)
set(TELEMETRY_DEPS Telemetry)
endif()

add_lldb_unittest(LLDBCoreTests
CommunicationTest.cpp
Expand Down Expand Up @@ -31,5 +28,5 @@ add_lldb_unittest(LLDBCoreTests
LLVMTestingSupport
LINK_COMPONENTS
Support
${TELEMETRY_DEPS}
Telemetry
)
15 changes: 7 additions & 8 deletions lldb/unittests/Core/TelemetryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/Config/llvm-config.h"

#ifdef LLVM_BUILD_TELEMETRY

#include "lldb/Core/PluginInterface.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Telemetry.h"
Expand Down Expand Up @@ -71,7 +66,13 @@ class FakePlugin : public telemetry::TelemetryManager {

} // namespace lldb_private

TEST(TelemetryTest, PluginTest) {
#if LLVM_ENABLE_TELEMETRY
#define TELEMETRY_TEST(suite, test) TEST(suite, test)
#else
#define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test)
#endif

TELEMETRY_TEST(TelemetryTest, PluginTest) {
// This would have been called by the plugin reg in a "real" plugin
// For tests, we just call it directly.
lldb_private::FakePlugin::Initialize();
Expand All @@ -94,5 +95,3 @@ TEST(TelemetryTest, PluginTest) {

ASSERT_EQ("FakeTelemetryPlugin", ins->GetInstanceName());
}

#endif // LLVM_BUILD_TELEMETRY
2 changes: 1 addition & 1 deletion llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OF
option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
option (LLVM_BUILD_TELEMETRY "Build the telemetry library. This does not enable telemetry." ON)
option (LLVM_ENABLE_TELEMETRY "Enable the telemetry library. If set to OFF, library cannot be enabled after build (eg., at runtime)" ON)

set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"
CACHE STRING "Doxygen-generated HTML documentation install directory")
Expand Down
2 changes: 1 addition & 1 deletion llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)

set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@)

set(LLVM_BUILD_TELEMETRY @LLVM_BUILD_TELEMETRY@)
set(LLVM_ENABLE_TELEMETRY @LLVM_ENABLE_TELEMETRY@)

if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "")
set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@")
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Config/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
/* Define if logf128 is available */
#cmakedefine LLVM_HAS_LOGF128

/* Define if building LLVM with LLVM_BUILD_TELEMETRY */
#cmakedefine LLVM_BUILD_TELEMETRY ${LLVM_BUILD_TELEMETRY}
/* Define if building LLVM with LLVM_ENABLE_TELEMETRY */
#cmakedefine01 LLVM_ENABLE_TELEMETRY

#endif
9 changes: 7 additions & 2 deletions llvm/include/llvm/Telemetry/Telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ class Serializer {
/// This struct can be extended as needed to add additional configuration
/// points specific to a vendor's implementation.
struct Config {
virtual ~Config() = default;
static constexpr bool BuildTimeEnableTelemetry = LLVM_ENABLE_TELEMETRY;

// If true, telemetry will be enabled.
const bool EnableTelemetry;
Config(bool E) : EnableTelemetry(E) {}

explicit Config() : EnableTelemetry(BuildTimeEnableTelemetry) {}

// Telemetry can only be enabled if both the runtime and buildtime flag
// are set.
explicit Config(bool E) : EnableTelemetry(E && BuildTimeEnableTelemetry) {}

virtual std::optional<std::string> makeSessionId() { return std::nullopt; }
};
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ add_subdirectory(ProfileData)
add_subdirectory(Passes)
add_subdirectory(TargetParser)
add_subdirectory(TextAPI)
if (LLVM_BUILD_TELEMETRY)
add_subdirectory(Telemetry)
endif()
add_subdirectory(Telemetry)
add_subdirectory(ToolDrivers)
add_subdirectory(XRay)
if (LLVM_INCLUDE_TESTS)
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Telemetry/Telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void TelemetryInfo::serialize(Serializer &serializer) const {
}

Error Manager::dispatch(TelemetryInfo *Entry) {
assert(Config::BuildTimeEnableTelemetry &&
"Telemetry should have been enabled");
Comment on lines +24 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be a problem for unit tests? I see you're enabling them, but I suspect they won't actually succeed with this setting turned off..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to say "if LLVM_ENABLE_TELEMETRY is not set, then skip the tests)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S: How about this? Adding GTEST_SKIP if the static flag is false.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work. Since this is a build-time condition another possibility would be to disable the test (gtest doesn't run tests whose name starts with DISABLED_ with some preprocessor trickery

#if LLVM_ENABLE_TELEMETRY
#define TELEMETRY_TEST(suite, test) TEST(suite, test)
#else
#define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test)
#end

.. though for just two tests, that doesn't really matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (Error Err = preDispatch(Entry))
return Err;

Expand Down
4 changes: 1 addition & 3 deletions llvm/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ add_subdirectory(Support)
add_subdirectory(TableGen)
add_subdirectory(Target)
add_subdirectory(TargetParser)
if (LLVM_BUILD_TELEMETRY)
add_subdirectory(Telemetry)
endif()
add_subdirectory(Telemetry)
add_subdirectory(Testing)
add_subdirectory(TextAPI)
add_subdirectory(Transforms)
Expand Down
10 changes: 8 additions & 2 deletions llvm/unittests/Telemetry/TelemetryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ std::shared_ptr<Config> getTelemetryConfig(const TestContext &Ctxt) {
return std::make_shared<Config>(false);
}

TEST(TelemetryTest, TelemetryDisabled) {
#if LLVM_ENABLE_TELEMETRY
#define TELEMETRY_TEST(suite, test) TEST(suite, test)
#else
#define TELEMETRY_TEST(suite, test) TEST(DISABLED_##suite, test)
#endif

TELEMETRY_TEST(TelemetryTest, TelemetryDisabled) {
TestContext Context;
Context.HasVendorPlugin = false;

Expand All @@ -221,7 +227,7 @@ TEST(TelemetryTest, TelemetryDisabled) {
EXPECT_EQ(nullptr, Manager);
}

TEST(TelemetryTest, TelemetryEnabled) {
TELEMETRY_TEST(TelemetryTest, TelemetryEnabled) {
const std::string ToolName = "TelemetryTestTool";

// Preset some params.
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ write_cmake_config("llvm-config") {
values = [
"LLVM_BUILD_LLVM_DYLIB=",
"LLVM_BUILD_SHARED_LIBS=",
"LLVM_BUILD_TELEMETRY=",
"LLVM_ENABLE_TELEMETRY=",
"LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple",
"LLVM_ENABLE_DUMP=",
"LLVM_ENABLE_HTTPLIB=",
Expand Down
4 changes: 2 additions & 2 deletions utils/bazel/llvm_configs/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
/* Define if logf128 is available */
#cmakedefine LLVM_HAS_LOGF128

/* Define if building LLVM with LLVM_BUILD_TELEMETRY */
#cmakedefine LLVM_BUILD_TELEMETRY ${LLVM_BUILD_TELEMETRY}
/* Define if building LLVM with LLVM_ENABLE_TELEMETRY */
#cmakedefine01 LLVM_ENABLE_TELEMETRY

#endif
Loading