MySQL 8.3.0
Source Code Documentation
aggregated_stats.h
Go to the documentation of this file.
1/* Copyright (c) 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef AGGREGATED_STATS_H
24#define AGGREGATED_STATS_H
25
27#include "include/my_thread_local.h" // my_thread_id
28
29/**
30 To facilitate calculating values of status variables aggregated per all THDs
31 in real-time, each THD will update its stats into a matching buffer shard.
32 Later we will aggregate the values accross all the shards to get the final
33 values.
34
35 This mechanism avoids possible contentions if all THDs would write directly
36 to a single shared global buffer.
37*/
39 constexpr static size_t STAT_SHARD_COUNT = 64;
40
42 const size_t shard_idx = thread_id % STAT_SHARD_COUNT;
43 return shards_[shard_idx];
44 }
45 void flush();
47 uint64_t get_single_total(size_t offset);
48
49 protected:
51};
52
53#endif /* AGGREGATES_STATS_H */
static my_thread_id thread_id
Definition: my_thr_init.cc:62
uint32 my_thread_id
Definition: my_thread_local.h:33
Similar to System_status_var, implements atomic counters for status variables whose values are calcul...
Definition: aggregated_stats_buffer.h:41
To facilitate calculating values of status variables aggregated per all THDs in real-time,...
Definition: aggregated_stats.h:38
aggregated_stats_buffer & get_shard(my_thread_id thread_id)
Definition: aggregated_stats.h:41
void flush()
Definition: aggregated_stats.cc:26
uint64_t get_single_total(size_t offset)
Definition: aggregated_stats.cc:39
constexpr static size_t STAT_SHARD_COUNT
Definition: aggregated_stats.h:39
aggregated_stats_buffer shards_[STAT_SHARD_COUNT]
Definition: aggregated_stats.h:50
void get_total(aggregated_stats_buffer &result)
Definition: aggregated_stats.cc:32
Definition: result.h:29