Skip to content

Commit

Permalink
logger and includes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelbon committed Oct 26, 2024
1 parent 867df3b commit b338426
Show file tree
Hide file tree
Showing 75 changed files with 396 additions and 361 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DerivePointerAlignment: false # disables 'Google' option which forces ignoring m
PointerAlignment: Left
ReferenceAlignment: Left
InsertNewlineAtEOF: true
IndentPPDirectives: BeforeHash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ src/api_types_cmp.cpp
include/tgbm/api/types_all.hpp
include/tgbm/api/types_fwd.hpp
include/tgbm/api/types.txt
**/tgbm_replace/*

.vs/
.vscode/
Expand Down
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,3 @@ if (WIN32)
message (STATUS "[tgbm] TGBM_WINDOWS_VERSION: ${TGBM_WINDOWS_VERSION}")
target_compile_definitions(tgbmlib PUBLIC _WIN32_WINNT=${TGBM_WINDOWS_VERSION})
endif()

add_executable(tgbm_main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
target_link_libraries(tgbm_main PUBLIC tgbmlib)

set_target_properties(tgbm_main PROPERTIES
CMAKE_CXX_EXTENSIONS OFF
LINKER_LANGUAGE CXX
CMAKE_CXX_STANDARD_REQUIRED ON
CXX_STANDARD 20)

2 changes: 1 addition & 1 deletion cmake/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CPMAddPackage(
unset(BOOST_INCLUDE_LIBRARIES)
find_package(Boost 1.84 COMPONENTS system asio property_tree pfr json REQUIRED)

CPMAddPackage("gh:fmtlib/fmt#10.2.0")
CPMAddPackage("gh:fmtlib/fmt#11.0.2")

CPMAddPackage(
NAME kelcoro
Expand Down
6 changes: 4 additions & 2 deletions gbench/bench_main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <benchmark/benchmark.h>
#include <tgbm/api/types_all.hpp>
#include <tgbm/tools/formatters.hpp>

#include <fuzzing.hpp>
#include <types.hpp>

#include "tgbm/api/types_all.hpp"
#include "tgbm/tools/formatters.hpp"

int main(int argc, char** argv) {
auto& storage = fuzzing::GetMutableStorage();
// clang-format off
Expand Down
6 changes: 3 additions & 3 deletions gbench/files.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "benchmark/benchmark.h"
#include "fuzzing.hpp"
#include "types.hpp"
#include <tgbm/api/types_all.hpp>
#include <tgbm/tools/json_tools/all.hpp>
#include <tgbm/tools/json_tools/parse_dom/all.hpp>
#include "tgbm/api/types_all.hpp"
#include "tgbm/tools/json_tools/all.hpp"
#include "tgbm/tools/json_tools/parse_dom/all.hpp"

template <typename T>
void execute_handler_rapid(std::string_view json) {
Expand Down
22 changes: 11 additions & 11 deletions gbench/fuzzing.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once
#include <fmt/format.h>

#include <filesystem>
#include <optional>
#include <string>
#include <random>
#include <type_traits>
#include <unordered_map>
#include <tgbm/tools/box.hpp>
#include <tgbm/tools/pfr_extension.hpp>
#include <tgbm/tools/traits.hpp>
#include <fstream>
#include <tgbm/logger.h>
#include <tgbm/tools/json_tools/boost_serialize_dom.hpp>

#include "tgbm/tools/box.hpp"
#include "tgbm/tools/pfr_extension.hpp"
#include "tgbm/tools/traits.hpp"
#include "tgbm/logger.hpp"
#include "tgbm/tools/json_tools/boost_serialize_dom.hpp"

namespace fuzzing {

Expand Down Expand Up @@ -186,7 +187,7 @@ struct Storage {
template <typename T>
void Add(std::string name, Config config) {
std::filesystem::path path(config.path);
LOG("Add: {}", path.generic_string());
TGBM_LOG_INFO("Add: {}", path.generic_string());
std::optional<std::string> json;
if (std::filesystem::exists(path)) {
std::fstream file(path);
Expand Down Expand Up @@ -217,7 +218,7 @@ struct Storage {
template <typename T, std::size_t N>
void AddArray(std::string name, Config config) {
std::filesystem::path path(config.path);
LOG("AddArray: {}", path.generic_string());
TGBM_LOG_INFO("AddArray: {}", path.generic_string());
std::optional<std::string> json;
if (std::filesystem::exists(path)) {
std::fstream file(path);
Expand Down Expand Up @@ -354,9 +355,8 @@ template <>
struct randomizer<std::string> {
static constexpr bool is_nesting = false;
static std::string generate(Context context, auto&& generator) {
// TODO: char fix
std::uniform_int_distribution<char> distribution('A', 'Z');
std::uniform_int_distribution<std::uint8_t> size_distr(0, 15);
std::uniform_int_distribution<size_t> distribution(size_t('A'), size_t('Z'));
std::uniform_int_distribution<size_t> size_distr(0, 15);
std::uint8_t size = size_distr(generator);
std::string result;
result.resize(size, '\0');
Expand Down
4 changes: 3 additions & 1 deletion gbench/types.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <string>
#include <tgbm/api/common.hpp>

#include "tgbm/api/common.hpp"
#include "tgbm/tools/pfr_extension.hpp"

namespace types {
Expand Down
18 changes: 9 additions & 9 deletions gtest/api/test_message.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#if 0

#include <gtest/gtest.h>
#include <gtest/gtest.h>

#include <tgbm/tools/to_boost_json.h>
#include <tgbm/api/types_all.hpp>
#include <tgbm/tools/from_boost_json.h>
#include <tgbm/tools/json_tools/parser/all.h>
#include <tgbm/tools/random.h>
#include "chaotic_test.hpp"
#include <helper.hpp>
#include <fmt/ranges.h>
#include "tgbm/tools/to_boost_json.h"
#include "tgbm/api/types_all.hpp"
#include "tgbm/tools/from_boost_json.h"
#include "tgbm/tools/json_tools/parser/all.h"
#include "tgbm/tools/random.h"
#include "chaotic_test.hpp"
#include <helper.hpp>
#include <fmt/ranges.h>

namespace api = tgbm::api;

Expand Down
4 changes: 3 additions & 1 deletion gtest/gtest_formater.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once

#include <iterator>
#include <tgbm/tools/formatters.hpp>

#include <fmt/ranges.h>

#include "tgbm/tools/formatters.hpp"

template <typename T>
concept formattable = fmt::is_formattable<T>::value;

Expand Down
5 changes: 3 additions & 2 deletions gtest/parsers/fixtures.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#include <gtest/gtest.h>
#include <gtest_formater.hpp>
#include <tgbm/api/common.hpp>
#include <tgbm/tools/json_tools/all.hpp>

#include "tgbm/api/common.hpp"
#include "tgbm/tools/json_tools/all.hpp"

struct DomRapid : testing::Test {
template <typename T>
Expand Down
10 changes: 5 additions & 5 deletions gtest/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#if 0

#include <tgbm/tools/json_tools/parser/all.h>
#include <sstream>
#include <rapidjson/reader.h>
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include "tgbm/tools/json_tools/parser/all.h"
#include <sstream>
#include <rapidjson/reader.h>
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>

namespace tests_json_parser {
struct Position {
Expand Down
13 changes: 7 additions & 6 deletions include/tgbm/api/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include <string>
#include <variant>
#include <vector>
#include <tgbm/tools/StringTools.h>
#include <tgbm/tools/box_union.hpp>
#include <tgbm/api/optional.hpp>
#include <tgbm/api/Integer.hpp>
#include <tgbm/api/floating.hpp>
#include <string_view>
#include <tgbm/tools/pfr_extension.hpp>

#include "tgbm/tools/StringTools.h"
#include "tgbm/tools/box_union.hpp"
#include "tgbm/api/optional.hpp"
#include "tgbm/api/Integer.hpp"
#include "tgbm/api/floating.hpp"
#include "tgbm/tools/pfr_extension.hpp"

namespace tgbm::api {

Expand Down
2 changes: 2 additions & 0 deletions include/tgbm/api/const_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct TGBM_TRIVIAL_ABI const_string {
return reinterpret_cast<char*>(&ptrlen);
}
char* buffer = (char*)malloc(sizeof(string_impl) + len);
if (!buffer) [[unlikely]]
throw std::bad_alloc{};
string_impl* impl = new (buffer) string_impl(1, len);
ptrlen = reinterpret_cast<uintptr_t>(impl);
return impl->data;
Expand Down
4 changes: 2 additions & 2 deletions include/tgbm/api/templates/default.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ifndef API_TYPE_PATH
#error API_TYPE_PATH should be defined
#error API_TYPE_PATH should be defined
#endif

#ifndef API_TYPE
#error API_TYPE should be defined
#error API_TYPE should be defined
#endif

namespace tgbm::api {
Expand Down
4 changes: 2 additions & 2 deletions include/tgbm/api/templates/oneof.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ifndef API_TYPE_PATH
#error API_TYPE_PATH should be defined
#error API_TYPE_PATH should be defined
#endif

#ifndef API_TYPE
#error API_TYPE should be defined
#error API_TYPE should be defined
#endif

namespace tgbm::api {
Expand Down
4 changes: 2 additions & 2 deletions include/tgbm/api/templates/oneof_field.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ifndef API_TYPE_PATH
#error API_TYPE_PATH should be defined
#error API_TYPE_PATH should be defined
#endif

#ifndef API_TYPE
#error API_TYPE should be defined
#error API_TYPE should be defined
#endif

namespace tgbm::api {
Expand Down
17 changes: 0 additions & 17 deletions include/tgbm/logger.h

This file was deleted.

32 changes: 32 additions & 0 deletions include/tgbm/logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
/*
simplest replacable logger
To replace logger user should create tgbm_replace/logger.hpp file
and add tgbm_replace into include dirs
*/

