internal_stats.cc 58.7 KB
Newer Older
S
Siying Dong 已提交
1 2 3
//  This source code is licensed under both the GPLv2 (found in the
//  COPYING file in the root directory) and Apache 2.0 License
//  (found in the LICENSE.Apache file in the root directory).
I
Igor Canadi 已提交
4 5 6 7 8 9
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "db/internal_stats.h"
L
liuhuahang 已提交
10 11

#ifndef __STDC_FORMAT_MACROS
I
Igor Canadi 已提交
12
#define __STDC_FORMAT_MACROS
L
liuhuahang 已提交
13 14
#endif

I
Igor Canadi 已提交
15
#include <inttypes.h>
16
#include <algorithm>
Y
Yi Wu 已提交
17 18
#include <limits>
#include <string>
19
#include <utility>
I
Igor Canadi 已提交
20
#include <vector>
21

Y
Yi Wu 已提交
22
#include "db/column_family.h"
23
#include "db/db_impl.h"
Y
Yi Wu 已提交
24
#include "table/block_based_table_factory.h"
25
#include "util/string_util.h"
I
Igor Canadi 已提交
26 27 28

namespace rocksdb {

29
#ifndef ROCKSDB_LITE
30 31 32 33 34 35

const std::map<LevelStatType, LevelStat> InternalStats::compaction_level_stats =
    {
        {LevelStatType::NUM_FILES, LevelStat{"NumFiles", "Files"}},
        {LevelStatType::COMPACTED_FILES,
         LevelStat{"CompactedFiles", "CompactedFiles"}},
36
        {LevelStatType::SIZE_BYTES, LevelStat{"SizeBytes", "Size"}},
37
        {LevelStatType::SCORE, LevelStat{"Score", "Score"}},
38 39 40 41 42 43
        {LevelStatType::READ_GB, LevelStat{"ReadGB", "Read(GB)"}},
        {LevelStatType::RN_GB, LevelStat{"RnGB", "Rn(GB)"}},
        {LevelStatType::RNP1_GB, LevelStat{"Rnp1GB", "Rnp1(GB)"}},
        {LevelStatType::WRITE_GB, LevelStat{"WriteGB", "Write(GB)"}},
        {LevelStatType::W_NEW_GB, LevelStat{"WnewGB", "Wnew(GB)"}},
        {LevelStatType::MOVED_GB, LevelStat{"MovedGB", "Moved(GB)"}},
44
        {LevelStatType::WRITE_AMP, LevelStat{"WriteAmp", "W-Amp"}},
45 46 47
        {LevelStatType::READ_MBPS, LevelStat{"ReadMBps", "Rd(MB/s)"}},
        {LevelStatType::WRITE_MBPS, LevelStat{"WriteMBps", "Wr(MB/s)"}},
        {LevelStatType::COMP_SEC, LevelStat{"CompSec", "Comp(sec)"}},
48 49
        {LevelStatType::COMP_CPU_SEC,
         LevelStat{"CompMergeCPU", "CompMergeCPU(sec)"}},
50 51
        {LevelStatType::COMP_COUNT, LevelStat{"CompCount", "Comp(cnt)"}},
        {LevelStatType::AVG_SEC, LevelStat{"AvgSec", "Avg(sec)"}},
52 53 54 55
        {LevelStatType::KEY_IN, LevelStat{"KeyIn", "KeyIn"}},
        {LevelStatType::KEY_DROP, LevelStat{"KeyDrop", "KeyDrop"}},
};

L
Lei Jin 已提交
56 57 58
namespace {
const double kMB = 1048576.0;
const double kGB = kMB * 1024;
59
const double kMicrosInSec = 1000000.0;
L
Lei Jin 已提交
60

61 62
void PrintLevelStatsHeader(char* buf, size_t len, const std::string& cf_name,
                           const std::string& group_by) {
63 64 65 66 67 68 69
  int written_size =
      snprintf(buf, len, "\n** Compaction Stats [%s] **\n", cf_name.c_str());
  auto hdr = [](LevelStatType t) {
    return InternalStats::compaction_level_stats.at(t).header_name.c_str();
  };
  int line_size = snprintf(
      buf + written_size, len - written_size,
70
      "%s    %s   %s     %s %s  %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
71
      // Note that we skip COMPACTED_FILES and merge it with Files column
72 73 74 75 76 77 78 79 80 81
      group_by.c_str(), hdr(LevelStatType::NUM_FILES),
      hdr(LevelStatType::SIZE_BYTES), hdr(LevelStatType::SCORE),
      hdr(LevelStatType::READ_GB), hdr(LevelStatType::RN_GB),
      hdr(LevelStatType::RNP1_GB), hdr(LevelStatType::WRITE_GB),
      hdr(LevelStatType::W_NEW_GB), hdr(LevelStatType::MOVED_GB),
      hdr(LevelStatType::WRITE_AMP), hdr(LevelStatType::READ_MBPS),
      hdr(LevelStatType::WRITE_MBPS), hdr(LevelStatType::COMP_SEC),
      hdr(LevelStatType::COMP_CPU_SEC), hdr(LevelStatType::COMP_COUNT),
      hdr(LevelStatType::AVG_SEC), hdr(LevelStatType::KEY_IN),
      hdr(LevelStatType::KEY_DROP));
82 83 84 85

  written_size += line_size;
  snprintf(buf + written_size, len - written_size, "%s\n",
           std::string(line_size, '-').c_str());
L
Lei Jin 已提交
86 87
}

88 89 90 91
void PrepareLevelStats(std::map<LevelStatType, double>* level_stats,
                       int num_files, int being_compacted,
                       double total_file_size, double score, double w_amp,
                       const InternalStats::CompactionStats& stats) {
92 93
  uint64_t bytes_read =
      stats.bytes_read_non_output_levels + stats.bytes_read_output_level;
94
  int64_t bytes_new = stats.bytes_written - stats.bytes_read_output_level;
95
  double elapsed = (stats.micros + 1) / kMicrosInSec;
L
Lei Jin 已提交
96

97 98
  (*level_stats)[LevelStatType::NUM_FILES] = num_files;
  (*level_stats)[LevelStatType::COMPACTED_FILES] = being_compacted;
99
  (*level_stats)[LevelStatType::SIZE_BYTES] = total_file_size;
100 101 102 103 104 105 106 107 108 109 110 111 112
  (*level_stats)[LevelStatType::SCORE] = score;
  (*level_stats)[LevelStatType::READ_GB] = bytes_read / kGB;
  (*level_stats)[LevelStatType::RN_GB] =
      stats.bytes_read_non_output_levels / kGB;
  (*level_stats)[LevelStatType::RNP1_GB] = stats.bytes_read_output_level / kGB;
  (*level_stats)[LevelStatType::WRITE_GB] = stats.bytes_written / kGB;
  (*level_stats)[LevelStatType::W_NEW_GB] = bytes_new / kGB;
  (*level_stats)[LevelStatType::MOVED_GB] = stats.bytes_moved / kGB;
  (*level_stats)[LevelStatType::WRITE_AMP] = w_amp;
  (*level_stats)[LevelStatType::READ_MBPS] = bytes_read / kMB / elapsed;
  (*level_stats)[LevelStatType::WRITE_MBPS] =
      stats.bytes_written / kMB / elapsed;
  (*level_stats)[LevelStatType::COMP_SEC] = stats.micros / kMicrosInSec;
113
  (*level_stats)[LevelStatType::COMP_CPU_SEC] = stats.cpu_micros / kMicrosInSec;
114 115 116 117 118 119 120 121 122 123 124
  (*level_stats)[LevelStatType::COMP_COUNT] = stats.count;
  (*level_stats)[LevelStatType::AVG_SEC] =
      stats.count == 0 ? 0 : stats.micros / kMicrosInSec / stats.count;
  (*level_stats)[LevelStatType::KEY_IN] =
      static_cast<double>(stats.num_input_records);
  (*level_stats)[LevelStatType::KEY_DROP] =
      static_cast<double>(stats.num_dropped_records);
}

void PrintLevelStats(char* buf, size_t len, const std::string& name,
                     const std::map<LevelStatType, double>& stat_value) {
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  snprintf(
      buf, len,
      "%4s "      /*  Level */
      "%6d/%-3d " /*  Files */
      "%8s "      /*  Size */
      "%5.1f "    /*  Score */
      "%8.1f "    /*  Read(GB) */
      "%7.1f "    /*  Rn(GB) */
      "%8.1f "    /*  Rnp1(GB) */
      "%9.1f "    /*  Write(GB) */
      "%8.1f "    /*  Wnew(GB) */
      "%9.1f "    /*  Moved(GB) */
      "%5.1f "    /*  W-Amp */
      "%8.1f "    /*  Rd(MB/s) */
      "%8.1f "    /*  Wr(MB/s) */
140 141
      "%9.2f "    /*  Comp(sec) */
      "%17.2f "   /*  CompMergeCPU(sec) */
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
      "%9d "      /*  Comp(cnt) */
      "%8.3f "    /*  Avg(sec) */
      "%7s "      /*  KeyIn */
      "%6s\n",    /*  KeyDrop */
      name.c_str(), static_cast<int>(stat_value.at(LevelStatType::NUM_FILES)),
      static_cast<int>(stat_value.at(LevelStatType::COMPACTED_FILES)),
      BytesToHumanString(
          static_cast<uint64_t>(stat_value.at(LevelStatType::SIZE_BYTES)))
          .c_str(),
      stat_value.at(LevelStatType::SCORE),
      stat_value.at(LevelStatType::READ_GB),
      stat_value.at(LevelStatType::RN_GB),
      stat_value.at(LevelStatType::RNP1_GB),
      stat_value.at(LevelStatType::WRITE_GB),
      stat_value.at(LevelStatType::W_NEW_GB),
      stat_value.at(LevelStatType::MOVED_GB),
      stat_value.at(LevelStatType::WRITE_AMP),
      stat_value.at(LevelStatType::READ_MBPS),
      stat_value.at(LevelStatType::WRITE_MBPS),
      stat_value.at(LevelStatType::COMP_SEC),
162
      stat_value.at(LevelStatType::COMP_CPU_SEC),
163 164 165 166 167 168 169 170
      static_cast<int>(stat_value.at(LevelStatType::COMP_COUNT)),
      stat_value.at(LevelStatType::AVG_SEC),
      NumberToHumanString(
          static_cast<std::int64_t>(stat_value.at(LevelStatType::KEY_IN)))
          .c_str(),
      NumberToHumanString(
          static_cast<std::int64_t>(stat_value.at(LevelStatType::KEY_DROP)))
          .c_str());
171 172 173 174 175 176 177 178 179 180
}

void PrintLevelStats(char* buf, size_t len, const std::string& name,
                     int num_files, int being_compacted, double total_file_size,
                     double score, double w_amp,
                     const InternalStats::CompactionStats& stats) {
  std::map<LevelStatType, double> level_stats;
  PrepareLevelStats(&level_stats, num_files, being_compacted, total_file_size,
                    score, w_amp, stats);
  PrintLevelStats(buf, len, name, level_stats);
L
Lei Jin 已提交
181
}
182 183 184 185 186 187 188 189 190 191 192 193 194

// Assumes that trailing numbers represent an optional argument. This requires
// property names to not end with numbers.
std::pair<Slice, Slice> GetPropertyNameAndArg(const Slice& property) {
  Slice name = property, arg = property;
  size_t sfx_len = 0;
  while (sfx_len < property.size() &&
         isdigit(property[property.size() - sfx_len - 1])) {
    ++sfx_len;
  }
  name.remove_suffix(sfx_len);
  arg.remove_prefix(property.size() - sfx_len);
  return {name, arg};
L
Lei Jin 已提交
195
}
196
}  // anonymous namespace
L
Lei Jin 已提交
197

198 199 200
static const std::string rocksdb_prefix = "rocksdb.";

static const std::string num_files_at_level_prefix = "num-files-at-level";
201 202
static const std::string compression_ratio_at_level_prefix =
    "compression-ratio-at-level";
203
static const std::string allstats = "stats";
204 205
static const std::string sstables = "sstables";
static const std::string cfstats = "cfstats";
206 207 208
static const std::string cfstats_no_file_histogram =
    "cfstats-no-file-histogram";
static const std::string cf_file_histogram = "cf-file-histogram";
209 210 211
static const std::string dbstats = "dbstats";
static const std::string levelstats = "levelstats";
static const std::string num_immutable_mem_table = "num-immutable-mem-table";
212 213
static const std::string num_immutable_mem_table_flushed =
    "num-immutable-mem-table-flushed";
214 215 216 217
static const std::string mem_table_flush_pending = "mem-table-flush-pending";
static const std::string compaction_pending = "compaction-pending";
static const std::string background_errors = "background-errors";
static const std::string cur_size_active_mem_table =
218
    "cur-size-active-mem-table";
219 220
static const std::string cur_size_all_mem_tables = "cur-size-all-mem-tables";
static const std::string size_all_mem_tables = "size-all-mem-tables";
221
static const std::string num_entries_active_mem_table =
222
    "num-entries-active-mem-table";
223
static const std::string num_entries_imm_mem_tables =
224
    "num-entries-imm-mem-tables";
225
static const std::string num_deletes_active_mem_table =
226
    "num-deletes-active-mem-table";
227
static const std::string num_deletes_imm_mem_tables =
228
    "num-deletes-imm-mem-tables";
229 230
static const std::string estimate_num_keys = "estimate-num-keys";
static const std::string estimate_table_readers_mem =
231
    "estimate-table-readers-mem";
232
static const std::string is_file_deletions_enabled =
233
    "is-file-deletions-enabled";
234 235 236
static const std::string num_snapshots = "num-snapshots";
static const std::string oldest_snapshot_time = "oldest-snapshot-time";
static const std::string num_live_versions = "num-live-versions";
237 238
static const std::string current_version_number =
    "current-super-version-number";
A
Andres Notzli 已提交
239
static const std::string estimate_live_data_size = "estimate-live-data-size";
240
static const std::string min_log_number_to_keep_str = "min-log-number-to-keep";
241 242
static const std::string min_obsolete_sst_number_to_keep_str =
    "min-obsolete-sst-number-to-keep";
243
static const std::string base_level_str = "base-level";
244
static const std::string total_sst_files_size = "total-sst-files-size";
245
static const std::string live_sst_files_size = "live-sst-files-size";
246 247
static const std::string estimate_pending_comp_bytes =
    "estimate-pending-compaction-bytes";
248 249 250 251
static const std::string aggregated_table_properties =
    "aggregated-table-properties";
static const std::string aggregated_table_properties_at_level =
    aggregated_table_properties + "-at-level";
252 253
static const std::string num_running_compactions = "num-running-compactions";
static const std::string num_running_flushes = "num-running-flushes";
254 255 256
static const std::string actual_delayed_write_rate =
    "actual-delayed-write-rate";
static const std::string is_write_stopped = "is-write-stopped";
Y
Yi Wu 已提交
257
static const std::string estimate_oldest_key_time = "estimate-oldest-key-time";
Y
Yi Wu 已提交
258 259 260
static const std::string block_cache_capacity = "block-cache-capacity";
static const std::string block_cache_usage = "block-cache-usage";
static const std::string block_cache_pinned_usage = "block-cache-pinned-usage";
261
static const std::string options_statistics = "options-statistics";
262 263

const std::string DB::Properties::kNumFilesAtLevelPrefix =
264
    rocksdb_prefix + num_files_at_level_prefix;
265
const std::string DB::Properties::kCompressionRatioAtLevelPrefix =
266
    rocksdb_prefix + compression_ratio_at_level_prefix;
267
const std::string DB::Properties::kStats = rocksdb_prefix + allstats;
268 269
const std::string DB::Properties::kSSTables = rocksdb_prefix + sstables;
const std::string DB::Properties::kCFStats = rocksdb_prefix + cfstats;
270 271 272 273
const std::string DB::Properties::kCFStatsNoFileHistogram =
    rocksdb_prefix + cfstats_no_file_histogram;
const std::string DB::Properties::kCFFileHistogram =
    rocksdb_prefix + cf_file_histogram;
274
const std::string DB::Properties::kDBStats = rocksdb_prefix + dbstats;
275
const std::string DB::Properties::kLevelStats = rocksdb_prefix + levelstats;
276
const std::string DB::Properties::kNumImmutableMemTable =
277
    rocksdb_prefix + num_immutable_mem_table;
278
const std::string DB::Properties::kNumImmutableMemTableFlushed =
279
    rocksdb_prefix + num_immutable_mem_table_flushed;
280
const std::string DB::Properties::kMemTableFlushPending =
281
    rocksdb_prefix + mem_table_flush_pending;
282
const std::string DB::Properties::kCompactionPending =
283
    rocksdb_prefix + compaction_pending;
284 285 286 287
const std::string DB::Properties::kNumRunningCompactions =
    rocksdb_prefix + num_running_compactions;
const std::string DB::Properties::kNumRunningFlushes =
    rocksdb_prefix + num_running_flushes;
288
const std::string DB::Properties::kBackgroundErrors =
289
    rocksdb_prefix + background_errors;
290
const std::string DB::Properties::kCurSizeActiveMemTable =
291
    rocksdb_prefix + cur_size_active_mem_table;
292
const std::string DB::Properties::kCurSizeAllMemTables =
293
    rocksdb_prefix + cur_size_all_mem_tables;
294 295
const std::string DB::Properties::kSizeAllMemTables =
    rocksdb_prefix + size_all_mem_tables;
296
const std::string DB::Properties::kNumEntriesActiveMemTable =
297
    rocksdb_prefix + num_entries_active_mem_table;
298
const std::string DB::Properties::kNumEntriesImmMemTables =
299
    rocksdb_prefix + num_entries_imm_mem_tables;
300
const std::string DB::Properties::kNumDeletesActiveMemTable =
301
    rocksdb_prefix + num_deletes_active_mem_table;
302
const std::string DB::Properties::kNumDeletesImmMemTables =
303
    rocksdb_prefix + num_deletes_imm_mem_tables;
304
const std::string DB::Properties::kEstimateNumKeys =
305
    rocksdb_prefix + estimate_num_keys;
306
const std::string DB::Properties::kEstimateTableReadersMem =
307
    rocksdb_prefix + estimate_table_readers_mem;
308
const std::string DB::Properties::kIsFileDeletionsEnabled =
309
    rocksdb_prefix + is_file_deletions_enabled;
310
const std::string DB::Properties::kNumSnapshots =
311
    rocksdb_prefix + num_snapshots;
312
const std::string DB::Properties::kOldestSnapshotTime =
313
    rocksdb_prefix + oldest_snapshot_time;
314
const std::string DB::Properties::kNumLiveVersions =
315
    rocksdb_prefix + num_live_versions;
316
const std::string DB::Properties::kCurrentSuperVersionNumber =
317
    rocksdb_prefix + current_version_number;
A
Andres Notzli 已提交
318
const std::string DB::Properties::kEstimateLiveDataSize =
319
    rocksdb_prefix + estimate_live_data_size;
320
const std::string DB::Properties::kMinLogNumberToKeep =
321
    rocksdb_prefix + min_log_number_to_keep_str;
322 323
const std::string DB::Properties::kMinObsoleteSstNumberToKeep =
    rocksdb_prefix + min_obsolete_sst_number_to_keep_str;
324
const std::string DB::Properties::kTotalSstFilesSize =
325
    rocksdb_prefix + total_sst_files_size;
326 327
const std::string DB::Properties::kLiveSstFilesSize =
    rocksdb_prefix + live_sst_files_size;
328
const std::string DB::Properties::kBaseLevel = rocksdb_prefix + base_level_str;
329 330
const std::string DB::Properties::kEstimatePendingCompactionBytes =
    rocksdb_prefix + estimate_pending_comp_bytes;
331 332 333 334
const std::string DB::Properties::kAggregatedTableProperties =
    rocksdb_prefix + aggregated_table_properties;
const std::string DB::Properties::kAggregatedTablePropertiesAtLevel =
    rocksdb_prefix + aggregated_table_properties_at_level;
335 336 337 338
const std::string DB::Properties::kActualDelayedWriteRate =
    rocksdb_prefix + actual_delayed_write_rate;
const std::string DB::Properties::kIsWriteStopped =
    rocksdb_prefix + is_write_stopped;
Y
Yi Wu 已提交
339 340
const std::string DB::Properties::kEstimateOldestKeyTime =
    rocksdb_prefix + estimate_oldest_key_time;
Y
Yi Wu 已提交
341 342 343 344 345 346
const std::string DB::Properties::kBlockCacheCapacity =
    rocksdb_prefix + block_cache_capacity;
const std::string DB::Properties::kBlockCacheUsage =
    rocksdb_prefix + block_cache_usage;
const std::string DB::Properties::kBlockCachePinnedUsage =
    rocksdb_prefix + block_cache_pinned_usage;
347 348
const std::string DB::Properties::kOptionsStatistics =
    rocksdb_prefix + options_statistics;
349

350 351 352
const std::unordered_map<std::string, DBPropertyInfo>
    InternalStats::ppt_name_to_info = {
        {DB::Properties::kNumFilesAtLevelPrefix,
353 354
         {false, &InternalStats::HandleNumFilesAtLevel, nullptr, nullptr,
          nullptr}},
355 356
        {DB::Properties::kCompressionRatioAtLevelPrefix,
         {false, &InternalStats::HandleCompressionRatioAtLevelPrefix, nullptr,
357
          nullptr, nullptr}},
358
        {DB::Properties::kLevelStats,
359
         {false, &InternalStats::HandleLevelStats, nullptr, nullptr, nullptr}},
360
        {DB::Properties::kStats,
361
         {false, &InternalStats::HandleStats, nullptr, nullptr, nullptr}},
362 363
        {DB::Properties::kCFStats,
         {false, &InternalStats::HandleCFStats, nullptr,
364
          &InternalStats::HandleCFMapStats, nullptr}},
365
        {DB::Properties::kCFStatsNoFileHistogram,
366
         {false, &InternalStats::HandleCFStatsNoFileHistogram, nullptr, nullptr,
367 368
          nullptr}},
        {DB::Properties::kCFFileHistogram,
369 370
         {false, &InternalStats::HandleCFFileHistogram, nullptr, nullptr,
          nullptr}},
371
        {DB::Properties::kDBStats,
372
         {false, &InternalStats::HandleDBStats, nullptr, nullptr, nullptr}},
373
        {DB::Properties::kSSTables,
374
         {false, &InternalStats::HandleSsTables, nullptr, nullptr, nullptr}},
375 376
        {DB::Properties::kAggregatedTableProperties,
         {false, &InternalStats::HandleAggregatedTableProperties, nullptr,
377
          nullptr, nullptr}},
378 379
        {DB::Properties::kAggregatedTablePropertiesAtLevel,
         {false, &InternalStats::HandleAggregatedTablePropertiesAtLevel,
380
          nullptr, nullptr, nullptr}},
381
        {DB::Properties::kNumImmutableMemTable,
382 383
         {false, nullptr, &InternalStats::HandleNumImmutableMemTable, nullptr,
          nullptr}},
384 385
        {DB::Properties::kNumImmutableMemTableFlushed,
         {false, nullptr, &InternalStats::HandleNumImmutableMemTableFlushed,
386
          nullptr, nullptr}},
387
        {DB::Properties::kMemTableFlushPending,
388 389
         {false, nullptr, &InternalStats::HandleMemTableFlushPending, nullptr,
          nullptr}},
390
        {DB::Properties::kCompactionPending,
391 392
         {false, nullptr, &InternalStats::HandleCompactionPending, nullptr,
          nullptr}},
393
        {DB::Properties::kBackgroundErrors,
394 395
         {false, nullptr, &InternalStats::HandleBackgroundErrors, nullptr,
          nullptr}},
396
        {DB::Properties::kCurSizeActiveMemTable,
397
         {false, nullptr, &InternalStats::HandleCurSizeActiveMemTable, nullptr,
398 399
          nullptr}},
        {DB::Properties::kCurSizeAllMemTables,
400 401
         {false, nullptr, &InternalStats::HandleCurSizeAllMemTables, nullptr,
          nullptr}},
402
        {DB::Properties::kSizeAllMemTables,
403 404
         {false, nullptr, &InternalStats::HandleSizeAllMemTables, nullptr,
          nullptr}},
405 406
        {DB::Properties::kNumEntriesActiveMemTable,
         {false, nullptr, &InternalStats::HandleNumEntriesActiveMemTable,
407
          nullptr, nullptr}},
408
        {DB::Properties::kNumEntriesImmMemTables,
409
         {false, nullptr, &InternalStats::HandleNumEntriesImmMemTables, nullptr,
410 411 412
          nullptr}},
        {DB::Properties::kNumDeletesActiveMemTable,
         {false, nullptr, &InternalStats::HandleNumDeletesActiveMemTable,
413
          nullptr, nullptr}},
414
        {DB::Properties::kNumDeletesImmMemTables,
415
         {false, nullptr, &InternalStats::HandleNumDeletesImmMemTables, nullptr,
416 417
          nullptr}},
        {DB::Properties::kEstimateNumKeys,
418 419
         {false, nullptr, &InternalStats::HandleEstimateNumKeys, nullptr,
          nullptr}},
420
        {DB::Properties::kEstimateTableReadersMem,
421
         {true, nullptr, &InternalStats::HandleEstimateTableReadersMem, nullptr,
422 423
          nullptr}},
        {DB::Properties::kIsFileDeletionsEnabled,
424
         {false, nullptr, &InternalStats::HandleIsFileDeletionsEnabled, nullptr,
425 426
          nullptr}},
        {DB::Properties::kNumSnapshots,
427 428
         {false, nullptr, &InternalStats::HandleNumSnapshots, nullptr,
          nullptr}},
429
        {DB::Properties::kOldestSnapshotTime,
430 431
         {false, nullptr, &InternalStats::HandleOldestSnapshotTime, nullptr,
          nullptr}},
432
        {DB::Properties::kNumLiveVersions,
433 434
         {false, nullptr, &InternalStats::HandleNumLiveVersions, nullptr,
          nullptr}},
435 436
        {DB::Properties::kCurrentSuperVersionNumber,
         {false, nullptr, &InternalStats::HandleCurrentSuperVersionNumber,
437
          nullptr, nullptr}},
438
        {DB::Properties::kEstimateLiveDataSize,
439 440
         {true, nullptr, &InternalStats::HandleEstimateLiveDataSize, nullptr,
          nullptr}},
441
        {DB::Properties::kMinLogNumberToKeep,
442 443
         {false, nullptr, &InternalStats::HandleMinLogNumberToKeep, nullptr,
          nullptr}},
444 445 446
        {DB::Properties::kMinObsoleteSstNumberToKeep,
         {false, nullptr, &InternalStats::HandleMinObsoleteSstNumberToKeep,
          nullptr, nullptr}},
447
        {DB::Properties::kBaseLevel,
448
         {false, nullptr, &InternalStats::HandleBaseLevel, nullptr, nullptr}},
449
        {DB::Properties::kTotalSstFilesSize,
450 451
         {false, nullptr, &InternalStats::HandleTotalSstFilesSize, nullptr,
          nullptr}},
452
        {DB::Properties::kLiveSstFilesSize,
453 454
         {false, nullptr, &InternalStats::HandleLiveSstFilesSize, nullptr,
          nullptr}},
455 456
        {DB::Properties::kEstimatePendingCompactionBytes,
         {false, nullptr, &InternalStats::HandleEstimatePendingCompactionBytes,
457
          nullptr, nullptr}},
458
        {DB::Properties::kNumRunningFlushes,
459 460
         {false, nullptr, &InternalStats::HandleNumRunningFlushes, nullptr,
          nullptr}},
461
        {DB::Properties::kNumRunningCompactions,
462
         {false, nullptr, &InternalStats::HandleNumRunningCompactions, nullptr,
463
          nullptr}},
464
        {DB::Properties::kActualDelayedWriteRate,
465
         {false, nullptr, &InternalStats::HandleActualDelayedWriteRate, nullptr,
466 467
          nullptr}},
        {DB::Properties::kIsWriteStopped,
468 469
         {false, nullptr, &InternalStats::HandleIsWriteStopped, nullptr,
          nullptr}},
Y
Yi Wu 已提交
470
        {DB::Properties::kEstimateOldestKeyTime,
471
         {false, nullptr, &InternalStats::HandleEstimateOldestKeyTime, nullptr,
Y
Yi Wu 已提交
472
          nullptr}},
Y
Yi Wu 已提交
473
        {DB::Properties::kBlockCacheCapacity,
474 475
         {false, nullptr, &InternalStats::HandleBlockCacheCapacity, nullptr,
          nullptr}},
Y
Yi Wu 已提交
476
        {DB::Properties::kBlockCacheUsage,
477 478
         {false, nullptr, &InternalStats::HandleBlockCacheUsage, nullptr,
          nullptr}},
Y
Yi Wu 已提交
479
        {DB::Properties::kBlockCachePinnedUsage,
480
         {false, nullptr, &InternalStats::HandleBlockCachePinnedUsage, nullptr,
Y
Yi Wu 已提交
481
          nullptr}},
482 483 484
        {DB::Properties::kOptionsStatistics,
         {false, nullptr, nullptr, nullptr,
          &DBImpl::GetPropertyHandleOptionsStatistics}},
485 486 487 488 489 490 491
};

const DBPropertyInfo* GetPropertyInfo(const Slice& property) {
  std::string ppt_name = GetPropertyNameAndArg(property).first.ToString();
  auto ppt_info_iter = InternalStats::ppt_name_to_info.find(ppt_name);
  if (ppt_info_iter == InternalStats::ppt_name_to_info.end()) {
    return nullptr;
492
  }
493 494
  return &ppt_info_iter->second;
}
495

496 497 498 499 500 501 502
bool InternalStats::GetStringProperty(const DBPropertyInfo& property_info,
                                      const Slice& property,
                                      std::string* value) {
  assert(value != nullptr);
  assert(property_info.handle_string != nullptr);
  Slice arg = GetPropertyNameAndArg(property).second;
  return (this->*(property_info.handle_string))(value, arg);
503 504
}

505
bool InternalStats::GetMapProperty(const DBPropertyInfo& property_info,
A
Andrew Kryczka 已提交
506
                                   const Slice& /*property*/,
507
                                   std::map<std::string, std::string>* value) {
508 509 510 511 512
  assert(value != nullptr);
  assert(property_info.handle_map != nullptr);
  return (this->*(property_info.handle_map))(value);
}

513 514
bool InternalStats::GetIntProperty(const DBPropertyInfo& property_info,
                                   uint64_t* value, DBImpl* db) {
515
  assert(value != nullptr);
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
  assert(property_info.handle_int != nullptr &&
         !property_info.need_out_of_mutex);
  db->mutex_.AssertHeld();
  return (this->*(property_info.handle_int))(value, db, nullptr /* version */);
}

bool InternalStats::GetIntPropertyOutOfMutex(
    const DBPropertyInfo& property_info, Version* version, uint64_t* value) {
  assert(value != nullptr);
  assert(property_info.handle_int != nullptr &&
         property_info.need_out_of_mutex);
  return (this->*(property_info.handle_int))(value, nullptr /* db */, version);
}

bool InternalStats::HandleNumFilesAtLevel(std::string* value, Slice suffix) {
  uint64_t level;
A
Andres Notzli 已提交
532
  const auto* vstorage = cfd_->current()->storage_info();
533 534 535 536 537 538 539 540 541 542 543 544
  bool ok = ConsumeDecimalNumber(&suffix, &level) && suffix.empty();
  if (!ok || static_cast<int>(level) >= number_levels_) {
    return false;
  } else {
    char buf[100];
    snprintf(buf, sizeof(buf), "%d",
             vstorage->NumLevelFiles(static_cast<int>(level)));
    *value = buf;
    return true;
  }
}

545 546 547 548 549 550 551 552 553 554 555 556 557
bool InternalStats::HandleCompressionRatioAtLevelPrefix(std::string* value,
                                                        Slice suffix) {
  uint64_t level;
  const auto* vstorage = cfd_->current()->storage_info();
  bool ok = ConsumeDecimalNumber(&suffix, &level) && suffix.empty();
  if (!ok || level >= static_cast<uint64_t>(number_levels_)) {
    return false;
  }
  *value = ToString(
      vstorage->GetEstimatedCompressionRatioAtLevel(static_cast<int>(level)));
  return true;
}

A
Andrew Kryczka 已提交
558
bool InternalStats::HandleLevelStats(std::string* value, Slice /*suffix*/) {
559 560 561 562 563 564
  char buf[1000];
  const auto* vstorage = cfd_->current()->storage_info();
  snprintf(buf, sizeof(buf),
           "Level Files Size(MB)\n"
           "--------------------\n");
  value->append(buf);
A
Andres Notzli 已提交
565

566 567 568 569 570
  for (int level = 0; level < number_levels_; level++) {
    snprintf(buf, sizeof(buf), "%3d %8d %8.0f\n", level,
             vstorage->NumLevelFiles(level),
             vstorage->NumLevelBytes(level) / kMB);
    value->append(buf);
571
  }
572
  return true;
573
}
574

575 576 577 578 579 580 581 582 583 584
bool InternalStats::HandleStats(std::string* value, Slice suffix) {
  if (!HandleCFStats(value, suffix)) {
    return false;
  }
  if (!HandleDBStats(value, suffix)) {
    return false;
  }
  return true;
}

585 586
bool InternalStats::HandleCFMapStats(
    std::map<std::string, std::string>* cf_stats) {
587 588 589 590
  DumpCFMapStats(cf_stats);
  return true;
}

A
Andrew Kryczka 已提交
591
bool InternalStats::HandleCFStats(std::string* value, Slice /*suffix*/) {
592 593 594 595
  DumpCFStats(value);
  return true;
}

596
bool InternalStats::HandleCFStatsNoFileHistogram(std::string* value,
A
Andrew Kryczka 已提交
597
                                                 Slice /*suffix*/) {
598 599 600 601
  DumpCFStatsNoFileHistogram(value);
  return true;
}

A
Andrew Kryczka 已提交
602 603
bool InternalStats::HandleCFFileHistogram(std::string* value,
                                          Slice /*suffix*/) {
604 605 606 607
  DumpCFFileHistogram(value);
  return true;
}

A
Andrew Kryczka 已提交
608
bool InternalStats::HandleDBStats(std::string* value, Slice /*suffix*/) {
609 610 611 612
  DumpDBStats(value);
  return true;
}

A
Andrew Kryczka 已提交
613
bool InternalStats::HandleSsTables(std::string* value, Slice /*suffix*/) {
S
sdong 已提交
614
  auto* current = cfd_->current();
615
  *value = current->DebugString(true, true);
616 617
  return true;
}
I
Igor Canadi 已提交
618

619
bool InternalStats::HandleAggregatedTableProperties(std::string* value,
A
Andrew Kryczka 已提交
620
                                                    Slice /*suffix*/) {
621 622 623 624
  std::shared_ptr<const TableProperties> tp;
  auto s = cfd_->current()->GetAggregatedTableProperties(&tp);
  if (!s.ok()) {
    return false;
625
  }
626 627
  *value = tp->ToString();
  return true;
628 629
}

630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
bool InternalStats::HandleAggregatedTablePropertiesAtLevel(std::string* value,
                                                           Slice suffix) {
  uint64_t level;
  bool ok = ConsumeDecimalNumber(&suffix, &level) && suffix.empty();
  if (!ok || static_cast<int>(level) >= number_levels_) {
    return false;
  }
  std::shared_ptr<const TableProperties> tp;
  auto s = cfd_->current()->GetAggregatedTableProperties(
      &tp, static_cast<int>(level));
  if (!s.ok()) {
    return false;
  }
  *value = tp->ToString();
  return true;
}

A
Andrew Kryczka 已提交
647 648
bool InternalStats::HandleNumImmutableMemTable(uint64_t* value, DBImpl* /*db*/,
                                               Version* /*version*/) {
649 650 651 652 653
  *value = cfd_->imm()->NumNotFlushed();
  return true;
}

bool InternalStats::HandleNumImmutableMemTableFlushed(uint64_t* value,
A
Andrew Kryczka 已提交
654 655
                                                      DBImpl* /*db*/,
                                                      Version* /*version*/) {
656 657 658 659
  *value = cfd_->imm()->NumFlushed();
  return true;
}

A
Andrew Kryczka 已提交
660 661
bool InternalStats::HandleMemTableFlushPending(uint64_t* value, DBImpl* /*db*/,
                                               Version* /*version*/) {
662 663 664 665 666 667
  // Return number of mem tables that are ready to flush (made immutable)
  *value = (cfd_->imm()->IsFlushPending() ? 1 : 0);
  return true;
}

bool InternalStats::HandleNumRunningFlushes(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
668
                                            Version* /*version*/) {
669 670 671 672
  *value = db->num_running_flushes();
  return true;
}

A
Andrew Kryczka 已提交
673 674
bool InternalStats::HandleCompactionPending(uint64_t* value, DBImpl* /*db*/,
                                            Version* /*version*/) {
675 676
  // 1 if the system already determines at least one compaction is needed.
  // 0 otherwise,
S
sdong 已提交
677
  const auto* vstorage = cfd_->current()->storage_info();
678 679 680
  *value = (cfd_->compaction_picker()->NeedsCompaction(vstorage) ? 1 : 0);
  return true;
}
681

682
bool InternalStats::HandleNumRunningCompactions(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
683
                                                Version* /*version*/) {
684 685 686 687
  *value = db->num_running_compactions_;
  return true;
}

A
Andrew Kryczka 已提交
688 689
bool InternalStats::HandleBackgroundErrors(uint64_t* value, DBImpl* /*db*/,
                                           Version* /*version*/) {
690 691 692 693 694
  // Accumulated number of  errors in background flushes or compactions.
  *value = GetBackgroundErrorCount();
  return true;
}

A
Andrew Kryczka 已提交
695 696
bool InternalStats::HandleCurSizeActiveMemTable(uint64_t* value, DBImpl* /*db*/,
                                                Version* /*version*/) {
697 698 699 700 701
  // Current size of the active memtable
  *value = cfd_->mem()->ApproximateMemoryUsage();
  return true;
}

A
Andrew Kryczka 已提交
702 703
bool InternalStats::HandleCurSizeAllMemTables(uint64_t* value, DBImpl* /*db*/,
                                              Version* /*version*/) {
704 705 706 707 708 709
  // Current size of the active memtable + immutable memtables
  *value = cfd_->mem()->ApproximateMemoryUsage() +
           cfd_->imm()->ApproximateUnflushedMemTablesMemoryUsage();
  return true;
}

A
Andrew Kryczka 已提交
710 711
bool InternalStats::HandleSizeAllMemTables(uint64_t* value, DBImpl* /*db*/,
                                           Version* /*version*/) {
712 713 714 715 716
  *value = cfd_->mem()->ApproximateMemoryUsage() +
           cfd_->imm()->ApproximateMemoryUsage();
  return true;
}

A
Andrew Kryczka 已提交
717 718 719
bool InternalStats::HandleNumEntriesActiveMemTable(uint64_t* value,
                                                   DBImpl* /*db*/,
                                                   Version* /*version*/) {
720 721 722 723 724
  // Current number of entires in the active memtable
  *value = cfd_->mem()->num_entries();
  return true;
}

A
Andrew Kryczka 已提交
725 726 727
bool InternalStats::HandleNumEntriesImmMemTables(uint64_t* value,
                                                 DBImpl* /*db*/,
                                                 Version* /*version*/) {
728 729 730 731 732
  // Current number of entries in the immutable memtables
  *value = cfd_->imm()->current()->GetTotalNumEntries();
  return true;
}

A
Andrew Kryczka 已提交
733 734 735
bool InternalStats::HandleNumDeletesActiveMemTable(uint64_t* value,
                                                   DBImpl* /*db*/,
                                                   Version* /*version*/) {
736 737 738 739 740
  // Current number of entires in the active memtable
  *value = cfd_->mem()->num_deletes();
  return true;
}

A
Andrew Kryczka 已提交
741 742 743
bool InternalStats::HandleNumDeletesImmMemTables(uint64_t* value,
                                                 DBImpl* /*db*/,
                                                 Version* /*version*/) {
744 745 746 747 748
  // Current number of entries in the immutable memtables
  *value = cfd_->imm()->current()->GetTotalNumDeletes();
  return true;
}

A
Andrew Kryczka 已提交
749 750
bool InternalStats::HandleEstimateNumKeys(uint64_t* value, DBImpl* /*db*/,
                                          Version* /*version*/) {
751 752 753
  // Estimate number of entries in the column family:
  // Use estimated entries in tables + total entries in memtables.
  const auto* vstorage = cfd_->current()->storage_info();
754 755 756 757 758 759 760 761
  uint64_t estimate_keys = cfd_->mem()->num_entries() +
                           cfd_->imm()->current()->GetTotalNumEntries() +
                           vstorage->GetEstimatedActiveKeys();
  uint64_t estimate_deletes =
      cfd_->mem()->num_deletes() + cfd_->imm()->current()->GetTotalNumDeletes();
  *value = estimate_keys > estimate_deletes * 2
               ? estimate_keys - (estimate_deletes * 2)
               : 0;
762 763 764 765
  return true;
}

bool InternalStats::HandleNumSnapshots(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
766
                                       Version* /*version*/) {
767 768 769 770 771
  *value = db->snapshots().count();
  return true;
}

bool InternalStats::HandleOldestSnapshotTime(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
772
                                             Version* /*version*/) {
773 774 775 776
  *value = static_cast<uint64_t>(db->snapshots().GetOldestSnapshotTime());
  return true;
}

A
Andrew Kryczka 已提交
777 778
bool InternalStats::HandleNumLiveVersions(uint64_t* value, DBImpl* /*db*/,
                                          Version* /*version*/) {
779 780 781 782
  *value = cfd_->GetNumLiveVersions();
  return true;
}

A
Andrew Kryczka 已提交
783 784 785
bool InternalStats::HandleCurrentSuperVersionNumber(uint64_t* value,
                                                    DBImpl* /*db*/,
                                                    Version* /*version*/) {
786 787 788 789
  *value = cfd_->GetSuperVersionNumber();
  return true;
}

790
bool InternalStats::HandleIsFileDeletionsEnabled(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
791
                                                 Version* /*version*/) {
792 793 794 795
  *value = db->IsFileDeletionsEnabled();
  return true;
}

A
Andrew Kryczka 已提交
796 797
bool InternalStats::HandleBaseLevel(uint64_t* value, DBImpl* /*db*/,
                                    Version* /*version*/) {
798 799 800 801 802
  const auto* vstorage = cfd_->current()->storage_info();
  *value = vstorage->base_level();
  return true;
}

803 804
bool InternalStats::HandleTotalSstFilesSize(uint64_t* value, DBImpl* /*db*/,
                                            Version* /*version*/) {
805 806 807 808
  *value = cfd_->GetTotalSstFilesSize();
  return true;
}

809 810 811 812 813 814
bool InternalStats::HandleLiveSstFilesSize(uint64_t* value, DBImpl* /*db*/,
                                           Version* /*version*/) {
  *value = cfd_->GetLiveSstFilesSize();
  return true;
}

815
bool InternalStats::HandleEstimatePendingCompactionBytes(uint64_t* value,
A
Andrew Kryczka 已提交
816 817
                                                         DBImpl* /*db*/,
                                                         Version* /*version*/) {
818 819 820 821 822
  const auto* vstorage = cfd_->current()->storage_info();
  *value = vstorage->estimated_compaction_needed_bytes();
  return true;
}

A
Andrew Kryczka 已提交
823 824
bool InternalStats::HandleEstimateTableReadersMem(uint64_t* value,
                                                  DBImpl* /*db*/,
825 826 827 828 829
                                                  Version* version) {
  *value = (version == nullptr) ? 0 : version->GetMemoryUsageByTableReaders();
  return true;
}

A
Andrew Kryczka 已提交
830
bool InternalStats::HandleEstimateLiveDataSize(uint64_t* value, DBImpl* /*db*/,
831 832
                                               Version* version) {
  const auto* vstorage = version->storage_info();
833 834
  *value = vstorage->EstimateLiveDataSize();
  return true;
I
Igor Canadi 已提交
835 836
}

837
bool InternalStats::HandleMinLogNumberToKeep(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
838
                                             Version* /*version*/) {
839 840 841 842
  *value = db->MinLogNumberToKeep();
  return true;
}

843 844 845 846 847 848 849
bool InternalStats::HandleMinObsoleteSstNumberToKeep(uint64_t* value,
                                                     DBImpl* db,
                                                     Version* /*version*/) {
  *value = db->MinObsoleteSstNumberToKeep();
  return true;
}

850
bool InternalStats::HandleActualDelayedWriteRate(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
851
                                                 Version* /*version*/) {
852 853 854 855 856 857 858 859 860 861
  const WriteController& wc = db->write_controller();
  if (!wc.NeedsDelay()) {
    *value = 0;
  } else {
    *value = wc.delayed_write_rate();
  }
  return true;
}

bool InternalStats::HandleIsWriteStopped(uint64_t* value, DBImpl* db,
A
Andrew Kryczka 已提交
862
                                         Version* /*version*/) {
863 864 865 866
  *value = db->write_controller().IsStopped() ? 1 : 0;
  return true;
}

Y
Yi Wu 已提交
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
bool InternalStats::HandleEstimateOldestKeyTime(uint64_t* value, DBImpl* /*db*/,
                                                Version* /*version*/) {
  // TODO(yiwu): The property is currently available for fifo compaction
  // with allow_compaction = false. This is because we don't propagate
  // oldest_key_time on compaction.
  if (cfd_->ioptions()->compaction_style != kCompactionStyleFIFO ||
      cfd_->GetCurrentMutableCFOptions()
          ->compaction_options_fifo.allow_compaction) {
    return false;
  }

  TablePropertiesCollection collection;
  auto s = cfd_->current()->GetPropertiesOfAllTables(&collection);
  if (!s.ok()) {
    return false;
  }
  *value = std::numeric_limits<uint64_t>::max();
  for (auto& p : collection) {
    *value = std::min(*value, p.second->oldest_key_time);
886 887 888
    if (*value == 0) {
      break;
    }
Y
Yi Wu 已提交
889
  }
890 891 892 893 894
  if (*value > 0) {
    *value = std::min({cfd_->mem()->ApproximateOldestKeyTime(),
                       cfd_->imm()->ApproximateOldestKeyTime(), *value});
  }
  return *value > 0 && *value < std::numeric_limits<uint64_t>::max();
Y
Yi Wu 已提交
895 896
}

Y
Yi Wu 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
bool InternalStats::HandleBlockCacheStat(Cache** block_cache) {
  assert(block_cache != nullptr);
  auto* table_factory = cfd_->ioptions()->table_factory;
  assert(table_factory != nullptr);
  if (BlockBasedTableFactory::kName != table_factory->Name()) {
    return false;
  }
  auto* table_options =
      reinterpret_cast<BlockBasedTableOptions*>(table_factory->GetOptions());
  if (table_options == nullptr) {
    return false;
  }
  *block_cache = table_options->block_cache.get();
  if (table_options->no_block_cache || *block_cache == nullptr) {
    return false;
  }
  return true;
}

bool InternalStats::HandleBlockCacheCapacity(uint64_t* value, DBImpl* /*db*/,
                                             Version* /*version*/) {
  Cache* block_cache;
  bool ok = HandleBlockCacheStat(&block_cache);
  if (!ok) {
    return false;
  }
  *value = static_cast<uint64_t>(block_cache->GetCapacity());
  return true;
}

bool InternalStats::HandleBlockCacheUsage(uint64_t* value, DBImpl* /*db*/,
                                          Version* /*version*/) {
  Cache* block_cache;
  bool ok = HandleBlockCacheStat(&block_cache);
  if (!ok) {
    return false;
  }
  *value = static_cast<uint64_t>(block_cache->GetUsage());
  return true;
}

bool InternalStats::HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* /*db*/,
                                                Version* /*version*/) {
  Cache* block_cache;
  bool ok = HandleBlockCacheStat(&block_cache);
  if (!ok) {
    return false;
  }
  *value = static_cast<uint64_t>(block_cache->GetPinnedUsage());
  return true;
}

