Przeglądaj źródła

对原版leveldb进行插桩

pull/2/head
cyq 8 miesięcy temu
rodzic
commit
fd14a089d5
2 zmienionych plików z 43 dodań i 1 usunięć
  1. +13
    -1
      db/db_impl.cc
  2. +30
    -0
      db/db_impl.h

+ 13
- 1
db/db_impl.cc Wyświetl plik

@ -1235,12 +1235,18 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
w.sync = options.sync;
w.done = false;
uint64_t start_ = env_->NowMicros();
MutexLock l(&mutex_);
count ++;
writers_.push_back(&w);
while (!w.done && &w != writers_.front()) {
w.cv.Wait();
}
if (w.done) {
Waiting_elapsed += env_->NowMicros() - start_;
waited_count ++;
Total_elapsed += env_->NowMicros() - start_;
// dumpStatistics();
return w.status;
}
@ -1259,6 +1265,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
// into mem_.
{
mutex_.Unlock();
uint64_t start_write = env_->NowMicros();
status = log_->AddRecord(WriteBatchInternal::Contents(write_batch));
bool sync_error = false;
if (status.ok() && options.sync) {
@ -1270,6 +1277,8 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
if (status.ok()) {
status = WriteBatchInternal::InsertInto(write_batch, mem_);
}
BatchSize += write_batch->ApproximateSize();
write_elapsed += env_->NowMicros() - start_write;
mutex_.Lock();
if (sync_error) {
// The state of the log file is indeterminate: the log record we
@ -1298,7 +1307,10 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
if (!writers_.empty()) {
writers_.front()->cv.Signal();
}
Total_elapsed += env_->NowMicros() - start_;
NoWaiting_elapsed += env_->NowMicros() - start_;
Nowaited_count ++;
dumpStatistics();
return status;
}

+ 30
- 0
db/db_impl.h Wyświetl plik

@ -6,7 +6,10 @@
#define STORAGE_LEVELDB_DB_DB_IMPL_H_
#include <atomic>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <ostream>
#include <set>
#include <string>
@ -210,6 +213,33 @@ class DBImpl : public DB {
Status bg_error_ GUARDED_BY(mutex_);
CompactionStats stats_[config::kNumLevels] GUARDED_BY(mutex_);
int count = 0;
int waited_count = 0;
int Nowaited_count = 0;
uint64_t Total_elapsed = 0;
uint64_t Waiting_elapsed = 0;
uint64_t NoWaiting_elapsed = 0;
uint64_t write_elapsed = 0;
uint64_t BatchSize = 0;
const double MB = 1024 * 1024;
const double KB = 1024;
inline void dumpStatistics() {
if(count && count % 500000 == 0) {
printf("==================================\n");
printf("Count: Total:%d Waited:%d Nowaited:%d\n",count,waited_count,Nowaited_count);
printf("%ld %ld %ld\n",Total_elapsed,Waiting_elapsed,NoWaiting_elapsed);
printf("Average Total elapsed: %lf ms\n",Total_elapsed * 1.0 / count);
printf("Average Waiting elapsed: %lf ms\n",Waiting_elapsed * 1.0 / count);
printf("For waiting request: %lf ms\n",Waiting_elapsed * 1.0 / waited_count);
printf("For Nowait request: %lf ms\n",NoWaiting_elapsed * 1.0 / Nowaited_count);
printf("Write elapsed: %lf ms\n",write_elapsed * 1.0 / Nowaited_count);
printf("Average BatchSize: %lfKB\n",BatchSize / KB / count);
printf("Average BatchSize per write:%lfKB\n",BatchSize / KB / Nowaited_count);
printf("==================================\n");
std::fflush(stdout);
}
}
};
// Sanitize db options. The caller should delete result.info_log if

Ładowanie…
Anuluj
Zapisz