#if __has_include("tgbm_replace/logger.hpp")
#include "tgbm_replace/logger.hpp"
#ifndef TGBM_LOG
#error "tgbm_replace/logger.hpp" must define TGBM_LOG(FMT_STR, ...ARGS)
#endif
#else

#include <fmt/format.h>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <fmt/chrono.h>

#define TGBM_LOG(FMT_STR, ...) ::fmt::println(stdout, FMT_STR __VA_OPT__(, ) __VA_ARGS__)

#endif

#define TGBM_LOG_INFO(FMT_STR, ...) TGBM_LOG("[INFO] " FMT_STR __VA_OPT__(, ) __VA_ARGS__)
#define TGBM_LOG_ERROR(FMT_STR, ...) TGBM_LOG("[ERROR] " FMT_STR __VA_OPT__(, ) __VA_ARGS__)
#define TGBM_LOG_WARN(FMT_STR, ...) TGBM_LOG("[WARN] " FMT_STR __VA_OPT__(, ) __VA_ARGS__)

#ifndef NDEBUG
#define TGBM_LOG_DEBUG(FMT_STR, ...) TGBM_LOG("[DEBUG] " FMT_STR __VA_OPT__(, ) __VA_ARGS__)
#else
#define TGBM_LOG_DEBUG(FMT_STR, ...) (void)0
#endif
1 change: 1 addition & 0 deletions include/tgbm/net/HttpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unordered_map>
#include <cassert>
#include <vector>
#include <iterator>

