Skip to content

Commit

Permalink
Explicit instantiation of spdlog template functions (cmu-db#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbutrovich committed Jul 2, 2020
1 parent 78d2946 commit 686eb69
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 20 deletions.
39 changes: 35 additions & 4 deletions src/include/loggers/loggers_util.h
@@ -1,17 +1,48 @@
#pragma once

#include <memory>
#include <string>
#include <string_view>

#include "spdlog/logger.h"

// flush the debug logs, every <n> seconds
#define DEBUG_LOG_FLUSH_INTERVAL 3

#include "spdlog/fmt/ostr.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"
namespace spdlog::details {
struct console_stdout;
struct console_mutex;
} // namespace spdlog::details

namespace spdlog::sinks {
template <typename TargetStream, typename ConsoleMutex>
class stdout_sink;

using stdout_sink_mt = stdout_sink<details::console_stdout, details::console_mutex>;
} // namespace spdlog::sinks

extern std::shared_ptr<spdlog::sinks::stdout_sink_mt> default_sink; // NOLINT

/// @cond DOXYGEN_IGNORE
extern template void spdlog::logger::trace<std::string>(const std::string &);
extern template void spdlog::logger::debug<std::string>(const std::string &);
extern template void spdlog::logger::info<std::string>(const std::string &);
extern template void spdlog::logger::warn<std::string>(const std::string &);
extern template void spdlog::logger::error<std::string>(const std::string &);

extern template void spdlog::logger::trace<>(const char *fmt);
extern template void spdlog::logger::debug<>(const char *fmt);
extern template void spdlog::logger::info<>(const char *fmt);
extern template void spdlog::logger::warn<>(const char *fmt);
extern template void spdlog::logger::error<>(const char *fmt);

extern template void spdlog::logger::trace<std::string_view>(const std::string_view &);
extern template void spdlog::logger::debug<std::string_view>(const std::string_view &);
extern template void spdlog::logger::info<std::string_view>(const std::string_view &);
extern template void spdlog::logger::warn<std::string_view>(const std::string_view &);
extern template void spdlog::logger::error<std::string_view>(const std::string_view &);
/// @endcond

namespace terrier {

/**
Expand Down
1 change: 1 addition & 0 deletions src/include/network/terrier_server.h
Expand Up @@ -9,6 +9,7 @@
#include <pthread.h>
#include <sys/file.h>

#include <condition_variable> // NOLINT
#include <csignal>
#include <cstdio>
#include <cstdlib>
Expand Down
3 changes: 1 addition & 2 deletions src/include/optimizer/binding.h
Expand Up @@ -7,7 +7,6 @@
#include <vector>

#include "loggers/optimizer_logger.h"

#include "optimizer/group.h"
#include "optimizer/memo.h"
#include "optimizer/operator_node.h"
Expand Down Expand Up @@ -74,7 +73,7 @@ class GroupBindingIterator : public BindingIterator {
num_group_items_(target_group_->GetLogicalExpressions().size()),
current_item_index_(0),
txn_(txn) {
OPTIMIZER_LOG_TRACE("Attempting to bind on group {0}", id);
OPTIMIZER_LOG_TRACE("Attempting to bind on group " + std::to_string(!id));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/include/storage/write_ahead_log/disk_log_consumer_task.h
@@ -1,7 +1,9 @@
#pragma once

#include <condition_variable> // NOLINT
#include <utility>
#include <vector>

#include "common/container/concurrent_blocking_queue.h"
#include "common/container/concurrent_queue.h"
#include "common/dedicated_thread_task.h"
Expand Down
1 change: 1 addition & 0 deletions src/include/storage/write_ahead_log/log_serializer_task.h
@@ -1,5 +1,6 @@
#pragma once

#include <condition_variable> // NOLINT
#include <queue>
#include <unordered_map>
#include <utility>
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/binder_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::binder {

std::shared_ptr<spdlog::logger> binder_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/catalog_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::catalog {

std::shared_ptr<spdlog::logger> catalog_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/common_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::common {

std::shared_ptr<spdlog::logger> common_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/execution_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::execution {

std::shared_ptr<spdlog::logger> execution_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/index_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::storage {

std::shared_ptr<spdlog::logger> index_logger = nullptr; // NOLINT
Expand Down
20 changes: 20 additions & 0 deletions src/loggers/loggers_util.cpp
Expand Up @@ -15,6 +15,8 @@
#include "loggers/settings_logger.h"
#include "loggers/storage_logger.h"
#include "loggers/transaction_logger.h"
#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

std::shared_ptr<spdlog::sinks::stdout_sink_mt> default_sink = nullptr; // NOLINT

Expand Down Expand Up @@ -55,3 +57,21 @@ void LoggersUtil::ShutDown() {
}
}
} // namespace terrier

template void spdlog::logger::trace<std::string>(const std::string &);
template void spdlog::logger::debug<std::string>(const std::string &);
template void spdlog::logger::info<std::string>(const std::string &);
template void spdlog::logger::warn<std::string>(const std::string &);
template void spdlog::logger::error<std::string>(const std::string &);

template void spdlog::logger::trace<>(const char *fmt);
template void spdlog::logger::debug<>(const char *fmt);
template void spdlog::logger::info<>(const char *fmt);
template void spdlog::logger::warn<>(const char *fmt);
template void spdlog::logger::error<>(const char *fmt);

template void spdlog::logger::trace<std::string_view>(const std::string_view &);
template void spdlog::logger::debug<std::string_view>(const std::string_view &);
template void spdlog::logger::info<std::string_view>(const std::string_view &);
template void spdlog::logger::warn<std::string_view>(const std::string_view &);
template void spdlog::logger::error<std::string_view>(const std::string_view &);
3 changes: 3 additions & 0 deletions src/loggers/metrics_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::metrics {

std::shared_ptr<spdlog::logger> metrics_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/network_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::network {

std::shared_ptr<spdlog::logger> network_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/optimizer_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::optimizer {

std::shared_ptr<spdlog::logger> optimizer_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/parser_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::parser {

std::shared_ptr<spdlog::logger> parser_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/settings_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::settings {

std::shared_ptr<spdlog::logger> settings_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/storage_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::storage {

std::shared_ptr<spdlog::logger> storage_logger = nullptr; // NOLINT
Expand Down
3 changes: 3 additions & 0 deletions src/loggers/transaction_logger.cpp
Expand Up @@ -2,6 +2,9 @@

#include <memory>

#include "spdlog/sinks/stdout_sinks.h"
#include "spdlog/spdlog.h"

namespace terrier::transaction {

std::shared_ptr<spdlog::logger> transaction_logger = nullptr; // NOLINT
Expand Down
5 changes: 3 additions & 2 deletions src/optimizer/binding.cpp
Expand Up @@ -69,8 +69,9 @@ GroupExprBindingIterator::GroupExprBindingIterator(const Memo &memo, GroupExpres
return;
}

OPTIMIZER_LOG_TRACE("Attempting to bind on group {0} with expression of type {1}, children size {2}",
gexpr->GetGroupID(), gexpr->Contents()->GetName().c_str(), child_groups.size())
OPTIMIZER_LOG_TRACE("Attempting to bind on group " + std::to_string(!gexpr->GetGroupID()) +
" with expression of type " + gexpr->Contents()->GetName() + ", children size " +
std::to_string(child_groups.size()))

// Find all bindings for children
children_bindings_.resize(child_groups.size());
Expand Down
5 changes: 3 additions & 2 deletions src/optimizer/group.cpp
@@ -1,4 +1,5 @@
#include "optimizer/group.h"

#include "loggers/optimizer_logger.h"

namespace terrier::optimizer {
Expand Down Expand Up @@ -38,8 +39,8 @@ void Group::AddExpression(GroupExpression *expr, bool enforced) {
}

bool Group::SetExpressionCost(GroupExpression *expr, double cost, PropertySet *properties) {
OPTIMIZER_LOG_TRACE("Adding expression cost on group {0} with op {1}", expr->GetGroupID(),
expr->Contents()->GetName().c_str())
OPTIMIZER_LOG_TRACE("Adding expression cost on group " + std::to_string(!expr->GetGroupID()) + " with op {1}" +
expr->Contents()->GetName())

auto it = lowest_cost_expressions_.find(properties);
if (it == lowest_cost_expressions_.end()) {
Expand Down
6 changes: 3 additions & 3 deletions src/optimizer/optimizer.cpp
Expand Up @@ -69,8 +69,8 @@ std::unique_ptr<planner::AbstractPlanNode> Optimizer::ChooseBestPlan(
Group *group = context_->GetMemo().GetGroupByID(id);
auto gexpr = group->GetBestExpression(required_props);

OPTIMIZER_LOG_TRACE("Choosing best plan for group {0} with op {1}", gexpr->GetGroupID(),
gexpr->Contents()->GetName().c_str());
OPTIMIZER_LOG_TRACE("Choosing best plan for group " + std::to_string(!gexpr->GetGroupID()) + " with op " +
gexpr->Contents()->GetName());

std::vector<group_id_t> child_groups = gexpr->GetChildGroupIDs();

Expand Down Expand Up @@ -110,7 +110,7 @@ std::unique_ptr<planner::AbstractPlanNode> Optimizer::ChooseBestPlan(
PlanGenerator generator;
auto plan = generator.ConvertOpNode(txn, accessor, op, required_props, required_cols, output_cols,
std::move(children_plans), std::move(children_expr_map));
OPTIMIZER_LOG_TRACE("Finish Choosing best plan for group {0}", id);
OPTIMIZER_LOG_TRACE("Finish Choosing best plan for group " + std::to_string(!id));

delete op;
return plan;
Expand Down
7 changes: 4 additions & 3 deletions src/optimizer/optimizer_task.cpp
@@ -1,3 +1,5 @@
#include "optimizer/optimizer_task.h"

#include <algorithm>
#include <functional>
#include <memory>
Expand All @@ -7,7 +9,6 @@
#include "optimizer/binding.h"
#include "optimizer/child_property_deriver.h"
#include "optimizer/optimizer_context.h"
#include "optimizer/optimizer_task.h"
#include "optimizer/property_enforcer.h"
#include "optimizer/statistics/child_stats_deriver.h"
#include "optimizer/statistics/stats_calculator.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ RuleSet &OptimizerTask::GetRuleSet() const { return context_->GetOptimizerContex
// OptimizeGroup
//===--------------------------------------------------------------------===//
void OptimizeGroup::Execute() {
OPTIMIZER_LOG_TRACE("OptimizeGroup::Execute() group {0}", group_->GetID());
OPTIMIZER_LOG_TRACE("OptimizeGroup::Execute() group " + std::to_string(!group_->GetID()));
if (group_->GetCostLB() > context_->GetCostUpperBound() || // Cost LB > Cost UB
group_->GetBestExpression(context_->GetRequiredProperties()) != nullptr) // Has optimized given the context
return;
Expand Down Expand Up @@ -203,7 +204,7 @@ void DeriveStats::Execute() {
auto children_required_stats =
deriver.DeriveInputStats(gexpr_, required_cols_, &context_->GetOptimizerContext()->GetMemo());
bool derive_children = false;
OPTIMIZER_LOG_TRACE("DeriveStats::Execute() group {0}", gexpr_->GetGroupID());
OPTIMIZER_LOG_TRACE("DeriveStats::Execute() group " + std::to_string(!gexpr_->GetGroupID()));

// If we haven't got enough stats to compute the current stats, derive them
// from the child first
Expand Down
1 change: 1 addition & 0 deletions test/network/network_test.cpp
Expand Up @@ -11,6 +11,7 @@
#include "gtest/gtest.h"
#include "network/connection_handle_factory.h"
#include "network/terrier_server.h"
#include "spdlog/spdlog.h"
#include "storage/garbage_collector.h"
#include "test_util/manual_packet_util.h"
#include "test_util/test_harness.h"
Expand Down
12 changes: 8 additions & 4 deletions test/optimizer/top_k_elements_test.cpp
@@ -1,3 +1,5 @@
#include "optimizer/statistics/top_k_elements.h"

#include <stack>
#include <string>
#include <unordered_map>
Expand All @@ -6,8 +8,6 @@
#include "gtest/gtest.h"
#include "loggers/optimizer_logger.h"
#include "optimizer/statistics/count_min_sketch.h"
#include "optimizer/statistics/top_k_elements.h"

#include "test_util/test_harness.h"

namespace terrier::optimizer {
Expand Down Expand Up @@ -45,7 +45,10 @@ TEST_F(TopKElementsTests, SimpleIncrementTest) {
top_k.Increment(5, 15);
EXPECT_EQ(top_k.GetSize(), 5);

OPTIMIZER_LOG_TRACE(top_k);
std::ostringstream stream;
stream << top_k;

OPTIMIZER_LOG_TRACE(stream.str());
}

// Check that if incrementally increase the count of a key that
Expand Down Expand Up @@ -134,7 +137,8 @@ TEST_F(TopKElementsTests, SortedKeyTest) {
// TODO(pavlo): This text case is in correct because we can't
// guarantee that the keys we shove in will have the exact amount
// that we originally set them to.
OPTIMIZER_LOG_TRACE("Top-{0}: {1} <-> {2}", i, key, expected_key);

OPTIMIZER_LOG_TRACE("Top-" + std::to_string(i) += ": " + key + " <-> " += expected_key);
// EXPECT_EQ(key, expected_key) << "Iteration #" << i;
i++;
}
Expand Down
1 change: 1 addition & 0 deletions test/parser/parser_test.cpp
Expand Up @@ -17,6 +17,7 @@
#include "parser/pg_trigger.h"
#include "parser/postgresparser.h"
#include "parser/statements.h"
#include "spdlog/spdlog.h"
#include "test_util/test_harness.h"

namespace terrier::parser {
Expand Down

0 comments on commit 686eb69

Please sign in to comment.