Databases Reference
In-Depth Information
As we remember, status variables are defined in terms of pointers to data. That is,
SHOW STATUS takes the st_mysql_show_var structure and shows the data pointed
to by its value member. It works well when a value to show is stored in a variable;
for example, in our vars plugin, where we have stored the value in a status_vars C
variable. But in this case we want to show the result of a function call. In other words,
we need to use SHOW_FUNC type of a "status variable". And because we have many
variables to show and all of their data are obtained from one function call, we put all of
these variables in an array and use SHOW_ARRAY to display it. Let's put it all together.
We start by including all headers that we will need:
#include <mysql/plugin.h>
#include <mysql_version.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdlib.h>
In addition to MySQL headers we will need a few system headers to be able to use
getrusage() . Now we declare our status variables. We declare only one "variable"
of the SHOW_FUNC type; MySQL will invoke the specified function to obtain the real
status variable and we will be able to collect getrusage() data and convert it into
status variables:
static struct st_mysql_show_var sys_status_var[] =
{
{"Sys", (char *) &make_var_array, SHOW_FUNC},
{0, 0, 0}
};
Let's write this function now. According to the table above, it should be declared as
taking a thread context, a status variable structure to fill in, and a convenience buffer
as arguments:
static int make_var_array(MYSQL_THD thd,
struct st_mysql_show_var* var,
char *buff)
{
In this function we will need to call getrusage() and create an array of status
variables. We may as well declare needed local variables now:
struct st_mysql_show_var *status;
struct rusage *rusage;
 
Search WWH ::




Custom Search