MySQL  8.0.18
Source Code Documentation
buf0stats.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2015, 2018, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/buf0stats.h
28  Buffer pool stats
29 
30  Created May 22, 2015 Vasil Dimov
31  *******************************************************/
32 
33 #ifndef buf0stats_h
34 #define buf0stats_h
35 
36 #include "univ.i"
37 
38 #include "dict0types.h" /* index_id_t, DICT_IBUF_ID_MIN */
39 #include "fsp0sysspace.h" /* srv_tmp_space */
40 #include "ibuf0ibuf.h" /* IBUF_SPACE_ID */
41 #include "ut0lock_free_hash.h" /* ut_lock_free_hash_t */
42 #include "ut0new.h" /* UT_NEW(), UT_DELETE() */
43 
44 /** Per index buffer pool statistics - contains how many pages for each index
45 are cached in the buffer pool(s). This is a key,value store where the key is
46 the index id and the value is the number of pages in the buffer pool that
47 belong to this index. */
49  public:
50  /** Constructor. */
52  m_store =
54  }
55 
56  /** Destructor. */
58 
59  /** Increment the number of pages for a given index with 1.
60  @param[in] id id of the index whose count to increment */
61  void inc(const index_id_t &id) {
62  if (should_skip(id)) {
63  return;
64  }
65 
66  m_store->inc(id.conv_to_int());
67  }
68 
69  /** Decrement the number of pages for a given index with 1.
70  @param[in] id id of the index whose count to decrement */
71  void dec(const index_id_t &id) {
72  if (should_skip(id)) {
73  return;
74  }
75 
76  m_store->dec(id.conv_to_int());
77  }
78 
79  /** Get the number of pages in the buffer pool for a given index.
80  @param[in] id id of the index whose pages to peek
81  @return number of pages */
82  uint64_t get(const index_id_t &id) {
83  if (should_skip(id)) {
84  return (0);
85  }
86 
87  const int64_t ret = m_store->get(id.conv_to_int());
88 
89  if (ret == ut_lock_free_hash_t::NOT_FOUND) {
90  /* If the index is not found in this structure,
91  then 0 of its pages are in the buffer pool. */
92  return (0);
93  }
94 
95  return (static_cast<uint64_t>(ret >= 0 ? ret : 0));
96  }
97 
98  private:
99  /** Assess if we should skip a page from accounting.
100  @param[in] id index_id of the page
101  @return true if it should not be accounted */
102  bool should_skip(const index_id_t &id) {
103  const bool is_temp = fsp_is_system_temporary(id.m_space_id);
104 
105  return (id.is_ibuf() || is_temp ||
106  (id.m_index_id & 0xFFFFFFFF00000000ULL) != 0);
107  }
108 
109  /** (key, value) storage. */
111 };
112 
113 /** Container for how many pages from each index are contained in the buffer
114 pool(s). */
116 
117 #endif /* buf0stats_h */
Multi file, shared, system tablespace implementation.
Lock free hash implementation.
PSI_memory_key mem_key_buf_stat_per_index_t
Definition: ut0new.cc:46
ut_lock_free_hash_t * m_store
(key, value) storage.
Definition: buf0stats.h:110
~buf_stat_per_index_t()
Destructor.
Definition: buf0stats.h:57
unsigned long id[MAX_DEAD]
Definition: xcom_base.c:426
bool fsp_is_system_temporary(space_id_t space_id)
Check if tablespace is system temporary.
Definition: fsp0fsp.cc:283
Globally unique index identifier.
Definition: dict0types.h:66
void dec(uint64_t key)
Decrement the value of a given key with 1 or insert a new tuple (key, -1).
Definition: ut0lock_free_hash.h:648
Data dictionary global types.
#define UT_DELETE(ptr)
Destroy, deallocate and trace the deallocation of an object created by UT_NEW() or UT_NEW_NOKEY()...
Definition: ut0new.h:1020
void inc(const index_id_t &id)
Increment the number of pages for a given index with 1.
Definition: buf0stats.h:61
Per index buffer pool statistics - contains how many pages for each index are cached in the buffer po...
Definition: buf0stats.h:48
void dec(const index_id_t &id)
Decrement the number of pages for a given index with 1.
Definition: buf0stats.h:71
#define UT_NEW(expr, key)
Allocate, trace the allocation and construct an object.
Definition: ut0new.h:995
Instrumented memory allocator.
Insert buffer.
int64_t get(uint64_t key) const
Get the value mapped to a given key.
Definition: ut0lock_free_hash.h:474
void inc(uint64_t key)
Increment the value for a given key with 1 or insert a new tuple (key, 1).
Definition: ut0lock_free_hash.h:634
Lock free hash table.
Definition: ut0lock_free_hash.h:421
buf_stat_per_index_t()
Constructor.
Definition: buf0stats.h:51
static const int64_t NOT_FOUND
The value that is returned when the searched for key is not found.
Definition: ut0lock_free_hash.h:53
bool should_skip(const index_id_t &id)
Assess if we should skip a page from accounting.
Definition: buf0stats.h:102
buf_stat_per_index_t * buf_stat_per_index
Container for how many pages from each index are contained in the buffer pool(s). ...
Definition: buf0buf.cc:319