1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 #pragma once
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <string>
10 
11 #include "rocksdb/rocksdb_namespace.h"
12 
13 namespace ROCKSDB_NAMESPACE {
14 struct CompactionJobStats {
CompactionJobStatsCompactionJobStats15   CompactionJobStats() { Reset(); }
16   void Reset();
17   // Aggregate the CompactionJobStats from another instance with this one
18   void Add(const CompactionJobStats& stats);
19 
20   // the elapsed time of this compaction in microseconds.
21   uint64_t elapsed_micros;
22 
23   // the elapsed CPU time of this compaction in microseconds.
24   uint64_t cpu_micros;
25 
26   // the number of compaction input records.
27   uint64_t num_input_records;
28   // the number of compaction input files.
29   size_t num_input_files;
30   // the number of compaction input files at the output level.
31   size_t num_input_files_at_output_level;
32 
33   // the number of compaction output records.
34   uint64_t num_output_records;
35   // the number of compaction output files.
36   size_t num_output_files;
37 
38   // true if the compaction is a manual compaction
39   bool is_manual_compaction;
40 
41   // the size of the compaction input in bytes.
42   uint64_t total_input_bytes;
43   // the size of the compaction output in bytes.
44   uint64_t total_output_bytes;
45 
46   // number of records being replaced by newer record associated with same key.
47   // this could be a new value or a deletion entry for that key so this field
48   // sums up all updated and deleted keys
49   uint64_t num_records_replaced;
50 
51   // the sum of the uncompressed input keys in bytes.
52   uint64_t total_input_raw_key_bytes;
53   // the sum of the uncompressed input values in bytes.
54   uint64_t total_input_raw_value_bytes;
55 
56   // the number of deletion entries before compaction. Deletion entries
57   // can disappear after compaction because they expired
58   uint64_t num_input_deletion_records;
59   // number of deletion records that were found obsolete and discarded
60   // because it is not possible to delete any more keys with this entry
61   // (i.e. all possible deletions resulting from it have been completed)
62   uint64_t num_expired_deletion_records;
63 
64   // number of corrupt keys (ParseInternalKey returned false when applied to
65   // the key) encountered and written out.
66   uint64_t num_corrupt_keys;
67 
68   // Following counters are only populated if
69   // options.report_bg_io_stats = true;
70 
71   // Time spent on file's Append() call.
72   uint64_t file_write_nanos;
73 
74   // Time spent on sync file range.
75   uint64_t file_range_sync_nanos;
76 
77   // Time spent on file fsync.
78   uint64_t file_fsync_nanos;
79 
80   // Time spent on preparing file write (fallocate, etc)
81   uint64_t file_prepare_write_nanos;
82 
83   // 0-terminated strings storing the first 8 bytes of the smallest and
84   // largest key in the output.
85   static const size_t kMaxPrefixLength = 8;
86 
87   std::string smallest_output_key_prefix;
88   std::string largest_output_key_prefix;
89 
90   // number of single-deletes which do not meet a put
91   uint64_t num_single_del_fallthru;
92 
93   // number of single-deletes which meet something other than a put
94   uint64_t num_single_del_mismatch;
95 };
96 }  // namespace ROCKSDB_NAMESPACE
97