|
8 | 8 | // found in the LICENSE file. See the AUTHORS file for names of contributors.
|
9 | 9 |
|
10 | 10 | #include "db/compaction.h"
|
| 11 | + |
| 12 | +#define __STDC_FORMAT_MACROS |
| 13 | +#include <inttypes.h> |
| 14 | +#include <vector> |
| 15 | + |
11 | 16 | #include "db/column_family.h"
|
| 17 | +#include "util/logging.h" |
12 | 18 |
|
13 | 19 | namespace rocksdb {
|
14 | 20 |
|
@@ -191,71 +197,51 @@ void Compaction::ResetNextCompactionIndex() {
|
191 | 197 | input_version_->ResetNextCompactionIndex(level_);
|
192 | 198 | }
|
193 | 199 |
|
194 |
| -/* |
195 |
| -for sizes >=10TB, print "XXTB" |
196 |
| -for sizes >=10GB, print "XXGB" |
197 |
| -etc. |
198 |
| -*/ |
199 |
| -static void FileSizeSummary(unsigned long long sz, char* output, int len) { |
200 |
| - const unsigned long long ull10 = 10; |
201 |
| - if (sz >= ull10<<40) { |
202 |
| - snprintf(output, len, "%lluTB", sz>>40); |
203 |
| - } else if (sz >= ull10<<30) { |
204 |
| - snprintf(output, len, "%lluGB", sz>>30); |
205 |
| - } else if (sz >= ull10<<20) { |
206 |
| - snprintf(output, len, "%lluMB", sz>>20); |
207 |
| - } else if (sz >= ull10<<10) { |
208 |
| - snprintf(output, len, "%lluKB", sz>>10); |
209 |
| - } else { |
210 |
| - snprintf(output, len, "%lluB", sz); |
211 |
| - } |
212 |
| -} |
213 |
| - |
214 |
| -static int InputSummary(std::vector<FileMetaData*>& files, char* output, |
215 |
| - int len) { |
| 200 | +namespace { |
| 201 | +int InputSummary(const std::vector<FileMetaData*>& files, char* output, |
| 202 | + int len) { |
216 | 203 | *output = '\0';
|
217 | 204 | int write = 0;
|
218 | 205 | for (unsigned int i = 0; i < files.size(); i++) {
|
219 | 206 | int sz = len - write;
|
220 | 207 | int ret;
|
221 | 208 | char sztxt[16];
|
222 |
| - FileSizeSummary((unsigned long long)files.at(i)->file_size, sztxt, 16); |
223 |
| - ret = snprintf(output + write, sz, "%lu(%s) ", |
224 |
| - (unsigned long)files.at(i)->number, |
| 209 | + AppendHumanBytes(files.at(i)->file_size, sztxt, 16); |
| 210 | + ret = snprintf(output + write, sz, "%" PRIu64 "(%s) ", files.at(i)->number, |
225 | 211 | sztxt);
|
226 |
| - if (ret < 0 || ret >= sz) |
227 |
| - break; |
| 212 | + if (ret < 0 || ret >= sz) break; |
228 | 213 | write += ret;
|
229 | 214 | }
|
230 |
| - return write; |
| 215 | + // if files.size() is non-zero, overwrite the last space |
| 216 | + return write - !!files.size(); |
231 | 217 | }
|
| 218 | +} // namespace |
232 | 219 |
|
233 | 220 | void Compaction::Summary(char* output, int len) {
|
234 |
| - int write = snprintf(output, len, |
235 |
| - "Base version %lu Base level %d, seek compaction:%d, inputs: [", |
236 |
| - (unsigned long)input_version_->GetVersionNumber(), |
237 |
| - level_, |
238 |
| - seek_compaction_); |
| 221 | + int write = |
| 222 | + snprintf(output, len, "Base version %" PRIu64 |
| 223 | + " Base level %d, seek compaction:%d, inputs: [", |
| 224 | + input_version_->GetVersionNumber(), level_, seek_compaction_); |
239 | 225 | if (write < 0 || write >= len) {
|
240 | 226 | return;
|
241 | 227 | }
|
242 | 228 |
|
243 |
| - write += InputSummary(inputs_[0], output+write, len-write); |
| 229 | + write += InputSummary(inputs_[0], output + write, len - write); |
244 | 230 | if (write < 0 || write >= len) {
|
245 | 231 | return;
|
246 | 232 | }
|
247 | 233 |
|
248 |
| - write += snprintf(output+write, len-write, "],["); |
| 234 | + write += snprintf(output + write, len - write, "], ["); |
249 | 235 | if (write < 0 || write >= len) {
|
250 | 236 | return;
|
251 | 237 | }
|
252 | 238 |
|
253 |
| - write += InputSummary(inputs_[1], output+write, len-write); |
| 239 | + write += InputSummary(inputs_[1], output + write, len - write); |
254 | 240 | if (write < 0 || write >= len) {
|
255 | 241 | return;
|
256 | 242 | }
|
257 | 243 |
|
258 |
| - snprintf(output+write, len-write, "]"); |
| 244 | + snprintf(output + write, len - write, "]"); |
259 | 245 | }
|
260 | 246 |
|
261 | 247 | } // namespace rocksdb
|
0 commit comments