949 950 951
void InternalStats::DumpDBStats(std::string* value) {
  char buf[1000];
  // DB-level stats, only available from default column family
952
  double seconds_up = (env_->NowMicros() - started_at_ + 1) / kMicrosInSec;
953 954 955 956 957 958
  double interval_seconds_up = seconds_up - db_stats_snapshot_.seconds_up;
  snprintf(buf, sizeof(buf),
           "\n** DB Stats **\nUptime(secs): %.1f total, %.1f interval\n",
           seconds_up, interval_seconds_up);
  value->append(buf);
  // Cumulative
959 960 961 962 963 964 965 966
  uint64_t user_bytes_written = GetDBStats(InternalStats::BYTES_WRITTEN);
  uint64_t num_keys_written = GetDBStats(InternalStats::NUMBER_KEYS_WRITTEN);
  uint64_t write_other = GetDBStats(InternalStats::WRITE_DONE_BY_OTHER);
  uint64_t write_self = GetDBStats(InternalStats::WRITE_DONE_BY_SELF);
  uint64_t wal_bytes = GetDBStats(InternalStats::WAL_FILE_BYTES);
  uint64_t wal_synced = GetDBStats(InternalStats::WAL_FILE_SYNCED);
  uint64_t write_with_wal = GetDBStats(InternalStats::WRITE_WITH_WAL);
  uint64_t write_stall_micros = GetDBStats(InternalStats::WRITE_STALL_MICROS);
967

968 969 970
  const int kHumanMicrosLen = 32;
  char human_micros[kHumanMicrosLen];

971
  // Data
S
sdong 已提交
972 973
  // writes: total number of write requests.
  // keys: total number of key updates issued by all the write requests
974 975
  // commit groups: number of group commits issued to the DB. Each group can
  //                contain one or more writes.
S
sdong 已提交
976
  // so writes/keys is the average number of put in multi-put or put
977
  // writes/groups is the average group commit size.
S
sdong 已提交
978 979
  //
  // The format is the same for interval stats.
980
  snprintf(buf, sizeof(buf),
981 982
           "Cumulative writes: %s writes, %s keys, %s commit groups, "
           "%.1f writes per commit group, ingest: %.2f GB, %.2f MB/s\n",
983 984 985
           NumberToHumanString(write_other + write_self).c_str(),
           NumberToHumanString(num_keys_written).c_str(),
           NumberToHumanString(write_self).c_str(),
986
           (write_other + write_self) / static_cast<double>(write_self + 1),
987
           user_bytes_written / kGB, user_bytes_written / kMB / seconds_up);
988 989 990
  value->append(buf);
  // WAL
  snprintf(buf, sizeof(buf),
991 992 993 994
           "Cumulative WAL: %s writes, %s syncs, "
           "%.2f writes per sync, written: %.2f GB, %.2f MB/s\n",
           NumberToHumanString(write_with_wal).c_str(),
           NumberToHumanString(wal_synced).c_str(),
995
           write_with_wal / static_cast<double>(wal_synced + 1),
996 997 998 999
           wal_bytes / kGB, wal_bytes / kMB / seconds_up);
  value->append(buf);
  // Stall
  AppendHumanMicros(write_stall_micros, human_micros, kHumanMicrosLen, true);
1000
  snprintf(buf, sizeof(buf), "Cumulative stall: %s, %.1f percent\n",
1001 1002 1003
           human_micros,
           // 10000 = divide by 1M to get secs, then multiply by 100 for pct
           write_stall_micros / 10000.0 / std::max(seconds_up, 0.001));
1004 1005 1006 1007 1008
  value->append(buf);

  // Interval
  uint64_t interval_write_other = write_other - db_stats_snapshot_.write_other;
  uint64_t interval_write_self = write_self - db_stats_snapshot_.write_self;
S
sdong 已提交
1009 1010
  uint64_t interval_num_keys_written =
      num_keys_written - db_stats_snapshot_.num_keys_written;
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
  snprintf(
      buf, sizeof(buf),
      "Interval writes: %s writes, %s keys, %s commit groups, "
      "%.1f writes per commit group, ingest: %.2f MB, %.2f MB/s\n",
      NumberToHumanString(interval_write_other + interval_write_self).c_str(),
      NumberToHumanString(interval_num_keys_written).c_str(),
      NumberToHumanString(interval_write_self).c_str(),
      static_cast<double>(interval_write_other + interval_write_self) /
          (interval_write_self + 1),
      (user_bytes_written - db_stats_snapshot_.ingest_bytes) / kMB,
      (user_bytes_written - db_stats_snapshot_.ingest_bytes) / kMB /
          std::max(interval_seconds_up, 0.001)),
      value->append(buf);
1024 1025 1026 1027 1028 1029

  uint64_t interval_write_with_wal =
      write_with_wal - db_stats_snapshot_.write_with_wal;
  uint64_t interval_wal_synced = wal_synced - db_stats_snapshot_.wal_synced;
  uint64_t interval_wal_bytes = wal_bytes - db_stats_snapshot_.wal_bytes;

1030 1031 1032 1033 1034 1035 1036 1037 1038
  snprintf(
      buf, sizeof(buf),
      "Interval WAL: %s writes, %s syncs, "
      "%.2f writes per sync, written: %.2f MB, %.2f MB/s\n",
      NumberToHumanString(interval_write_with_wal).c_str(),
      NumberToHumanString(interval_wal_synced).c_str(),
      interval_write_with_wal / static_cast<double>(interval_wal_synced + 1),
      interval_wal_bytes / kGB,
      interval_wal_bytes / kMB / std::max(interval_seconds_up, 0.001));
1039 1040 1041
  value->append(buf);

  // Stall
1042 1043 1044
  AppendHumanMicros(write_stall_micros - db_stats_snapshot_.write_stall_micros,
                    human_micros, kHumanMicrosLen, true);
  snprintf(buf, sizeof(buf), "Interval stall: %s, %.1f percent\n", human_micros,
1045 1046 1047
           // 10000 = divide by 1M to get secs, then multiply by 100 for pct
           (write_stall_micros - db_stats_snapshot_.write_stall_micros) /
               10000.0 / std::max(interval_seconds_up, 0.001));
1048 1049 1050 1051 1052 1053
  value->append(buf);

  db_stats_snapshot_.seconds_up = seconds_up;
  db_stats_snapshot_.ingest_bytes = user_bytes_written;
  db_stats_snapshot_.write_other = write_other;
  db_stats_snapshot_.write_self = write_self;
S
sdong 已提交
1054
  db_stats_snapshot_.num_keys_written = num_keys_written;
1055 1056 1057
  db_stats_snapshot_.wal_bytes = wal_bytes;
  db_stats_snapshot_.wal_synced = wal_synced;
  db_stats_snapshot_.write_with_wal = write_with_wal;
S
sdong 已提交
1058
  db_stats_snapshot_.write_stall_micros = write_stall_micros;
1059 1060
}

