Fix a bug in PosixClock (#9695)

Summary:
Multiplier here should be 1e6 to get microseconds.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9695

Reviewed By: ajkr

Differential Revision: D34897086

Pulled By: jay-zhuang

fbshipit-source-id: 9c1d0811ea740ba0a007edc2da199edbd000b88b
This commit is contained in:
KNOEEE 2022-03-21 16:11:02 -07:00 committed by Andrew Kryczka
parent 6a385e90cd
commit de91718e99
3 changed files with 7 additions and 7 deletions

View File

@ -1228,7 +1228,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
} }
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE
uint64_t prev_cpu_micros = db_options_.clock->CPUNanos() / 1000; uint64_t prev_cpu_micros = db_options_.clock->CPUMicros();
ColumnFamilyData* cfd = sub_compact->compaction->column_family_data(); ColumnFamilyData* cfd = sub_compact->compaction->column_family_data();
@ -1572,7 +1572,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
} }
sub_compact->compaction_job_stats.cpu_micros = sub_compact->compaction_job_stats.cpu_micros =
db_options_.clock->CPUNanos() / 1000 - prev_cpu_micros; db_options_.clock->CPUMicros() - prev_cpu_micros;
if (measure_io_stats_) { if (measure_io_stats_) {
sub_compact->compaction_job_stats.file_write_nanos += sub_compact->compaction_job_stats.file_write_nanos +=

View File

@ -351,7 +351,7 @@ Status FlushJob::MemPurge() {
// Measure purging time. // Measure purging time.
const uint64_t start_micros = clock_->NowMicros(); const uint64_t start_micros = clock_->NowMicros();
const uint64_t start_cpu_micros = clock_->CPUNanos() / 1000; const uint64_t start_cpu_micros = clock_->CPUMicros();
MemTable* new_mem = nullptr; MemTable* new_mem = nullptr;
// For performance/log investigation purposes: // For performance/log investigation purposes:
@ -603,7 +603,7 @@ Status FlushJob::MemPurge() {
TEST_SYNC_POINT("DBImpl::FlushJob:MemPurgeUnsuccessful"); TEST_SYNC_POINT("DBImpl::FlushJob:MemPurgeUnsuccessful");
} }
const uint64_t micros = clock_->NowMicros() - start_micros; const uint64_t micros = clock_->NowMicros() - start_micros;
const uint64_t cpu_micros = clock_->CPUNanos() / 1000 - start_cpu_micros; const uint64_t cpu_micros = clock_->CPUMicros() - start_cpu_micros;
ROCKS_LOG_INFO(db_options_.info_log, ROCKS_LOG_INFO(db_options_.info_log,
"[%s] [JOB %d] Mempurge lasted %" PRIu64 "[%s] [JOB %d] Mempurge lasted %" PRIu64
" microseconds, and %" PRIu64 " microseconds, and %" PRIu64
@ -789,7 +789,7 @@ Status FlushJob::WriteLevel0Table() {
ThreadStatus::STAGE_FLUSH_WRITE_L0); ThreadStatus::STAGE_FLUSH_WRITE_L0);
db_mutex_->AssertHeld(); db_mutex_->AssertHeld();
const uint64_t start_micros = clock_->NowMicros(); const uint64_t start_micros = clock_->NowMicros();
const uint64_t start_cpu_micros = clock_->CPUNanos() / 1000; const uint64_t start_cpu_micros = clock_->CPUMicros();
Status s; Status s;
std::vector<BlobFileAddition> blob_file_additions; std::vector<BlobFileAddition> blob_file_additions;
@ -976,7 +976,7 @@ Status FlushJob::WriteLevel0Table() {
// Note that here we treat flush as level 0 compaction in internal stats // Note that here we treat flush as level 0 compaction in internal stats
InternalStats::CompactionStats stats(CompactionReason::kFlush, 1); InternalStats::CompactionStats stats(CompactionReason::kFlush, 1);
const uint64_t micros = clock_->NowMicros() - start_micros; const uint64_t micros = clock_->NowMicros() - start_micros;
const uint64_t cpu_micros = clock_->CPUNanos() / 1000 - start_cpu_micros; const uint64_t cpu_micros = clock_->CPUMicros() - start_cpu_micros;
stats.micros = micros; stats.micros = micros;
stats.cpu_micros = cpu_micros; stats.cpu_micros = cpu_micros;

2
env/env_posix.cc vendored
View File

@ -166,7 +166,7 @@ class PosixClock : public SystemClock {
defined(OS_AIX) || (defined(__MACH__) && defined(__MAC_10_12)) defined(OS_AIX) || (defined(__MACH__) && defined(__MAC_10_12))
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return static_cast<uint64_t>(ts.tv_sec) * 1000000000; return (static_cast<uint64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec) / 1000;
#endif #endif
return 0; return 0;
} }