MySQL 8.4.0
Source Code Documentation
aggregated_stats.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef AGGREGATED_STATS_H
25#define AGGREGATED_STATS_H
26
28#include "include/my_thread_local.h" // my_thread_id
29
30/**
31 To facilitate calculating values of status variables aggregated per all THDs
32 in real-time, each THD will update its stats into a matching buffer shard.
33 Later we will aggregate the values accross all the shards to get the final
34 values.
35
36 This mechanism avoids possible contentions if all THDs would write directly
37 to a single shared global buffer.
38*/
40 constexpr static size_t STAT_SHARD_COUNT = 64;
41
43 const size_t shard_idx = thread_id % STAT_SHARD_COUNT;
44 return shards_[shard_idx];
45 }
46 void flush();
48 uint64_t get_single_total(size_t offset);
49
50 protected:
52};
53
54#endif /* AGGREGATES_STATS_H */
static my_thread_id thread_id
Definition: my_thr_init.cc:63
uint32 my_thread_id
Definition: my_thread_local.h:34
Similar to System_status_var, implements atomic counters for status variables whose values are calcul...
Definition: aggregated_stats_buffer.h:42
To facilitate calculating values of status variables aggregated per all THDs in real-time,...
Definition: aggregated_stats.h:39
aggregated_stats_buffer & get_shard(my_thread_id thread_id)
Definition: aggregated_stats.h:42
void flush()
Definition: aggregated_stats.cc:27
uint64_t get_single_total(size_t offset)
Definition: aggregated_stats.cc:40
constexpr static size_t STAT_SHARD_COUNT
Definition: aggregated_stats.h:40
aggregated_stats_buffer shards_[STAT_SHARD_COUNT]
Definition: aggregated_stats.h:51
void get_total(aggregated_stats_buffer &result)
Definition: aggregated_stats.cc:33
Definition: result.h:30