Skip to content

Commit

Permalink
fix: add nlohmann json.hpp and use it for gc stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Feb 8, 2024
1 parent 8bcb72c commit 1e958b2
Show file tree
Hide file tree
Showing 4 changed files with 24,618 additions and 12 deletions.
5 changes: 5 additions & 0 deletions include/shirakami/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static constexpr std::int32_t log_warning = 20;
*/
static constexpr std::int32_t log_info = 30;

/**
* @brief logging level constant for stats information about gc
*/
static constexpr std::int32_t log_info_gc_stats = 33;

/**
* @brief logging level constant for debug timing event information.
*
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_library(shirakami
target_include_directories(shirakami
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${PROJECT_SOURCE_DIR}/third_party
)

find_package(Threads REQUIRED)
Expand Down
28 changes: 16 additions & 12 deletions src/concurrency_control/garbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#include "yakushima/include/kvs.h"

// third_party

#include "glog/logging.h"

#include "nlohmann/json.hpp"

namespace shirakami::garbage {

void init() {
Expand Down Expand Up @@ -371,26 +375,26 @@ void release_key_memory() {
}

void output_gc_stats(stats_info_type const& stats_info) {
std::stringstream ss;
ss.clear();
ss << log_location_prefix_detail_info << "===Stats by GC===" << std::endl
<< "# storages: " << stats_info.size() << std::endl;
//std::stringstream ss;
//ss.clear();
VLOG(log_info_gc_stats) << log_location_prefix_detail_info
<< "===Stats by GC===" << std::endl
<< "# storages: " << stats_info.size() << std::endl;

for (const auto& elem : stats_info) {
std::string str_st_key{};
/**
* It may be fail if it executes after delete_storage against it.
*/
storage::key_handle_map_get_key(std::get<0>(elem), str_st_key);
ss << "storage key: " << str_st_key << std::endl
<< "# entries: " << std::get<1>(elem) << std::endl
<< "avarage length of version list per entry: " << std::get<2>(elem)
<< std::endl
<< "average key size per entry: " << std::get<3>(elem) << std::endl
<< "average value size per entry: " << std::get<4>(elem)
<< std::endl;
nlohmann::json j;
j["storage_key"] = str_st_key;
j["num_entries"] = std::get<1>(elem);
j["av_len_ver_list_per_entry"] = std::get<2>(elem);
j["av_key_size_per_entry"] = std::get<3>(elem);
j["av_val_size_per_entry"] = std::get<4>(elem);
VLOG(log_info_gc_stats) << log_location_prefix_detail_info << j;
}
VLOG(log_trace) << ss.str();
}

void work_cleaner() {
Expand Down
Loading

0 comments on commit 1e958b2

Please sign in to comment.