From 466508332c553e89aee96d2b4bafa05d4f711cf1 Mon Sep 17 00:00:00 2001 From: FluorineDog Date: Wed, 30 Sep 2020 18:36:27 +0800 Subject: [PATCH] Enable backtrace for better debugging Signed-off-by: FluorineDog --- core/src/dog_segment/CMakeLists.txt | 5 +++- core/src/dog_segment/EasyAssert.cpp | 26 +++++++++++++++++ core/src/dog_segment/EasyAssert.h | 15 ++++------ core/src/dog_segment/SegmentDefs.h | 4 +-- core/src/dog_segment/SegmentNaive.cpp | 3 -- core/unittest/test_dog_segment.cpp | 42 +++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 17 deletions(-) create mode 100644 core/src/dog_segment/EasyAssert.cpp diff --git a/core/src/dog_segment/CMakeLists.txt b/core/src/dog_segment/CMakeLists.txt index 43890955c..58f79fde8 100644 --- a/core/src/dog_segment/CMakeLists.txt +++ b/core/src/dog_segment/CMakeLists.txt @@ -1,5 +1,6 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../pb PB_SRC_FILES) +# add_definitions(-DBOOST_STACKTRACE_USE_ADDR2LINE) set(DOG_SEGMENT_FILES SegmentNaive.cpp IndexMeta.cpp @@ -9,6 +10,7 @@ set(DOG_SEGMENT_FILES collection_c.cpp partition_c.cpp segment_c.cpp + EasyAssert.cpp ${PB_SRC_FILES} ) add_library(milvus_dog_segment SHARED @@ -18,4 +20,5 @@ add_library(milvus_dog_segment SHARED #add_dependencies( segment sqlite mysqlpp ) -target_link_libraries(milvus_dog_segment tbb utils pthread knowhere log libprotobuf) +target_link_libraries(milvus_dog_segment tbb utils pthread knowhere log libprotobuf dl backtrace +) diff --git a/core/src/dog_segment/EasyAssert.cpp b/core/src/dog_segment/EasyAssert.cpp new file mode 100644 index 000000000..794ad8963 --- /dev/null +++ b/core/src/dog_segment/EasyAssert.cpp @@ -0,0 +1,26 @@ + +#include +#include "EasyAssert.h" +// #define BOOST_STACKTRACE_USE_ADDR2LINE +#define BOOST_STACKTRACE_USE_BACKTRACE +#include + + +namespace milvus::impl { +void EasyAssertInfo(bool value, std::string_view expr_str, std::string_view filename, int lineno, + std::string_view extra_info) { + if (!value) { + std::string info; + info += "Assert \"" + std::string(expr_str) + "\""; + info += " at " + std::string(filename) + ":" + std::to_string(lineno) + "\n"; + if(!extra_info.empty()) { + info += " => " + std::string(extra_info); + } + auto fuck = boost::stacktrace::stacktrace(); + std::cout << fuck; + // std::string s = fuck; + // info += ; + throw std::runtime_error(info); + } +} +} \ No newline at end of file diff --git a/core/src/dog_segment/EasyAssert.h b/core/src/dog_segment/EasyAssert.h index b60fd7e82..b9c027442 100644 --- a/core/src/dog_segment/EasyAssert.h +++ b/core/src/dog_segment/EasyAssert.h @@ -1,18 +1,13 @@ #pragma once #include +#include +#include + +/* Paste this on the file you want to debug. */ namespace milvus::impl { -inline void EasyAssertInfo(bool value, std::string_view expr_str, std::string_view filename, int lineno, - std::string_view extra_info) { - if (!value) { - std::string info; - info += "Assert \"" + std::string(expr_str) + "\""; - info += " at " + std::string(filename) + ":" + std::to_string(lineno); - info += " => " + std::string(extra_info); - throw std::runtime_error(info); - } -} + std::string_view extra_info); } #define AssertInfo(expr, info) impl::EasyAssertInfo(bool(expr), #expr, __FILE__, __LINE__, (info)) diff --git a/core/src/dog_segment/SegmentDefs.h b/core/src/dog_segment/SegmentDefs.h index 2156a56bb..cb0c187a7 100644 --- a/core/src/dog_segment/SegmentDefs.h +++ b/core/src/dog_segment/SegmentDefs.h @@ -171,9 +171,7 @@ class Schema { const FieldMeta& operator[](const std::string& field_name) const { auto offset_iter = offsets_.find(field_name); - if (offset_iter == offsets_.end()) { - throw std::runtime_error("Cannot found field_name: " + field_name); - } + AssertInfo(offset_iter != offsets_.end(), "Cannot found field_name: " + field_name); auto offset = offset_iter->second; return (*this)[offset]; } diff --git a/core/src/dog_segment/SegmentNaive.cpp b/core/src/dog_segment/SegmentNaive.cpp index 10120caf3..46b2e1ad9 100644 --- a/core/src/dog_segment/SegmentNaive.cpp +++ b/core/src/dog_segment/SegmentNaive.cpp @@ -96,9 +96,6 @@ auto SegmentNaive::get_deleted_bitmap(int64_t del_barrier, Timestamp query_times if (offset >= insert_barrier) { continue; } - if (offset >= insert_barrier) { - continue; - } if (record_.timestamps_[offset] < query_timestamp) { Assert(offset < insert_barrier); the_offset = std::max(the_offset, offset); diff --git a/core/unittest/test_dog_segment.cpp b/core/unittest/test_dog_segment.cpp index 1202cd7ac..0ccdcda60 100644 --- a/core/unittest/test_dog_segment.cpp +++ b/core/unittest/test_dog_segment.cpp @@ -24,6 +24,34 @@ using std::cin; using std::cout; using std::endl; +namespace { +auto +generate_data(int N) { + std::vector raw_data; + std::vector timestamps; + std::vector uids; + std::default_random_engine er(42); + std::normal_distribution<> distribution(0.0, 1.0); + std::default_random_engine ei(42); + + for (int i = 0; i < N; ++i) { + uids.push_back(10 * N + i); + timestamps.push_back(0); + // append vec + float vec[16]; + for (auto& x : vec) { + x = distribution(er); + } + raw_data.insert( + raw_data.end(), (const char*)std::begin(vec), (const char*)std::end(vec)); + int age = ei() % 100; + raw_data.insert( + raw_data.end(), (const char*)&age, ((const char*)&age) + sizeof(age)); + } + return std::make_tuple(raw_data, timestamps, uids); +} +} // namespace + TEST(DogSegmentTest, TestABI) { using namespace milvus::engine; @@ -32,6 +60,20 @@ TEST(DogSegmentTest, TestABI) { assert(true); } +TEST(DogSegmentTest, NormalDistributionTest) { + using namespace milvus::dog_segment; + using namespace milvus::engine; + auto schema = std::make_shared(); + schema->AddField("fakevec", DataType::VECTOR_FLOAT, 16); + schema->AddField("age", DataType::INT32); + int N = 1000* 1000; + auto [raw_data, timestamps, uids] = generate_data(N); + auto segment = CreateSegment(schema); + segment->PreInsert(N); + segment->PreDelete(N); + +} + TEST(DogSegmentTest, MockTest) { using namespace milvus::dog_segment; -- GitLab