1061
/**
1062 1063 1064 1065 1066 1067
 * Dump Compaction Level stats to a map of stat name with "compaction." prefix
 * to value in double as string. The level in stat name is represented with
 * a prefix "Lx" where "x" is the level number. A special level "Sum"
 * represents the sum of a stat for all levels.
 * The result also contains IO stall counters which keys start with "io_stalls."
 * and values represent uint64 encoded as strings.
1068
 */
1069
void InternalStats::DumpCFMapStats(
1070
    std::map<std::string, std::string>* cf_stats) {
1071
  CompactionStats compaction_stats_sum;
1072 1073 1074 1075 1076 1077 1078 1079
  std::map<int, std::map<LevelStatType, double>> levels_stats;
  DumpCFMapStats(&levels_stats, &compaction_stats_sum);
  for (auto const& level_ent : levels_stats) {
    auto level_str =
        level_ent.first == -1 ? "Sum" : "L" + ToString(level_ent.first);
    for (auto const& stat_ent : level_ent.second) {
      auto stat_type = stat_ent.first;
      auto key_str =
1080
          "compaction." + level_str + "." +
1081
          InternalStats::compaction_level_stats.at(stat_type).property_name;
1082
      (*cf_stats)[key_str] = std::to_string(stat_ent.second);
1083 1084
    }
  }
1085 1086

  DumpCFMapStatsIOStalls(cf_stats);
1087 1088
}

