Skip to content

Commit edd95ef

Browse files
make hide addresses a runtime option
1 parent 5faf0bc commit edd95ef

File tree

10 files changed

+77
-47
lines changed

10 files changed

+77
-47
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- name: cmake
7474
shell: bash
7575
run: |
76-
cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -DLOGGING_HIDE_ADDRESSES=ON -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ matrix.flags }} -G Ninja -S . -B .
76+
cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ matrix.flags }} -G Ninja -S . -B .
7777
- name: build
7878
shell: bash
7979
run: |

.github/workflows/sanitizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: cmake
4141
shell: bash
4242
run: |
43-
cmake -DCMAKE_BUILD_TYPE=Release -DLOGGING_HIDE_ADDRESSES=ON -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ matrix.flags }} -G Ninja -S . -B .
43+
cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ matrix.flags }} -G Ninja -S . -B .
4444
- name: build
4545
shell: bash
4646
run: |

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cmake_dependent_option(NAUTILUS_DOWNLOAD_MLIR "USE_PRE_BUILD_MLIR" ON "ENABLE_ML
1515
cmake_dependent_option(ENABLE_C_BACKEND "Enable the C compiler backend" ON "ENABLE_COMPILER" OFF)
1616
cmake_dependent_option(ENABLE_BC_BACKEND "Enable the bytecode interpreter backend" ON "ENABLE_COMPILER" OFF)
1717
cmake_dependent_option(ENABLE_ASMJIT_BACKEND "Enable the asmjit interpreter backend" OFF "ENABLE_COMPILER" OFF)
18-
option(LOGGING_HIDE_ADDRESSES "Enable logging of addresses (disable for testing)" OFF)
1918

2019
option(ENABLE_TEST_COVERAGE "Enable the collection of test coverage." OFF)
2120
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer." OFF)

nautilus/include/nautilus/common/config.h.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
#cmakedefine TEST_DATA_FOLDER "@TEST_DATA_FOLDER@"
1111

1212
// Backends
13-
#cmakedefine NAUTILUS_ACTIVATE_MLIR_BACKEND
14-
#cmakedefine LOGGING_HIDE_ADDRESSES
13+
#cmakedefine NAUTILUS_ACTIVATE_MLIR_BACKEND

nautilus/src/nautilus/compiler/ir/IRGraph.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "nautilus/compiler/ir/operations/ProxyCallOperation.hpp"
1818
#include "nautilus/compiler/ir/operations/ReturnOperation.hpp"
1919
#include "nautilus/compiler/ir/operations/StoreOperation.hpp"
20+
#include "nautilus/logging.hpp"
2021
#include <fmt/format.h>
2122
#include <utility>
2223

@@ -119,8 +120,8 @@ struct formatter<nautilus::compiler::ir::IRGraph> : formatter<std::string_view>
119120

120121
template <>
121122
struct formatter<nautilus::compiler::ir::OperationIdentifier> : formatter<std::string_view> {
122-
static auto format(const nautilus::compiler::ir::OperationIdentifier& op, format_context& ctx)
123-
-> format_context::iterator {
123+
static auto format(const nautilus::compiler::ir::OperationIdentifier& op,
124+
format_context& ctx) -> format_context::iterator {
124125
auto out = ctx.out();
125126
fmt::format_to(out, "${}", op.getId());
126127
return out;
@@ -129,8 +130,8 @@ struct formatter<nautilus::compiler::ir::OperationIdentifier> : formatter<std::s
129130

130131
template <>
131132
struct formatter<nautilus::compiler::ir::BasicBlockInvocation> : formatter<std::string_view> {
132-
static auto format(const nautilus::compiler::ir::BasicBlockInvocation& op, format_context& ctx)
133-
-> format_context::iterator {
133+
static auto format(const nautilus::compiler::ir::BasicBlockInvocation& op,
134+
format_context& ctx) -> format_context::iterator {
134135
auto out = ctx.out();
135136
fmt::format_to(out, "Block_{}(", op.getBlock()->getIdentifier());
136137
const auto& args = op.getArguments();
@@ -157,18 +158,18 @@ struct formatter<nautilus::compiler::ir::IfOperation> : formatter<std::string_vi
157158

158159
template <>
159160
struct formatter<nautilus::compiler::ir::ProxyCallOperation> : formatter<std::string_view> {
160-
static auto format(const nautilus::compiler::ir::ProxyCallOperation& op, format_context& ctx)
161-
-> format_context::iterator {
161+
static auto format(const nautilus::compiler::ir::ProxyCallOperation& op,
162+
format_context& ctx) -> format_context::iterator {
162163
auto out = ctx.out();
163164

164165
if (op.getStamp() != nautilus::Type::v) {
165166
fmt::format_to(out, "${} = ", op.getIdentifier().getId());
166167
}
167-
#ifdef LOGGING_HIDE_ADDRESSES
168-
fmt::format_to(out, "func_*(");
169-
#else
168+
if (nautilus::log::options::getLogAddresses()) {
170169
fmt::format_to(out, "{}(", op.getFunctionName());
171-
#endif
170+
} else {
171+
fmt::format_to(out, "func_*(");
172+
}
172173
const auto& args = op.getInputArguments();
173174
for (size_t i = 0; i < args.size(); ++i) {
174175
if (i > 0) {
@@ -238,8 +239,8 @@ struct formatter<nautilus::compiler::ir::Operation> : formatter<std::string_view
238239

239240
template <>
240241
struct formatter<nautilus::compiler::ir::BasicBlock> : formatter<std::string_view> {
241-
static auto format(const nautilus::compiler::ir::BasicBlock& block, format_context& ctx)
242-
-> format_context::iterator {
242+
static auto format(const nautilus::compiler::ir::BasicBlock& block,
243+
format_context& ctx) -> format_context::iterator {
243244
auto out = ctx.out();
244245
fmt::format_to(out, "\nBlock_{}(", block.getIdentifier());
245246
const auto& args = block.getArguments();
@@ -260,8 +261,8 @@ struct formatter<nautilus::compiler::ir::BasicBlock> : formatter<std::string_vie
260261

261262
template <>
262263
struct formatter<nautilus::compiler::ir::FunctionOperation> : formatter<std::string_view> {
263-
static auto format(const nautilus::compiler::ir::FunctionOperation& func, format_context& ctx)
264-
-> format_context::iterator {
264+
static auto format(const nautilus::compiler::ir::FunctionOperation& func,
265+
format_context& ctx) -> format_context::iterator {
265266
auto out = ctx.out();
266267
fmt::format_to(out, "{}(", func.getName());
267268
for (const auto& arg : func.getInputArgNames()) {

nautilus/src/nautilus/logging.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
#include <nautilus/logging.hpp>
2+
3+
namespace nautilus::log::options {
4+
static bool logAddresses = true;
5+
bool getLogAddresses() {
6+
return logAddresses;
7+
}
8+
void setLogAddresses(bool value) {
9+
logAddresses = value;
10+
}
11+
} // namespace nautilus::log::options

nautilus/src/nautilus/logging.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace nautilus::log {
99
template <typename... Args>
10-
void info([[maybe_unused]] const char* fmt, [[maybe_unused]]Args&&... args) {
10+
void info([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
1111
#ifdef ENABLE_LOGGING
1212
spdlog::info("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
1313
#endif
@@ -23,7 +23,7 @@ void debug([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
2323
template <typename... Args>
2424
void trace([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
2525
#ifdef ENABLE_LOGGING
26-
spdlog::trace("{}",fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
26+
spdlog::trace("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
2727
#endif
2828
}
2929

@@ -33,4 +33,11 @@ void error([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
3333
spdlog::error("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
3434
#endif
3535
}
36+
37+
namespace options {
38+
39+
bool getLogAddresses();
40+
void setLogAddresses(bool);
41+
42+
} // namespace options
3643
} // namespace nautilus::log

nautilus/src/nautilus/tracing/ExecutionTrace.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <algorithm>
55
#include <fmt/format.h>
66
#include <nautilus/config.hpp>
7+
#include <nautilus/logging.hpp>
78

89
namespace nautilus::tracing {
910

@@ -283,8 +284,8 @@ auto formatter<nautilus::tracing::ExecutionTrace>::format(const nautilus::tracin
283284
return out;
284285
}
285286

286-
auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block& block, format_context& ctx)
287-
-> format_context::iterator {
287+
auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block& block,
288+
format_context& ctx) -> format_context::iterator {
288289
auto out = ctx.out();
289290
fmt::format_to(out, "(");
290291
for (size_t i = 0; i < block.arguments.size(); i++) {
@@ -306,8 +307,8 @@ auto formatter<nautilus::tracing::Block>::format(const nautilus::tracing::Block&
306307

307308
template <>
308309
struct formatter<nautilus::tracing::TypedValueRef> : formatter<std::string_view> {
309-
static auto format(const nautilus::tracing::TypedValueRef& typeValRef, format_context& ctx)
310-
-> format_context::iterator {
310+
static auto format(const nautilus::tracing::TypedValueRef& typeValRef,
311+
format_context& ctx) -> format_context::iterator {
311312
auto out = ctx.out();
312313
fmt::format_to(out, "${}", typeValRef.ref);
313314
return out;
@@ -334,11 +335,12 @@ template <>
334335
struct formatter<nautilus::tracing::FunctionCall> : formatter<std::string_view> {
335336
static auto format(const nautilus::tracing::FunctionCall& call, format_context& ctx) -> format_context::iterator {
336337
auto out = ctx.out();
337-
#ifdef LOGGING_HIDE_ADDRESSES
338-
fmt::format_to(out, "func_*(");
339-
#else
340-
fmt::format_to(out, "{}(", call.functionName);
341-
#endif
338+
if (nautilus::log::options::getLogAddresses()) {
339+
fmt::format_to(out, "{}(", call.functionName);
340+
} else {
341+
fmt::format_to(out, "func_*(");
342+
}
343+
342344
for (size_t i = 0; i < call.arguments.size(); i++) {
343345
if (i != 0) {
344346
fmt::format_to(out, ",");

nautilus/test/execution-tests/CMakeLists.txt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
1414

1515
catch_discover_tests(nautilus-execution-tests EXTRA_ARGS --allow-running-no-tests)
1616

17-
if (ENABLE_TRACING AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
18-
# using Clang
19-
add_executable(nautilus-tracing-tests
20-
TracingTest.cpp
21-
)
22-
23-
target_include_directories(nautilus-tracing-tests PRIVATE
24-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../common>
25-
$<INSTALL_INTERFACE:src/nautilus/>)
26-
27-
target_include_directories(nautilus-tracing-tests PRIVATE
28-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../src>
29-
$<INSTALL_INTERFACE:src/nautilus/>)
30-
31-
target_link_libraries(nautilus-tracing-tests PUBLIC nautilus Catch2::Catch2WithMain)
32-
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
33-
catch_discover_tests(nautilus-tracing-tests EXTRA_ARGS --allow-running-no-tests)
17+
if (ENABLE_TRACING)
18+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
19+
# using Clang
20+
add_executable(nautilus-tracing-tests
21+
TracingTest.cpp
22+
)
23+
24+
target_include_directories(nautilus-tracing-tests PRIVATE
25+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../common>
26+
$<INSTALL_INTERFACE:src/nautilus/>)
27+
28+
target_include_directories(nautilus-tracing-tests PRIVATE
29+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../src>
30+
$<INSTALL_INTERFACE:src/nautilus/>)
31+
32+
target_link_libraries(nautilus-tracing-tests PUBLIC nautilus Catch2::Catch2WithMain)
33+
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
34+
catch_discover_tests(nautilus-tracing-tests EXTRA_ARGS --allow-running-no-tests)
35+
else ()
36+
message(WARNING "Tracing Tests are only available on clang-based compilers!")
37+
endif ()
3438
endif ()
3539

3640
add_subdirectory(std)

nautilus/test/execution-tests/TracingTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <iostream>
2121
#include <sstream>
2222

23+
namespace nautilus::log::options {
24+
25+
bool getLogAddresses();
26+
void setLogAddresses(bool);
27+
28+
} // namespace nautilus::log::options
2329
namespace nautilus::engine {
2430

2531
namespace details {
@@ -132,6 +138,8 @@ bool checkTestFile(T* trace, const std::string category, const std::string group
132138
}
133139

134140
void runTraceTests(const std::string& category, std::vector<std::tuple<std::string, std::function<void()>>>& tests) {
141+
// disable logging of addresses such that the trace is deterministic
142+
nautilus::log::options::setLogAddresses(false);
135143
for (auto& test : tests) {
136144
auto func = std::get<1>(test);
137145
auto name = std::get<0>(test);

0 commit comments

Comments
 (0)