github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/eventlistener.cc (about)

     1  // Copyright 2016 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  #include "eventlistener.h"
    12  #include <rocksdb/table_properties.h>
    13  
    14  static const bool kDebug = false;
    15  
    16  DBEventListener::DBEventListener() : flushes_(0), compactions_(0) {}
    17  
    18  void DBEventListener::OnFlushCompleted(rocksdb::DB* db,
    19                                         const rocksdb::FlushJobInfo& flush_job_info) {
    20    ++flushes_;
    21  
    22    if (kDebug) {
    23      const rocksdb::TableProperties& p = flush_job_info.table_properties;
    24      fprintf(stderr,
    25              "OnFlushCompleted:\n  %40s:  entries=%d  data=%.1fMB  "
    26              "index=%.1fMB  filter=%.1fMB\n",
    27              flush_job_info.file_path.c_str(), (int)p.num_entries,
    28              float(p.data_size) / (1024.0 * 1024.0), float(p.index_size) / (1024.0 * 1024.0),
    29              float(p.filter_size) / (1024.0 * 1024.0));
    30    }
    31  }
    32  
    33  void DBEventListener::OnCompactionCompleted(rocksdb::DB* db, const rocksdb::CompactionJobInfo& ci) {
    34    ++compactions_;
    35  
    36    if (kDebug) {
    37      fprintf(stderr, "OnCompactionCompleted: input=%d output=%d\n", ci.base_input_level,
    38              ci.output_level);
    39      for (auto iter = ci.table_properties.begin(); iter != ci.table_properties.end(); ++iter) {
    40        const rocksdb::TableProperties& p = *iter->second;
    41        fprintf(stderr, "  %40s: entries=%d  data=%.1fMB  index=%.1fMB  filter=%.1fMB\n",
    42                iter->first.c_str(), (int)p.num_entries, float(p.data_size) / (1024.0 * 1024.0),
    43                float(p.index_size) / (1024.0 * 1024.0), float(p.filter_size) / (1024.0 * 1024.0));
    44      }
    45    }
    46  }
    47  
    48  uint64_t DBEventListener::GetFlushes() const { return flushes_.load(); }
    49  
    50  uint64_t DBEventListener::GetCompactions() const { return compactions_.load(); }