1089
void InternalStats::DumpCFMapStats(
1090 1091
    std::map<int, std::map<LevelStatType, double>>* levels_stats,
    CompactionStats* compaction_stats_sum) {
S
sdong 已提交
1092
  const VersionStorageInfo* vstorage = cfd_->current()->storage_info();
1093 1094

  int num_levels_to_check =
1095
      (cfd_->ioptions()->compaction_style != kCompactionStyleFIFO)
1096
          ? vstorage->num_levels() - 1
1097
          : 1;
S
sdong 已提交
1098

1099
  // Compaction scores are sorted based on its value. Restore them to the
1100 1101 1102
  // level order
  std::vector<double> compaction_score(number_levels_, 0);
  for (int i = 0; i < num_levels_to_check; ++i) {
1103 1104
    compaction_score[vstorage->CompactionScoreLevel(i)] =
        vstorage->CompactionScore(i);
1105 1106 1107
  }
  // Count # of files being compacted for each level
  std::vector<int> files_being_compacted(number_levels_, 0);
1108
  for (int level = 0; level < number_levels_; ++level) {
1109
    for (auto* f : vstorage->LevelFiles(level)) {
1110 1111 1112 1113 1114 1115 1116 1117 1118
      if (f->being_compacted) {
        ++files_being_compacted[level];
      }
    }
  }

  int total_files = 0;
  int total_files_being_compacted = 0;
  double total_file_size = 0;
1119 1120 1121
  uint64_t flush_ingest = cf_stats_value_[BYTES_FLUSHED];
  uint64_t add_file_ingest = cf_stats_value_[BYTES_INGESTED_ADD_FILE];
  uint64_t curr_ingest = flush_ingest + add_file_ingest;
1122
  for (int level = 0; level < number_levels_; level++) {
S
sdong 已提交
1123
    int files = vstorage->NumLevelFiles(level);
1124 1125 1126
    total_files += files;
    total_files_being_compacted += files_being_compacted[level];
    if (comp_stats_[level].micros > 0 || files > 0) {
1127
      compaction_stats_sum->Add(comp_stats_[level]);
S
sdong 已提交
1128
      total_file_size += vstorage->NumLevelBytes(level);
1129 1130 1131 1132 1133 1134
      uint64_t input_bytes;
      if (level == 0) {
        input_bytes = curr_ingest;
      } else {
        input_bytes = comp_stats_[level].bytes_read_non_output_levels;
      }
1135
      double w_amp =
1136
          (input_bytes == 0)
1137 1138
              ? 0.0
              : static_cast<double>(comp_stats_[level].bytes_written) /
1139
                    input_bytes;
1140 1141 1142 1143 1144
      std::map<LevelStatType, double> level_stats;
      PrepareLevelStats(&level_stats, files, files_being_compacted[level],
                        static_cast<double>(vstorage->NumLevelBytes(level)),
                        compaction_score[level], w_amp, comp_stats_[level]);
      (*levels_stats)[level] = level_stats;
1145 1146
    }
  }
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
  // Cumulative summary
  double w_amp = compaction_stats_sum->bytes_written /
                 static_cast<double>(curr_ingest + 1);
  // Stats summary across levels
  std::map<LevelStatType, double> sum_stats;
  PrepareLevelStats(&sum_stats, total_files, total_files_being_compacted,
                    total_file_size, 0, w_amp, *compaction_stats_sum);
  (*levels_stats)[-1] = sum_stats;  //  -1 is for the Sum level
}

