2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-06-03 02:07:16 +02:00
|
|
|
#pragma once
|
2014-07-04 01:28:03 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
|
2015-06-02 11:07:58 +02:00
|
|
|
#include "rocksdb/perf_level.h"
|
|
|
|
|
2014-07-04 01:28:03 +02:00
|
|
|
// A thread local context for gathering io-stats efficiently and transparently.
|
2015-06-02 11:07:58 +02:00
|
|
|
// Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats.
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-07-04 01:28:03 +02:00
|
|
|
|
2021-10-07 23:57:02 +02:00
|
|
|
// EXPERIMENTAL: the IO statistics for tiered storage. It matches with each
|
|
|
|
// item in Temperature class.
|
|
|
|
struct FileIOByTemperature {
|
|
|
|
// the number of bytes read to Temperature::kHot file
|
|
|
|
uint64_t hot_file_bytes_read;
|
|
|
|
// the number of bytes read to Temperature::kWarm file
|
|
|
|
uint64_t warm_file_bytes_read;
|
|
|
|
// the number of bytes read to Temperature::kCold file
|
|
|
|
uint64_t cold_file_bytes_read;
|
|
|
|
// total number of reads to Temperature::kHot file
|
|
|
|
uint64_t hot_file_read_count;
|
|
|
|
// total number of reads to Temperature::kWarm file
|
|
|
|
uint64_t warm_file_read_count;
|
|
|
|
// total number of reads to Temperature::kCold file
|
|
|
|
uint64_t cold_file_read_count;
|
|
|
|
// reset all the statistics to 0.
|
|
|
|
void Reset() {
|
|
|
|
hot_file_bytes_read = 0;
|
|
|
|
warm_file_bytes_read = 0;
|
|
|
|
cold_file_bytes_read = 0;
|
|
|
|
hot_file_read_count = 0;
|
|
|
|
warm_file_read_count = 0;
|
|
|
|
cold_file_read_count = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-04 01:28:03 +02:00
|
|
|
struct IOStatsContext {
|
|
|
|
// reset all io-stats counter to zero
|
|
|
|
void Reset();
|
|
|
|
|
2016-02-23 19:26:24 +01:00
|
|
|
std::string ToString(bool exclude_zero_counters = false) const;
|
2014-07-04 01:28:03 +02:00
|
|
|
|
|
|
|
// 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;
|
2015-06-02 11:07:58 +02:00
|
|
|
|
|
|
|
// time spent in open() and fopen().
|
|
|
|
uint64_t open_nanos;
|
|
|
|
// time spent in fallocate().
|
|
|
|
uint64_t allocate_nanos;
|
|
|
|
// time spent in write() and pwrite().
|
|
|
|
uint64_t write_nanos;
|
2015-06-19 20:25:33 +02:00
|
|
|
// time spent in read() and pread()
|
|
|
|
uint64_t read_nanos;
|
2015-06-02 11:07:58 +02:00
|
|
|
// time spent in sync_file_range().
|
|
|
|
uint64_t range_sync_nanos;
|
Add options.compaction_measure_io_stats to print write I/O stats in compactions
Summary:
Add options.compaction_measure_io_stats to print out / pass to listener accumulated time spent on write calls. Example outputs in info logs:
2015/08/12-16:27:59.463944 7fd428bff700 (Original Log Time 2015/08/12-16:27:59.463922) EVENT_LOG_v1 {"time_micros": 1439422079463897, "job": 6, "event": "compaction_finished", "output_level": 1, "num_output_files": 4, "total_output_size": 6900525, "num_input_records": 111483, "num_output_records": 106877, "file_write_nanos": 15663206, "file_range_sync_nanos": 649588, "file_fsync_nanos": 349614797, "file_prepare_write_nanos": 1505812, "lsm_state": [2, 4, 0, 0, 0, 0, 0]}
Add two more counters in iostats_context.
Also add a parameter of db_bench.
Test Plan: Add a unit test. Also manually verify LOG outputs in db_bench
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D44115
2015-08-13 02:24:45 +02:00
|
|
|
// time spent in fsync
|
|
|
|
uint64_t fsync_nanos;
|
|
|
|
// time spent in preparing write (fallocate etc).
|
|
|
|
uint64_t prepare_write_nanos;
|
2015-06-02 11:07:58 +02:00
|
|
|
// time spent in Logger::Logv().
|
|
|
|
uint64_t logger_nanos;
|
2019-01-30 01:23:21 +01:00
|
|
|
// CPU time spent in write() and pwrite()
|
|
|
|
uint64_t cpu_write_nanos;
|
|
|
|
// CPU time spent in read() and pread()
|
|
|
|
uint64_t cpu_read_nanos;
|
2021-10-07 23:57:02 +02:00
|
|
|
|
|
|
|
FileIOByTemperature file_io_stats_by_temperature;
|
2014-07-04 01:28:03 +02:00
|
|
|
};
|
|
|
|
|
2021-04-13 16:55:58 +02:00
|
|
|
// If RocksDB is compiled with -DNIOSTATS_CONTEXT, then a pointer to a global,
|
|
|
|
// non-thread-local IOStatsContext object will be returned. Attempts to update
|
|
|
|
// this object will be ignored, and reading from it will also be no-op.
|
|
|
|
// Otherwise,
|
|
|
|
// a) if thread-local is supported on the platform, then a pointer to
|
|
|
|
// a thread-local IOStatsContext object will be returned.
|
|
|
|
// b) if thread-local is NOT supported, then compilation will fail.
|
|
|
|
//
|
|
|
|
// This function never returns nullptr.
|
2017-06-03 02:12:39 +02:00
|
|
|
IOStatsContext* get_iostats_context();
|
2014-07-04 01:28:03 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|