@ -24,6 +24,7 @@ int FLAGS_total_keys = 100;
int FLAGS_write_buffer_size = 1000000000 ;
int FLAGS_write_buffer_size = 1000000000 ;
int FLAGS_max_write_buffer_number = 8 ;
int FLAGS_max_write_buffer_number = 8 ;
int FLAGS_min_write_buffer_number_to_merge = 7 ;
int FLAGS_min_write_buffer_number_to_merge = 7 ;
bool FLAGS_verbose = false ;
// Path to the database on file system
// Path to the database on file system
const std : : string kDbName = rocksdb : : test : : TmpDir ( ) + " /perf_context_test " ;
const std : : string kDbName = rocksdb : : test : : TmpDir ( ) + " /perf_context_test " ;
@ -43,9 +44,6 @@ std::shared_ptr<DB> OpenDb(bool read_only = false) {
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
options . prefix_extractor . reset ( rocksdb : : NewFixedPrefixTransform ( 0 ) ) ;
options . prefix_extractor . reset ( rocksdb : : NewFixedPrefixTransform ( 0 ) ) ;
options . memtable_factory . reset ( NewHashSkipListRepFactory ( ) ) ;
options . memtable_factory . reset ( NewHashSkipListRepFactory ( ) ) ;
# else
fprintf ( stderr , " Prefix hash is not supported in lite mode \n " ) ;
exit ( 1 ) ;
# endif // ROCKSDB_LITE
# endif // ROCKSDB_LITE
}
}
@ -95,8 +93,10 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
hist_get_time . Add ( elapsed_nanos ) ;
hist_get_time . Add ( elapsed_nanos ) ;
}
}
if ( FLAGS_verbose ) {
std : : cout < < " Get user key comparison: \n " < < hist_get . ToString ( )
std : : cout < < " Get user key comparison: \n " < < hist_get . ToString ( )
< < " Get time: \n " < < hist_get_time . ToString ( ) ;
< < " Get time: \n " < < hist_get_time . ToString ( ) ;
}
{
{
HistogramImpl hist_seek_to_first ;
HistogramImpl hist_seek_to_first ;
@ -108,6 +108,7 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
hist_seek_to_first . Add ( perf_context . user_key_comparison_count ) ;
hist_seek_to_first . Add ( perf_context . user_key_comparison_count ) ;
auto elapsed_nanos = timer . ElapsedNanos ( ) ;
auto elapsed_nanos = timer . ElapsedNanos ( ) ;
if ( FLAGS_verbose ) {
std : : cout < < " SeekToFirst uesr key comparison: \n "
std : : cout < < " SeekToFirst uesr key comparison: \n "
< < hist_seek_to_first . ToString ( )
< < hist_seek_to_first . ToString ( )
< < " ikey skipped: " < < perf_context . internal_key_skipped_count
< < " ikey skipped: " < < perf_context . internal_key_skipped_count
@ -116,6 +117,7 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
< < perf_context . internal_delete_skipped_count < < " \n "
< < perf_context . internal_delete_skipped_count < < " \n "
< < " elapsed: " < < elapsed_nanos < < " \n " ;
< < " elapsed: " < < elapsed_nanos < < " \n " ;
}
}
}
HistogramImpl hist_seek ;
HistogramImpl hist_seek ;
for ( int i = 0 ; i < FLAGS_total_keys ; + + i ) {
for ( int i = 0 ; i < FLAGS_total_keys ; + + i ) {
@ -127,22 +129,29 @@ TEST_F(PerfContextTest, SeekIntoDeletion) {
iter - > Seek ( key ) ;
iter - > Seek ( key ) ;
auto elapsed_nanos = timer . ElapsedNanos ( ) ;
auto elapsed_nanos = timer . ElapsedNanos ( ) ;
hist_seek . Add ( perf_context . user_key_comparison_count ) ;
hist_seek . Add ( perf_context . user_key_comparison_count ) ;
if ( FLAGS_verbose ) {
std : : cout < < " seek cmp: " < < perf_context . user_key_comparison_count
std : : cout < < " seek cmp: " < < perf_context . user_key_comparison_count
< < " ikey skipped " < < perf_context . internal_key_skipped_count
< < " ikey skipped " < < perf_context . internal_key_skipped_count
< < " idelete skipped " < < perf_context . internal_delete_skipped_count
< < " idelete skipped "
< < perf_context . internal_delete_skipped_count
< < " elapsed: " < < elapsed_nanos < < " ns \n " ;
< < " elapsed: " < < elapsed_nanos < < " ns \n " ;
}
perf_context . Reset ( ) ;
perf_context . Reset ( ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
StopWatchNano timer2 ( Env : : Default ( ) , true ) ;
StopWatchNano timer2 ( Env : : Default ( ) , true ) ;
iter - > Next ( ) ;
iter - > Next ( ) ;
auto elapsed_nanos2 = timer2 . ElapsedNanos ( ) ;
auto elapsed_nanos2 = timer2 . ElapsedNanos ( ) ;
if ( FLAGS_verbose ) {
std : : cout < < " next cmp: " < < perf_context . user_key_comparison_count
std : : cout < < " next cmp: " < < perf_context . user_key_comparison_count
< < " elapsed: " < < elapsed_nanos2 < < " ns \n " ;
< < " elapsed: " < < elapsed_nanos2 < < " ns \n " ;
}
}
}
if ( FLAGS_verbose ) {
std : : cout < < " Seek uesr key comparison: \n " < < hist_seek . ToString ( ) ;
std : : cout < < " Seek uesr key comparison: \n " < < hist_seek . ToString ( ) ;
}
}
}
TEST_F ( PerfContextTest , StopWatchNanoOverhead ) {
TEST_F ( PerfContextTest , StopWatchNanoOverhead ) {
// profile the timer cost by itself!
// profile the timer cost by itself!
@ -159,8 +168,10 @@ TEST_F(PerfContextTest, StopWatchNanoOverhead) {
histogram . Add ( timing ) ;
histogram . Add ( timing ) ;
}
}
if ( FLAGS_verbose ) {
std : : cout < < histogram . ToString ( ) ;
std : : cout < < histogram . ToString ( ) ;
}
}
}
TEST_F ( PerfContextTest , StopWatchOverhead ) {
TEST_F ( PerfContextTest , StopWatchOverhead ) {
// profile the timer cost by itself!
// profile the timer cost by itself!
@ -180,8 +191,10 @@ TEST_F(PerfContextTest, StopWatchOverhead) {
prev_timing = timing ;
prev_timing = timing ;
}
}
if ( FLAGS_verbose ) {
std : : cout < < histogram . ToString ( ) ;
std : : cout < < histogram . ToString ( ) ;
}
}
}
void ProfileQueries ( bool enabled_time = false ) {
void ProfileQueries ( bool enabled_time = false ) {
DestroyDB ( kDbName , Options ( ) ) ; // Start this test with a fresh DB
DestroyDB ( kDbName , Options ( ) ) ; // Start this test with a fresh DB
@ -213,7 +226,9 @@ void ProfileQueries(bool enabled_time = false) {
uint64_t total_db_mutex_nanos = 0 ;
uint64_t total_db_mutex_nanos = 0 ;
if ( FLAGS_verbose ) {
std : : cout < < " Inserting " < < FLAGS_total_keys < < " key/value pairs \n ... \n " ;
std : : cout < < " Inserting " < < FLAGS_total_keys < < " key/value pairs \n ... \n " ;
}
std : : vector < int > keys ;
std : : vector < int > keys ;
const int kFlushFlag = - 1 ;
const int kFlushFlag = - 1 ;
@ -287,18 +302,19 @@ void ProfileQueries(bool enabled_time = false) {
hist_mget . Add ( perf_context . user_key_comparison_count ) ;
hist_mget . Add ( perf_context . user_key_comparison_count ) ;
}
}
if ( FLAGS_verbose ) {
std : : cout < < " Put uesr key comparison: \n " < < hist_put . ToString ( )
std : : cout < < " Put uesr key comparison: \n " < < hist_put . ToString ( )
< < " Get uesr key comparison: \n " < < hist_get . ToString ( )
< < " Get uesr key comparison: \n " < < hist_get . ToString ( )
< < " MultiGet uesr key comparison: \n " < < hist_get . ToString ( ) ;
< < " MultiGet uesr key comparison: \n " < < hist_get . ToString ( ) ;
std : : cout < < " Put(): Pre and Post Process Time: \n "
std : : cout < < " Put(): Pre and Post Process Time: \n "
< < hist_write_pre_post . ToString ( )
< < hist_write_pre_post . ToString ( ) < < " Writing WAL time: \n "
< < " Writing WAL time: \n "
< < hist_write_wal_time . ToString ( ) < < " \n "
< < hist_write_wal_time . ToString ( ) < < " \n "
< < " Writing Mem Table time: \n "
< < " Writing Mem Table time: \n "
< < hist_write_memtable_time . ToString ( ) < < " \n "
< < hist_write_memtable_time . ToString ( ) < < " \n "
< < " Total DB mutex nanos: \n " < < total_db_mutex_nanos < < " \n " ;
< < " Total DB mutex nanos: \n " < < total_db_mutex_nanos < < " \n " ;
std : : cout < < " Get(): Time to get snapshot: \n " < < hist_get_snapshot . ToString ( )
std : : cout < < " Get(): Time to get snapshot: \n "
< < hist_get_snapshot . ToString ( )
< < " Time to get value from memtables: \n "
< < " Time to get value from memtables: \n "
< < hist_get_memtable . ToString ( ) < < " \n "
< < hist_get_memtable . ToString ( ) < < " \n "
< < " Time to get value from output files: \n "
< < " Time to get value from output files: \n "
@ -316,8 +332,9 @@ void ProfileQueries(bool enabled_time = false) {
< < hist_mget_files . ToString ( ) < < " \n "
< < hist_mget_files . ToString ( ) < < " \n "
< < " Number of memtables checked: \n "
< < " Number of memtables checked: \n "
< < hist_mget_num_memtable_checked . ToString ( ) < < " \n "
< < hist_mget_num_memtable_checked . ToString ( ) < < " \n "
< < " Time to post process: \n " < < hist_mget_post_process . ToString ( )
< < " Time to post process: \n "
< < " \n " ;
< < hist_mget_post_process . ToString ( ) < < " \n " ;
}
if ( enabled_time ) {
if ( enabled_time ) {
ASSERT_GT ( hist_get . Average ( ) , 0 ) ;
ASSERT_GT ( hist_get . Average ( ) , 0 ) ;
@ -381,6 +398,7 @@ void ProfileQueries(bool enabled_time = false) {
hist_mget . Add ( perf_context . user_key_comparison_count ) ;
hist_mget . Add ( perf_context . user_key_comparison_count ) ;
}
}
if ( FLAGS_verbose ) {
std : : cout < < " ReadOnly Get uesr key comparison: \n " < < hist_get . ToString ( )
std : : cout < < " ReadOnly Get uesr key comparison: \n " < < hist_get . ToString ( )
< < " ReadOnly MultiGet uesr key comparison: \n "
< < " ReadOnly MultiGet uesr key comparison: \n "
< < hist_mget . ToString ( ) ;
< < hist_mget . ToString ( ) ;
@ -404,8 +422,9 @@ void ProfileQueries(bool enabled_time = false) {
< < hist_mget_files . ToString ( ) < < " \n "
< < hist_mget_files . ToString ( ) < < " \n "
< < " Number of memtables checked: \n "
< < " Number of memtables checked: \n "
< < hist_mget_num_memtable_checked . ToString ( ) < < " \n "
< < hist_mget_num_memtable_checked . ToString ( ) < < " \n "
< < " Time to post process: \n " < < hist_mget_post_process . ToString ( )
< < " Time to post process: \n "
< < " \n " ;
< < hist_mget_post_process . ToString ( ) < < " \n " ;
}
if ( enabled_time ) {
if ( enabled_time ) {
ASSERT_GT ( hist_get . Average ( ) , 0 ) ;
ASSERT_GT ( hist_get . Average ( ) , 0 ) ;
@ -454,7 +473,9 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
WriteOptions write_options ;
WriteOptions write_options ;
ReadOptions read_options ;
ReadOptions read_options ;
if ( FLAGS_verbose ) {
std : : cout < < " Inserting " < < FLAGS_total_keys < < " key/value pairs \n ... \n " ;
std : : cout < < " Inserting " < < FLAGS_total_keys < < " key/value pairs \n ... \n " ;
}
std : : vector < int > keys ;
std : : vector < int > keys ;
for ( int i = 0 ; i < FLAGS_total_keys ; + + i ) {
for ( int i = 0 ; i < FLAGS_total_keys ; + + i ) {
@ -484,9 +505,11 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
hist_time_diff . Add ( put_time - perf_context . write_wal_time ) ;
hist_time_diff . Add ( put_time - perf_context . write_wal_time ) ;
}
}
std : : cout < < " Put time: \n " < < hist_put_time . ToString ( )
if ( FLAGS_verbose ) {
< < " WAL time: \n " < < hist_wal_time . ToString ( )
std : : cout < < " Put time: \n " < < hist_put_time . ToString ( ) < < " WAL time: \n "
< < " time diff: \n " < < hist_time_diff . ToString ( ) ;
< < hist_wal_time . ToString ( ) < < " time diff: \n "
< < hist_time_diff . ToString ( ) ;
}
HistogramImpl hist_seek ;
HistogramImpl hist_seek ;
HistogramImpl hist_next ;
HistogramImpl hist_next ;
@ -510,8 +533,10 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
hist_next . Add ( perf_context . user_key_comparison_count ) ;
hist_next . Add ( perf_context . user_key_comparison_count ) ;
}
}
std : : cout < < " Seek: \n " < < hist_seek . ToString ( )
if ( FLAGS_verbose ) {
< < " Next: \n " < < hist_next . ToString ( ) ;
std : : cout < < " Seek: \n " < < hist_seek . ToString ( ) < < " Next: \n "
< < hist_next . ToString ( ) ;
}
}
}
}
}
@ -541,9 +566,15 @@ int main(int argc, char** argv) {
FLAGS_use_set_based_memetable = n ;
FLAGS_use_set_based_memetable = n ;
}
}
if ( sscanf ( argv [ i ] , " --verbose=%d%c " , & n , & junk ) = = 1 & &
( n = = 0 | | n = = 1 ) ) {
FLAGS_verbose = n ;
}
}
}
if ( FLAGS_verbose ) {
std : : cout < < kDbName < < " \n " ;
std : : cout < < kDbName < < " \n " ;
}
return RUN_ALL_TESTS ( ) ;
return RUN_ALL_TESTS ( ) ;
}
}