1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
void InternalStats::DumpCFMapStatsByPriority(
    std::map<int, std::map<LevelStatType, double>>* priorities_stats) {
  for (size_t priority = 0; priority < comp_stats_by_pri_.size(); priority++) {
    if (comp_stats_by_pri_[priority].micros > 0) {
      std::map<LevelStatType, double> priority_stats;
      PrepareLevelStats(&priority_stats, 0 /* num_files */,
                        0 /* being_compacted */, 0 /* total_file_size */,
                        0 /* compaction_score */, 0 /* w_amp */,
                        comp_stats_by_pri_[priority]);
      (*priorities_stats)[static_cast<int>(priority)] = priority_stats;
    }
  }
}

1171 1172 1173
void InternalStats::DumpCFMapStatsIOStalls(
    std::map<std::string, std::string>* cf_stats) {
  (*cf_stats)["io_stalls.level0_slowdown"] =
1174
      std::to_string(cf_stats_count_[L0_FILE_COUNT_LIMIT_SLOWDOWNS]);
1175
  (*cf_stats)["io_stalls.level0_slowdown_with_compaction"] =
1176
      std::to_string(cf_stats_count_[LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS]);
1177
  (*cf_stats)["io_stalls.level0_numfiles"] =
1178
      std::to_string(cf_stats_count_[L0_FILE_COUNT_LIMIT_STOPS]);
1179
  (*cf_stats)["io_stalls.level0_numfiles_with_compaction"] =
1180
      std::to_string(cf_stats_count_[LOCKED_L0_FILE_COUNT_LIMIT_STOPS]);
1181
  (*cf_stats)["io_stalls.stop_for_pending_compaction_bytes"] =
1182
      std::to_string(cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_STOPS]);
