Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf Level By Bit Field #230

Closed
wants to merge 9 commits into from
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4800 /wd4996 /wd4351 /wd4100 /wd4204 /wd4324")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing -w")
if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
add_definitions(-D_POSIX_C_SOURCE=1)
Expand Down Expand Up @@ -584,6 +584,7 @@ set(SOURCES
monitoring/instrumented_mutex.cc
monitoring/iostats_context.cc
monitoring/perf_context.cc
monitoring/perf_flags.cc
monitoring/perf_level.cc
monitoring/persistent_stats_history.cc
monitoring/statistics.cc
Expand Down
18 changes: 14 additions & 4 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include <unordered_set>
#include <map>

using rocksdb::PerfContext;
using rocksdb::PerfLevel;
using rocksdb::PerfFlags;
using rocksdb::BytewiseComparator;
using rocksdb::Cache;
using rocksdb::ColumnFamilyDescriptor;
Expand Down Expand Up @@ -113,8 +116,9 @@ using rocksdb::Transaction;
using rocksdb::Checkpoint;
using rocksdb::TransactionLogIterator;
using rocksdb::BatchResult;
using rocksdb::PerfLevel;
using rocksdb::PerfContext;
using rocksdb::WritableFile;
using rocksdb::WriteBatch;
using rocksdb::WriteBatchWithIndex;
using rocksdb::MemoryUtil;

using std::shared_ptr;
Expand Down Expand Up @@ -2740,7 +2744,7 @@ rocksdb_ratelimiter_t* rocksdb_writeampbasedratelimiter_create(
return rate_limiter;
}

void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t *limiter) {
void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t* limiter) {
delete limiter;
}

Expand All @@ -2749,8 +2753,14 @@ void rocksdb_set_perf_level(int v) {
SetPerfLevel(level);
}

void rocksdb_set_perf_flags_by_mask(uint8_t* flags_bytes) {
PerfFlags flags;
memmove(&flags,flags_bytes,sizeof(PerfFlags));
SetPerfFlags(flags);
}

rocksdb_perfcontext_t* rocksdb_perfcontext_create() {
rocksdb_perfcontext_t* context = new rocksdb_perfcontext_t;
auto* context = new rocksdb_perfcontext_t;
Comment on lines -2753 to +2763
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect whether this will cause issues in some build platforms.

context->rep = rocksdb::get_perf_context();
return context;
}
Expand Down
5 changes: 3 additions & 2 deletions db/compaction/compaction_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include <cinttypes>
#include "db/compaction/compaction_job.h"

#include <algorithm>
#include <cinttypes>
#include <functional>
#include <list>
#include <memory>
Expand All @@ -19,7 +21,6 @@
#include <vector>

#include "db/builder.h"
#include "db/compaction/compaction_job.h"
#include "db/db_impl/db_impl.h"
#include "db/db_iter.h"
#include "db/dbformat.h"
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include "db/error_handler.h"
#include "db/event_helpers.h"
#include "db/external_sst_file_ingestion_job.h"
#include "db/import_column_family_job.h"
#include "db/flush_job.h"
#include "db/forward_iterator.h"
#include "db/import_column_family_job.h"
#include "db/job_context.h"
#include "db/log_reader.h"
#include "db/log_writer.h"
Expand Down
3 changes: 1 addition & 2 deletions db/db_impl/db_impl_compaction_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "db/db_impl/db_impl.h"

#include <cinttypes>

#include "db/builder.h"
#include "db/db_impl/db_impl.h"
#include "db/error_handler.h"
#include "db/event_helpers.h"
#include "file/sst_file_manager_impl.h"
Expand Down
3 changes: 2 additions & 1 deletion db/db_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "db/db_iter.h"
#include <string>

#include <iostream>
#include <limits>
#include <string>

