1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use std::mem;
use std::str;
use std::slice;
use std::fmt;
use rocks_sys as ll;
use crate::to_raw::FromRaw;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum ThreadType {
HighPriority = 0,
LowPriority,
User,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum OperationType {
Unknown = 0,
Compaction,
Flush,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum OperationStage {
Unknown = 0,
FlushRun,
FlushWriteL0,
CompactionPrepare,
CompactionRun,
CompactionProcessKv,
CompactionInstall,
CompactionSyncFile,
PickMemtablesToFlush,
MemtableRollback,
MemtableInstallFlushResults,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum CompactionPropertyType {
JobId = 0,
InputOutputLevel,
PropFlags,
TotalInputBytes,
BytesRead,
BytesWritten,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum FlushPropertyType {
JobId = 0,
BytesMemtables,
BytesWritten,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum StateType {
Unknown = 0,
MutexWait = 1,
}
#[repr(C)]
pub struct ThreadStatus {
raw: *mut ll::rocks_thread_status_t,
}
impl FromRaw<ll::rocks_thread_status_t> for ThreadStatus {
unsafe fn from_ll(raw: *mut ll::rocks_thread_status_t) -> ThreadStatus {
ThreadStatus { raw: raw }
}
}
impl Drop for ThreadStatus {
fn drop(&mut self) {
unsafe {
ll::rocks_thread_status_destroy(self.raw);
}
}
}
impl fmt::Debug for ThreadStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ThreadStatus")
.field("id", &self.thread_id())
.field("type", &self.thread_type())
.field("db", &self.db_name())
.field("cf", &self.cf_name())
.field("operation_type", &self.operation_type())
.field("op_elapsed_micros", &self.op_elapsed_micros())
.field("operation_stage", &self.operation_stage())
.field("state_type", &self.state_type())
.finish()
}
}
impl ThreadStatus {
pub fn thread_id(&self) -> u64 {
unsafe { ll::rocks_thread_status_get_thread_id(self.raw) }
}
pub fn thread_type(&self) -> ThreadType {
unsafe { mem::transmute(ll::rocks_thread_status_get_thread_type(self.raw)) }
}
pub fn db_name(&self) -> &str {
let mut len = 0;
unsafe {
let ptr = ll::rocks_thread_status_get_db_name(self.raw, &mut len);
str::from_utf8_unchecked(slice::from_raw_parts(ptr as *const u8, len))
}
}
pub fn cf_name(&self) -> &str {
let mut len = 0;
unsafe {
let ptr = ll::rocks_thread_status_get_cf_name(self.raw, &mut len);
str::from_utf8_unchecked(slice::from_raw_parts(ptr as *const u8, len))
}
}
pub fn operation_type(&self) -> OperationType {
unsafe { mem::transmute(ll::rocks_thread_status_get_operation_type(self.raw)) }
}
pub fn op_elapsed_micros(&self) -> u64 {
unsafe { ll::rocks_thread_status_get_op_elapsed_micros(self.raw) }
}
pub fn operation_stage(&self) -> OperationStage {
unsafe { mem::transmute(ll::rocks_thread_status_get_operation_stage(self.raw)) }
}
pub fn op_properties(&self) -> &[u64] {
let mut len = 0;
unsafe {
let ptr = ll::rocks_thread_status_get_op_properties(self.raw, &mut len);
slice::from_raw_parts(ptr, len)
}
}
pub fn state_type(&self) -> StateType {
unsafe { mem::transmute(ll::rocks_thread_status_get_state_type(self.raw)) }
}
}