1183
  (*cf_stats)["io_stalls.slowdown_for_pending_compaction_bytes"] =
1184
      std::to_string(cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS]);
1185
  (*cf_stats)["io_stalls.memtable_compaction"] =
1186
      std::to_string(cf_stats_count_[MEMTABLE_LIMIT_STOPS]);
1187
  (*cf_stats)["io_stalls.memtable_slowdown"] =
1188
      std::to_string(cf_stats_count_[MEMTABLE_LIMIT_SLOWDOWNS]);
1189

1190 1191 1192
  uint64_t total_stop = cf_stats_count_[L0_FILE_COUNT_LIMIT_STOPS] +
                        cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_STOPS] +
                        cf_stats_count_[MEMTABLE_LIMIT_STOPS];
1193 1194

  uint64_t total_slowdown =
1195 1196 1197
      cf_stats_count_[L0_FILE_COUNT_LIMIT_SLOWDOWNS] +
      cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS] +
      cf_stats_count_[MEMTABLE_LIMIT_SLOWDOWNS];
1198 1199 1200 1201 1202

  (*cf_stats)["io_stalls.total_stop"] = std::to_string(total_stop);
  (*cf_stats)["io_stalls.total_slowdown"] = std::to_string(total_slowdown);
}

1203
void InternalStats::DumpCFStats(std::string* value) {
1204 1205 1206 1207 1208
  DumpCFStatsNoFileHistogram(value);
  DumpCFFileHistogram(value);
}

