File: api0status.c

package info (click to toggle)
libinnodb 1.0.6.6750-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 8,072 kB
  • ctags: 7,325
  • sloc: ansic: 107,290; sh: 9,930; lex: 664; yacc: 530; makefile: 335; perl: 46
file content (254 lines) | stat: -rw-r--r-- 6,846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***********************************************************************
Copyright (c) 2009 Innobase Oy. All rights reserved.
Copyright (c) 2009 Oracle. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

************************************************************************/

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#include "univ.i"
#include "srv0srv.h"
#include "api0api.h"
#include "api0ucode.h"

/** InnoDB status variables types. */
typedef enum {
	IB_STATUS_IBOOL,		/*!< Boolean status variable, ibool */
	IB_STATUS_I64,			/*!< ib_int64_t status variable */
	IB_STATUS_ULINT			/*!< uling status variable */
} ib_status_type_t;

/** InnoDB status variables */
typedef struct {
	const char*		name;	/*!< Status variable name */

	ib_status_type_t	type;	/*!< Status varable type */

	const void*		val;	/*!< Pointer to status value */
} ib_status_t;

/* All status variables that a user can query. */
UNIV_STATIC const ib_status_t status_vars[] = {
	/* IO system related */
	{"read_req_pending",		IB_STATUS_ULINT,
		&export_vars.innodb_data_pending_reads},

	{"write_req_pending",		IB_STATUS_ULINT,
		&export_vars.innodb_data_pending_writes},

	{"fsync_req_pending",		IB_STATUS_ULINT,
		&export_vars.innodb_data_pending_fsyncs},

	{"write_req_done",		IB_STATUS_ULINT,
		&export_vars.innodb_data_writes},

	{"read_req_done",		IB_STATUS_ULINT,
		&export_vars.innodb_data_reads},

	{"fsync_req_done",		IB_STATUS_ULINT,
		&export_vars.innodb_data_fsyncs},

	{"bytes_total_written",		IB_STATUS_ULINT,
		&export_vars.innodb_data_written},

	{"bytes_total_read",		IB_STATUS_ULINT,
		&export_vars.innodb_data_read},


	/* Buffer pool related */
	{"buffer_pool_current_size",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_total},

	{"buffer_pool_data_pages",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_data},

	{"buffer_pool_dirty_pages",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_dirty},

	{"buffer_pool_misc_pages",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_misc},

	{"buffer_pool_free_pages",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_free},

	{"buffer_pool_read_reqs",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_read_requests},

	{"buffer_pool_reads",		IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_reads},

	{"buffer_pool_waited_for_free",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_wait_free},

	{"buffer_pool_pages_flushed",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_pages_flushed},

	{"buffer_pool_write_reqs",	IB_STATUS_ULINT,
		&export_vars.innodb_buffer_pool_write_requests},

	{"buffer_pool_total_pages",	IB_STATUS_ULINT,
		&export_vars.innodb_pages_created},

	{"buffer_pool_pages_read",	IB_STATUS_ULINT,
		&export_vars.innodb_pages_read},

	{"buffer_pool_pages_written",	IB_STATUS_ULINT,
		&export_vars.innodb_pages_written},


	/* Double write buffer related */
	{"double_write_pages_written",	IB_STATUS_ULINT,
		&export_vars.innodb_dblwr_pages_written},

	{"double_write_invoked",	IB_STATUS_ULINT,
		&export_vars.innodb_dblwr_writes},


	/* Log related */
	{"log_buffer_slot_waits",	IB_STATUS_ULINT,
		&export_vars.innodb_log_waits},

	{"log_write_reqs",		IB_STATUS_ULINT,
		&export_vars.innodb_log_write_requests},

	{"log_write_flush_count",	IB_STATUS_ULINT,
		&export_vars.innodb_log_writes},

	{"log_bytes_written",		IB_STATUS_ULINT,
		&export_vars.innodb_os_log_written},

	{"log_fsync_req_done",		IB_STATUS_ULINT,
		&export_vars.innodb_os_log_fsyncs},

	{"log_write_req_pending",	IB_STATUS_ULINT,
		&export_vars.innodb_os_log_pending_writes},

	{"log_fsync_req_pending",	IB_STATUS_ULINT,
		&export_vars.innodb_os_log_pending_fsyncs},


	/* Lock related */
	{"lock_row_waits",		IB_STATUS_ULINT,
		&export_vars.innodb_row_lock_waits},

	{"lock_row_waiting",		IB_STATUS_ULINT,
		&export_vars.innodb_row_lock_current_waits},

	{"lock_total_wait_time_in_secs",IB_STATUS_ULINT,
		&export_vars.innodb_row_lock_time},

	{"lock_wait_time_avg_in_secs",	IB_STATUS_ULINT,
		&export_vars.innodb_row_lock_time_avg},

	{"lock_max_wait_time_in_secs",IB_STATUS_ULINT,
		&export_vars.innodb_row_lock_time_max},


	/* Row operations */
	{"row_total_read",		IB_STATUS_ULINT,
		&export_vars.innodb_rows_read},
	{"row_total_inserted",		IB_STATUS_ULINT,
		&export_vars.innodb_rows_inserted},
	{"row_total_updated",		IB_STATUS_ULINT,
		&export_vars.innodb_rows_updated},
	{"row_total_deleted",		IB_STATUS_ULINT,
		&export_vars.innodb_rows_deleted},

	/* Miscellaneous */
	{"page_size",			IB_STATUS_ULINT,
		&export_vars.innodb_page_size},

	{"have_atomic_builtins",	IB_STATUS_IBOOL,
		&export_vars.innodb_have_atomic_builtins},

	{ NULL, 0, 0}};

/*******************************************************************//*
Get the status variable that matches name.

@return DB_SUCCESS if found else DB_NOT_FOUND */
UNIV_STATIC
ib_err_t
ib_status_lookup(
/*=============*/
	const char*	name,		/*!< in: Variable to lookup */
	const ib_status_t** var)	/*!< out: pointer to entry */
{
	const ib_status_t*	ptr;

	*var = NULL;

	for (ptr = status_vars; ptr && ptr->name != NULL; ++ptr) {
		if (ib_utf8_strcasecmp(name, ptr->name) == 0) {
			*var = ptr;
			return(DB_SUCCESS);
		}
	}

	return(DB_NOT_FOUND);
}

/*******************************************************************//**
Get the value of an INT status variable.
@file api/api0status.c

@return	DB_SUCCESS if found and type is INT,
	DB_DATA_MISMATCH if found but type is not INT,
	DB_NOT_FOUND otherwise. */

ib_err_t
ib_status_get_i64(
/*==============*/
	const char*	name,		/*!< in: Status variable name */
	ib_i64_t*	dst)		/*!< out: Variable value */
{
	ib_err_t	err;
	const ib_status_t*	var;

	err = ib_status_lookup(name, &var);

	if (err == DB_SUCCESS) {

		/* Read the latest values into export_vars. */
		srv_export_innodb_status();

		switch (var->type) {
		case IB_STATUS_ULINT:
			*dst = *(ulint*) var->val;
			break;

		case IB_STATUS_IBOOL:
			*dst = *(ibool*) var->val;
			break;

		case IB_STATUS_I64:
			*dst = *(ib_int64_t*) var->val;
			break;

		default:
			/* Currently the status variables are all INTs. If
			we add other types then this will signal to the user
			that the variable type is different. */	
			err = DB_DATA_MISMATCH;
			break;
		}
	}

	return(err);
}