#include "db/dbformat.h"
#include "db/merge_context.h"
Expand Down
6 changes: 4 additions & 2 deletions db/db_iter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ TEST_F(DBIteratorTest, DBIteratorPrevNext) {
db_iter->SeekToLast();

ASSERT_TRUE(db_iter->Valid());
ASSERT_EQ(static_cast<int>(get_perf_context()->internal_key_skipped_count), 1);
ASSERT_EQ(static_cast<int>(get_perf_context()->internal_key_skipped_count),
1);
ASSERT_EQ(db_iter->key().ToString(), "b");

SetPerfLevel(kDisable);
Expand Down Expand Up @@ -543,7 +544,8 @@ TEST_F(DBIteratorTest, DBIteratorPrevNext) {
db_iter->SeekToLast();

ASSERT_TRUE(db_iter->Valid());
ASSERT_EQ(static_cast<int>(get_perf_context()->internal_delete_skipped_count), 0);
ASSERT_EQ(
static_cast<int>(get_perf_context()->internal_delete_skipped_count), 0);
ASSERT_EQ(db_iter->key().ToString(), "b");

SetPerfLevel(kDisable);
Expand Down
4 changes: 3 additions & 1 deletion db/dbformat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "db/dbformat.h"

#include <cinttypes>
#include <stdio.h>

#include <cinttypes>

#include "monitoring/perf_context_imp.h"
#include "port/port.h"
#include "util/coding.h"
Expand Down
2 changes: 2 additions & 0 deletions db/dbformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

#pragma once
#include <stdio.h>

#include <memory>
#include <string>
#include <utility>

#include "db/lookup_key.h"
#include "db/merge_context.h"
#include "logging/logging.h"
Expand Down
3 changes: 1 addition & 2 deletions db/flush_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

#include "db/flush_job.h"

#include <cinttypes>

#include <algorithm>
#include <cinttypes>
#include <vector>

#include "db/builder.h"
Expand Down
3 changes: 2 additions & 1 deletion db/perf_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
//
#include "rocksdb/perf_context.h"

#include <algorithm>
#include <iostream>
#include <thread>
Expand All @@ -15,7 +17,6 @@
#include "port/port.h"
#include "rocksdb/db.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/perf_context.h"
#include "rocksdb/slice_transform.h"
#include "test_util/testharness.h"
#include "util/stop_watch.h"
Expand Down
1 change: 0 additions & 1 deletion db/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "db/snapshot_impl.h"
#include "db/version_edit.h"
#include "file/filename.h"

#include "monitoring/perf_context_imp.h"
#include "rocksdb/statistics.h"
#include "table/block_based/block_based_table_reader.h"
Expand Down
2 changes: 2 additions & 0 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "db/version_set.h"

#include <stdio.h>

#include <algorithm>
#include <array>
#include <cinttypes>
Expand All @@ -19,6 +20,7 @@
#include <string>
#include <unordered_map>
#include <vector>

#include "compaction/compaction.h"
#include "db/internal_stats.h"
#include "db/log_reader.h"
Expand Down
1 change: 1 addition & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ enum {
};

extern ROCKSDB_LIBRARY_API void rocksdb_set_perf_level(int);
extern ROCKSDB_LIBRARY_API void rocksdb_set_perf_flags_by_mask(uint8_t* flags_bytes);
extern ROCKSDB_LIBRARY_API rocksdb_perfcontext_t* rocksdb_perfcontext_create();
extern ROCKSDB_LIBRARY_API void rocksdb_perfcontext_reset(
rocksdb_perfcontext_t* context);
Expand Down
3 changes: 2 additions & 1 deletion include/rocksdb/perf_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#pragma once

#include <stdint.h>

#include <map>
#include <string>

#include "rocksdb/perf_flags.h"
#include "rocksdb/perf_level.h"

namespace rocksdb {

// A thread local context for gathering performance counter efficiently
Expand Down
110 changes: 110 additions & 0 deletions include/rocksdb/perf_flags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once
#include <stdint.h>

namespace rocksdb {
struct PerfFlags {
// represent original Level 2
// TODO: think a better design for context_by_level structure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo?

uint8_t enable_perf_context_by_level_count_bit : 1; // 2
uint8_t enable_user_key_comparison_count_bit : 1; // 2
LemonHX marked this conversation as resolved.
Show resolved Hide resolved
uint8_t enable_block_cache_hit_count_bit : 1; // 2
uint8_t enable_block_read_count_bit : 1; // 2
uint8_t enable_block_read_byte_bit : 1; // 2
uint8_t enable_block_cache_index_hit_count_bit : 1; // 2
uint8_t enable_index_block_read_count_bit : 1; // 2
uint8_t enable_block_cache_filter_hit_count_bit : 1; // 2
uint8_t enable_filter_block_read_count_bit : 1; // 2
uint8_t enable_compression_dict_block_read_count_bit : 1; // 2
uint8_t enable_get_read_bytes_bit : 1; // 2
uint8_t enable_multiget_read_bytes_bit : 1; // 2
uint8_t enable_iter_read_bytes_bit : 1; // 2
uint8_t enable_internal_key_skipped_count_bit : 1; // 2
uint8_t enable_internal_delete_skipped_count_bit : 1; // 2
uint8_t enable_internal_recent_skipped_count_bit : 1; // 2
uint8_t enable_internal_merge_count_bit : 1; // 2
uint8_t enable_get_from_memtable_count_bit : 1; // 2
uint8_t enable_seek_on_memtable_count_bit : 1; // 2
uint8_t enable_next_on_memtable_count_bit : 1; // 2
uint8_t enable_prev_on_memtable_count_bit : 1; // 2
uint8_t enable_seek_child_seek_count_bit : 1; // 2
uint8_t enable_bloom_memtable_hit_count_bit : 1; // 2
uint8_t enable_bloom_memtable_miss_count_bit : 1; // 2
uint8_t enable_bloom_sst_hit_count_bit : 1; // 2
uint8_t enable_bloom_sst_miss_count_bit : 1; // 2
uint8_t enable_key_lock_wait_count_bit : 1; // 2

// represent original Level 3
uint8_t enable_measure_cpu_time_bit : 1; // 3
uint8_t enable_block_read_time_bit : 1; // 3
uint8_t enable_block_checksum_time_bit : 1; // 3
uint8_t enable_block_decompress_time_bit : 1; // 3
uint8_t enable_get_snapshot_time_bit : 1; // 3
uint8_t enable_get_from_memtable_time_bit : 1; // 3
uint8_t enable_get_post_process_time_bit : 1; // 3
uint8_t enable_get_from_output_files_time_bit : 1; // 3
uint8_t enable_seek_on_memtable_time_bit : 1; // 3
uint8_t enable_seek_child_seek_time_bit : 1; // 3
uint8_t enable_seek_min_heap_time_bit : 1; // 3
uint8_t enable_seek_max_heap_time_bit : 1; // 3
uint8_t enable_seek_internal_seek_time_bit : 1; // 3
uint8_t enable_find_next_user_entry_time_bit : 1; // 3
uint8_t enable_write_wal_time_bit : 1; // 3
uint8_t enable_write_memtable_time_bit : 1; // 3
uint8_t enable_write_delay_time_bit : 1; // 3
uint8_t enable_write_scheduling_flushes_compactions_time_bit : 1; // 3
uint8_t enable_write_pre_and_post_process_time_bit : 1; // 3
uint8_t enable_write_thread_wait_nanos_bit : 1; // 3
uint8_t enable_merge_operator_time_nanos_bit : 1; // 3
uint8_t enable_read_index_block_nanos_bit : 1; // 3
uint8_t enable_read_filter_block_nanos_bit : 1; // 3
uint8_t enable_new_table_block_iter_nanos_bit : 1; // 3
uint8_t enable_new_table_iterator_nanos_bit : 1; // 3
uint8_t enable_block_seek_nanos_bit : 1; // 3
uint8_t enable_find_table_nanos_bit : 1; // 3
uint8_t enable_key_lock_wait_time_bit : 1; // 3
uint8_t enable_env_new_sequential_file_nanos_bit : 1; // 3
uint8_t enable_env_new_random_access_file_nanos_bit : 1; // 3
uint8_t enable_env_new_writable_file_nanos_bit : 1; // 3
uint8_t enable_env_reuse_writable_file_nanos_bit : 1; // 3
uint8_t enable_env_new_random_rw_file_nanos_bit : 1; // 3
uint8_t enable_env_new_directory_nanos_bit : 1; // 3
uint8_t enable_env_file_exists_nanos_bit : 1; // 3
uint8_t enable_env_get_children_nanos_bit : 1; // 3
uint8_t enable_env_get_children_file_attributes_nanos_bit : 1; // 3
uint8_t enable_env_delete_file_nanos_bit : 1; // 3
uint8_t enable_env_create_dir_nanos_bit : 1; // 3
uint8_t enable_env_create_dir_if_missing_nanos_bit : 1; // 3
uint8_t enable_env_delete_dir_nanos_bit : 1; // 3
uint8_t enable_env_get_file_size_nanos_bit : 1; // 3
uint8_t enable_env_get_file_modification_time_nanos_bit : 1; // 3
uint8_t enable_env_rename_file_nanos_bit : 1; // 3
uint8_t enable_env_link_file_nanos_bit : 1; // 3
uint8_t enable_env_lock_file_nanos_bit : 1; // 3
uint8_t enable_env_unlock_file_nanos_bit : 1; // 3
uint8_t enable_env_new_logger_nanos_bit : 1; // 3
uint8_t enable_encrypt_data_nanos_bit : 1; // 3
uint8_t enable_decrypt_data_nanos_bit : 1; // 3

// represent original Level 4
// TODO: think a better design for iostats
uint8_t enable_iostats_cpu_timer_bit : 1; // 4
uint8_t enable_get_cpu_nanos_bit : 1; // 4
uint8_t enable_iter_next_cpu_nanos_bit : 1; // 4
uint8_t enable_iter_prev_cpu_nanos_bit : 1; // 4
uint8_t enable_iter_seek_cpu_nanos_bit : 1; // 4

// represent original Level 5
uint8_t enable_db_mutex_lock_nanos_bit : 1; // 5
uint8_t enable_db_condition_wait_nanos_bit : 1; // 5
};
extern const PerfFlags PERF_LEVEL2;
extern const PerfFlags PERF_LEVEL3;
extern const PerfFlags PERF_LEVEL4;
extern const PerfFlags PERF_LEVEL5;
// set the perf flags for current thread
void SetPerfFlags(PerfFlags pbf);

// get current perf flags for current thread
PerfFlags GetPerfFlags();

} // namespace rocksdb
5 changes: 3 additions & 2 deletions include/rocksdb/perf_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ enum PerfLevel : unsigned char {
// time (neither wall time nor CPU time) for mutexes.
kEnableTimeAndCPUTimeExceptForMutex = 4,
kEnableTime = 5, // enable count and time stats
kOutOfBounds = 6 // N.B. Must always be the last value!
kCustomFlags = 6, // could not measured by level because is a custom bit flags configuration
kOutOfBounds = 7, // N.B. Must always be the last value!
};

// set the perf stats level for current thread
void SetPerfLevel(PerfLevel level);

// get current perf stats level for current thread
// get current estimated perf stats level for current thread
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer estimated?

PerfLevel GetPerfLevel();

} // namespace rocksdb
6 changes: 3 additions & 3 deletions monitoring/iostats_context_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory).
//
#pragma once
#include "monitoring/perf_flags_imp.h"
#include "monitoring/perf_step_timer.h"
#include "rocksdb/iostats_context.h"

Expand Down Expand Up @@ -34,14 +35,13 @@ extern __thread IOStatsContext iostats_context;

// Declare and set start time of the timer
#define IOSTATS_TIMER_GUARD(metric) \
PerfStepTimer iostats_step_timer_##metric(&(iostats_context.metric)); \
PerfStepTimer iostats_step_timer_##metric(&(iostats_context.metric),(bool)perf_flags.enable_iostats_cpu_timer_bit); \
iostats_step_timer_##metric.Start();

// Declare and set start time of the timer
#define IOSTATS_CPU_TIMER_GUARD(metric, env) \
PerfStepTimer iostats_step_timer_##metric( \
&(iostats_context.metric), env, true, \
PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \
&(iostats_context.metric),(bool)perf_flags.enable_iostats_cpu_timer_bit, env, true); \
iostats_step_timer_##metric.Start();

#else // ROCKSDB_SUPPORT_THREAD_LOCAL
Expand Down
Loading