fix compile error #4
@ -279,13 +279,13 @@ if(TILE_BUILD_TESTS)
|
||||
target_sources(${PROJECT_NAME}_test_all PRIVATE ${test_file})
|
||||
endmacro()
|
||||
|
||||
tile_add_test(base_exposed_var_test "tile/base/exposed_var_test.cc")
|
||||
macro(tile_add_test test_name test_file)
|
||||
tile_add_custom_test(${test_name} ${test_file})
|
||||
add_test(NAME ${test_name} COMMAND ${test_name})
|
||||
endmacro()
|
||||
|
||||
tile_add_test(fiber_detail_scheduler_test "tile/fiber/detail/scheduler_test.cc")
|
||||
tile_add_test(base_exposed_var_test "tile/base/exposed_var_test.cc")
|
||||
tile_add_test(fiber_detail_scheduler_test "tile/fiber/detail/scheduler_test.cc")
|
||||
tile_add_test(base_internal_meta_test "tile/base/internal/meta_test.cc")
|
||||
# tile_add_test(net_internal_http_engine_test
|
||||
# "tile/net/internal/http_engine_test.cc")
|
||||
|
6
third_party/glog/CMakeLists.txt
vendored
6
third_party/glog/CMakeLists.txt
vendored
@ -39,7 +39,7 @@ option(PRINT_UNSYMBOLIZED_STACK_TRACES
|
||||
"Print file offsets in traces instead of symbolizing" OFF)
|
||||
option(WITH_CUSTOM_PREFIX "Enable support for user-generated message prefixes"
|
||||
ON)
|
||||
option(WITH_GFLAGS "Use gflags" ON)
|
||||
option(WITH_GFLAGS "Use gflags" OFF)
|
||||
option(WITH_GTEST "Use Google Test" OFF)
|
||||
option(WITH_PKGCONFIG "Enable pkg-config support" OFF)
|
||||
option(WITH_SYMBOLIZE "Enable symbolize module" ON)
|
||||
@ -699,8 +699,8 @@ endif(HAVE_PTHREAD)
|
||||
|
||||
if(gflags_FOUND)
|
||||
# Prefer the gflags target that uses double colon convention
|
||||
# target_link_libraries(glog PRIVATE gflags::gflags)
|
||||
# if (TARGET
|
||||
# target_link_libraries(glog PRIVATE gflags::gflags)
|
||||
# if (TARGET
|
||||
# gflags::gflags) target_link_libraries (glog PUBLIC gflags::gflags) else
|
||||
# (TARGET gflags::gflags) target_link_libraries (glog PUBLIC gflags) endif
|
||||
# (TARGET gflags::gflags)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "tile/base/string.h"
|
||||
|
||||
namespace tile {
|
||||
namespace exposed_var {
|
||||
// namespace exposed_var {
|
||||
|
||||
namespace {
|
||||
#define CHECK_PATH(path) \
|
||||
@ -63,19 +63,20 @@ std::string JoinPath(Slice a, Slice b) {
|
||||
|
||||
std::string SubstituteEscapedSlashForZero(Slice path) {
|
||||
TILE_CHECK(path.find('\0') == tile::Slice::npos);
|
||||
return Replace(path, "\\/", "\0");
|
||||
return Replace(path, "\\/", '\0');
|
||||
}
|
||||
|
||||
std::string SubstituteZeroForEscapedSlash(Slice path) {
|
||||
return Replace(path, "\0", "\\/");
|
||||
return Replace(path, '\0', "\\/");
|
||||
}
|
||||
|
||||
std::string UnescapeZeroToPlainSlash(Slice path) {
|
||||
return Replace(path, "\0", "/");
|
||||
return Replace(path, '\0', '/');
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// } // namespace exposed_var
|
||||
ExposedVarGroup::Handle
|
||||
ExposedVarGroup::Add(Slice rel_path, std::function<Json::Value()> value) {
|
||||
|
||||
@ -296,5 +297,4 @@ std::optional<Json::Value> ExposedVarDynamicTree::TryGet(Slice rel_path) const {
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
} // namespace exposed_var
|
||||
} // namespace tile
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "tile/base/chrono.h"
|
||||
#include "tile/base/deferred.h"
|
||||
#include "tile/base/internal/meta.h"
|
||||
#include "tile/base/optional.h"
|
||||
@ -46,15 +47,21 @@ auto ToJsonValue(const T &t)
|
||||
|
||||
template <typename T>
|
||||
auto ToJsonValue(const T &t)
|
||||
-> enable_if_t<std::is_same<std::string,
|
||||
decltype(format_as(std::declval<T>()))>::value,
|
||||
Json::Value> {
|
||||
-> enable_if_t<
|
||||
!std::is_integral<T>::value && !std::is_floating_point<T>::value &&
|
||||
!std::is_same<T, std::string>::value &&
|
||||
!std::is_same<T, const char *>::value &&
|
||||
!std::is_same<T, bool>::value &&
|
||||
std::is_same<std::string,
|
||||
decltype(format_as(std::declval<T>()))>::value,
|
||||
Json::Value> {
|
||||
return Json::Value(format_as(t));
|
||||
}
|
||||
|
||||
template <class T> Json::Value ToJsonValue(const std::atomic<T> &v) {
|
||||
return ToJsonValue(v.load(std::memory_order_relaxed));
|
||||
}
|
||||
} // namespace exposed_var
|
||||
|
||||
class ExposedVarDynamicTree;
|
||||
|
||||
@ -142,7 +149,45 @@ private:
|
||||
ExposedVarGroup::Handle handle_;
|
||||
};
|
||||
|
||||
} // namespace exposed_var
|
||||
namespace detail {
|
||||
template <typename T> struct IdentityTime {
|
||||
std::uint64_t operator()(const T &val) const {
|
||||
return (ReadSteadyClock() - std::chrono::steady_clock::time_point()) /
|
||||
std::chrono::nanoseconds(1);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, typename F = detail::IdentityTime<T>>
|
||||
class ExposedMetrics {
|
||||
public:
|
||||
explicit ExposedMetrics(Slice rel_path) {
|
||||
LinkToParent(rel_path, ExposedVarGroup::FindOrCreate("/"));
|
||||
}
|
||||
|
||||
private:
|
||||
Json::Value ToJsonValue(const T &v) {
|
||||
Json::Value result;
|
||||
std::unordered_map<std::string, T> m = {{"1s", 1}};
|
||||
for (auto &&item : m) {
|
||||
}
|
||||
}
|
||||
|
||||
void LinkToParent(Slice rel_path, ExposedVarGroup *parent) {
|
||||
handle_ = parent->Add(rel_path, [this] { return ToJsonValue(obj_); });
|
||||
}
|
||||
|
||||
private:
|
||||
T obj_{};
|
||||
ExposedVarGroup::Handle handle_;
|
||||
};
|
||||
|
||||
template <typename T> using ExposedCounter = ExposedVar<T>;
|
||||
template <typename T> using ExposedGauge = ExposedVar<T>;
|
||||
template <typename T> using ExposedMiner = ExposedVar<T>;
|
||||
template <typename T> using ExposedMaxer = ExposedVar<T>;
|
||||
template <typename T> using ExposedAverager = ExposedVar<T>;
|
||||
|
||||
} // namespace tile
|
||||
|
||||
#endif // TILE_BASE_EXPOSED_VAR_H
|
||||
|
@ -3,4 +3,36 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "json/json.h"
|
||||
|
||||
namespace tile {}
|
||||
namespace tile {
|
||||
ExposedVarGroup *GetFancyGroup() {
|
||||
return ExposedVarGroup::FindOrCreate("/a/b");
|
||||
}
|
||||
Json::Value GetTree() {
|
||||
Json::Value jsv;
|
||||
jsv["dir"]["sub-dir"]["key"] = 5;
|
||||
jsv["key"] = "6";
|
||||
return jsv;
|
||||
}
|
||||
|
||||
ExposedVar<int> v1("v1", 5);
|
||||
|
||||
ExposedVar<double> f1("f1", 6.2, ExposedVarGroup::FindOrCreate("/x/y/z"));
|
||||
|
||||
auto GreatGroup = ExposedVarGroup::FindOrCreate("/a/b");
|
||||
|
||||
// `/a/b/ds1`
|
||||
ExposedVarDynamic<std::string>
|
||||
ds1("ds1", [] { return "test_str"; }, GetFancyGroup());
|
||||
|
||||
TEST(ExposedVar, Mutate) {
|
||||
auto opt = ExposedVarGroup::TryGet("/");
|
||||
ASSERT_TRUE(opt);
|
||||
auto &&jsv = *opt;
|
||||
ASSERT_EQ(5, jsv["v1"].asInt());
|
||||
*v1 = 6;
|
||||
jsv = *ExposedVarGroup::TryGet("/");
|
||||
ASSERT_EQ(6, jsv["v1"].asInt());
|
||||
*v1 = 5;
|
||||
}
|
||||
|
||||
} // namespace tile
|
||||
|
0
tile/base/write_mostly.h
Normal file
0
tile/base/write_mostly.h
Normal file
36
tile/base/write_mostly/metrics.h
Normal file
36
tile/base/write_mostly/metrics.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef TILE_BASE_WRITE_MOSTLY_METRICS_H
|
||||
#define TILE_BASE_WRITE_MOSTLY_METRICS_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "tile/base/internal/meta.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
namespace tile {
|
||||
|
||||
namespace write_mostly {
|
||||
namespace detail {
|
||||
template <typename T> struct MetricsStats;
|
||||
}
|
||||
} // namespace write_mostly
|
||||
|
||||
template <typename T> struct MetricsStats {
|
||||
using SumType = internal::conditional_t<
|
||||
std::is_integral<T>::value,
|
||||
internal::conditional_t<std::is_signed<T>::value, std::int64_t,
|
||||
std::uint64_t>,
|
||||
long double>;
|
||||
|
||||
SumType sum;
|
||||
std::size_t cnt;
|
||||
T max;
|
||||
T min;
|
||||
T average;
|
||||
};
|
||||
|
||||
} // namespace tile
|
||||
|
||||
#endif // TILE_BASE_WRITE_MOSTLY_METRICS_H
|
18
tile/base/write_mostly/write_mostly.h
Normal file
18
tile/base/write_mostly/write_mostly.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef TILE_BASE_WRITE_MOSTLY_WRITE_MOSTLY_H
|
||||
#define TILE_BASE_WRITE_MOSTLY_WRITE_MOSTLY_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace tile {
|
||||
template <typename Traits> class WriteMostly {
|
||||
using T = typename Traits::Type;
|
||||
|
||||
public:
|
||||
};
|
||||
} // namespace tile
|
||||
|
||||
#endif // TILE_BASE_WRITE_MOSTLY_WRITE_MOSTLY_H
|
@ -53,17 +53,22 @@ int Start(int argc, char **argv, std::function<int(int, char **)> cb,
|
||||
google::InstallFailureSignalHandler();
|
||||
}
|
||||
|
||||
// Init gflags
|
||||
gflags::SetVersionString("0.1.0");
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
detail::ApplyFlagOverrider();
|
||||
|
||||
// Init Glog
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
TILE_LOG_INFO("Tile started.");
|
||||
|
||||
TILE_PCHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR);
|
||||
|
||||
// Init BasicRuntime
|
||||
InitializeBasicRuntime();
|
||||
|
||||
// Run all initializers
|
||||
detail::RunAllInitializers();
|
||||
|
||||
int rc = 0;
|
||||
|
@ -11,9 +11,9 @@ namespace testing {
|
||||
int InitAndRunAllTests(int *argc, char **argv) {
|
||||
::testing::InitGoogleTest(argc, argv);
|
||||
|
||||
if (gflags::GetCommandLineFlagInfoOrDie("logtostderr").is_default) {
|
||||
FLAGS_logtostderr = true;
|
||||
}
|
||||
// if (gflags::GetCommandLineFlagInfoOrDie("logtostderr").is_default) {
|
||||
// FLAGS_logtostderr = true;
|
||||
// }
|
||||
|
||||
return Start(*argc, argv, [](int, char **) { return ::RUN_ALL_TESTS(); });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user