Skip to content

Commit c199e0e

Browse files
author
Ankit Gupta
committed
Add statistics
1 parent a044398 commit c199e0e

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

java/org/rocksdb/Statistics.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
6+
package org.rocksdb;
7+
8+
/**
9+
* Statistics to analyze the performance of a db. Pointer for statistics object
10+
* is managed by Options class.
11+
*/
12+
public class Statistics {
13+
14+
private long statsHandle_;
15+
16+
public Statistics(long statsHandle) {
17+
statsHandle_ = statsHandle;
18+
}
19+
20+
public long getTickerCount(StatisticsType statisticsType) {
21+
assert(isInitialized());
22+
return getTickerCount0(statisticsType.getValue(), statsHandle_);
23+
}
24+
25+
private boolean isInitialized() {
26+
return (statsHandle_ != 0);
27+
}
28+
29+
private native long getTickerCount0(int ticker, long handle);
30+
}

java/org/rocksdb/StatisticsType.java

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
6+
package org.rocksdb;
7+
8+
public enum StatisticsType {
9+
// total block cache misses
10+
// REQUIRES: BLOCK_CACHE_MISS == BLOCK_CACHE_INDEX_MISS +
11+
// BLOCK_CACHE_FILTER_MISS +
12+
// BLOCK_CACHE_DATA_MISS;
13+
BLOCK_CACHE_MISS(0),
14+
// total block cache hit
15+
// REQUIRES: BLOCK_CACHE_HIT == BLOCK_CACHE_INDEX_HIT +
16+
// BLOCK_CACHE_FILTER_HIT +
17+
// BLOCK_CACHE_DATA_HIT;
18+
BLOCK_CACHE_HIT(1),
19+
// # of blocks added to block cache.
20+
BLOCK_CACHE_ADD(2),
21+
// # of times cache miss when accessing index block from block cache.
22+
BLOCK_CACHE_INDEX_MISS(3),
23+
// # of times cache hit when accessing index block from block cache.
24+
BLOCK_CACHE_INDEX_HIT(4),
25+
// # of times cache miss when accessing filter block from block cache.
26+
BLOCK_CACHE_FILTER_MISS(5),
27+
// # of times cache hit when accessing filter block from block cache.
28+
BLOCK_CACHE_FILTER_HIT(6),
29+
// # of times cache miss when accessing data block from block cache.
30+
BLOCK_CACHE_DATA_MISS(7),
31+
// # of times cache hit when accessing data block from block cache.
32+
BLOCK_CACHE_DATA_HIT(8),
33+
// # of times bloom filter has avoided file reads.
34+
BLOOM_FILTER_USEFUL(9),
35+
36+
// # of memtable hits.
37+
MEMTABLE_HIT(10),
38+
// # of memtable misses.
39+
MEMTABLE_MISS(11),
40+
41+
/**
42+
* COMPACTION_KEY_DROP_* count the reasons for key drop during compaction
43+
* There are 3 reasons currently.
44+
*/
45+
COMPACTION_KEY_DROP_NEWER_ENTRY(12), // key was written with a newer value.
46+
COMPACTION_KEY_DROP_OBSOLETE(13), // The key is obsolete.
47+
COMPACTION_KEY_DROP_USER(14), // user compaction function has dropped the key.
48+
49+
// Number of keys written to the database via the Put and Write call's
50+
NUMBER_KEYS_WRITTEN(15),
51+
// Number of Keys read,
52+
NUMBER_KEYS_READ(16),
53+
// Number keys updated, if inplace update is enabled
54+
NUMBER_KEYS_UPDATED(17),
55+
// Bytes written / read
56+
BYTES_WRITTEN(18),
57+
BYTES_READ(19),
58+
NO_FILE_CLOSES(20),
59+
NO_FILE_OPENS(21),
60+
NO_FILE_ERRORS(22),
61+
// Time system had to wait to do LO-L1 compactions
62+
STALL_L0_SLOWDOWN_MICROS(23),
63+
// Time system had to wait to move memtable to L1.
64+
STALL_MEMTABLE_COMPACTION_MICROS(24),
65+
// write throttle because of too many files in L0
66+
STALL_L0_NUM_FILES_MICROS(25),
67+
RATE_LIMIT_DELAY_MILLIS(26),
68+
NO_ITERATORS(27), // number of iterators currently open
69+
70+
// Number of MultiGet calls, keys read, and bytes read
71+
NUMBER_MULTIGET_CALLS(28),
72+
NUMBER_MULTIGET_KEYS_READ(29),
73+
NUMBER_MULTIGET_BYTES_READ(30),
74+
75+
// Number of deletes records that were not required to be
76+
// written to storage because key does not exist
77+
NUMBER_FILTERED_DELETES(31),
78+
NUMBER_MERGE_FAILURES(32),
79+
SEQUENCE_NUMBER(33),
80+
81+
// number of times bloom was checked before creating iterator on a
82+
// file, and the number of times the check was useful in avoiding
83+
// iterator creation (and thus likely IOPs).
84+
BLOOM_FILTER_PREFIX_CHECKED(34),
85+
BLOOM_FILTER_PREFIX_USEFUL(35),
86+
87+
// Number of times we had to reseek inside an iteration to skip
88+
// over large number of keys with same userkey.
89+
NUMBER_OF_RESEEKS_IN_ITERATION(36),
90+
91+
// Record the number of calls to GetUpadtesSince. Useful to keep track of
92+
// transaction log iterator refreshes
93+
GET_UPDATES_SINCE_CALLS(37),
94+
BLOCK_CACHE_COMPRESSED_MISS(38), // miss in the compressed block cache
95+
BLOCK_CACHE_COMPRESSED_HIT(39), // hit in the compressed block cache
96+
WAL_FILE_SYNCED(40), // Number of times WAL sync is done
97+
WAL_FILE_BYTES(41), // Number of bytes written to WAL
98+
99+
// Writes can be processed by requesting thread or by the thread at the
100+
// head of the writers queue.
101+
WRITE_DONE_BY_SELF(42),
102+
WRITE_DONE_BY_OTHER(43),
103+
WRITE_WITH_WAL(44), // Number of Write calls that request WAL
104+
COMPACT_READ_BYTES(45), // Bytes read during compaction
105+
COMPACT_WRITE_BYTES(46), // Bytes written during compaction
106+
107+
// Number of table's properties loaded directly from file, without creating
108+
// table reader object.
109+
NUMBER_DIRECT_LOAD_TABLE_PROPERTIES(47),
110+
NUMBER_SUPERVERSION_ACQUIRES(48),
111+
NUMBER_SUPERVERSION_RELEASES(49),
112+
NUMBER_SUPERVERSION_CLEANUPS(50);
113+
114+
private final int value_;
115+
116+
private StatisticsType(int value) {
117+
value_ = value;
118+
}
119+
120+
public int getValue() {
121+
return value_;
122+
}
123+
}

java/rocksjni/statistics.cc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
//
6+
// This file implements the "bridge" between Java and C++ and enables
7+
// calling c++ rocksdb::Statistics methods from Java side.
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <jni.h>
12+
#include <string>
13+
#include <memory>
14+
15+
#include "include/org_rocksdb_Statistics.h"
16+
#include "rocksjni/portal.h"
17+
#include "rocksdb/statistics.h"
18+
#include "rocksdb/options.h"
19+
20+
/*
21+
* Class: org_rocksdb_Statistics
22+
* Method: getTickerCount0
23+
* Signature: (IJ)J
24+
*/
25+
jlong Java_org_rocksdb_Statistics_getTickerCount0(
26+
JNIEnv* env, jobject jobj, int ticker, jlong handle) {
27+
auto st = reinterpret_cast<rocksdb::Statistics*>(handle);
28+
assert(st != nullptr);
29+
30+
return st->getTickerCount(static_cast<rocksdb::Tickers>(ticker));
31+
}

0 commit comments

Comments
 (0)