| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2015, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/buf0stats.h |
| 29 |
Buffer pool stats |
| 30 |
|
| 31 |
Created May 22, 2015 Vasil Dimov |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#ifndef buf0stats_h |
| 35 |
#define buf0stats_h |
| 36 |
|
| 37 |
#include "univ.i" |
| 38 |
|
| 39 |
#include "dict0types.h" /* index_id_t, DICT_IBUF_ID_MIN */ |
| 40 |
#include "fsp0sysspace.h" /* srv_tmp_space */ |
| 41 |
#include "ibuf0ibuf.h" /* IBUF_SPACE_ID */ |
| 42 |
#include "ut0lock_free_hash.h" /* ut_lock_free_hash_t */ |
| 43 |
#include "ut0new.h" /* ut::new_withkey(), ut::delete_() */ |
| 44 |
|
| 45 |
/** Per index buffer pool statistics - contains how many pages for each index |
| 46 |
are cached in the buffer pool(s). This is a key,value store where the key is |
| 47 |
the index id and the value is the number of pages in the buffer pool that |
| 48 |
belong to this index. */ |
| 49 |
class buf_stat_per_index_t { |
| 50 |
public: |
| 51 |
/** Constructor. */ |
| 52 |
buf_stat_per_index_t() { |
| 53 |
m_store = ut::new_withkey<ut_lock_free_hash_t>( |
| 54 |
ut::make_psi_memory_key(mem_key_buf_stat_per_index_t), 1024, true); |
| 55 |
} |
| 56 |
|
| 57 |
/** Destructor. */ |
| 58 |
~buf_stat_per_index_t() { ut::delete_(m_store); } |
| 59 |
|
| 60 |
/** Increment the number of pages for a given index with 1. |
| 61 |
@param[in] id id of the index whose count to increment */ |
| 62 |
void inc(const index_id_t &id) { |
| 63 |
if (should_skip(id)) { |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
m_store->inc(id.conv_to_int()); |
| 68 |
} |
| 69 |
|
| 70 |
/** Decrement the number of pages for a given index with 1. |
| 71 |
@param[in] id id of the index whose count to decrement */ |
| 72 |
void dec(const index_id_t &id) { |
| 73 |
if (should_skip(id)) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
m_store->dec(id.conv_to_int()); |
| 78 |
} |
| 79 |
|
| 80 |
/** Get the number of pages in the buffer pool for a given index. |
| 81 |
@param[in] id id of the index whose pages to peek |
| 82 |
@return number of pages */ |
| 83 |
uint64_t get(const index_id_t &id) { |
| 84 |
if (should_skip(id)) { |
| 85 |
return (0); |
| 86 |
} |
| 87 |
|
| 88 |
const int64_t ret = m_store->get(id.conv_to_int()); |
| 89 |
|
| 90 |
if (ret == ut_lock_free_hash_t::NOT_FOUND) { |
| 91 |
/* If the index is not found in this structure, |
| 92 |
then 0 of its pages are in the buffer pool. */ |
| 93 |
return (0); |
| 94 |
} |
| 95 |
|
| 96 |
return (static_cast<uint64_t>(ret >= 0 ? ret : 0)); |
| 97 |
} |
| 98 |
|
| 99 |
private: |
| 100 |
/** Assess if we should skip a page from accounting. |
| 101 |
@param[in] id index_id of the page |
| 102 |
@return true if it should not be accounted */ |
| 103 |
bool should_skip(const index_id_t &id) { |
| 104 |
const bool is_temp = fsp_is_system_temporary(id.m_space_id); |
| 105 |
|
| 106 |
return (id.is_ibuf() || is_temp || |
| 107 |
(id.m_index_id & 0xFFFFFFFF00000000ULL) != 0); |
| 108 |
} |
| 109 |
|
| 110 |
/** (key, value) storage. */ |
| 111 |
ut_lock_free_hash_t *m_store; |
| 112 |
}; |
| 113 |
|
| 114 |
/** Container for how many pages from each index are contained in the buffer |
| 115 |
pool(s). */ |
| 116 |
extern buf_stat_per_index_t *buf_stat_per_index; |
| 117 |
|
| 118 |
#endif /* buf0stats_h */ |