#include "tgbm/tools/macro.hpp"
#include "tgbm/tools/StringTools.h"
Expand Down
23 changes: 5 additions & 18 deletions include/tgbm/net/connectiion_pool.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#pragma once

#include <cassert>
#include <coroutine>
#include <anyany/anyany.hpp>
#include <kelcoro/task.hpp>
#include <cassert>
#include <mutex>

#include "tgbm/tools/scope_exit.h"
#include <anyany/anyany.hpp>

#include <kelcoro/task.hpp>

#include <boost/intrusive/list_hook.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/slist.hpp>
#include <boost/intrusive/slist_hook.hpp>

#include "tgbm/tools/scope_exit.h"
#include "tgbm/tools/boost_intrusive.hpp"

#include "tgbm/logger.h"

#include "tgbm/tools/macro.hpp"

namespace tgbm {
Expand All @@ -41,17 +39,6 @@ struct noop_events_handler_t {
}
};

// TODO into another file or smth like, utils
struct null_mutex {
static constexpr void lock() noexcept {
}
static constexpr void unlock() noexcept {
}
static constexpr bool try_lock() noexcept {
return true;
}
};

// TODO coro allocator multithread (interface)
template <typename T, pool_events_handler_for<T> H = noop_events_handler_t<T>>
struct pool_t {
Expand Down
1 change: 0 additions & 1 deletion include/tgbm/net/http11_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "tgbm/net/http_client.hpp"
#include "tgbm/net/connectiion_pool.hpp"
#include "tgbm/logger.h"

#include "tgbm/net/tcp_connection.hpp"

Expand Down
12 changes: 0 additions & 12 deletions include/tgbm/net/http2/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,3 @@ inline bool strip_padding(std::span<byte_t>& bytes) {
void parse_http2_request_headers(hpack::decoder& d, std::span<const hpack::byte_t> bytes, http_request& req);

} // namespace tgbm::http2

namespace fmt {

template <>
struct formatter<::tgbm::http2::frame_header> : fmt::formatter<std::string_view> {
auto format(const ::tgbm::http2::frame_header& header, auto& ctx) -> decltype(ctx.out()) {
return fmt::format_to(ctx.out(), "length: {}\n, type: {}\n, flags: {}\n, stream_id: {}", header.length,
(int)header.type, (int)header.flags, header.stream_id);
}
};

} // namespace fmt
Loading

0 comments on commit b338426

Please sign in to comment.