Summary: This diff allows the I/O stats about Flush and Compaction to be reported in a more accurate way. Instead of measuring the size of a file, it measure I/O cost in per read / write basis. Test Plan: make all check Reviewers: sdong, igor, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D19383main
parent
a1df6c1fc8
commit
90a6aca48e
@ -0,0 +1,34 @@ |
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
#ifndef INCLUDE_ROCKSDB_IOSTATS_CONTEXT_H_ |
||||||
|
#define INCLUDE_ROCKSDB_IOSTATS_CONTEXT_H_ |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
#include <string> |
||||||
|
|
||||||
|
// A thread local context for gathering io-stats efficiently and transparently.
|
||||||
|
namespace rocksdb { |
||||||
|
|
||||||
|
struct IOStatsContext { |
||||||
|
// reset all io-stats counter to zero
|
||||||
|
void Reset(); |
||||||
|
|
||||||
|
std::string ToString() const; |
||||||
|
|
||||||
|
// the thread pool id
|
||||||
|
uint64_t thread_pool_id; |
||||||
|
|
||||||
|
// number of bytes that has been written.
|
||||||
|
uint64_t bytes_written; |
||||||
|
// number of bytes that has been read.
|
||||||
|
uint64_t bytes_read; |
||||||
|
}; |
||||||
|
|
||||||
|
extern __thread IOStatsContext iostats_context; |
||||||
|
|
||||||
|
} // namespace rocksdb
|
||||||
|
|
||||||
|
#endif // INCLUDE_ROCKSDB_IOSTATS_CONTEXT_H_
|
@ -0,0 +1,30 @@ |
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
#include <sstream> |
||||||
|
#include "rocksdb/env.h" |
||||||
|
#include "util/iostats_context_imp.h" |
||||||
|
|
||||||
|
namespace rocksdb { |
||||||
|
|
||||||
|
__thread IOStatsContext iostats_context; |
||||||
|
|
||||||
|
void IOStatsContext::Reset() { |
||||||
|
thread_pool_id = Env::Priority::TOTAL; |
||||||
|
bytes_read = 0; |
||||||
|
bytes_written = 0; |
||||||
|
} |
||||||
|
|
||||||
|
#define OUTPUT(counter) #counter << " = " << counter << ", " |
||||||
|
|
||||||
|
std::string IOStatsContext::ToString() const { |
||||||
|
std::ostringstream ss; |
||||||
|
ss << OUTPUT(thread_pool_id) |
||||||
|
<< OUTPUT(bytes_read) |
||||||
|
<< OUTPUT(bytes_written); |
||||||
|
return ss.str(); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace rocksdb
|
@ -0,0 +1,32 @@ |
|||||||
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
//
|
||||||
|
#pragma once |
||||||
|
#include "rocksdb/iostats_context.h" |
||||||
|
|
||||||
|
// increment a specific counter by the specified value
|
||||||
|
#define IOSTATS_ADD(metric, value) \ |
||||||
|
(iostats_context.metric += value) |
||||||
|
|
||||||
|
// Increase metric value only when it is positive
|
||||||
|
#define IOSTATS_ADD_IF_POSITIVE(metric, value) \ |
||||||
|
if (value > 0) { IOSTATS_ADD(metric, value); } |
||||||
|
|
||||||
|
// reset a specific counter to zero
|
||||||
|
#define IOSTATS_RESET(metric) \ |
||||||
|
(iostats_context.metric = 0) |
||||||
|
|
||||||
|
// reset all counters to zero
|
||||||
|
#define IOSTATS_RESET_ALL() \ |
||||||
|
(iostats_context.Reset()) |
||||||
|
|
||||||
|
#define IOSTATS_SET_THREAD_POOL_ID(value) \ |
||||||
|
(iostats_context.thread_pool_id = value) |
||||||
|
|
||||||
|
#define IOSTATS_THREAD_POOL_ID() \ |
||||||
|
(iostats_context.thread_pool_id) |
||||||
|
|
||||||
|
#define IOSTATS(metric) \ |
||||||
|
(iostats_context.metric) |
Loading…
Reference in new issue