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
Closed

Perf Level By Bit Field #230

wants to merge 9 commits into from

Conversation

LemonHX
Copy link

@LemonHX LemonHX commented Mar 15, 2021

Created Structure PerfLevelByBitField and using that structure to control the perf level tracing instead of PerfLevel, which allows us to more accurately control the behavior recorded by perf level.

And redirect set perf level to that for compatibility reason.

related issue No.543 in rust-rocksdb

…hods to perf_bit_field, also adding three default value for compatibility.
include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
monitoring/perf_context_imp.h Outdated Show resolved Hide resolved
} \
} \
// TODO: 添加一个flag count
#define PERF_COUNTER_BY_LEVEL_ADD(metric, value, level) \
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to change this part?

monitoring/perf_level.cc Outdated Show resolved Hide resolved
monitoring/perf_level_by_bitfield.cc Outdated Show resolved Hide resolved
monitoring/perf_level_by_bitfield.cc Outdated Show resolved Hide resolved
#define PERF_TIMER_STOP(metric)
#define PERF_TIMER_START(metric)
#define PERF_TIMER_GUARD(metric)
#define PERF_TIMER_GUARD_WITH_ENV(metric, env)
Copy link
Member

Choose a reason for hiding this comment

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

It's interesting that the original one does not have this definition.. Is it a mistake in RocksDB?

include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
include/rocksdb/perf_level_by_bitfield.h Outdated Show resolved Hide resolved
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

Please figure out a way to resolve this correctness problem.

monitoring/perf_flags.cc Outdated Show resolved Hide resolved
uint8_t enable_key_lock_wait_count_bit : 1; // 2

// flag enable for using cpu time prob useless in TiKV port
uint8_t enable_measure_cpu_time_bit : 1; // 3 -> with CPU time flag
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this bit?

include/rocksdb/perf_flags.h Show resolved Hide resolved
include/rocksdb/perf_flags.h Outdated Show resolved Hide resolved
} \
// TODO: add a flag count
#define PERF_COUNTER_BY_LEVEL_ADD(metric, value, level) \
if (perf_context.per_level_perf_context_enabled && \
Copy link
Member

Choose a reason for hiding this comment

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

Seems that there is an optimization in the original implementation that it checks whether the perf is enabled. You should check it as well I think, considering that checking perf flags should be faster than the xxx.find() below.

monitoring/perf_flags.cc Outdated Show resolved Hide resolved
monitoring/perf_flags.cc Outdated Show resolved Hide resolved
also removed field .perf_level in PerfFlags
…e same time, it has the ability to adjust using BitMask, speeds up initialization, reduces unnecessary macros, and is compatible with PerfLevel's Get and Set.

PerfLevel Get will now return an estimated PerfLevel instead of an accurate one.
@breezewish breezewish added the status/WIP Status: Working in progress label Mar 28, 2021
Comment on lines -2753 to +2763
rocksdb_perfcontext_t* context = new rocksdb_perfcontext_t;
auto* context = new rocksdb_perfcontext_t;
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.

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?

};

// 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?

monitoring/perf_context.cc Show resolved Hide resolved
Comment on lines +20 to +29
.enable_internal_merge_count_bit = 1, \
.enable_get_from_memtable_count_bit = 1, \
.enable_seek_on_memtable_count_bit = 1, \
.enable_next_on_memtable_count_bit = 1, \
.enable_prev_on_memtable_count_bit = 1, \
.enable_seek_child_seek_count_bit = 1, \
.enable_bloom_memtable_hit_count_bit = 1, \
.enable_bloom_memtable_miss_count_bit = 1, \
.enable_bloom_sst_hit_count_bit = 1, .enable_bloom_sst_miss_count_bit = 1, \
.enable_key_lock_wait_count_bit = 1
Copy link
Member

Choose a reason for hiding this comment

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

bad ident?

perf_level = level;
switch (level) {
case kEnableTime:
perf_flags = PERF_LEVEL5;
Copy link
Member

Choose a reason for hiding this comment

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

How about defining an array for these constants?

monitoring/perf_level.cc Show resolved Hide resolved
PerfLevel GetPerfLevel() {
return perf_level;
void* levels[5] = {(void*)&PERF_LEVEL1, (void*)&PERF_LEVEL2,
Copy link
Member

Choose a reason for hiding this comment

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

I guess you can define PERF_LEVEL as a constant array, then you don't need to build the array here.

Comment on lines +11 to +14

#include <string>
#include <vector>

Copy link
Member

Choose a reason for hiding this comment

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

I suggest to change as less as possible. Otherwise it will be pain to merge upstream.

Comment on lines +14 to +16
#include "memory/arena.h"
#include "monitoring/histogram.h"
#include "monitoring/perf_context_imp.h"
Copy link
Member

Choose a reason for hiding this comment

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

Ditto. I suggest to only change necessary part, in order to reduce merge upstream effort.

@LemonHX LemonHX closed this Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/WIP Status: Working in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants