1 /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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 #include "sql/system_variables.h"
24
25 #include <string.h>
26
27 /*
28 Add all status variables to another status variable array
29
30 SYNOPSIS
31 add_to_status()
32 to_var add to this array
33 from_var from this array
34
35 NOTES
36 This function assumes that all variables are longlong/ulonglong.
37 If this assumption will change, then we have to explictely add
38 the other variables after the while loop
39 */
40
add_to_status(System_status_var * to_var,System_status_var * from_var)41 void add_to_status(System_status_var *to_var, System_status_var *from_var) {
42 int c;
43 ulonglong *end = (ulonglong *)((uchar *)to_var +
44 offsetof(System_status_var, LAST_STATUS_VAR) +
45 sizeof(ulonglong));
46 ulonglong *to = (ulonglong *)to_var, *from = (ulonglong *)from_var;
47
48 while (to != end) *(to++) += *(from++);
49
50 to_var->com_other += from_var->com_other;
51
52 for (c = 0; c < SQLCOM_END; c++)
53 to_var->com_stat[(uint)c] += from_var->com_stat[(uint)c];
54 }
55
56 /*
57 Add the difference between two status variable arrays to another one.
58
59 SYNOPSIS
60 add_diff_to_status
61 to_var add to this array
62 from_var from this array
63 dec_var minus this array
64
65 NOTE
66 This function assumes that all variables are longlong/ulonglong.
67 */
68
add_diff_to_status(System_status_var * to_var,System_status_var * from_var,System_status_var * dec_var)69 void add_diff_to_status(System_status_var *to_var, System_status_var *from_var,
70 System_status_var *dec_var) {
71 int c;
72 ulonglong *end = (ulonglong *)((uchar *)to_var +
73 offsetof(System_status_var, LAST_STATUS_VAR) +
74 sizeof(ulonglong));
75 ulonglong *to = (ulonglong *)to_var, *from = (ulonglong *)from_var,
76 *dec = (ulonglong *)dec_var;
77
78 while (to != end) *(to++) += *(from++) - *(dec++);
79
80 to_var->com_other += from_var->com_other - dec_var->com_other;
81
82 for (c = 0; c < SQLCOM_END; c++)
83 to_var->com_stat[(uint)c] +=
84 from_var->com_stat[(uint)c] - dec_var->com_stat[(uint)c];
85 }
86
87 /*
88 Reset a block of status variables.
89
90 SYNOPSIS
91 reset_system_status_vars
92 status_vars Struct of status variables to reset
93 */
reset_system_status_vars(System_status_var * status_vars)94 void reset_system_status_vars(System_status_var *status_vars) {
95 memset(status_vars, 0, sizeof(*status_vars));
96 }
97