Skip to content

Commit

Permalink
Statistics support in C API, additional improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
amatveev-cf committed Jul 28, 2023
1 parent ee915d5 commit d68bc6f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
41 changes: 17 additions & 24 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,7 @@ struct rocksdb_compactionfiltercontext_t {
CompactionFilter::Context rep;
};

struct rocksdb_statistics_histogram_data_t {
rocksdb_statistics_histogram_data_t() : rep() {}

HistogramData rep;
};
struct rocksdb_statistics_histogram_data_t : public HistogramData {};

struct rocksdb_compactionfilter_t : public CompactionFilter {
void* state_;
Expand Down Expand Up @@ -3893,20 +3889,20 @@ char* rocksdb_options_statistics_get_string(rocksdb_options_t* opt) {
}

uint64_t rocksdb_options_statistics_get_ticker_count(rocksdb_options_t* opt,
uint32_t type) {
uint32_t ticker_type) {
ROCKSDB_NAMESPACE::Statistics* statistics = opt->rep.statistics.get();
if (statistics) {
return statistics->getTickerCount(type);
return statistics->getTickerCount(ticker_type);
}
return 0;
}

void rocksdb_options_statistics_get_histogram_data(
rocksdb_options_t* opt, uint32_t type,
rocksdb_statistics_histogram_data_t* data) {
rocksdb_statistics_histogram_data_t* const data) {
ROCKSDB_NAMESPACE::Statistics* statistics = opt->rep.statistics.get();
if (statistics) {
statistics->histogramData(type, &data->rep);
statistics->histogramData(type, data);
} else {
*data = rocksdb_statistics_histogram_data_t{};
}
Expand Down Expand Up @@ -5674,8 +5670,7 @@ int rocksdb_transactiondb_property_int(rocksdb_transactiondb_t* db,
}
}

rocksdb_t* rocksdb_transactiondb_get_base_db(
rocksdb_transactiondb_t* txn_db) {
rocksdb_t* rocksdb_transactiondb_get_base_db(rocksdb_transactiondb_t* txn_db) {
DB* base_db = txn_db->rep->GetBaseDB();

if (base_db != nullptr) {
Expand All @@ -5687,9 +5682,7 @@ rocksdb_t* rocksdb_transactiondb_get_base_db(
return nullptr;
}

void rocksdb_transactiondb_close_base_db(rocksdb_t* base_db) {
delete base_db;
}
void rocksdb_transactiondb_close_base_db(rocksdb_t* base_db) { delete base_db; }

rocksdb_transaction_t* rocksdb_transaction_begin(
rocksdb_transactiondb_t* txn_db,
Expand Down Expand Up @@ -6670,7 +6663,7 @@ void rocksdb_enable_manual_compaction(rocksdb_t* db) {

rocksdb_statistics_histogram_data_t*
rocksdb_statistics_histogram_data_create() {
return new rocksdb_statistics_histogram_data_t;
return new rocksdb_statistics_histogram_data_t{};
}

void rocksdb_statistics_histogram_data_destroy(
Expand All @@ -6680,47 +6673,47 @@ void rocksdb_statistics_histogram_data_destroy(

double rocksdb_statistics_histogram_data_get_median(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.median;
return data->median;
}

double rocksdb_statistics_histogram_data_get_p95(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.percentile95;
return data->percentile95;
}

double rocksdb_statistics_histogram_data_get_p99(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.percentile99;
return data->percentile99;
}

double rocksdb_statistics_histogram_data_get_average(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.average;
return data->average;
}

double rocksdb_statistics_histogram_data_get_std_dev(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.standard_deviation;
return data->standard_deviation;
}

double rocksdb_statistics_histogram_data_get_max(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.max;
return data->max;
}

uint64_t rocksdb_statistics_histogram_data_get_count(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.count;
return data->count;
}

uint64_t rocksdb_statistics_histogram_data_get_sum(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.sum;
return data->sum;
}

double rocksdb_statistics_histogram_data_get_min(
rocksdb_statistics_histogram_data_t* data) {
return data->rep.min;
return data->min;
}

} // end extern "C"
14 changes: 11 additions & 3 deletions db/c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3128,12 +3128,12 @@ int main(int argc, char** argv) {
CheckTxnDBGetCF(txn_db, roptions, cfh, "cf_foo", NULL);
CheckTxnDBPinGetCF(txn_db, roptions, cfh, "cf_foo", NULL);


//memory usage
// memory usage
rocksdb_t* base_db = rocksdb_transactiondb_get_base_db(txn_db);
rocksdb_memory_consumers_t* consumers = rocksdb_memory_consumers_create();
rocksdb_memory_consumers_add_db(consumers, base_db);
rocksdb_memory_usage_t* usage = rocksdb_approximate_memory_usage_create(consumers, &err);
rocksdb_memory_usage_t* usage =
rocksdb_approximate_memory_usage_create(consumers, &err);
CheckNoError(err);
rocksdb_approximate_memory_usage_destroy(usage);
rocksdb_memory_consumers_destroy(consumers);
Expand Down Expand Up @@ -3666,7 +3666,15 @@ int main(int argc, char** argv) {
CheckCondition(0 != rocksdb_options_statistics_get_ticker_count(
options, BYTES_WRITTEN_TICKER));
rocksdb_options_statistics_get_histogram_data(options, DB_WRITE_HIST, hist);
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_median(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_p95(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_p99(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_average(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_std_dev(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_max(hist));
CheckCondition(0 != rocksdb_statistics_histogram_data_get_count(hist));
CheckCondition(0 != rocksdb_statistics_histogram_data_get_sum(hist));
CheckCondition(0.0 != rocksdb_statistics_histogram_data_get_min(hist));

rocksdb_statistics_histogram_data_destroy(hist);
}
Expand Down
14 changes: 7 additions & 7 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1256,14 +1256,14 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_statistics(
rocksdb_options_t*);

enum {
rocksdb_statistics_level_disable_all,
rocksdb_statistics_level_disable_all = 0,
rocksdb_statistics_level_except_tickers =
rocksdb_statistics_level_disable_all,
rocksdb_statistics_level_except_histogram_or_timers,
rocksdb_statistics_level_except_timers,
rocksdb_statistics_level_except_detailed_timers,
rocksdb_statistics_level_except_time_for_mutex,
rocksdb_statistics_level_all,
rocksdb_statistics_level_except_histogram_or_timers = 1,
rocksdb_statistics_level_except_timers = 2,
rocksdb_statistics_level_except_detailed_timers = 3,
rocksdb_statistics_level_except_time_for_mutex = 4,
rocksdb_statistics_level_all = 5,
};

extern ROCKSDB_LIBRARY_API void rocksdb_options_set_statistics_level(
Expand Down Expand Up @@ -1350,7 +1350,7 @@ extern ROCKSDB_LIBRARY_API uint64_t rocksdb_options_statistics_get_ticker_count(
rocksdb_options_t* opt, uint32_t ticker_type);
extern ROCKSDB_LIBRARY_API void rocksdb_options_statistics_get_histogram_data(
rocksdb_options_t* opt, uint32_t histogram_type,
rocksdb_statistics_histogram_data_t* data);
rocksdb_statistics_histogram_data_t* const data);

extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_write_buffer_number(
rocksdb_options_t*, int);
Expand Down

0 comments on commit d68bc6f

Please sign in to comment.