void InternalStats::DumpCFStatsNoFileHistogram(std::string* value) {
J
Jonathan Lee 已提交
1209
  char buf[2000];
1210
  // Per-ColumnFamily stats
1211
  PrintLevelStatsHeader(buf, sizeof(buf), cfd_->GetName(), "Level");
1212 1213 1214 1215
  value->append(buf);

  // Print stats for each level
  std::map<int, std::map<LevelStatType, double>> levels_stats;
1216
  CompactionStats compaction_stats_sum;
1217 1218
  DumpCFMapStats(&levels_stats, &compaction_stats_sum);
  for (int l = 0; l < number_levels_; ++l) {
1219 1220 1221 1222 1223
    if (levels_stats.find(l) != levels_stats.end()) {
      PrintLevelStats(buf, sizeof(buf), "L" + ToString(l), levels_stats[l]);
      value->append(buf);
    }
  }
1224

1225 1226 1227 1228 1229 1230
  // Print sum of level stats
  PrintLevelStats(buf, sizeof(buf), "Sum", levels_stats[-1]);
  value->append(buf);

  uint64_t flush_ingest = cf_stats_value_[BYTES_FLUSHED];
  uint64_t add_file_ingest = cf_stats_value_[BYTES_INGESTED_ADD_FILE];
1231 1232 1233 1234
  uint64_t ingest_files_addfile = cf_stats_value_[INGESTED_NUM_FILES_TOTAL];
  uint64_t ingest_l0_files_addfile =
      cf_stats_value_[INGESTED_LEVEL0_NUM_FILES_TOTAL];
  uint64_t ingest_keys_addfile = cf_stats_value_[INGESTED_NUM_KEYS_TOTAL];
1235
  // Cumulative summary
1236
  uint64_t total_stall_count =
1237 1238 1239 1240 1241 1242
      cf_stats_count_[L0_FILE_COUNT_LIMIT_SLOWDOWNS] +
      cf_stats_count_[L0_FILE_COUNT_LIMIT_STOPS] +
      cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS] +
      cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_STOPS] +
      cf_stats_count_[MEMTABLE_LIMIT_STOPS] +
      cf_stats_count_[MEMTABLE_LIMIT_SLOWDOWNS];
