From 18a261a6dda42660937aa9701941570870aa7d7c Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Thu, 4 Jan 2018 09:27:09 +0300 Subject: [PATCH 1/5] Add CMake support --- .gitignore | 4 ++ CMakeLists.txt | 96 ++++++++++++++++++++++++++++++++++++++++ build.sh | 18 ++++++++ src/tools/CMakeLists.txt | 42 ++++++++++++++++++ test/CMakeLists.txt | 34 ++++++++++++++ tutorial/CMakeLists.txt | 11 +++++ 6 files changed, 205 insertions(+) create mode 100644 CMakeLists.txt create mode 100755 build.sh create mode 100644 src/tools/CMakeLists.txt create mode 100644 test/CMakeLists.txt create mode 100644 tutorial/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 117141cb..06a2d4a3 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,7 @@ Win32/ x64/ x86/ test.log + +cmake-build-* +build-* +.idea \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..b7dd4c6f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,96 @@ +cmake_minimum_required(VERSION 2.8.7) + +set(TARGET libmdbx) +project(${TARGET}) + +enable_language(C) +enable_language(CXX) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED on) + +add_definitions(-DNDEBUG=1 -DMDBX_DEBUG=0 -DLIBMDBX_EXPORTS=1 -D_GNU_SOURCE=1) + +get_directory_property(hasParent PARENT_DIRECTORY) +if (hasParent) + set(STANDALONE_BUILD 0) +else () + set(STANDALONE_BUILD 1) + enable_testing() + + if (CMAKE_C_COMPILER_ID MATCHES GNU) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-constant-logical-operand") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES GNU) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-security") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wwrite-strings") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Wmissing-declarations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-functions-called-once") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-packed-bitfield-compat") + + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3") + endif () + + if (COVERAGE) + if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug Current value=${CMAKE_BUILD_TYPE}") + endif () + + message(STATUS "Setting coverage compiler flags") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") + + add_definitions(-DCOVERAGE_TEST) + endif () + + if (TRAVIS) + add_definitions(-DNO_MLOCK) + else () + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fstack-protector-strong -static-libasan") + endif () +endif () + +add_library(${TARGET} STATIC + mdbx.h + src/bits.h + src/defs.h + src/lck-posix.c + src/mdbx.c + src/osal.c + src/osal.h + src/version.c + ) + +target_include_directories(${TARGET} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +add_subdirectory(tutorial) +add_subdirectory(test) +add_subdirectory(src/tools) diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..c11445c5 --- /dev/null +++ b/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +CONFIG=$1 + +if [[ -z "${CONFIG}" ]]; then + CONFIG=Debug +fi +if [[ -r /opt/rh/devtoolset-6/enable ]]; then + source /opt/rh/devtoolset-6/enable +fi +#rm -f -r build || true +mkdir -p build-${CONFIG} +pushd build-${CONFIG} &> /dev/null +if [[ ! -r Makefile ]]; then + cmake .. -DCMAKE_BUILD_TYPE=${CONFIG} +fi +make -j8 || exit 1 +popd &> /dev/null diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt new file mode 100644 index 00000000..f9e8f89e --- /dev/null +++ b/src/tools/CMakeLists.txt @@ -0,0 +1,42 @@ +project(mdbx_tools) + +add_executable(mdbx_chk + mdbx_chk.c + ) + +target_link_libraries(mdbx_chk + libmdbx + ) + +add_executable(mdbx_copy + mdbx_copy.c + ) + +target_link_libraries(mdbx_copy + libmdbx + ) + +add_executable(mdbx_dump + mdbx_dump.c + ) + +target_link_libraries(mdbx_dump + libmdbx + ) + + +add_executable(mdbx_load + mdbx_load.c + ) + +target_link_libraries(mdbx_load + libmdbx + ) + +add_executable(mdbx_stat + mdbx_stat.c + ) + +target_link_libraries(mdbx_stat + libmdbx + ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..af20c333 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,34 @@ +set(TARGET mdbx_test) +project(${TARGET}) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cast-qual") + +add_executable(${TARGET} + base.h + cases.cc + chrono.cc + chrono.h + config.cc + config.h + dead.cc + hill.cc + jitter.cc + keygen.cc + keygen.h + log.cc + log.h + main.cc + osal.h + osal-unix.cc + test.cc + test.h + try.cc + utils.cc + utils.h +) + +target_link_libraries(${TARGET} + libmdbx + ) + diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt new file mode 100644 index 00000000..3b466884 --- /dev/null +++ b/tutorial/CMakeLists.txt @@ -0,0 +1,11 @@ +set(TARGET mdbx_tutorial) +project(${TARGET}) + +add_executable(${TARGET} + sample-mdbx.c +) + +target_link_libraries(${TARGET} + libmdbx + ) + From 987940ee6cc527808b344f282214ffdba0e13aa2 Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Thu, 4 Jan 2018 09:30:42 +0300 Subject: [PATCH 2/5] Add endline --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 06a2d4a3..aa431599 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,4 @@ test.log cmake-build-* build-* -.idea \ No newline at end of file +.idea From 35537e05f44f8f24045ac9c39fd3f4cba940ace0 Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Fri, 5 Jan 2018 05:57:33 +0300 Subject: [PATCH 3/5] Add pcrf_test --- CMakeLists.txt | 1 + build.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7dd4c6f..1b3b4c22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,3 +94,4 @@ target_include_directories(${TARGET} PUBLIC add_subdirectory(tutorial) add_subdirectory(test) add_subdirectory(src/tools) +add_subdirectory(pcrf_test) diff --git a/build.sh b/build.sh index c11445c5..51708822 100755 --- a/build.sh +++ b/build.sh @@ -9,8 +9,8 @@ if [[ -r /opt/rh/devtoolset-6/enable ]]; then source /opt/rh/devtoolset-6/enable fi #rm -f -r build || true -mkdir -p build-${CONFIG} -pushd build-${CONFIG} &> /dev/null +mkdir -p cmake-build-${CONFIG} +pushd cmake-build-${CONFIG} &> /dev/null if [[ ! -r Makefile ]]; then cmake .. -DCMAKE_BUILD_TYPE=${CONFIG} fi From 294d4ac0b9093c7f990330593f67b558eeb3a42f Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Fri, 5 Jan 2018 05:57:54 +0300 Subject: [PATCH 4/5] Add pcrf_test --- pcrf_test/CMakeLists.txt | 11 ++ pcrf_test/README.md | 2 + pcrf_test/pcrf_test.c | 384 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 pcrf_test/CMakeLists.txt create mode 100644 pcrf_test/README.md create mode 100644 pcrf_test/pcrf_test.c diff --git a/pcrf_test/CMakeLists.txt b/pcrf_test/CMakeLists.txt new file mode 100644 index 00000000..4d39135e --- /dev/null +++ b/pcrf_test/CMakeLists.txt @@ -0,0 +1,11 @@ +set(TARGET pcrf_test) +project(${TARGET}) + +add_executable(${TARGET} + pcrf_test.c +) + +target_link_libraries(${TARGET} + libmdbx + ) + diff --git a/pcrf_test/README.md b/pcrf_test/README.md new file mode 100644 index 00000000..b2c9b5ce --- /dev/null +++ b/pcrf_test/README.md @@ -0,0 +1,2 @@ +PCRF Session DB emulation test + diff --git a/pcrf_test/pcrf_test.c b/pcrf_test/pcrf_test.c new file mode 100644 index 00000000..7e69f435 --- /dev/null +++ b/pcrf_test/pcrf_test.c @@ -0,0 +1,384 @@ +/* + * Copyright 2016-2017 Leonid Yuriev . + * Copyright 2015 Vladimir Romanov , Yota Lab. + * + * This file is part of libmdbx. + * + * ReOpenMDBX is free software; you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * ReOpenMDBX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "mdbx.h" +#include + +#define IP_PRINTF_ARG_HOST(addr) (int)((addr) >> 24), (int)((addr) >> 16 & 0xff), (int)((addr) >> 8 & 0xff), (int)((addr) & 0xff) + +char opt_db_path[PATH_MAX] = "/root/lmdbx_bench2"; +static MDBX_env *env; +#define REC_COUNT 10240000 +int64_t ids[REC_COUNT * 10]; +int32_t ids_count = 0; + +int64_t mdbx_add_count = 0; +int64_t mdbx_del_count = 0; +uint64_t mdbx_add_time = 0; +uint64_t mdbx_del_time = 0; +int64_t obj_id = 0; +int64_t mdbx_data_size = 0; +int64_t mdbx_key_size = 0; + +typedef struct { + char session_id1[100]; + char session_id2[100]; + char ip[20]; + uint8_t fill[100]; +} session_data_t; + +typedef struct { + int64_t obj_id; + int8_t event_type; +} __attribute__((__packed__)) event_data_t; + +static void add_id_to_pool(int64_t id) { + ids[ids_count] = id; + ids_count++; +} + +static inline int64_t getClockUs(void) { + struct timespec val; +#ifdef CYGWIN + clock_gettime(CLOCK_REALTIME, &val); +#else + clock_gettime(CLOCK_MONOTONIC, &val); +#endif + return val.tv_sec * ((int64_t) 1000000) + val.tv_nsec / 1000; +} + +static int64_t get_id_from_pool() { + if (ids_count == 0) { + return -1; + } + int32_t index = rand() % ids_count; + int64_t id = ids[index]; + ids[index] = ids[ids_count - 1]; + ids_count--; + return id; +} + +#define MDBX_CHECK(x) \ + do {\ + const int rc = (x);\ + if ( rc != MDBX_SUCCESS ) {\ + printf("Error [%d] %s in %s at %s:%d\n", rc, mdbx_strerror(rc), #x, __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + }\ + } while(0) + +static void db_connect() { + MDBX_dbi dbi_session; + MDBX_dbi dbi_session_id; + MDBX_dbi dbi_event; + MDBX_dbi dbi_ip; + + MDBX_CHECK(mdbx_env_create(&env)); + MDBX_CHECK(mdbx_env_set_mapsize(env, REC_COUNT * sizeof(session_data_t) * 10)); + MDBX_CHECK(mdbx_env_set_maxdbs(env, 30)); + MDBX_CHECK(mdbx_env_open(env, opt_db_path, MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC| MDBX_NOSYNC | MDBX_LIFORECLAIM, 0664)); + MDBX_txn *txn; + + // transaction init + MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); + // open database in read-write mode + MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); + MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); + MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); + MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); + // transaction commit + MDBX_CHECK(mdbx_txn_commit(txn)); + printf("Connection open\n"); +} + +static void create_record(int64_t record_id) { + MDBX_dbi dbi_session; + MDBX_dbi dbi_session_id; + MDBX_dbi dbi_event; + MDBX_dbi dbi_ip; + event_data_t event; + MDBX_txn *txn; + session_data_t data; + // transaction init + snprintf(data.session_id1, sizeof(data.session_id1), "prefix%02ld_%02ld.fill.fill.fill.fill.fill.fill;%ld", + record_id % 3 + 1, record_id % 9 + 1, record_id); + snprintf(data.session_id2, sizeof(data.session_id2), "dprefix%ld;%ld.fill.fill.;suffix", record_id, + record_id % 1000000000 + 99999); + snprintf(data.ip, sizeof(data.ip), "%d.%d.%d.%d", IP_PRINTF_ARG_HOST(record_id & 0xFFFFFFFF)); + event.obj_id = record_id; + event.event_type = 1; + + MDBX_val _session_id1_rec = {data.session_id1, strlen(data.session_id1)}; + MDBX_val _session_id2_rec = {data.session_id2, strlen(data.session_id2)}; + MDBX_val _ip_rec = {data.ip, strlen(data.ip)}; + MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)}; + MDBX_val _data_rec = {&data, offsetof(session_data_t, fill) + (rand() % sizeof(data.fill))}; + MDBX_val _event_rec = {&event, sizeof(event)}; + + uint64_t start = getClockUs(); + MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); + MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); + MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); + MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); + MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); + MDBX_CHECK(mdbx_put(txn, dbi_session, &_obj_id_rec, &_data_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); + MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id1_rec, &_obj_id_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); + MDBX_CHECK(mdbx_put(txn, dbi_session_id, &_session_id2_rec, &_obj_id_rec, MDBX_NOOVERWRITE | MDBX_NODUPDATA)); + MDBX_CHECK(mdbx_put(txn, dbi_ip, &_ip_rec, &_obj_id_rec, 0)); + MDBX_CHECK(mdbx_put(txn, dbi_event, &_event_rec, &_obj_id_rec, 0)); + MDBX_CHECK(mdbx_txn_commit(txn)); + + mdbx_data_size += (_data_rec.iov_len + _obj_id_rec.iov_len * 4); + mdbx_key_size += (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len + + _event_rec.iov_len); + + // transaction commit + mdbx_add_count++; + mdbx_add_time += (getClockUs() - start); +} + +static void delete_record(int64_t record_id) { + MDBX_dbi dbi_session; + MDBX_dbi dbi_session_id; + MDBX_dbi dbi_event; + MDBX_dbi dbi_ip; + event_data_t event; + MDBX_txn *txn; + + // transaction init + uint64_t start = getClockUs(); + MDBX_CHECK(mdbx_txn_begin(env, NULL, 0, &txn)); + // open database in read-write mode + MDBX_CHECK(mdbx_dbi_open(txn, "session", MDBX_CREATE, &dbi_session)); + MDBX_CHECK(mdbx_dbi_open(txn, "session_id", MDBX_CREATE, &dbi_session_id)); + MDBX_CHECK(mdbx_dbi_open(txn, "event", MDBX_CREATE, &dbi_event)); + MDBX_CHECK(mdbx_dbi_open(txn, "ip", MDBX_CREATE, &dbi_ip)); + // put data + MDBX_val _obj_id_rec = {&record_id, sizeof(record_id)}; + MDBX_val _data_rec; + // get data + MDBX_CHECK(mdbx_get(txn, dbi_session, &_obj_id_rec, &_data_rec)); + session_data_t *data = (session_data_t *) _data_rec.iov_base; + + MDBX_val _session_id1_rec = {data->session_id1, strlen(data->session_id1)}; + MDBX_val _session_id2_rec = {data->session_id2, strlen(data->session_id2)}; + MDBX_val _ip_rec = {data->ip, strlen(data->ip)}; + MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id1_rec, NULL)); + MDBX_CHECK(mdbx_del(txn, dbi_session_id, &_session_id2_rec, NULL)); + MDBX_CHECK(mdbx_del(txn, dbi_ip, &_ip_rec, NULL)); + event.obj_id = record_id; + event.event_type = 1; + MDBX_val _event_rec = {&event, sizeof(event)}; + MDBX_CHECK(mdbx_del(txn, dbi_event, &_event_rec, NULL)); + MDBX_CHECK(mdbx_del(txn, dbi_session, &_obj_id_rec, NULL)); + + mdbx_data_size -= (_data_rec.iov_len + _obj_id_rec.iov_len * 4); + mdbx_key_size -= (_obj_id_rec.iov_len + _session_id1_rec.iov_len + _session_id2_rec.iov_len + _ip_rec.iov_len + + _event_rec.iov_len); + + // transaction commit + MDBX_CHECK(mdbx_txn_commit(txn)); + mdbx_del_count++; + mdbx_del_time += (getClockUs() - start); +} + +static void db_disconnect() { + mdbx_env_close(env); + printf("Connection closed\n"); +} + +static void get_db_stat(const char *db, int64_t *ms_branch_pages, int64_t *ms_leaf_pages) { + MDBX_txn *txn; + MDBX_stat stat; + MDBX_dbi dbi; + + MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn)); + MDBX_CHECK(mdbx_dbi_open(txn, db, MDBX_CREATE, &dbi)); + MDBX_CHECK(mdbx_dbi_stat(txn, dbi, &stat, sizeof(stat))); + mdbx_txn_abort(txn); + printf("%15s | %15ld | %5u | %10ld | %10ld | %11ld |\n", + db, + stat.ms_branch_pages, + stat.ms_depth, + stat.ms_entries, + stat.ms_leaf_pages, + stat.ms_overflow_pages); + (*ms_branch_pages) += stat.ms_branch_pages; + (*ms_leaf_pages) += stat.ms_leaf_pages; +} + +static void periodic_stat(void) { + int64_t ms_branch_pages = 0; + int64_t ms_leaf_pages = 0; + MDBX_stat mst; + MDBX_envinfo mei; + MDBX_CHECK(mdbx_env_stat(env, &mst, sizeof(mst))); + MDBX_CHECK(mdbx_env_info(env, &mei, sizeof(mei))); + printf("Environment Info\n"); + printf(" Pagesize: %u\n", mst.ms_psize); + if (mei.mi_geo.lower != mei.mi_geo.upper) { + printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64 + "/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64 + "/-%" PRIu64 ")\n", + mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow, + mei.mi_geo.shrink, mei.mi_geo.lower / mst.ms_psize, + mei.mi_geo.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize, + mei.mi_geo.shrink / mst.ms_psize); + printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", + mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize); + } else { + printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", + mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize); + } + printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n", + mei.mi_mapsize, mei.mi_mapsize / mst.ms_psize); + printf(" Number of pages used: %" PRIu64 "\n", mei.mi_last_pgno + 1); + printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid); + printf(" Tail transaction ID: %" PRIu64 " (%" PRIi64 ")\n", + mei.mi_latter_reader_txnid, + mei.mi_latter_reader_txnid - mei.mi_recent_txnid); + printf(" Max readers: %u\n", mei.mi_maxreaders); + printf(" Number of readers used: %u\n", mei.mi_numreaders); + + printf(" Name | ms_branch_pages | depth | entries | leaf_pages | overf_pages |\n"); + get_db_stat("session", &ms_branch_pages, &ms_leaf_pages); + get_db_stat("session_id", &ms_branch_pages, &ms_leaf_pages); + get_db_stat("event", &ms_branch_pages, &ms_leaf_pages); + get_db_stat("ip", &ms_branch_pages, &ms_leaf_pages); + printf("%15s | %15ld | %5s | %10s | %10ld | %11s |\n", "", ms_branch_pages, "", "", ms_leaf_pages, ""); + + static int64_t prev_add_count; + static int64_t prev_del_count; + static uint64_t prev_add_time; + static uint64_t prev_del_time; + static int64_t t = -1; + if (t > 0) { + int64_t delta = (getClockUs() - t); + printf("CPS: add %ld, delete %ld, items processed - %ldK data=%ldK key=%ldK\n", + (mdbx_add_count - prev_add_count) * 1000000 / delta, (mdbx_del_count - prev_del_count) * 1000000 / delta, + obj_id / 1024, mdbx_data_size / 1024, mdbx_key_size / 1024); + printf("usage data=%ld%%", + ((mdbx_data_size + mdbx_key_size) * 100) / ((ms_leaf_pages + ms_branch_pages) * 4096)); + if (prev_add_time != mdbx_add_time) { + printf(" Add : %ld c/s", (mdbx_add_count - prev_add_count) * 1000000 / (mdbx_add_time - prev_add_time)); + } + if (prev_del_time != mdbx_del_time) { + printf(" Del : %ld c/s", (mdbx_del_count - prev_del_count) * 1000000 / (mdbx_del_time - prev_del_time)); + } + if (mdbx_add_time) { + printf(" tAdd : %ld c/s", mdbx_add_count * 1000000 / mdbx_add_time); + } + if (mdbx_del_time) { + printf(" tDel : %ld c/s", mdbx_del_count * 1000000 / mdbx_del_time); + } + puts(""); + } + t = getClockUs(); + prev_add_count = mdbx_add_count; + prev_del_count = mdbx_del_count; + prev_add_time = mdbx_add_time; + prev_del_time = mdbx_del_time; +} + +//static void periodic_add_rec() { +// for (int i = 0; i < 10240; i++) { +// if (ids_count <= REC_COUNT) { +// int64_t id = obj_id++; +// create_record(id); +// add_id_to_pool(id); +// } +// if (ids_count > REC_COUNT) { +// int64_t id = get_id_from_pool(); +// delete_record(id); +// } +// } +// periodic_stat(); +//} + +int main(int argc, char **argv) { + (void) argc; + (void) argv; + + char filename[PATH_MAX]; + int i; + + mkdir(opt_db_path, 0775); + + strcpy(filename, opt_db_path); + strcat(filename, "/mdbx.dat"); + remove(filename); + + strcpy(filename, opt_db_path); + strcat(filename, "/mdbx.lck"); + remove(filename); + + puts("Open DB..."); + db_connect(); + puts("Create data..."); + int64_t t = getClockUs(); + for (i = 0; i < REC_COUNT; i++) { + int64_t id = obj_id++; + create_record(id); + add_id_to_pool(id); + if (i%1000==0) { + int64_t now = getClockUs(); + if ((now - t) > 1000000L) { + periodic_stat(); + t = now; + } + } + } + periodic_stat(); + while (1) { + int i; + for (i = 0; i < 1000; i++) { + int64_t id = obj_id++; + create_record(id); + add_id_to_pool(id); + id = get_id_from_pool(); + delete_record(id); + } +// for (i = 0; i < 50; i++) { +// int64_t id = obj_id++; +// create_record(id); +// add_id_to_pool(id); +// } + //int64_t id = obj_id++; + //create_record(id); + //add_id_to_pool(id); + int64_t now = getClockUs(); + if ((now - t) > 10000000L) { + periodic_stat(); + t = now; + } + } + db_disconnect(); + return 0; +} From 4ed8eddf4276d1525a95031f754e4b54515bc703 Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Sun, 7 Jan 2018 15:10:06 +0300 Subject: [PATCH 5/5] Improve cmake support. Add rpm generation --- CMakeLists.txt | 94 ++++++++++++++++++++++++++++++++++++++-- package.sh | 25 +++++++++++ pcrf_test/CMakeLists.txt | 2 +- src/tools/CMakeLists.txt | 55 ++++++++--------------- test/CMakeLists.txt | 2 +- tutorial/CMakeLists.txt | 2 +- 6 files changed, 137 insertions(+), 43 deletions(-) create mode 100755 package.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3b4c22..ec64bd10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,17 @@ cmake_minimum_required(VERSION 2.8.7) -set(TARGET libmdbx) +set(TARGET mdbx) project(${TARGET}) +set(MDBX_VERSION_MAJOR 0) +set(MDBX_VERSION_MINOR 0) +set(MDBX_VERSION_PATCH 0) +set(MDBX_VERSION_STRING ${MDBX_VERSION_MAJOR}.${MDBX_VERSION_MINOR}.${MDBX_VERSION_PATCH}) + +add_definitions(-DMDBX_VERSION_MAJOR=${MDBX_VERSION_MAJOR}) +add_definitions(-DMDBX_VERSION_MINOR=${MDBX_VERSION_MINOR}) +add_definitions(-DMDBX_VERSION_PATCH=${MDBX_VERSION_PATCH}) + enable_language(C) enable_language(CXX) @@ -76,7 +85,7 @@ else () endif () endif () -add_library(${TARGET} STATIC +set(${TARGET}_SRC mdbx.h src/bits.h src/defs.h @@ -87,11 +96,90 @@ add_library(${TARGET} STATIC src/version.c ) -target_include_directories(${TARGET} PUBLIC +add_library(${TARGET}_STATIC STATIC + ${${TARGET}_SRC} + ) + +add_library(${TARGET} ALIAS ${TARGET}_STATIC) + +add_library(${TARGET}_SHARED SHARED + ${${TARGET}_SRC} + ) + +set_target_properties(${TARGET}_SHARED PROPERTIES + VERSION ${MDBX_VERSION_STRING} + SOVERSION ${MDBX_VERSION_MAJOR} + OUTPUT_NAME ${TARGET} + CLEAN_DIRECT_OUTPUT 1 + ) + +set_target_properties(${TARGET}_STATIC PROPERTIES + VERSION ${MDBX_VERSION_STRING} + SOVERSION ${MDBX_VERSION_MAJOR} + OUTPUT_NAME ${TARGET} + CLEAN_DIRECT_OUTPUT 1 + ) + +target_include_directories(${TARGET}_STATIC PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +target_include_directories(${TARGET}_SHARED PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +install(TARGETS ${TARGET}_STATIC DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx) +install(TARGETS ${TARGET}_SHARED DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64 COMPONENT mdbx) +install(FILES mdbx.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT mdbx-devel) + add_subdirectory(tutorial) add_subdirectory(test) add_subdirectory(src/tools) add_subdirectory(pcrf_test) + + +set(CPACK_GENERATOR "RPM") +set(CPACK_RPM_COMPONENT_INSTALL ON) + +#Version +if (NOT "$ENV{BUILD_NUMBER}" STREQUAL "") + set(CPACK_PACKAGE_RELEASE $ENV{BUILD_NUMBER}) +else () + if (NOT "$ENV{CI_PIPELINE_ID}" STREQUAL "") + set(CPACK_PACKAGE_RELEASE $ENV{CI_PIPELINE_ID}) + else () + set(CPACK_PACKAGE_RELEASE 1) + endif () +endif () +set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE}) + +set(CPACK_PACKAGE_VERSION ${MDBX_VERSION_STRING}) +set(CPACK_PACKAGE_VERSION_FULL ${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}) + +set(CPACK_RPM_mdbx-devel_PACKAGE_REQUIRES "mdbx = ${CPACK_PACKAGE_VERSION}") + +set(CPACK_RPM_SPEC_INSTALL_POST "/bin/true") +set(CPACK_RPM_mdbx_PACKAGE_NAME mdbx) +set(CPACK_RPM_mdbx-devel_PACKAGE_NAME mdbx-devel) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The revised and extended descendant of Symas LMDB") + +set(CPACK_PACKAGE_VENDOR "???") +set(CPACK_PACKAGE_CONTACT "Vladimir Romanov") +set(CPACK_PACKAGE_RELOCATABLE false) +set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") +set(CPACK_RPM_PACKAGE_REQUIRES "") +set(CPACK_RPM_PACKAGE_GROUP "Applications/Database") + +set(CPACK_RPM_mdbx_FILE_NAME "${CPACK_RPM_mdbx_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") +set(CPACK_RPM_mdbx-devel_FILE_NAME "${CPACK_RPM_mdbx-devel_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_FULL}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") + +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION + /usr/local + /usr/local/bin + /usr/local/lib64 + /usr/local/include + /usr/local/man + /usr/local/man/man1 + ) + +include(CPack) diff --git a/package.sh b/package.sh new file mode 100755 index 00000000..d7f9ab29 --- /dev/null +++ b/package.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +CONFIG=$1 + +if [[ -z "${CONFIG}" ]]; then + CONFIG=Debug +fi + +DIRNAME=`dirname ${BASH_SOURCE[0]}` +DIRNAME=`readlink --canonicalize ${DIRNAME}` + +if [[ -r /opt/rh/devtoolset-6/enable ]]; then + source /opt/rh/devtoolset-6/enable +fi + +mkdir -p cmake-build-${CONFIG} +pushd cmake-build-${CONFIG} &> /dev/null +if [[ ! -r Makefile ]]; then + cmake .. -DCMAKE_BUILD_TYPE=${CONFIG} +fi +rm -f *.rpm +make -j8 package || exit 1 +rm -f *-Unspecified.rpm +popd &> /dev/null diff --git a/pcrf_test/CMakeLists.txt b/pcrf_test/CMakeLists.txt index 4d39135e..784b4189 100644 --- a/pcrf_test/CMakeLists.txt +++ b/pcrf_test/CMakeLists.txt @@ -6,6 +6,6 @@ add_executable(${TARGET} ) target_link_libraries(${TARGET} - libmdbx + mdbx ) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index f9e8f89e..d24a3e80 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -1,42 +1,23 @@ project(mdbx_tools) -add_executable(mdbx_chk - mdbx_chk.c +set(MDBX_TOOLS + mdbx_chk + mdbx_copy + mdbx_dump + mdbx_load + mdbx_stat ) -target_link_libraries(mdbx_chk - libmdbx - ) +foreach (D_FILE ${MDBX_TOOLS}) + add_executable(${D_FILE} + ${D_FILE}.c + ) -add_executable(mdbx_copy - mdbx_copy.c - ) - -target_link_libraries(mdbx_copy - libmdbx - ) - -add_executable(mdbx_dump - mdbx_dump.c - ) - -target_link_libraries(mdbx_dump - libmdbx - ) - - -add_executable(mdbx_load - mdbx_load.c - ) - -target_link_libraries(mdbx_load - libmdbx - ) - -add_executable(mdbx_stat - mdbx_stat.c - ) - -target_link_libraries(mdbx_stat - libmdbx - ) + target_link_libraries(${D_FILE} + mdbx + ) + install(TARGETS ${D_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT mdbx) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${D_FILE}.1) + install(FILES ${D_FILE}.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 COMPONENT mdbx) + endif() +endforeach () diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index af20c333..3ed01bdd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,6 @@ add_executable(${TARGET} ) target_link_libraries(${TARGET} - libmdbx + mdbx ) diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index 3b466884..200d1671 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -6,6 +6,6 @@ add_executable(${TARGET} ) target_link_libraries(${TARGET} - libmdbx + mdbx )