rdb_perf_context.h 3.75 KB
Newer Older
Sergei Petrunia's avatar
Sergei Petrunia committed
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
/*
   Portions Copyright (c) 2015-Present, Facebook, Inc.
   Portions Copyright (c) 2012,2013 Monty Program Ab

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
#pragma once

/* C++ standard header files */
#include <atomic>
#include <cstdint>
#include <string>

/* MySQL header files */
#include "./handler.h"
#include <my_global.h>

28 29
#include "rdb_mariadb_port.h"

Sergei Petrunia's avatar
Sergei Petrunia committed
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
namespace myrocks {

enum {
  PC_USER_KEY_COMPARISON_COUNT = 0,
  PC_BLOCK_CACHE_HIT_COUNT,
  PC_BLOCK_READ_COUNT,
  PC_BLOCK_READ_BYTE,
  PC_BLOCK_READ_TIME,
  PC_BLOCK_CHECKSUM_TIME,
  PC_BLOCK_DECOMPRESS_TIME,
  PC_KEY_SKIPPED,
  PC_DELETE_SKIPPED,
  PC_GET_SNAPSHOT_TIME,
  PC_GET_FROM_MEMTABLE_TIME,
  PC_GET_FROM_MEMTABLE_COUNT,
  PC_GET_POST_PROCESS_TIME,
  PC_GET_FROM_OUTPUT_FILES_TIME,
  PC_SEEK_ON_MEMTABLE_TIME,
  PC_SEEK_ON_MEMTABLE_COUNT,
  PC_SEEK_CHILD_SEEK_TIME,
  PC_SEEK_CHILD_SEEK_COUNT,
  PC_SEEK_MIN_HEAP_TIME,
  PC_SEEK_INTERNAL_SEEK_TIME,
  PC_FIND_NEXT_USER_ENTRY_TIME,
  PC_WRITE_WAL_TIME,
  PC_WRITE_MEMTABLE_TIME,
  PC_WRITE_DELAY_TIME,
  PC_WRITE_PRE_AND_POST_PROCESSS_TIME,
  PC_DB_MUTEX_LOCK_NANOS,
  PC_DB_CONDITION_WAIT_NANOS,
  PC_MERGE_OPERATOR_TIME_NANOS,
  PC_READ_INDEX_BLOCK_NANOS,
  PC_READ_FILTER_BLOCK_NANOS,
  PC_NEW_TABLE_BLOCK_ITER_NANOS,
  PC_NEW_TABLE_ITERATOR_NANOS,
  PC_BLOCK_SEEK_NANOS,
  PC_FIND_TABLE_NANOS,
  PC_IO_THREAD_POOL_ID,
  PC_IO_BYTES_WRITTEN,
  PC_IO_BYTES_READ,
  PC_IO_OPEN_NANOS,
  PC_IO_ALLOCATE_NANOS,
  PC_IO_WRITE_NANOS,
  PC_IO_READ_NANOS,
  PC_IO_RANGE_SYNC_NANOS,
  PC_IO_LOGGER_NANOS,
  PC_MAX_IDX
};

class Rdb_perf_counters;

/*
  A collection of performance counters that can be safely incremented by
  multiple threads since it stores atomic datapoints.
*/
Sergei Petrunia's avatar
Sergei Petrunia committed
85
struct Rdb_atomic_perf_counters {
Sergei Petrunia's avatar
Sergei Petrunia committed
86 87 88 89 90 91 92
  std::atomic_ullong m_value[PC_MAX_IDX];
};

/*
  A collection of performance counters that is meant to be incremented by
  a single thread.
*/
Sergei Petrunia's avatar
Sergei Petrunia committed
93 94 95 96 97
class Rdb_perf_counters {
  Rdb_perf_counters(const Rdb_perf_counters &) = delete;
  Rdb_perf_counters &operator=(const Rdb_perf_counters &) = delete;

public:
Sergei Petrunia's avatar
Sergei Petrunia committed
98
  Rdb_perf_counters() = default;
Sergei Petrunia's avatar
Sergei Petrunia committed
99 100 101 102 103 104 105 106 107 108
  uint64_t m_value[PC_MAX_IDX];

  void load(const Rdb_atomic_perf_counters &atomic_counters);
};

extern std::string rdb_pc_stat_types[PC_MAX_IDX];

/*
  Perf timers for data reads
 */
Sergei Petrunia's avatar
Sergei Petrunia committed
109
class Rdb_io_perf {
Sergei Petrunia's avatar
Sergei Petrunia committed
110
  // Context management
Sergei Petrunia's avatar
Sergei Petrunia committed
111 112 113 114 115 116 117 118 119 120 121
  Rdb_atomic_perf_counters *m_atomic_counters = nullptr;
  my_io_perf_atomic_t *m_shared_io_perf_read = nullptr;
  ha_statistics *m_stats = nullptr;

public:
  Rdb_io_perf(const Rdb_io_perf &) = delete;
  Rdb_io_perf &operator=(const Rdb_io_perf &) = delete;

  void init(Rdb_atomic_perf_counters *const atomic_counters,
            my_io_perf_atomic_t *const shared_io_perf_read,
            ha_statistics *const stats) {
Sergei Petrunia's avatar
Sergei Petrunia committed
122 123 124 125
    DBUG_ASSERT(atomic_counters != nullptr);
    DBUG_ASSERT(shared_io_perf_read != nullptr);
    DBUG_ASSERT(stats != nullptr);

Sergei Petrunia's avatar
Sergei Petrunia committed
126 127 128
    m_atomic_counters = atomic_counters;
    m_shared_io_perf_read = shared_io_perf_read;
    m_stats = stats;
Sergei Petrunia's avatar
Sergei Petrunia committed
129 130
  }

Sergei Petrunia's avatar
Sergei Petrunia committed
131 132
  bool start(const uint32_t perf_context_level);
  void end_and_record(const uint32_t perf_context_level);
Sergei Petrunia's avatar
Sergei Petrunia committed
133

Sergei Petrunia's avatar
Sergei Petrunia committed
134 135 136
  explicit Rdb_io_perf()
      : m_atomic_counters(nullptr), m_shared_io_perf_read(nullptr),
        m_stats(nullptr) {}
Sergei Petrunia's avatar
Sergei Petrunia committed
137 138
};

Sergei Petrunia's avatar
Sergei Petrunia committed
139
} // namespace myrocks