1243
  // Interval summary
1244 1245 1246
  uint64_t interval_flush_ingest =
      flush_ingest - cf_stats_snapshot_.ingest_bytes_flush;
  uint64_t interval_add_file_inget =
1247
      add_file_ingest - cf_stats_snapshot_.ingest_bytes_addfile;
1248
  uint64_t interval_ingest =
1249
      interval_flush_ingest + interval_add_file_inget + 1;
1250
  CompactionStats interval_stats(compaction_stats_sum);
1251
  interval_stats.Subtract(cf_stats_snapshot_.comp_stats);
1252 1253
  double w_amp =
      interval_stats.bytes_written / static_cast<double>(interval_ingest);
1254
  PrintLevelStats(buf, sizeof(buf), "Int", 0, 0, 0, 0, w_amp, interval_stats);
1255 1256
  value->append(buf);

1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
  PrintLevelStatsHeader(buf, sizeof(buf), cfd_->GetName(), "Priority");
  value->append(buf);
  std::map<int, std::map<LevelStatType, double>> priorities_stats;
  DumpCFMapStatsByPriority(&priorities_stats);
  for (size_t priority = 0; priority < comp_stats_by_pri_.size(); ++priority) {
    if (priorities_stats.find(static_cast<int>(priority)) !=
        priorities_stats.end()) {
      PrintLevelStats(
          buf, sizeof(buf),
          Env::PriorityToString(static_cast<Env::Priority>(priority)),
          priorities_stats[static_cast<int>(priority)]);
      value->append(buf);
    }
  }

1272 1273 1274 1275 1276
  double seconds_up = (env_->NowMicros() - started_at_ + 1) / kMicrosInSec;
  double interval_seconds_up = seconds_up - cf_stats_snapshot_.seconds_up;
  snprintf(buf, sizeof(buf), "Uptime(secs): %.1f total, %.1f interval\n",
           seconds_up, interval_seconds_up);
  value->append(buf);
1277 1278
  snprintf(buf, sizeof(buf), "Flush(GB): cumulative %.3f, interval %.3f\n",
           flush_ingest / kGB, interval_flush_ingest / kGB);
1279
  value->append(buf);
1280 1281
  snprintf(buf, sizeof(buf), "AddFile(GB): cumulative %.3f, interval %.3f\n",
           add_file_ingest / kGB, interval_add_file_inget / kGB);
1282 1283
  value->append(buf);

1284 1285
  uint64_t interval_ingest_files_addfile =
      ingest_files_addfile - cf_stats_snapshot_.ingest_files_addfile;
1286 1287 1288
  snprintf(buf, sizeof(buf),
           "AddFile(Total Files): cumulative %" PRIu64 ", interval %" PRIu64
           "\n",
1289 1290 1291 1292 1293 1294
           ingest_files_addfile, interval_ingest_files_addfile);
  value->append(buf);

  uint64_t interval_ingest_l0_files_addfile =
      ingest_l0_files_addfile - cf_stats_snapshot_.ingest_l0_files_addfile;
  snprintf(buf, sizeof(buf),
I
Islam AbdelRahman 已提交
1295
           "AddFile(L0 Files): cumulative %" PRIu64 ", interval %" PRIu64 "\n",
1296 1297 1298 1299 1300
           ingest_l0_files_addfile, interval_ingest_l0_files_addfile);
  value->append(buf);

  uint64_t interval_ingest_keys_addfile =
      ingest_keys_addfile - cf_stats_snapshot_.ingest_keys_addfile;
I
Islam AbdelRahman 已提交
1301 1302
  snprintf(buf, sizeof(buf),
           "AddFile(Keys): cumulative %" PRIu64 ", interval %" PRIu64 "\n",
1303 1304 1305
           ingest_keys_addfile, interval_ingest_keys_addfile);
  value->append(buf);

1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
  // Compact
  uint64_t compact_bytes_read = 0;
  uint64_t compact_bytes_write = 0;
  uint64_t compact_micros = 0;
  for (int level = 0; level < number_levels_; level++) {
    compact_bytes_read += comp_stats_[level].bytes_read_output_level +
                          comp_stats_[level].bytes_read_non_output_levels;
    compact_bytes_write += comp_stats_[level].bytes_written;
    compact_micros += comp_stats_[level].micros;
  }

  snprintf(buf, sizeof(buf),
           "Cumulative compaction: %.2f GB write, %.2f MB/s write, "
           "%.2f GB read, %.2f MB/s read, %.1f seconds\n",
           compact_bytes_write / kGB, compact_bytes_write / kMB / seconds_up,
           compact_bytes_read / kGB, compact_bytes_read / kMB / seconds_up,
           compact_micros / kMicrosInSec);
  value->append(buf);

  // Compaction interval
  uint64_t interval_compact_bytes_write =
      compact_bytes_write - cf_stats_snapshot_.compact_bytes_write;
  uint64_t interval_compact_bytes_read =
      compact_bytes_read - cf_stats_snapshot_.compact_bytes_read;
  uint64_t interval_compact_micros =
      compact_micros - cf_stats_snapshot_.compact_micros;

  snprintf(
      buf, sizeof(buf),
      "Interval compaction: %.2f GB write, %.2f MB/s write, "
      "%.2f GB read, %.2f MB/s read, %.1f seconds\n",
      interval_compact_bytes_write / kGB,
      interval_compact_bytes_write / kMB / std::max(interval_seconds_up, 0.001),
      interval_compact_bytes_read / kGB,
      interval_compact_bytes_read / kMB / std::max(interval_seconds_up, 0.001),
      interval_compact_micros / kMicrosInSec);
  value->append(buf);
  cf_stats_snapshot_.compact_bytes_write = compact_bytes_write;
  cf_stats_snapshot_.compact_bytes_read = compact_bytes_read;
  cf_stats_snapshot_.compact_micros = compact_micros;

1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
  snprintf(buf, sizeof(buf),
           "Stalls(count): %" PRIu64
           " level0_slowdown, "
           "%" PRIu64
           " level0_slowdown_with_compaction, "
           "%" PRIu64
           " level0_numfiles, "
           "%" PRIu64
           " level0_numfiles_with_compaction, "
           "%" PRIu64
           " stop for pending_compaction_bytes, "
           "%" PRIu64
           " slowdown for pending_compaction_bytes, "
           "%" PRIu64
           " memtable_compaction, "
           "%" PRIu64
           " memtable_slowdown, "
           "interval %" PRIu64 " total count\n",
           cf_stats_count_[L0_FILE_COUNT_LIMIT_SLOWDOWNS],
           cf_stats_count_[LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS],
           cf_stats_count_[L0_FILE_COUNT_LIMIT_STOPS],
           cf_stats_count_[LOCKED_L0_FILE_COUNT_LIMIT_STOPS],
           cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_STOPS],
           cf_stats_count_[PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS],
           cf_stats_count_[MEMTABLE_LIMIT_STOPS],
           cf_stats_count_[MEMTABLE_LIMIT_SLOWDOWNS],
1373
           total_stall_count - cf_stats_snapshot_.stall_count);
1374 1375
  value->append(buf);

1376
  cf_stats_snapshot_.seconds_up = seconds_up;
1377
  cf_stats_snapshot_.ingest_bytes_flush = flush_ingest;
1378 1379 1380 1381
  cf_stats_snapshot_.ingest_bytes_addfile = add_file_ingest;
  cf_stats_snapshot_.ingest_files_addfile = ingest_files_addfile;
  cf_stats_snapshot_.ingest_l0_files_addfile = ingest_l0_files_addfile;
  cf_stats_snapshot_.ingest_keys_addfile = ingest_keys_addfile;
1382
  cf_stats_snapshot_.comp_stats = compaction_stats_sum;
1383 1384 1385
  cf_stats_snapshot_.stall_count = total_stall_count;
}

1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
void InternalStats::DumpCFFileHistogram(std::string* value) {
  char buf[2000];
  snprintf(buf, sizeof(buf),
           "\n** File Read Latency Histogram By Level [%s] **\n",
           cfd_->GetName().c_str());
  value->append(buf);

  for (int level = 0; level < number_levels_; level++) {
    if (!file_read_latency_[level].Empty()) {
      char buf2[5000];
      snprintf(buf2, sizeof(buf2),
               "** Level %d read latency histogram (micros):\n%s\n", level,
               file_read_latency_[level].ToString().c_str());
      value->append(buf2);
    }
  }
}
1403 1404 1405

#else

1406 1407 1408
const DBPropertyInfo* GetPropertyInfo(const Slice& /*property*/) {
  return nullptr;
}
1409 1410 1411

#endif  // !ROCKSDB_LITE

I
Igor Canadi 已提交
1412
}  // namespace rocksdb